• R/O
  • HTTP
  • SSH
  • HTTPS

pexports: 提交

Windows DLL exported symbols listing utility


Commit MetaInfo

修订版f60a4c6b8bd39074cb651d5e69782d0aebcdf414 (tree)
时间2011-09-15 05:07:54
作者Keith Marshall <keithmarshall@user...>
CommiterKeith Marshall

Log Message

Avoid segmentation faults in forwarder function checks.

更改概述

差异

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,19 @@
1+2011-09-14 Daniel Collins <solemnwarning@solemnwarning.net>
2+
3+ Avoid segmentation faults in forwarder function checks.
4+
5+ * pexports.h (dump_exports): Adjust prototype to accommodate new
6+ 'exports_size' argument; this is to be assigned and passed from...
7+ * pexports.c (main): ...here; assigned value is determined from the
8+ export table size recorded in the PE file image, whence passed to...
9+ (dump_exports): ...here; it is used to avoid crashing or corruption
10+ when the export table isn't at the end of its section. Also check
11+ for, and filter out duplicated symbol reports.
12+
113 2009-09-15 Charles Wilson <cwilso11@users.sourceforge.net>
214
315 Slight build improvements.
16+
417 * README: Update.
518 * Makefile: Rewrite dist rule to create a .tar.lzma instead
619 of a .zip (and don't create a tarbomb).
@@ -8,6 +21,7 @@
821 2009-09-15 Charles Wilson <cwilso11@users.sourceforge.net>
922
1023 Package 0.44-1-mingw32 fixes.
24+
1125 * pexports.c (main): Fix typo in usage statement.
1226 * pexports.h: Ensure ULONGLONG is defined.
1327 * Makefile: Force use of flex and bison, not lex and yacc.
@@ -15,6 +29,7 @@
1529 2008-08-31 Tor Lillqvist <tml@novell.com>
1630
1731 Release 0.44. Add support for 64-bit executables.
32+
1833 * hlex.l
1934 * hparse.y
2035 * pexports.h
--- a/pexports.c
+++ b/pexports.c
@@ -64,7 +64,7 @@ int
6464 main(int argc, char *argv[])
6565 {
6666 PIMAGE_SECTION_HEADER section;
67- DWORD exp_rva;
67+ DWORD exp_rva, exp_size;
6868 int i;
6969 #if defined(_WIN32) && !defined(_WIN64)
7070
@@ -174,10 +174,13 @@ main(int argc, char *argv[])
174174 nt_hdr32 = (PIMAGE_NT_HEADERS32) ((char *) dos_hdr + dos_hdr->e_lfanew);
175175 nt_hdr64 = (PIMAGE_NT_HEADERS64) nt_hdr32;
176176
177- if (nt_hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_I386)
177+ if (nt_hdr32->FileHeader.Machine == IMAGE_FILE_MACHINE_I386) {
178178 exp_rva = nt_hdr32->OptionalHeader.DataDirectory[0].VirtualAddress;
179- else
179+ exp_size = nt_hdr32->OptionalHeader.DataDirectory[0].Size;
180+ }else{
180181 exp_rva = nt_hdr64->OptionalHeader.DataDirectory[0].VirtualAddress;
182+ exp_size = nt_hdr64->OptionalHeader.DataDirectory[0].Size;
183+ }
181184
182185 if (verbose)
183186 {
@@ -196,10 +199,10 @@ main(int argc, char *argv[])
196199 {
197200 section = IMAGE_SECTION_HDR(i);
198201 if (memcmp(section->Name, exp_sign, sizeof(exp_sign)) == 0)
199- dump_exports(section->VirtualAddress);
202+ dump_exports(section->VirtualAddress, exp_size);
200203 else if ((exp_rva >= section->VirtualAddress) &&
201204 (exp_rva < (section->VirtualAddress + section->SizeOfRawData)))
202- dump_exports(exp_rva);
205+ dump_exports(exp_rva, exp_size);
203206 }
204207
205208 free(dos_hdr);
@@ -208,7 +211,7 @@ main(int argc, char *argv[])
208211
209212 /* dump exported symbols on stdout */
210213 void
211-dump_exports(DWORD exports_rva)
214+dump_exports(DWORD exports_rva, DWORD exports_size)
212215 {
213216 PIMAGE_SECTION_HEADER section;
214217 PIMAGE_EXPORT_DIRECTORY exports;
@@ -259,21 +262,35 @@ dump_exports(DWORD exports_rva)
259262 dump_symbol(RVA_TO_PTR(name_table[i],char*),
260263 ordinal_table[i] + exports->Base,
261264 function_table[ordinal_table[i]]);
265+
266+ int f_off = ordinal_table[i];
267+
268+ if(function_table[f_off] >= exports_rva && function_table[f_off] < (exports_rva + exports_size) && verbose) {
269+ printf(" ; Forwarder (%s)", RVA_TO_PTR(function_table[f_off], char*));
270+ }
271+
262272 printf("\n");
263273 }
264274
265275 for (i = 0; i < exports->NumberOfFunctions; i++)
266276 {
267277 if ( (function_table[i] >= exports_rva) &&
268- (function_table[i] <= (section->VirtualAddress + section->SizeOfRawData)))
278+ (function_table[i] < (exports_rva + exports_size)))
269279 {
270- dump_symbol(strchr(RVA_TO_PTR(function_table[i],char*), '.')+1,
271- i + exports->Base,
272- function_table[i]);
273- if (verbose)
274- printf(" ; Forwarder\n");
275- else
276- printf("\n");
280+ int name_present = 0, n;
281+
282+ for(n = 0; n < exports->NumberOfNames; n++) {
283+ if(ordinal_table[n] == i) {
284+ name_present = 1;
285+ break;
286+ }
287+ }
288+
289+ if(!name_present) {
290+ dump_symbol(strchr(RVA_TO_PTR(function_table[i],char*), '.')+1, i + exports->Base, function_table[i]);
291+
292+ printf(" ; WARNING: Symbol name guessed from forwarder (%s)\n", RVA_TO_PTR(function_table[i], char*));
293+ }
277294 }
278295 }
279296 }
--- a/pexports.h
+++ b/pexports.h
@@ -207,7 +207,7 @@ void *
207207 rva_to_ptr(DWORD rva);
208208
209209 void
210-dump_exports(DWORD exports_rva);
210+dump_exports(DWORD exports_rva, DWORD exports_size);
211211
212212 #define ADD_FUNCTION(nm,n) str_tree_add(&symbols, nm, (void*)(INT_PTR)n)
213213 extern str_tree *symbols;
Show on old repository browser