4 * Copyright 2001 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
37 #ifdef HAVE_SYS_MMAN_H
42 #define NONAMELESSUNION
43 #define NONAMELESSSTRUCT
49 static IMAGE_NT_HEADERS32
* PE_nt_headers
;
51 static const char* get_machine_str(DWORD mach
)
55 case IMAGE_FILE_MACHINE_UNKNOWN
: return "Unknown";
56 case IMAGE_FILE_MACHINE_I860
: return "i860";
57 case IMAGE_FILE_MACHINE_I386
: return "i386";
58 case IMAGE_FILE_MACHINE_R3000
: return "R3000";
59 case IMAGE_FILE_MACHINE_R4000
: return "R4000";
60 case IMAGE_FILE_MACHINE_R10000
: return "R10000";
61 case IMAGE_FILE_MACHINE_ALPHA
: return "Alpha";
62 case IMAGE_FILE_MACHINE_POWERPC
: return "PowerPC";
63 case IMAGE_FILE_MACHINE_AMD64
: return "AMD64";
64 case IMAGE_FILE_MACHINE_IA64
: return "IA64";
69 static void* RVA(unsigned long rva
, unsigned long len
)
71 IMAGE_SECTION_HEADER
* sectHead
;
74 if (rva
== 0) return NULL
;
76 sectHead
= IMAGE_FIRST_SECTION(PE_nt_headers
);
77 for (i
= PE_nt_headers
->FileHeader
.NumberOfSections
- 1; i
>= 0; i
--)
79 if (sectHead
[i
].VirtualAddress
<= rva
&&
80 rva
+ len
<= (DWORD
)sectHead
[i
].VirtualAddress
+ sectHead
[i
].SizeOfRawData
)
82 /* return image import directory offset */
83 return PRD(sectHead
[i
].PointerToRawData
+ rva
- sectHead
[i
].VirtualAddress
, len
);
90 static void *get_dir_and_size(unsigned int idx
, unsigned int *size
)
92 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
94 IMAGE_OPTIONAL_HEADER64
*opt
= (IMAGE_OPTIONAL_HEADER64
*)&PE_nt_headers
->OptionalHeader
;
95 if (idx
>= opt
->NumberOfRvaAndSizes
)
98 *size
= opt
->DataDirectory
[idx
].Size
;
99 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
100 opt
->DataDirectory
[idx
].Size
);
104 IMAGE_OPTIONAL_HEADER32
*opt
= (IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
;
105 if (idx
>= opt
->NumberOfRvaAndSizes
)
108 *size
= opt
->DataDirectory
[idx
].Size
;
109 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
110 opt
->DataDirectory
[idx
].Size
);
114 static void* get_dir(unsigned idx
)
116 return get_dir_and_size(idx
, 0);
119 static const char* DirectoryNames
[16] = {
120 "EXPORT", "IMPORT", "RESOURCE", "EXCEPTION",
121 "SECURITY", "BASERELOC", "DEBUG", "ARCHITECTURE",
122 "GLOBALPTR", "TLS", "LOAD_CONFIG", "Bound IAT",
123 "IAT", "Delay IAT", "COM Descript", ""
126 static char *get_magic_type(WORD magic
)
129 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
131 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
133 case IMAGE_ROM_OPTIONAL_HDR_MAGIC
:
139 static inline void print_word(const char *title
, WORD value
)
141 printf(" %-34s 0x%-4X %u\n", title
, value
, value
);
144 static inline void print_dword(const char *title
, DWORD value
)
146 printf(" %-34s 0x%-8lx %lu\n", title
, value
, value
);
149 static inline void print_longlong(const char *title
, ULONGLONG value
)
151 printf(" %-34s 0x", title
);
153 printf("%lx%08lx\n", (unsigned long)(value
>> 32), (unsigned long)value
);
155 printf("%lx\n", (unsigned long)value
);
158 static inline void print_ver(const char *title
, BYTE major
, BYTE minor
)
160 printf(" %-34s %u.%02u\n", title
, major
, minor
);
163 static inline void print_subsys(const char *title
, WORD value
)
169 case IMAGE_SUBSYSTEM_UNKNOWN
: str
= "Unknown"; break;
170 case IMAGE_SUBSYSTEM_NATIVE
: str
= "Native"; break;
171 case IMAGE_SUBSYSTEM_WINDOWS_GUI
: str
= "Windows GUI"; break;
172 case IMAGE_SUBSYSTEM_WINDOWS_CUI
: str
= "Windows CUI"; break;
173 case IMAGE_SUBSYSTEM_OS2_CUI
: str
= "OS/2 CUI"; break;
174 case IMAGE_SUBSYSTEM_POSIX_CUI
: str
= "Posix CUI"; break;
176 printf(" %-34s 0x%X (%s)\n", title
, value
, str
);
179 static inline void print_dllflags(const char *title
, WORD value
)
181 printf(" %-34s 0x%X\n", title
, value
);
182 #define X(f,s) if (value & f) printf(" %s\n", s)
183 X(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
, "NO_ISOLATION");
184 X(IMAGE_DLLCHARACTERISTICS_NO_SEH
, "NO_SEH");
185 X(IMAGE_DLLCHARACTERISTICS_NO_BIND
, "NO_BIND");
186 X(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
, "WDM_DRIVER");
187 X(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
, "TERMINAL_SERVER_AWARE");
191 static inline void print_datadirectory(DWORD n
, IMAGE_DATA_DIRECTORY
*directory
)
194 printf("Data Directory\n");
195 printf("%ld\n", n
* sizeof(IMAGE_DATA_DIRECTORY
));
197 for (i
= 0; i
< n
&& i
< 16; i
++)
199 printf(" %-12s rva: 0x%-8lX size: %8lu\n",
200 DirectoryNames
[i
], directory
[i
].VirtualAddress
,
205 static void dump_optional_header32(IMAGE_OPTIONAL_HEADER32
*optionalHeader
)
207 print_word("Magic", optionalHeader
->Magic
);
208 print_ver("linker version",
209 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
210 print_dword("size of code", optionalHeader
->SizeOfCode
);
211 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
212 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
213 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
214 print_dword("base of code", optionalHeader
->BaseOfCode
);
215 print_dword("base of data", optionalHeader
->BaseOfData
);
216 print_dword("image base", optionalHeader
->ImageBase
);
217 print_dword("section align", optionalHeader
->SectionAlignment
);
218 print_dword("file align", optionalHeader
->FileAlignment
);
219 print_ver("required OS version",
220 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
221 print_ver("image version",
222 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
223 print_ver("subsystem version",
224 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
225 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
226 print_dword("size of image", optionalHeader
->SizeOfImage
);
227 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
228 print_dword("checksum", optionalHeader
->CheckSum
);
229 print_subsys("Subsystem", optionalHeader
->Subsystem
);
230 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
231 print_dword("stack reserve size", optionalHeader
->SizeOfStackReserve
);
232 print_dword("stack commit size", optionalHeader
->SizeOfStackCommit
);
233 print_dword("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
234 print_dword("heap commit size", optionalHeader
->SizeOfHeapCommit
);
235 print_dword("loader flags", optionalHeader
->LoaderFlags
);
236 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
238 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
241 static void dump_optional_header64(IMAGE_OPTIONAL_HEADER64
*optionalHeader
)
243 print_word("Magic", optionalHeader
->Magic
);
244 print_ver("linker version",
245 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
246 print_dword("size of code", optionalHeader
->SizeOfCode
);
247 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
248 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
249 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
250 print_dword("base of code", optionalHeader
->BaseOfCode
);
251 print_longlong("image base", optionalHeader
->ImageBase
);
252 print_dword("section align", optionalHeader
->SectionAlignment
);
253 print_dword("file align", optionalHeader
->FileAlignment
);
254 print_ver("required OS version",
255 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
256 print_ver("image version",
257 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
258 print_ver("subsystem version",
259 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
260 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
261 print_dword("size of image", optionalHeader
->SizeOfImage
);
262 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
263 print_dword("checksum", optionalHeader
->CheckSum
);
264 print_subsys("Subsystem", optionalHeader
->Subsystem
);
265 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
266 print_longlong("stack reserve size", optionalHeader
->SizeOfStackReserve
);
267 print_longlong("stack commit size", optionalHeader
->SizeOfStackCommit
);
268 print_longlong("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
269 print_longlong("heap commit size", optionalHeader
->SizeOfHeapCommit
);
270 print_dword("loader flags", optionalHeader
->LoaderFlags
);
271 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
273 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
276 static void dump_pe_header(void)
278 IMAGE_FILE_HEADER
*fileHeader
;
280 printf("File Header\n");
281 fileHeader
= &PE_nt_headers
->FileHeader
;
283 printf(" Machine: %04X (%s)\n",
284 fileHeader
->Machine
, get_machine_str(fileHeader
->Machine
));
285 printf(" Number of Sections: %d\n", fileHeader
->NumberOfSections
);
286 printf(" TimeDateStamp: %08lX (%s) offset %lu\n",
287 fileHeader
->TimeDateStamp
, get_time_str(fileHeader
->TimeDateStamp
),
288 Offset(&(fileHeader
->TimeDateStamp
)));
289 printf(" PointerToSymbolTable: %08lX\n", fileHeader
->PointerToSymbolTable
);
290 printf(" NumberOfSymbols: %08lX\n", fileHeader
->NumberOfSymbols
);
291 printf(" SizeOfOptionalHeader: %04X\n", fileHeader
->SizeOfOptionalHeader
);
292 printf(" Characteristics: %04X\n", fileHeader
->Characteristics
);
293 #define X(f,s) if (fileHeader->Characteristics & f) printf(" %s\n", s)
294 X(IMAGE_FILE_RELOCS_STRIPPED
, "RELOCS_STRIPPED");
295 X(IMAGE_FILE_EXECUTABLE_IMAGE
, "EXECUTABLE_IMAGE");
296 X(IMAGE_FILE_LINE_NUMS_STRIPPED
, "LINE_NUMS_STRIPPED");
297 X(IMAGE_FILE_LOCAL_SYMS_STRIPPED
, "LOCAL_SYMS_STRIPPED");
298 X(IMAGE_FILE_AGGRESIVE_WS_TRIM
, "AGGRESIVE_WS_TRIM");
299 X(IMAGE_FILE_LARGE_ADDRESS_AWARE
, "LARGE_ADDRESS_AWARE");
300 X(IMAGE_FILE_16BIT_MACHINE
, "16BIT_MACHINE");
301 X(IMAGE_FILE_BYTES_REVERSED_LO
, "BYTES_REVERSED_LO");
302 X(IMAGE_FILE_32BIT_MACHINE
, "32BIT_MACHINE");
303 X(IMAGE_FILE_DEBUG_STRIPPED
, "DEBUG_STRIPPED");
304 X(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
, "REMOVABLE_RUN_FROM_SWAP");
305 X(IMAGE_FILE_NET_RUN_FROM_SWAP
, "NET_RUN_FROM_SWAP");
306 X(IMAGE_FILE_SYSTEM
, "SYSTEM");
307 X(IMAGE_FILE_DLL
, "DLL");
308 X(IMAGE_FILE_UP_SYSTEM_ONLY
, "UP_SYSTEM_ONLY");
309 X(IMAGE_FILE_BYTES_REVERSED_HI
, "BYTES_REVERSED_HI");
313 /* hope we have the right size */
314 printf("Optional Header (%s)\n", get_magic_type(PE_nt_headers
->OptionalHeader
.Magic
));
315 switch(PE_nt_headers
->OptionalHeader
.Magic
) {
316 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
317 dump_optional_header32((IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
);
319 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
320 dump_optional_header64((IMAGE_OPTIONAL_HEADER64
*)&PE_nt_headers
->OptionalHeader
);
323 printf(" Unknown header magic: 0x%-4X\n", PE_nt_headers
->OptionalHeader
.Magic
);
329 static void dump_sections(void* addr
, unsigned num_sect
)
331 IMAGE_SECTION_HEADER
* sectHead
= addr
;
334 printf("Section Table\n");
335 for (i
= 0; i
< num_sect
; i
++, sectHead
++)
337 printf(" %02d %-8.8s VirtSize: %-8lu VirtAddr: %-8lu 0x%08lx\n",
338 i
+ 1, sectHead
->Name
, sectHead
->Misc
.VirtualSize
, sectHead
->VirtualAddress
,
339 sectHead
->VirtualAddress
);
340 printf(" raw data offs: %-8lu raw data size: %-8lu\n",
341 sectHead
->PointerToRawData
, sectHead
->SizeOfRawData
);
342 printf(" relocation offs: %-8lu relocations: %-8u\n",
343 sectHead
->PointerToRelocations
, sectHead
->NumberOfRelocations
);
344 printf(" line # offs: %-8lu line #'s: %-8u\n",
345 sectHead
->PointerToLinenumbers
, sectHead
->NumberOfLinenumbers
);
346 printf(" characteristics: 0x%08lx\n", sectHead
->Characteristics
);
348 #define X(b,s) if (sectHead->Characteristics & b) printf(s " ")
349 /* #define IMAGE_SCN_TYPE_REG 0x00000000 - Reserved */
350 /* #define IMAGE_SCN_TYPE_DSECT 0x00000001 - Reserved */
351 /* #define IMAGE_SCN_TYPE_NOLOAD 0x00000002 - Reserved */
352 /* #define IMAGE_SCN_TYPE_GROUP 0x00000004 - Reserved */
353 /* #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - Reserved */
354 /* #define IMAGE_SCN_TYPE_COPY 0x00000010 - Reserved */
356 X(IMAGE_SCN_CNT_CODE
, "CODE");
357 X(IMAGE_SCN_CNT_INITIALIZED_DATA
, "INITIALIZED_DATA");
358 X(IMAGE_SCN_CNT_UNINITIALIZED_DATA
, "UNINITIALIZED_DATA");
360 X(IMAGE_SCN_LNK_OTHER
, "LNK_OTHER");
361 X(IMAGE_SCN_LNK_INFO
, "LNK_INFO");
362 /* #define IMAGE_SCN_TYPE_OVER 0x00000400 - Reserved */
363 X(IMAGE_SCN_LNK_REMOVE
, "LNK_REMOVE");
364 X(IMAGE_SCN_LNK_COMDAT
, "LNK_COMDAT");
366 /* 0x00002000 - Reserved */
367 /* #define IMAGE_SCN_MEM_PROTECTED 0x00004000 - Obsolete */
368 X(IMAGE_SCN_MEM_FARDATA
, "MEM_FARDATA");
370 /* #define IMAGE_SCN_MEM_SYSHEAP 0x00010000 - Obsolete */
371 X(IMAGE_SCN_MEM_PURGEABLE
, "MEM_PURGEABLE");
372 X(IMAGE_SCN_MEM_16BIT
, "MEM_16BIT");
373 X(IMAGE_SCN_MEM_LOCKED
, "MEM_LOCKED");
374 X(IMAGE_SCN_MEM_PRELOAD
, "MEM_PRELOAD");
376 X(IMAGE_SCN_ALIGN_1BYTES
, "ALIGN_1BYTES");
377 X(IMAGE_SCN_ALIGN_2BYTES
, "ALIGN_2BYTES");
378 X(IMAGE_SCN_ALIGN_4BYTES
, "ALIGN_4BYTES");
379 X(IMAGE_SCN_ALIGN_8BYTES
, "ALIGN_8BYTES");
380 X(IMAGE_SCN_ALIGN_16BYTES
, "ALIGN_16BYTES");
381 X(IMAGE_SCN_ALIGN_32BYTES
, "ALIGN_32BYTES");
382 X(IMAGE_SCN_ALIGN_64BYTES
, "ALIGN_64BYTES");
383 /* 0x00800000 - Unused */
385 X(IMAGE_SCN_LNK_NRELOC_OVFL
, "LNK_NRELOC_OVFL");
387 X(IMAGE_SCN_MEM_DISCARDABLE
, "MEM_DISCARDABLE");
388 X(IMAGE_SCN_MEM_NOT_CACHED
, "MEM_NOT_CACHED");
389 X(IMAGE_SCN_MEM_NOT_PAGED
, "MEM_NOT_PAGED");
390 X(IMAGE_SCN_MEM_SHARED
, "MEM_SHARED");
391 X(IMAGE_SCN_MEM_EXECUTE
, "MEM_EXECUTE");
392 X(IMAGE_SCN_MEM_READ
, "MEM_READ");
393 X(IMAGE_SCN_MEM_WRITE
, "MEM_WRITE");
400 static void dump_dir_exported_functions(void)
402 unsigned int size
= 0;
403 IMAGE_EXPORT_DIRECTORY
*exportDir
= get_dir_and_size(IMAGE_FILE_EXPORT_DIRECTORY
, &size
);
409 parsed_symbol symbol
;
411 if (!exportDir
) return;
413 printf("Exports table:\n");
415 printf(" Name: %s\n", (char*)RVA(exportDir
->Name
, sizeof(DWORD
)));
416 printf(" Characteristics: %08lx\n", exportDir
->Characteristics
);
417 printf(" TimeDateStamp: %08lX %s\n",
418 exportDir
->TimeDateStamp
, get_time_str(exportDir
->TimeDateStamp
));
419 printf(" Version: %u.%02u\n", exportDir
->MajorVersion
, exportDir
->MinorVersion
);
420 printf(" Ordinal base: %lu\n", exportDir
->Base
);
421 printf(" # of functions: %lu\n", exportDir
->NumberOfFunctions
);
422 printf(" # of Names: %lu\n", exportDir
->NumberOfNames
);
423 printf("Addresses of functions: %08lX\n", exportDir
->AddressOfFunctions
);
424 printf("Addresses of name ordinals: %08lX\n", exportDir
->AddressOfNameOrdinals
);
425 printf("Addresses of names: %08lX\n", exportDir
->AddressOfNames
);
427 printf(" Entry Pt Ordn Name\n");
429 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
430 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
431 pName
= RVA(exportDir
->AddressOfNames
, exportDir
->NumberOfNames
* sizeof(DWORD
));
432 if (!pName
) {printf("Can't grab functions' name table\n"); return;}
433 pOrdl
= RVA(exportDir
->AddressOfNameOrdinals
, exportDir
->NumberOfNames
* sizeof(WORD
));
434 if (!pOrdl
) {printf("Can't grab functions' ordinal table\n"); return;}
436 /* bit map of used funcs */
437 map
= calloc(((exportDir
->NumberOfFunctions
+ 31) & ~31) / 32, sizeof(DWORD
));
438 if (!map
) fatal("no memory");
440 for (i
= 0; i
< exportDir
->NumberOfNames
; i
++, pName
++, pOrdl
++)
444 map
[*pOrdl
/ 32] |= 1 << (*pOrdl
% 32);
446 name
= (char*)RVA(*pName
, sizeof(DWORD
));
447 if (name
&& globals
.do_demangle
)
449 printf(" %08lX %4lu ", pFunc
[*pOrdl
], exportDir
->Base
+ *pOrdl
);
451 symbol_init(&symbol
, name
);
452 if (symbol_demangle(&symbol
) == -1)
454 else if (symbol
.flags
& SYM_DATA
)
455 printf(symbol
.arg_text
[0]);
457 output_prototype(stdout
, &symbol
);
458 symbol_clear(&symbol
);
462 printf(" %08lX %4lu %s", pFunc
[*pOrdl
], exportDir
->Base
+ *pOrdl
, name
);
464 /* check for forwarded function */
465 if ((char *)RVA(pFunc
[*pOrdl
],sizeof(void*)) >= (char *)exportDir
&&
466 (char *)RVA(pFunc
[*pOrdl
],sizeof(void*)) < (char *)exportDir
+ size
)
467 printf( " (-> %s)", (char *)RVA(pFunc
[*pOrdl
],1));
470 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
471 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
472 for (i
= 0; i
< exportDir
->NumberOfFunctions
; i
++)
474 if (pFunc
[i
] && !(map
[i
/ 32] & (1 << (i
% 32))))
476 printf(" %08lX %4lu <by ordinal>\n", pFunc
[i
], exportDir
->Base
+ i
);
483 static void dump_image_thunk_data64(IMAGE_THUNK_DATA64
*il
)
485 /* FIXME: This does not properly handle large images */
486 IMAGE_IMPORT_BY_NAME
* iibn
;
487 for (; il
->u1
.Ordinal
; il
++)
489 if (IMAGE_SNAP_BY_ORDINAL64(il
->u1
.Ordinal
))
490 printf(" %4lu <by ordinal>\n", (DWORD
)IMAGE_ORDINAL64(il
->u1
.Ordinal
));
493 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
, sizeof(DWORD
));
495 printf("Can't grab import by name info, skipping to next ordinal\n");
497 printf(" %4u %s %lx\n", iibn
->Hint
, iibn
->Name
, (DWORD
)il
->u1
.AddressOfData
);
502 static void dump_image_thunk_data32(IMAGE_THUNK_DATA32
*il
)
504 IMAGE_IMPORT_BY_NAME
* iibn
;
505 for (; il
->u1
.Ordinal
; il
++)
507 if (IMAGE_SNAP_BY_ORDINAL32(il
->u1
.Ordinal
))
508 printf(" %4lu <by ordinal>\n", IMAGE_ORDINAL32(il
->u1
.Ordinal
));
511 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
, sizeof(DWORD
));
513 printf("Can't grab import by name info, skipping to next ordinal\n");
515 printf(" %4u %s %lx\n", iibn
->Hint
, iibn
->Name
, (DWORD
)il
->u1
.AddressOfData
);
520 static void dump_dir_imported_functions(void)
522 IMAGE_IMPORT_DESCRIPTOR
*importDesc
= get_dir(IMAGE_FILE_IMPORT_DIRECTORY
);
526 if (!importDesc
) return;
527 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
529 IMAGE_OPTIONAL_HEADER64
*opt
= (IMAGE_OPTIONAL_HEADER64
*)&PE_nt_headers
->OptionalHeader
;
530 directorySize
= opt
->DataDirectory
[IMAGE_FILE_IMPORT_DIRECTORY
].Size
;
534 IMAGE_OPTIONAL_HEADER32
*opt
= (IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
;
535 directorySize
= opt
->DataDirectory
[IMAGE_FILE_IMPORT_DIRECTORY
].Size
;
537 nb_imp
= directorySize
/ sizeof(*importDesc
);
540 printf("Import Table size: %lu\n", directorySize
);/* FIXME */
542 for (i
= 0; i
< nb_imp
- 1; i
++) /* the last descr is set as 0 as a sentinel */
544 IMAGE_THUNK_DATA32
* il
;
546 if (!importDesc
->Name
||
547 (importDesc
->u
.OriginalFirstThunk
== 0 && importDesc
->FirstThunk
== 0))
550 printf("<<<<<<<null entry\n");
553 printf(" offset %lu %s\n", Offset(importDesc
), (char*)RVA(importDesc
->Name
, sizeof(DWORD
)));
554 printf(" Hint/Name Table: %08lX\n", (DWORD
)importDesc
->u
.OriginalFirstThunk
);
555 printf(" TimeDataStamp: %08lX (%s)\n",
556 importDesc
->TimeDateStamp
, get_time_str(importDesc
->TimeDateStamp
));
557 printf(" ForwarderChain: %08lX\n", importDesc
->ForwarderChain
);
558 printf(" First thunk RVA: %08lX (delta: %u 0x%x)\n",
559 (DWORD
)importDesc
->FirstThunk
, -1, -1); /* FIXME */
561 printf(" Ordn Name\n");
563 il
= (importDesc
->u
.OriginalFirstThunk
!= 0) ?
564 RVA((DWORD
)importDesc
->u
.OriginalFirstThunk
, sizeof(DWORD
)) :
565 RVA((DWORD
)importDesc
->FirstThunk
, sizeof(DWORD
));
567 if (!il
) {printf("Can't grab thunk data, going to next imported DLL\n"); continue;}
569 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
570 dump_image_thunk_data64((IMAGE_THUNK_DATA64
*)il
);
572 dump_image_thunk_data32(il
);
579 static void dump_dir_debug_dir(IMAGE_DEBUG_DIRECTORY
* idd
, int idx
)
583 printf("Directory %02u\n", idx
+ 1);
584 printf(" Characteristics: %08lX\n", idd
->Characteristics
);
585 printf(" TimeDateStamp: %08lX %s\n",
586 idd
->TimeDateStamp
, get_time_str(idd
->TimeDateStamp
));
587 printf(" Version %u.%02u\n", idd
->MajorVersion
, idd
->MinorVersion
);
591 case IMAGE_DEBUG_TYPE_UNKNOWN
: str
= "UNKNOWN"; break;
592 case IMAGE_DEBUG_TYPE_COFF
: str
= "COFF"; break;
593 case IMAGE_DEBUG_TYPE_CODEVIEW
: str
= "CODEVIEW"; break;
594 case IMAGE_DEBUG_TYPE_FPO
: str
= "FPO"; break;
595 case IMAGE_DEBUG_TYPE_MISC
: str
= "MISC"; break;
596 case IMAGE_DEBUG_TYPE_EXCEPTION
: str
= "EXCEPTION"; break;
597 case IMAGE_DEBUG_TYPE_FIXUP
: str
= "FIXUP"; break;
598 case IMAGE_DEBUG_TYPE_OMAP_TO_SRC
: str
= "OMAP_TO_SRC"; break;
599 case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
:str
= "OMAP_FROM_SRC"; break;
600 case IMAGE_DEBUG_TYPE_BORLAND
: str
= "BORLAND"; break;
601 case IMAGE_DEBUG_TYPE_RESERVED10
: str
= "RESERVED10"; break;
603 printf(" Type: %lu (%s)\n", idd
->Type
, str
);
604 printf(" SizeOfData: %lu\n", idd
->SizeOfData
);
605 printf(" AddressOfRawData: %08lX\n", idd
->AddressOfRawData
);
606 printf(" PointerToRawData: %08lX\n", idd
->PointerToRawData
);
610 case IMAGE_DEBUG_TYPE_UNKNOWN
:
612 case IMAGE_DEBUG_TYPE_COFF
:
613 dump_coff(idd
->PointerToRawData
, idd
->SizeOfData
,
614 (char*)PE_nt_headers
+ sizeof(DWORD
) + sizeof(IMAGE_FILE_HEADER
) + PE_nt_headers
->FileHeader
.SizeOfOptionalHeader
);
616 case IMAGE_DEBUG_TYPE_CODEVIEW
:
617 dump_codeview(idd
->PointerToRawData
, idd
->SizeOfData
);
619 case IMAGE_DEBUG_TYPE_FPO
:
620 dump_frame_pointer_omission(idd
->PointerToRawData
, idd
->SizeOfData
);
622 case IMAGE_DEBUG_TYPE_MISC
:
624 IMAGE_DEBUG_MISC
* misc
= PRD(idd
->PointerToRawData
, idd
->SizeOfData
);
625 if (!misc
) {printf("Can't get misc debug information\n"); break;}
626 printf(" DataType: %lu (%s)\n",
628 (misc
->DataType
== IMAGE_DEBUG_MISC_EXENAME
) ? "Exe name" : "Unknown");
629 printf(" Length: %lu\n", misc
->Length
);
630 printf(" Unicode: %s\n", misc
->Unicode
? "Yes" : "No");
631 printf(" Data: %s\n", misc
->Data
);
634 case IMAGE_DEBUG_TYPE_EXCEPTION
:
636 case IMAGE_DEBUG_TYPE_FIXUP
:
638 case IMAGE_DEBUG_TYPE_OMAP_TO_SRC
:
640 case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
:
642 case IMAGE_DEBUG_TYPE_BORLAND
:
644 case IMAGE_DEBUG_TYPE_RESERVED10
:
650 static void dump_dir_debug(void)
652 IMAGE_DEBUG_DIRECTORY
* debugDir
= get_dir(IMAGE_FILE_DEBUG_DIRECTORY
);
655 if (!debugDir
) return;
656 nb_dbg
= PE_nt_headers
->OptionalHeader
.DataDirectory
[IMAGE_FILE_DEBUG_DIRECTORY
].Size
/
660 printf("Debug Table (%u directories)\n", nb_dbg
);
662 for (i
= 0; i
< nb_dbg
; i
++)
664 dump_dir_debug_dir(debugDir
, i
);
670 static void dump_dir_tls(void)
672 IMAGE_TLS_DIRECTORY64 dir
;
673 const DWORD
*callbacks
;
674 const IMAGE_TLS_DIRECTORY32
*pdir
= get_dir(IMAGE_FILE_THREAD_LOCAL_STORAGE
);
678 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
679 memcpy(&dir
, pdir
, sizeof(dir
));
682 dir
.StartAddressOfRawData
= pdir
->StartAddressOfRawData
;
683 dir
.EndAddressOfRawData
= pdir
->EndAddressOfRawData
;
684 dir
.AddressOfIndex
= pdir
->AddressOfIndex
;
685 dir
.AddressOfCallBacks
= pdir
->AddressOfCallBacks
;
686 dir
.SizeOfZeroFill
= pdir
->SizeOfZeroFill
;
687 dir
.Characteristics
= pdir
->Characteristics
;
690 /* FIXME: This does not properly handle large images */
691 printf( "Thread Local Storage\n" );
692 printf( " Raw data %08lx-%08lx (data size %lx zero fill size %lx)\n",
693 (DWORD
)dir
.StartAddressOfRawData
, (DWORD
)dir
.EndAddressOfRawData
,
694 (DWORD
)(dir
.EndAddressOfRawData
- dir
.StartAddressOfRawData
),
695 (DWORD
)dir
.SizeOfZeroFill
);
696 printf( " Index address %08lx\n", (DWORD
)dir
.AddressOfIndex
);
697 printf( " Characteristics %08lx\n", dir
.Characteristics
);
698 printf( " Callbacks %08lx -> {", (DWORD
)dir
.AddressOfCallBacks
);
699 if (dir
.AddressOfCallBacks
)
701 DWORD addr
= (DWORD
)dir
.AddressOfCallBacks
- PE_nt_headers
->OptionalHeader
.ImageBase
;
702 while ((callbacks
= RVA(addr
, sizeof(DWORD
))) && *callbacks
)
704 printf( " %08lx", *callbacks
);
705 addr
+= sizeof(DWORD
);
711 void dump_separate_dbg(void)
713 IMAGE_SEPARATE_DEBUG_HEADER
*separateDebugHead
= PRD(0, sizeof(separateDebugHead
));
716 IMAGE_DEBUG_DIRECTORY
* debugDir
;
718 if (!separateDebugHead
) {printf("Can't grab the separate header, aborting\n"); return;}
720 printf ("Signature: %.2s (0x%4X)\n",
721 (char*)&separateDebugHead
->Signature
, separateDebugHead
->Signature
);
722 printf ("Flags: 0x%04X\n", separateDebugHead
->Flags
);
723 printf ("Machine: 0x%04X (%s)\n",
724 separateDebugHead
->Machine
, get_machine_str(separateDebugHead
->Machine
));
725 printf ("Characteristics: 0x%04X\n", separateDebugHead
->Characteristics
);
726 printf ("TimeDateStamp: 0x%08lX (%s)\n",
727 separateDebugHead
->TimeDateStamp
, get_time_str(separateDebugHead
->TimeDateStamp
));
728 printf ("CheckSum: 0x%08lX\n", separateDebugHead
->CheckSum
);
729 printf ("ImageBase: 0x%08lX\n", separateDebugHead
->ImageBase
);
730 printf ("SizeOfImage: 0x%08lX\n", separateDebugHead
->SizeOfImage
);
731 printf ("NumberOfSections: 0x%08lX\n", separateDebugHead
->NumberOfSections
);
732 printf ("ExportedNamesSize: 0x%08lX\n", separateDebugHead
->ExportedNamesSize
);
733 printf ("DebugDirectorySize: 0x%08lX\n", separateDebugHead
->DebugDirectorySize
);
735 if (!PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
),
736 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)))
737 {printf("Can't get the sections, aborting\n"); return;}
739 dump_sections(separateDebugHead
+ 1, separateDebugHead
->NumberOfSections
);
741 nb_dbg
= separateDebugHead
->DebugDirectorySize
/ sizeof(IMAGE_DEBUG_DIRECTORY
);
742 debugDir
= PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
) +
743 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
) +
744 separateDebugHead
->ExportedNamesSize
,
745 nb_dbg
* sizeof(IMAGE_DEBUG_DIRECTORY
));
746 if (!debugDir
) {printf("Couldn't get the debug directory info, aborting\n");return;}
748 printf("Debug Table (%u directories)\n", nb_dbg
);
750 for (i
= 0; i
< nb_dbg
; i
++)
752 dump_dir_debug_dir(debugDir
, i
);
757 static const char *get_resource_type( unsigned int id
)
759 static const char *types
[] =
787 if ((size_t)id
< sizeof(types
)/sizeof(types
[0])) return types
[id
];
791 /* dump an ASCII string with proper escaping */
792 static int dump_strA( const unsigned char *str
, size_t len
)
794 static const char escapes
[32] = ".......abtnvfr.............e....";
799 for (; len
; str
++, len
--)
801 if (pos
> buffer
+ sizeof(buffer
) - 8)
803 fwrite( buffer
, pos
- buffer
, 1, stdout
);
804 count
+= pos
- buffer
;
807 if (*str
> 127) /* hex escape */
809 pos
+= sprintf( pos
, "\\x%02x", *str
);
812 if (*str
< 32) /* octal or C escape */
814 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
815 if (escapes
[*str
] != '.')
816 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
817 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
818 pos
+= sprintf( pos
, "\\%03o", *str
);
820 pos
+= sprintf( pos
, "\\%o", *str
);
823 if (*str
== '\\') *pos
++ = '\\';
826 fwrite( buffer
, pos
- buffer
, 1, stdout
);
827 count
+= pos
- buffer
;
831 /* dump a Unicode string with proper escaping */
832 static int dump_strW( const WCHAR
*str
, size_t len
)
834 static const char escapes
[32] = ".......abtnvfr.............e....";
839 for (; len
; str
++, len
--)
841 if (pos
> buffer
+ sizeof(buffer
) - 8)
843 fwrite( buffer
, pos
- buffer
, 1, stdout
);
844 count
+= pos
- buffer
;
847 if (*str
> 127) /* hex escape */
849 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
850 pos
+= sprintf( pos
, "\\x%04x", *str
);
852 pos
+= sprintf( pos
, "\\x%x", *str
);
855 if (*str
< 32) /* octal or C escape */
857 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
858 if (escapes
[*str
] != '.')
859 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
860 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
861 pos
+= sprintf( pos
, "\\%03o", *str
);
863 pos
+= sprintf( pos
, "\\%o", *str
);
866 if (*str
== '\\') *pos
++ = '\\';
869 fwrite( buffer
, pos
- buffer
, 1, stdout
);
870 count
+= pos
- buffer
;
874 /* dump data for a STRING resource */
875 static void dump_string_data( const WCHAR
*ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
879 for (i
= 0; i
< 16 && size
; i
++)
881 unsigned len
= *ptr
++;
888 else size
-= len
+ 1;
892 printf( "%s%04x \"", prefix
, (id
- 1) * 16 + i
);
893 dump_strW( ptr
, len
);
900 /* dump data for a MESSAGETABLE resource */
901 static void dump_msgtable_data( const void *ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
903 const MESSAGE_RESOURCE_DATA
*data
= ptr
;
904 const MESSAGE_RESOURCE_BLOCK
*block
= data
->Blocks
;
907 for (i
= 0; i
< data
->NumberOfBlocks
; i
++, block
++)
909 const MESSAGE_RESOURCE_ENTRY
*entry
;
911 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)data
+ block
->OffsetToEntries
);
912 for (j
= block
->LowId
; j
<= block
->HighId
; j
++)
914 if (entry
->Flags
& MESSAGE_RESOURCE_UNICODE
)
916 const WCHAR
*str
= (const WCHAR
*)entry
->Text
;
917 printf( "%s%08x L\"", prefix
, j
);
918 dump_strW( str
, strlenW(str
) );
923 const char *str
= (const char *) entry
->Text
;
924 printf( "%s%08x \"", prefix
, j
);
925 dump_strA( entry
->Text
, strlen(str
) );
928 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)entry
+ entry
->Length
);
933 static void dump_dir_resource(void)
935 const IMAGE_RESOURCE_DIRECTORY
*root
= get_dir(IMAGE_FILE_RESOURCE_DIRECTORY
);
936 const IMAGE_RESOURCE_DIRECTORY
*namedir
;
937 const IMAGE_RESOURCE_DIRECTORY
*langdir
;
938 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*e1
, *e2
, *e3
;
939 const IMAGE_RESOURCE_DIR_STRING_U
*string
;
940 const IMAGE_RESOURCE_DATA_ENTRY
*data
;
945 printf( "Resources:" );
947 for (i
= 0; i
< root
->NumberOfNamedEntries
+ root
->NumberOfIdEntries
; i
++)
949 e1
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(root
+ 1) + i
;
950 namedir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e1
->u2
.s3
.OffsetToDirectory
);
951 for (j
= 0; j
< namedir
->NumberOfNamedEntries
+ namedir
->NumberOfIdEntries
; j
++)
953 e2
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(namedir
+ 1) + j
;
954 langdir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e2
->u2
.s3
.OffsetToDirectory
);
955 for (k
= 0; k
< langdir
->NumberOfNamedEntries
+ langdir
->NumberOfIdEntries
; k
++)
957 e3
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(langdir
+ 1) + k
;
960 if (e1
->u1
.s1
.NameIsString
)
962 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*)((const char *)root
+ e1
->u1
.s1
.NameOffset
);
963 dump_unicode_str( string
->NameString
, string
->Length
);
967 const char *type
= get_resource_type( e1
->u1
.s2
.Id
);
968 if (type
) printf( "%s", type
);
969 else printf( "%04x", e1
->u1
.s2
.Id
);
973 if (e2
->u1
.s1
.NameIsString
)
975 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*) ((const char *)root
+ e2
->u1
.s1
.NameOffset
);
976 dump_unicode_str( string
->NameString
, string
->Length
);
979 printf( "%04x", e2
->u1
.s2
.Id
);
981 printf( " Language=%04x:\n", e3
->u1
.s2
.Id
);
982 data
= (const IMAGE_RESOURCE_DATA_ENTRY
*)((const char *)root
+ e3
->u2
.OffsetToData
);
983 if (e1
->u1
.s1
.NameIsString
)
985 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
987 else switch(e1
->u1
.s2
.Id
)
990 dump_string_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
,
994 dump_msgtable_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
,
998 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
1007 void pe_dump(void* pmt
)
1009 int all
= (globals
.dumpsect
!= NULL
) && strcmp(globals
.dumpsect
, "ALL") == 0;
1011 PE_nt_headers
= pmt
;
1012 if (globals
.do_dumpheader
)
1015 /* FIXME: should check ptr */
1016 dump_sections((char*)PE_nt_headers
+ sizeof(DWORD
) +
1017 sizeof(IMAGE_FILE_HEADER
) + PE_nt_headers
->FileHeader
.SizeOfOptionalHeader
,
1018 PE_nt_headers
->FileHeader
.NumberOfSections
);
1020 else if (!globals
.dumpsect
)
1022 /* show at least something here */
1026 if (globals
.dumpsect
)
1028 if (all
|| !strcmp(globals
.dumpsect
, "import"))
1029 dump_dir_imported_functions();
1030 if (all
|| !strcmp(globals
.dumpsect
, "export"))
1031 dump_dir_exported_functions();
1032 if (all
|| !strcmp(globals
.dumpsect
, "debug"))
1034 if (all
|| !strcmp(globals
.dumpsect
, "resource"))
1035 dump_dir_resource();
1036 if (all
|| !strcmp(globals
.dumpsect
, "tls"))
1039 /* FIXME: not implemented yet */
1040 if (all
|| !strcmp(globals
.dumpsect
, "reloc"))
1046 typedef struct _dll_symbol
{
1051 static dll_symbol
*dll_symbols
= NULL
;
1052 static dll_symbol
*dll_current_symbol
= NULL
;
1054 /* Compare symbols by ordinal for qsort */
1055 static int symbol_cmp(const void *left
, const void *right
)
1057 return ((const dll_symbol
*)left
)->ordinal
> ((const dll_symbol
*)right
)->ordinal
;
1060 /*******************************************************************
1063 * Free resources used by DLL
1065 /* FIXME: Not used yet
1066 static void dll_close (void)
1071 fatal("No symbols");
1073 for (ds = dll_symbols; ds->symbol; ds++)
1080 static void do_grab_sym( enum FileSig sig
, void* pmt
)
1082 IMAGE_EXPORT_DIRECTORY
*exportDir
;
1090 PE_nt_headers
= pmt
;
1091 if (!(exportDir
= get_dir(IMAGE_FILE_EXPORT_DIRECTORY
))) return;
1093 pName
= RVA(exportDir
->AddressOfNames
, exportDir
->NumberOfNames
* sizeof(DWORD
));
1094 if (!pName
) {printf("Can't grab functions' name table\n"); return;}
1095 pOrdl
= RVA(exportDir
->AddressOfNameOrdinals
, exportDir
->NumberOfNames
* sizeof(WORD
));
1096 if (!pOrdl
) {printf("Can't grab functions' ordinal table\n"); return;}
1100 if (!(dll_symbols
= (dll_symbol
*) malloc((exportDir
->NumberOfFunctions
+ 1) *
1101 sizeof (dll_symbol
))))
1102 fatal ("Out of memory");
1103 if (exportDir
->AddressOfFunctions
!= exportDir
->NumberOfNames
|| exportDir
->Base
> 1)
1104 globals
.do_ordinals
= 1;
1106 /* bit map of used funcs */
1107 map
= calloc(((exportDir
->NumberOfFunctions
+ 31) & ~31) / 32, sizeof(DWORD
));
1108 if (!map
) fatal("no memory");
1110 for (j
= 0; j
< exportDir
->NumberOfNames
; j
++, pOrdl
++)
1112 map
[*pOrdl
/ 32] |= 1 << (*pOrdl
% 32);
1113 ptr
= RVA(*pName
++, sizeof(DWORD
));
1114 if (!ptr
) ptr
= "cant_get_function";
1115 dll_symbols
[j
].symbol
= strdup(ptr
);
1116 dll_symbols
[j
].ordinal
= exportDir
->Base
+ *pOrdl
;
1117 assert(dll_symbols
[j
].symbol
);
1119 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
1120 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
1122 for (i
= 0; i
< exportDir
->NumberOfFunctions
; i
++)
1124 if (pFunc
[i
] && !(map
[i
/ 32] & (1 << (i
% 32))))
1126 char ordinal_text
[256];
1127 /* Ordinal only entry */
1128 snprintf (ordinal_text
, sizeof(ordinal_text
), "%s_%lu",
1129 globals
.forward_dll
? globals
.forward_dll
: OUTPUT_UC_DLL_NAME
,
1130 exportDir
->Base
+ i
);
1131 str_toupper(ordinal_text
);
1132 dll_symbols
[j
].symbol
= strdup(ordinal_text
);
1133 assert(dll_symbols
[j
].symbol
);
1134 dll_symbols
[j
].ordinal
= exportDir
->Base
+ i
;
1136 assert(j
<= exportDir
->NumberOfFunctions
);
1142 printf("%lu named symbols in DLL, %lu total, %d unique (ordinal base = %ld)\n",
1143 exportDir
->NumberOfNames
, exportDir
->NumberOfFunctions
, j
, exportDir
->Base
);
1145 qsort( dll_symbols
, j
, sizeof(dll_symbol
), symbol_cmp
);
1147 dll_symbols
[j
].symbol
= NULL
;
1149 dll_current_symbol
= dll_symbols
;
1152 /*******************************************************************
1155 * Open a DLL and read in exported symbols
1157 int dll_open (const char *dll_name
)
1159 return dump_analysis(dll_name
, do_grab_sym
, SIG_PE
);
1162 /*******************************************************************
1165 * Get next exported symbol from dll
1167 int dll_next_symbol (parsed_symbol
* sym
)
1169 if (!dll_current_symbol
->symbol
)
1172 assert (dll_symbols
);
1174 sym
->symbol
= strdup (dll_current_symbol
->symbol
);
1175 sym
->ordinal
= dll_current_symbol
->ordinal
;
1176 dll_current_symbol
++;