penalyze2-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Penalyze2-commit] penalyze2 include/pe.h src/Makefile src/pe.c sr...


From: Stephan Peijnik
Subject: [Penalyze2-commit] penalyze2 include/pe.h src/Makefile src/pe.c sr...
Date: Tue, 22 Aug 2006 23:03:24 +0000

CVSROOT:        /sources/penalyze2
Module name:    penalyze2
Changes by:     Stephan Peijnik <sp>    06/08/22 23:03:24

Modified files:
        include        : pe.h 
        src            : Makefile pe.c penalyze2.c 
Added files:
        src            : exportinfo.c 

Log message:
        include/pe.h
                * Add declarations for for_each_export
        src/pe.c
                * Implement for_each_export
        src/Makefile
                * Include exportinfo in compilation and cleaning
        src/exportinfo.c
                * exportinfo utility
        src/penalyze2.c
                * typo fix

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/penalyze2/include/pe.h?cvsroot=penalyze2&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/penalyze2/src/Makefile?cvsroot=penalyze2&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/penalyze2/src/pe.c?cvsroot=penalyze2&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/penalyze2/src/penalyze2.c?cvsroot=penalyze2&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/penalyze2/src/exportinfo.c?cvsroot=penalyze2&rev=1.1

Patches:
Index: include/pe.h
===================================================================
RCS file: /sources/penalyze2/penalyze2/include/pe.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- include/pe.h        17 Aug 2006 20:03:40 -0000      1.1
+++ include/pe.h        22 Aug 2006 23:03:24 -0000      1.2
@@ -235,11 +235,14 @@
 typedef void pe_import_library_callback(struct pe *, byte *name, dword head, 
void *);
 typedef void pe_import_function_callback(struct pe *, const char *lib_name,
                                          byte *name, word ordinal, dword 
patch_rva, void *);
+typedef void pe_export_callback(struct pe *, byte *, word);
 
 extern void pe_for_each_section(struct pe *pe, pe_section_callback *cb, void 
*);
 extern void pe_for_each_library(struct pe *pe, pe_import_library_callback *cb, 
void *);
 extern void pe_for_each_function(struct pe *pe, const char *lib_name,
                                  dword first_thunk_rva, 
                                  pe_import_function_callback *cb, void *);
+extern void
+for_each_export(struct pe *pe, pe_export_callback *cb);
 
 #endif /* _PE_H */

Index: src/Makefile
===================================================================
RCS file: /sources/penalyze2/penalyze2/src/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/Makefile        17 Aug 2006 20:03:40 -0000      1.1
+++ src/Makefile        22 Aug 2006 23:03:24 -0000      1.2
@@ -36,9 +36,10 @@
 
 all: build
 
-build: chooks_init ${OBJS}
+build: chooks_init ${OBJS} exportinfo.o
        ${MAKE} -C ../libdasm-1.4
        ${CC} ${CFLAGS} ${INCLUDE} -o ${TARGET} ${OBJS} ../libdasm-1.4/libdasm.a
+       ${CC} ${CFLAGS} ${INCLUDE} -o exportinfo pe.o exportinfo.o
 
 .c.o:
        ${CC} ${CFLAGS} ${INCLUDE} -o $@ -c $^
@@ -47,5 +48,6 @@
        cd vm_chooks; ./gen_vm_chooks_init.c.sh
 
 clean:
-       rm -f ${TARGET} ${OBJS} vm_chooks/vm_chooks_init.[co]
+       rm -f ${TARGET} ${OBJS} vm_chooks/vm_chooks_init.[co] exportinfo.o \
+         exportinfo
        ${MAKE} -C ../libdasm-1.4 clean

Index: src/pe.c
===================================================================
RCS file: /sources/penalyze2/penalyze2/src/pe.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- src/pe.c    17 Aug 2006 20:03:40 -0000      1.1
+++ src/pe.c    22 Aug 2006 23:03:24 -0000      1.2
@@ -417,6 +417,7 @@
     unsigned short hint;
     unsigned char  name[1];
   };
+  
   struct pe_thunk_data
   {
     union
@@ -434,6 +435,7 @@
   
   while(1)
   {
+    /* this is completly sane, ordinals start at 0x1 */
     if (tdp->u0.ordinal == 0x0)
       break;
     
@@ -462,6 +464,71 @@
 
 /**
  * @param pe Pointer to pe structure
+ * @param cb Pointer to callback function
+ *
+ * Calls cb for each exproted function
+ */
+void
+for_each_export(struct pe *pe, pe_export_callback *cb)
+{
+  /* local structures */
+  struct export_directory
+  {
+    dword characteristics;
+    dword timedatestamp;
+    word MajorVersion;
+    word MinorVersion;
+    dword name_rva;
+    dword base;
+    dword NumberOfFunctions;
+    dword NumberOfNames;
+    dword functions_rva;
+    dword function_names_rva;
+    dword function_ordinals_rva;
+  };
+
+  dword dir_rva = 0x0;
+  dword i = 0;
+  struct export_directory *dirp = 0x0;
+  word *function_ordinals_array = 0x0;
+  dword *function_names_array = 0x0;
+  
+  /* Check if an export directory is present */
+  if (pe_pe(pe)->directory[PE_DIR_EXPORT].virtual_address == 0x0)
+    return;
+  
+  dir_rva = pe_pe(pe)->directory[PE_DIR_EXPORT].virtual_address;
+  dirp = pe_rva_to_ptr(pe, dir_rva);
+  
+  assert(NULL != dirp);
+  
+  printf("name             : %s\n", (char *) pe_rva_to_ptr(pe, 
dirp->name_rva));
+  printf("base             : %d\n", dirp->base);
+  printf("function names   : 0x%.8x\n", dirp->function_names_rva);
+  printf("function ordinals: 0x%.8x\n", dirp->function_ordinals_rva);
+  printf("name count       : %d\n", dirp->NumberOfNames);
+  printf("function count   : %d\n", dirp->NumberOfFunctions);
+  
+  function_names_array = (dword *) pe_rva_to_ptr(pe, dirp->function_names_rva);
+  function_ordinals_array = (word *) pe_rva_to_ptr(pe, 
dirp->function_ordinals_rva);
+
+  for(i = 0; i < dirp->NumberOfNames; i++)
+  {
+    dword name_rva;
+    word index;
+    byte *name_ptr;
+    
+    name_rva = function_names_array[i];
+    name_ptr = pe_rva_to_ptr(pe, name_rva);
+    index = function_ordinals_array[i];
+    
+    cb(pe, name_ptr, index+dirp->base);
+  }  
+  
+}
+
+/**
+ * @param pe Pointer to pe structure
  * @param rva RVA to convert
  * @return Pointer to real address
  *

Index: src/penalyze2.c
===================================================================
RCS file: /sources/penalyze2/penalyze2/src/penalyze2.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- src/penalyze2.c     22 Aug 2006 09:03:20 -0000      1.2
+++ src/penalyze2.c     22 Aug 2006 23:03:24 -0000      1.3
@@ -40,7 +40,7 @@
 static void library_callback(struct pe *pe, byte *name, dword head,
                              void *udata);
 static void function_callback(struct pe *pe, const char *lib_name, byte *name,
-                              word ordinal, dword patch_rva, void *);
+                              word ordinal, dword patch_rva, void *udata);
 
 
 static char unsup_found = 0;

Index: src/exportinfo.c
===================================================================
RCS file: src/exportinfo.c
diff -N src/exportinfo.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/exportinfo.c    22 Aug 2006 23:03:24 -0000      1.1
@@ -0,0 +1,101 @@
+/*
+ * penalyze2
+ * exportinfo.c
+ *
+ * Copyright (C) 2006 Stephan Peijnik
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301  USA.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "pe.h"
+#include "version.h"
+
+void
+usage(const char *progname);
+void
+version_and_copyright_header(void);
+
+static void
+export_callback(struct pe *pe, byte *name, word ordinal);
+
+int main(int argc, char **argv)
+{
+  struct pe *pe;
+  
+  version_and_copyright_header();
+  
+  if (argc < 2)
+  {
+    usage(argv[0]);
+    return 1;
+  }
+  
+  printf("Opening %s...\n", argv[1]);
+  
+  pe = pe_open(argv[1]);
+  
+  if (!pe)
+  {
+    return 2;
+  }
+  
+  printf("Checking for export directory: ");
+  
+  if (pe_pe(pe)->directory[PE_DIR_EXPORT].virtual_address == 0x0)
+  {
+    printf("NOT PRESENT, exiting...\n");
+    return 3;
+  }
+  printf("present\n");
+  
+  printf("Export listing:\n");
+  
+  for_each_export(pe, export_callback);
+  
+  pe_close(pe);
+  
+  printf("Done.\n");
+  
+  return 0;
+}
+
+void
+usage(const char *progname)
+{
+  printf("Usage: %s <filename>\n", progname);
+}
+
+void
+version_and_copyright_header(void)
+{
+  printf("exportinfo v%s\n\n", PENALYZE2_VERSION);
+  printf("Copyright (C) 2006 Stephan Peijnik\n");
+  printf("  exportinfo comes with NO WARRANTY,\n");
+  printf("  to the extent permitted by law.\n");
+  printf("  You may redistribute copies of penalyze2\n");
+  printf("  under the terms of the GNU General Public License.\n");
+  printf("  For more information about these matters,\n");
+  printf("  see the file named COPYING.\n\n");
+}
+
+static void
+export_callback(struct pe *pe, byte *name, word ordinal)
+{
+  printf(" - %s (@0x%.4x - @%d)\n", name, ordinal, ordinal);
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]