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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
35 static const IMAGE_NT_HEADERS32
* PE_nt_headers
;
37 static const char builtin_signature
[] = "Wine builtin DLL";
38 static const char fakedll_signature
[] = "Wine placeholder DLL";
39 static int is_builtin
;
41 const char *get_machine_str(int mach
)
45 case IMAGE_FILE_MACHINE_UNKNOWN
: return "Unknown";
46 case IMAGE_FILE_MACHINE_I860
: return "i860";
47 case IMAGE_FILE_MACHINE_I386
: return "i386";
48 case IMAGE_FILE_MACHINE_R3000
: return "R3000";
49 case IMAGE_FILE_MACHINE_R4000
: return "R4000";
50 case IMAGE_FILE_MACHINE_R10000
: return "R10000";
51 case IMAGE_FILE_MACHINE_ALPHA
: return "Alpha";
52 case IMAGE_FILE_MACHINE_POWERPC
: return "PowerPC";
53 case IMAGE_FILE_MACHINE_AMD64
: return "AMD64";
54 case IMAGE_FILE_MACHINE_IA64
: return "IA64";
55 case IMAGE_FILE_MACHINE_ARM64
: return "ARM64";
56 case IMAGE_FILE_MACHINE_ARM
: return "ARM";
57 case IMAGE_FILE_MACHINE_ARMNT
: return "ARMNT";
58 case IMAGE_FILE_MACHINE_THUMB
: return "ARM Thumb";
63 static const void* RVA(unsigned long rva
, unsigned long len
)
65 IMAGE_SECTION_HEADER
* sectHead
;
68 if (rva
== 0) return NULL
;
70 sectHead
= IMAGE_FIRST_SECTION(PE_nt_headers
);
71 for (i
= PE_nt_headers
->FileHeader
.NumberOfSections
- 1; i
>= 0; i
--)
73 if (sectHead
[i
].VirtualAddress
<= rva
&&
74 rva
+ len
<= (DWORD
)sectHead
[i
].VirtualAddress
+ sectHead
[i
].SizeOfRawData
)
76 /* return image import directory offset */
77 return PRD(sectHead
[i
].PointerToRawData
+ rva
- sectHead
[i
].VirtualAddress
, len
);
84 static const IMAGE_NT_HEADERS32
*get_nt_header( void )
86 const IMAGE_DOS_HEADER
*dos
;
87 dos
= PRD(0, sizeof(*dos
));
88 if (!dos
) return NULL
;
89 is_builtin
= (dos
->e_lfanew
>= sizeof(*dos
) + 32 &&
90 !memcmp( dos
+ 1, builtin_signature
, sizeof(builtin_signature
) ));
91 return PRD(dos
->e_lfanew
, sizeof(DWORD
) + sizeof(IMAGE_FILE_HEADER
));
94 void print_fake_dll( void )
96 const IMAGE_DOS_HEADER
*dos
;
98 dos
= PRD(0, sizeof(*dos
) + 32);
99 if (dos
&& dos
->e_lfanew
>= sizeof(*dos
) + 32)
101 if (!memcmp( dos
+ 1, builtin_signature
, sizeof(builtin_signature
) ))
102 printf( "*** This is a Wine builtin DLL ***\n\n" );
103 else if (!memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) ))
104 printf( "*** This is a Wine fake DLL ***\n\n" );
108 static const void *get_dir_and_size(unsigned int idx
, unsigned int *size
)
110 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
112 const IMAGE_OPTIONAL_HEADER64
*opt
= (const IMAGE_OPTIONAL_HEADER64
*)&PE_nt_headers
->OptionalHeader
;
113 if (idx
>= opt
->NumberOfRvaAndSizes
)
116 *size
= opt
->DataDirectory
[idx
].Size
;
117 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
118 opt
->DataDirectory
[idx
].Size
);
122 const IMAGE_OPTIONAL_HEADER32
*opt
= (const IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
;
123 if (idx
>= opt
->NumberOfRvaAndSizes
)
126 *size
= opt
->DataDirectory
[idx
].Size
;
127 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
128 opt
->DataDirectory
[idx
].Size
);
132 static const void* get_dir(unsigned idx
)
134 return get_dir_and_size(idx
, 0);
137 static const char * const DirectoryNames
[16] = {
138 "EXPORT", "IMPORT", "RESOURCE", "EXCEPTION",
139 "SECURITY", "BASERELOC", "DEBUG", "ARCHITECTURE",
140 "GLOBALPTR", "TLS", "LOAD_CONFIG", "Bound IAT",
141 "IAT", "Delay IAT", "CLR Header", ""
144 static const char *get_magic_type(WORD magic
)
147 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
149 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
151 case IMAGE_ROM_OPTIONAL_HDR_MAGIC
:
157 static inline void print_word(const char *title
, WORD value
)
159 printf(" %-34s 0x%-4X %u\n", title
, value
, value
);
162 static inline void print_dword(const char *title
, UINT value
)
164 printf(" %-34s 0x%-8x %u\n", title
, value
, value
);
167 static inline void print_longlong(const char *title
, ULONGLONG value
)
169 printf(" %-34s 0x", title
);
170 if (sizeof(value
) > sizeof(unsigned long) && value
>> 32)
171 printf("%lx%08lx\n", (unsigned long)(value
>> 32), (unsigned long)value
);
173 printf("%lx\n", (unsigned long)value
);
176 static inline void print_ver(const char *title
, BYTE major
, BYTE minor
)
178 printf(" %-34s %u.%02u\n", title
, major
, minor
);
181 static inline void print_subsys(const char *title
, WORD value
)
187 case IMAGE_SUBSYSTEM_UNKNOWN
: str
= "Unknown"; break;
188 case IMAGE_SUBSYSTEM_NATIVE
: str
= "Native"; break;
189 case IMAGE_SUBSYSTEM_WINDOWS_GUI
: str
= "Windows GUI"; break;
190 case IMAGE_SUBSYSTEM_WINDOWS_CUI
: str
= "Windows CUI"; break;
191 case IMAGE_SUBSYSTEM_OS2_CUI
: str
= "OS/2 CUI"; break;
192 case IMAGE_SUBSYSTEM_POSIX_CUI
: str
= "Posix CUI"; break;
193 case IMAGE_SUBSYSTEM_NATIVE_WINDOWS
: str
= "native Win9x driver"; break;
194 case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
: str
= "Windows CE GUI"; break;
195 case IMAGE_SUBSYSTEM_EFI_APPLICATION
: str
= "EFI application"; break;
196 case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
: str
= "EFI driver (boot)"; break;
197 case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
: str
= "EFI driver (runtime)"; break;
198 case IMAGE_SUBSYSTEM_EFI_ROM
: str
= "EFI ROM"; break;
199 case IMAGE_SUBSYSTEM_XBOX
: str
= "Xbox application"; break;
200 case IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION
: str
= "Boot application"; break;
202 printf(" %-34s 0x%X (%s)\n", title
, value
, str
);
205 static inline void print_dllflags(const char *title
, WORD value
)
207 printf(" %-34s 0x%04X\n", title
, value
);
208 #define X(f,s) do { if (value & f) printf(" %s\n", s); } while(0)
209 if (is_builtin
) X(IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE
, "PREFER_NATIVE (Wine extension)");
210 X(IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
, "HIGH_ENTROPY_VA");
211 X(IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
, "DYNAMIC_BASE");
212 X(IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
, "FORCE_INTEGRITY");
213 X(IMAGE_DLLCHARACTERISTICS_NX_COMPAT
, "NX_COMPAT");
214 X(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
, "NO_ISOLATION");
215 X(IMAGE_DLLCHARACTERISTICS_NO_SEH
, "NO_SEH");
216 X(IMAGE_DLLCHARACTERISTICS_NO_BIND
, "NO_BIND");
217 X(IMAGE_DLLCHARACTERISTICS_APPCONTAINER
, "APPCONTAINER");
218 X(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
, "WDM_DRIVER");
219 X(IMAGE_DLLCHARACTERISTICS_GUARD_CF
, "GUARD_CF");
220 X(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
, "TERMINAL_SERVER_AWARE");
224 static inline void print_datadirectory(DWORD n
, const IMAGE_DATA_DIRECTORY
*directory
)
227 printf("Data Directory\n");
229 for (i
= 0; i
< n
&& i
< 16; i
++)
231 printf(" %-12s rva: 0x%-8x size: 0x%-8x\n",
232 DirectoryNames
[i
], (UINT
)directory
[i
].VirtualAddress
,
233 (UINT
)directory
[i
].Size
);
237 static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32
*image_oh
, UINT header_size
)
239 IMAGE_OPTIONAL_HEADER32 oh
;
240 const IMAGE_OPTIONAL_HEADER32
*optionalHeader
;
242 /* in case optional header is missing or partial */
243 memset(&oh
, 0, sizeof(oh
));
244 memcpy(&oh
, image_oh
, min(header_size
, sizeof(oh
)));
245 optionalHeader
= &oh
;
247 print_word("Magic", optionalHeader
->Magic
);
248 print_ver("linker version",
249 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
250 print_dword("size of code", optionalHeader
->SizeOfCode
);
251 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
252 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
253 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
254 print_dword("base of code", optionalHeader
->BaseOfCode
);
255 print_dword("base of data", optionalHeader
->BaseOfData
);
256 print_dword("image base", optionalHeader
->ImageBase
);
257 print_dword("section align", optionalHeader
->SectionAlignment
);
258 print_dword("file align", optionalHeader
->FileAlignment
);
259 print_ver("required OS version",
260 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
261 print_ver("image version",
262 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
263 print_ver("subsystem version",
264 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
265 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
266 print_dword("size of image", optionalHeader
->SizeOfImage
);
267 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
268 print_dword("checksum", optionalHeader
->CheckSum
);
269 print_subsys("Subsystem", optionalHeader
->Subsystem
);
270 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
271 print_dword("stack reserve size", optionalHeader
->SizeOfStackReserve
);
272 print_dword("stack commit size", optionalHeader
->SizeOfStackCommit
);
273 print_dword("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
274 print_dword("heap commit size", optionalHeader
->SizeOfHeapCommit
);
275 print_dword("loader flags", optionalHeader
->LoaderFlags
);
276 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
278 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
282 static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64
*image_oh
, UINT header_size
)
284 IMAGE_OPTIONAL_HEADER64 oh
;
285 const IMAGE_OPTIONAL_HEADER64
*optionalHeader
;
287 /* in case optional header is missing or partial */
288 memset(&oh
, 0, sizeof(oh
));
289 memcpy(&oh
, image_oh
, min(header_size
, sizeof(oh
)));
290 optionalHeader
= &oh
;
292 print_word("Magic", optionalHeader
->Magic
);
293 print_ver("linker version",
294 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
295 print_dword("size of code", optionalHeader
->SizeOfCode
);
296 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
297 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
298 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
299 print_dword("base of code", optionalHeader
->BaseOfCode
);
300 print_longlong("image base", optionalHeader
->ImageBase
);
301 print_dword("section align", optionalHeader
->SectionAlignment
);
302 print_dword("file align", optionalHeader
->FileAlignment
);
303 print_ver("required OS version",
304 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
305 print_ver("image version",
306 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
307 print_ver("subsystem version",
308 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
309 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
310 print_dword("size of image", optionalHeader
->SizeOfImage
);
311 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
312 print_dword("checksum", optionalHeader
->CheckSum
);
313 print_subsys("Subsystem", optionalHeader
->Subsystem
);
314 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
315 print_longlong("stack reserve size", optionalHeader
->SizeOfStackReserve
);
316 print_longlong("stack commit size", optionalHeader
->SizeOfStackCommit
);
317 print_longlong("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
318 print_longlong("heap commit size", optionalHeader
->SizeOfHeapCommit
);
319 print_dword("loader flags", optionalHeader
->LoaderFlags
);
320 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
322 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
326 void dump_optional_header(const IMAGE_OPTIONAL_HEADER32
*optionalHeader
, UINT header_size
)
328 printf("Optional Header (%s)\n", get_magic_type(optionalHeader
->Magic
));
330 switch(optionalHeader
->Magic
) {
331 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
332 dump_optional_header32(optionalHeader
, header_size
);
334 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
335 dump_optional_header64((const IMAGE_OPTIONAL_HEADER64
*)optionalHeader
, header_size
);
338 printf(" Unknown optional header magic: 0x%-4X\n", optionalHeader
->Magic
);
343 void dump_file_header(const IMAGE_FILE_HEADER
*fileHeader
)
345 printf("File Header\n");
347 printf(" Machine: %04X (%s)\n",
348 fileHeader
->Machine
, get_machine_str(fileHeader
->Machine
));
349 printf(" Number of Sections: %d\n", fileHeader
->NumberOfSections
);
350 printf(" TimeDateStamp: %08X (%s) offset %lu\n",
351 (UINT
)fileHeader
->TimeDateStamp
, get_time_str(fileHeader
->TimeDateStamp
),
352 Offset(&(fileHeader
->TimeDateStamp
)));
353 printf(" PointerToSymbolTable: %08X\n", (UINT
)fileHeader
->PointerToSymbolTable
);
354 printf(" NumberOfSymbols: %08X\n", (UINT
)fileHeader
->NumberOfSymbols
);
355 printf(" SizeOfOptionalHeader: %04X\n", (UINT
)fileHeader
->SizeOfOptionalHeader
);
356 printf(" Characteristics: %04X\n", (UINT
)fileHeader
->Characteristics
);
357 #define X(f,s) if (fileHeader->Characteristics & f) printf(" %s\n", s)
358 X(IMAGE_FILE_RELOCS_STRIPPED
, "RELOCS_STRIPPED");
359 X(IMAGE_FILE_EXECUTABLE_IMAGE
, "EXECUTABLE_IMAGE");
360 X(IMAGE_FILE_LINE_NUMS_STRIPPED
, "LINE_NUMS_STRIPPED");
361 X(IMAGE_FILE_LOCAL_SYMS_STRIPPED
, "LOCAL_SYMS_STRIPPED");
362 X(IMAGE_FILE_AGGRESIVE_WS_TRIM
, "AGGRESIVE_WS_TRIM");
363 X(IMAGE_FILE_LARGE_ADDRESS_AWARE
, "LARGE_ADDRESS_AWARE");
364 X(IMAGE_FILE_16BIT_MACHINE
, "16BIT_MACHINE");
365 X(IMAGE_FILE_BYTES_REVERSED_LO
, "BYTES_REVERSED_LO");
366 X(IMAGE_FILE_32BIT_MACHINE
, "32BIT_MACHINE");
367 X(IMAGE_FILE_DEBUG_STRIPPED
, "DEBUG_STRIPPED");
368 X(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
, "REMOVABLE_RUN_FROM_SWAP");
369 X(IMAGE_FILE_NET_RUN_FROM_SWAP
, "NET_RUN_FROM_SWAP");
370 X(IMAGE_FILE_SYSTEM
, "SYSTEM");
371 X(IMAGE_FILE_DLL
, "DLL");
372 X(IMAGE_FILE_UP_SYSTEM_ONLY
, "UP_SYSTEM_ONLY");
373 X(IMAGE_FILE_BYTES_REVERSED_HI
, "BYTES_REVERSED_HI");
378 static void dump_pe_header(void)
380 dump_file_header(&PE_nt_headers
->FileHeader
);
381 dump_optional_header((const IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
, PE_nt_headers
->FileHeader
.SizeOfOptionalHeader
);
384 void dump_section_characteristics(DWORD characteristics
, const char* sep
)
386 #define X(b,s) if (characteristics & b) printf("%s%s", sep, s)
387 /* #define IMAGE_SCN_TYPE_REG 0x00000000 - Reserved */
388 /* #define IMAGE_SCN_TYPE_DSECT 0x00000001 - Reserved */
389 /* #define IMAGE_SCN_TYPE_NOLOAD 0x00000002 - Reserved */
390 /* #define IMAGE_SCN_TYPE_GROUP 0x00000004 - Reserved */
391 /* #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - Reserved */
392 /* #define IMAGE_SCN_TYPE_COPY 0x00000010 - Reserved */
394 X(IMAGE_SCN_CNT_CODE
, "CODE");
395 X(IMAGE_SCN_CNT_INITIALIZED_DATA
, "INITIALIZED_DATA");
396 X(IMAGE_SCN_CNT_UNINITIALIZED_DATA
, "UNINITIALIZED_DATA");
398 X(IMAGE_SCN_LNK_OTHER
, "LNK_OTHER");
399 X(IMAGE_SCN_LNK_INFO
, "LNK_INFO");
400 /* #define IMAGE_SCN_TYPE_OVER 0x00000400 - Reserved */
401 X(IMAGE_SCN_LNK_REMOVE
, "LNK_REMOVE");
402 X(IMAGE_SCN_LNK_COMDAT
, "LNK_COMDAT");
404 /* 0x00002000 - Reserved */
405 /* #define IMAGE_SCN_MEM_PROTECTED 0x00004000 - Obsolete */
406 X(IMAGE_SCN_MEM_FARDATA
, "MEM_FARDATA");
408 /* #define IMAGE_SCN_MEM_SYSHEAP 0x00010000 - Obsolete */
409 X(IMAGE_SCN_MEM_PURGEABLE
, "MEM_PURGEABLE");
410 X(IMAGE_SCN_MEM_16BIT
, "MEM_16BIT");
411 X(IMAGE_SCN_MEM_LOCKED
, "MEM_LOCKED");
412 X(IMAGE_SCN_MEM_PRELOAD
, "MEM_PRELOAD");
414 switch (characteristics
& IMAGE_SCN_ALIGN_MASK
)
416 #define X2(b,s) case b: printf("%s%s", sep, s); break
417 X2(IMAGE_SCN_ALIGN_1BYTES
, "ALIGN_1BYTES");
418 X2(IMAGE_SCN_ALIGN_2BYTES
, "ALIGN_2BYTES");
419 X2(IMAGE_SCN_ALIGN_4BYTES
, "ALIGN_4BYTES");
420 X2(IMAGE_SCN_ALIGN_8BYTES
, "ALIGN_8BYTES");
421 X2(IMAGE_SCN_ALIGN_16BYTES
, "ALIGN_16BYTES");
422 X2(IMAGE_SCN_ALIGN_32BYTES
, "ALIGN_32BYTES");
423 X2(IMAGE_SCN_ALIGN_64BYTES
, "ALIGN_64BYTES");
424 X2(IMAGE_SCN_ALIGN_128BYTES
, "ALIGN_128BYTES");
425 X2(IMAGE_SCN_ALIGN_256BYTES
, "ALIGN_256BYTES");
426 X2(IMAGE_SCN_ALIGN_512BYTES
, "ALIGN_512BYTES");
427 X2(IMAGE_SCN_ALIGN_1024BYTES
, "ALIGN_1024BYTES");
428 X2(IMAGE_SCN_ALIGN_2048BYTES
, "ALIGN_2048BYTES");
429 X2(IMAGE_SCN_ALIGN_4096BYTES
, "ALIGN_4096BYTES");
430 X2(IMAGE_SCN_ALIGN_8192BYTES
, "ALIGN_8192BYTES");
434 X(IMAGE_SCN_LNK_NRELOC_OVFL
, "LNK_NRELOC_OVFL");
436 X(IMAGE_SCN_MEM_DISCARDABLE
, "MEM_DISCARDABLE");
437 X(IMAGE_SCN_MEM_NOT_CACHED
, "MEM_NOT_CACHED");
438 X(IMAGE_SCN_MEM_NOT_PAGED
, "MEM_NOT_PAGED");
439 X(IMAGE_SCN_MEM_SHARED
, "MEM_SHARED");
440 X(IMAGE_SCN_MEM_EXECUTE
, "MEM_EXECUTE");
441 X(IMAGE_SCN_MEM_READ
, "MEM_READ");
442 X(IMAGE_SCN_MEM_WRITE
, "MEM_WRITE");
446 void dump_section(const IMAGE_SECTION_HEADER
*sectHead
, const char* strtable
)
450 /* long section name ? */
451 if (strtable
&& sectHead
->Name
[0] == '/' &&
452 ((offset
= atoi((const char*)sectHead
->Name
+ 1)) < *(const DWORD
*)strtable
))
453 printf(" %.8s (%s)", sectHead
->Name
, strtable
+ offset
);
455 printf(" %-8.8s", sectHead
->Name
);
456 printf(" VirtSize: 0x%08x VirtAddr: 0x%08x\n",
457 (UINT
)sectHead
->Misc
.VirtualSize
, (UINT
)sectHead
->VirtualAddress
);
458 printf(" raw data offs: 0x%08x raw data size: 0x%08x\n",
459 (UINT
)sectHead
->PointerToRawData
, (UINT
)sectHead
->SizeOfRawData
);
460 printf(" relocation offs: 0x%08x relocations: 0x%08x\n",
461 (UINT
)sectHead
->PointerToRelocations
, (UINT
)sectHead
->NumberOfRelocations
);
462 printf(" line # offs: %-8u line #'s: %-8u\n",
463 (UINT
)sectHead
->PointerToLinenumbers
, (UINT
)sectHead
->NumberOfLinenumbers
);
464 printf(" characteristics: 0x%08x\n", (UINT
)sectHead
->Characteristics
);
466 dump_section_characteristics(sectHead
->Characteristics
, " ");
471 static void dump_sections(const void *base
, const void* addr
, unsigned num_sect
)
473 const IMAGE_SECTION_HEADER
* sectHead
= addr
;
475 const char* strtable
;
477 if (PE_nt_headers
&& PE_nt_headers
->FileHeader
.PointerToSymbolTable
&& PE_nt_headers
->FileHeader
.NumberOfSymbols
)
479 strtable
= (const char*)base
+
480 PE_nt_headers
->FileHeader
.PointerToSymbolTable
+
481 PE_nt_headers
->FileHeader
.NumberOfSymbols
* sizeof(IMAGE_SYMBOL
);
483 else strtable
= NULL
;
485 printf("Section Table\n");
486 for (i
= 0; i
< num_sect
; i
++, sectHead
++)
488 dump_section(sectHead
, strtable
);
490 if (globals
.do_dump_rawdata
)
492 dump_data((const unsigned char *)base
+ sectHead
->PointerToRawData
, sectHead
->SizeOfRawData
, " " );
498 static char *get_str( char *buffer
, unsigned int rva
, unsigned int len
)
500 const WCHAR
*wstr
= PRD( rva
, len
);
503 len
/= sizeof(WCHAR
);
504 while (len
--) *buffer
++ = *wstr
++;
509 static void dump_section_apiset(void)
511 const IMAGE_SECTION_HEADER
*sect
= IMAGE_FIRST_SECTION(PE_nt_headers
);
512 const UINT
*ptr
, *entry
, *value
, *hash
;
513 unsigned int i
, j
, count
, val_count
, rva
;
516 for (i
= 0; i
< PE_nt_headers
->FileHeader
.NumberOfSections
; i
++, sect
++)
518 if (strncmp( (const char *)sect
->Name
, ".apiset", 8 )) continue;
519 rva
= sect
->PointerToRawData
;
520 ptr
= PRD( rva
, sizeof(*ptr
) );
521 printf( "ApiSet section:\n" );
522 switch (ptr
[0]) /* version */
525 printf( " Version: %u\n", ptr
[0] );
526 printf( " Count: %08x\n", ptr
[1] );
528 if (!(entry
= PRD( rva
+ 2 * sizeof(*ptr
), count
* 3 * sizeof(*entry
) ))) break;
529 for (i
= 0; i
< count
; i
++, entry
+= 3)
531 printf( " %s ->", get_str( buffer
, rva
+ entry
[0], entry
[1] ));
532 if (!(value
= PRD( rva
+ entry
[2], sizeof(*value
) ))) break;
533 val_count
= *value
++;
534 for (j
= 0; j
< val_count
; j
++, value
+= 4)
537 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[0], value
[1] ));
538 printf( "%s", get_str( buffer
, rva
+ value
[2], value
[3] ));
544 printf( " Version: %u\n", ptr
[0] );
545 printf( " Size: %08x\n", ptr
[1] );
546 printf( " Flags: %08x\n", ptr
[2] );
547 printf( " Count: %08x\n", ptr
[3] );
549 if (!(entry
= PRD( rva
+ 4 * sizeof(*ptr
), count
* 6 * sizeof(*entry
) ))) break;
550 for (i
= 0; i
< count
; i
++, entry
+= 6)
552 printf( " %08x %s ->", entry
[0], get_str( buffer
, rva
+ entry
[1], entry
[2] ));
553 if (!(value
= PRD( rva
+ entry
[5], sizeof(*value
) ))) break;
555 val_count
= *value
++;
556 for (j
= 0; j
< val_count
; j
++, value
+= 5)
559 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[1], value
[2] ));
560 printf( "%s", get_str( buffer
, rva
+ value
[3], value
[4] ));
566 printf( " Version: %u\n", ptr
[0] );
567 printf( " Size: %08x\n", ptr
[1] );
568 printf( " Flags: %08x\n", ptr
[2] );
569 printf( " Count: %08x\n", ptr
[3] );
570 printf( " EntryOffset: %08x\n", ptr
[4] );
571 printf( " HashOffset: %08x\n", ptr
[5] );
572 printf( " HashFactor: %08x\n", ptr
[6] );
574 if (!(entry
= PRD( rva
+ ptr
[4], count
* 6 * sizeof(*entry
) ))) break;
575 for (i
= 0; i
< count
; i
++, entry
+= 6)
577 printf( " %08x %s ->", entry
[0], get_str( buffer
, rva
+ entry
[1], entry
[2] ));
578 if (!(value
= PRD( rva
+ entry
[4], entry
[5] * 5 * sizeof(*value
) ))) break;
579 for (j
= 0; j
< entry
[5]; j
++, value
+= 5)
582 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[1], value
[2] ));
583 printf( "%s", get_str( buffer
, rva
+ value
[3], value
[4] ));
587 printf( " Hash table:\n" );
588 if (!(hash
= PRD( rva
+ ptr
[5], count
* 2 * sizeof(*hash
) ))) break;
589 for (i
= 0; i
< count
; i
++, hash
+= 2)
591 entry
= PRD( rva
+ ptr
[4] + hash
[1] * 6 * sizeof(*entry
), 6 * sizeof(*entry
) );
592 printf( " %08x -> %s\n", hash
[0], get_str( buffer
, rva
+ entry
[1], entry
[3] ));
596 printf( "*** Unknown version %u\n", ptr
[0] );
603 static void dump_dir_exported_functions(void)
605 unsigned int size
= 0;
606 const IMAGE_EXPORT_DIRECTORY
*exportDir
= get_dir_and_size(IMAGE_FILE_EXPORT_DIRECTORY
, &size
);
612 if (!exportDir
) return;
614 printf("Exports table:\n");
616 printf(" Name: %s\n", (const char*)RVA(exportDir
->Name
, sizeof(DWORD
)));
617 printf(" Characteristics: %08x\n", (UINT
)exportDir
->Characteristics
);
618 printf(" TimeDateStamp: %08X %s\n",
619 (UINT
)exportDir
->TimeDateStamp
, get_time_str(exportDir
->TimeDateStamp
));
620 printf(" Version: %u.%02u\n", exportDir
->MajorVersion
, exportDir
->MinorVersion
);
621 printf(" Ordinal base: %u\n", (UINT
)exportDir
->Base
);
622 printf(" # of functions: %u\n", (UINT
)exportDir
->NumberOfFunctions
);
623 printf(" # of Names: %u\n", (UINT
)exportDir
->NumberOfNames
);
624 printf("Addresses of functions: %08X\n", (UINT
)exportDir
->AddressOfFunctions
);
625 printf("Addresses of name ordinals: %08X\n", (UINT
)exportDir
->AddressOfNameOrdinals
);
626 printf("Addresses of names: %08X\n", (UINT
)exportDir
->AddressOfNames
);
628 printf(" Entry Pt Ordn Name\n");
630 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
631 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
632 pName
= RVA(exportDir
->AddressOfNames
, exportDir
->NumberOfNames
* sizeof(DWORD
));
633 pOrdl
= RVA(exportDir
->AddressOfNameOrdinals
, exportDir
->NumberOfNames
* sizeof(WORD
));
635 funcs
= calloc( exportDir
->NumberOfFunctions
, sizeof(*funcs
) );
636 if (!funcs
) fatal("no memory");
638 for (i
= 0; i
< exportDir
->NumberOfNames
; i
++) funcs
[pOrdl
[i
]] = pName
[i
];
640 for (i
= 0; i
< exportDir
->NumberOfFunctions
; i
++)
642 if (!pFunc
[i
]) continue;
643 printf(" %08X %5u ", pFunc
[i
], (UINT
)exportDir
->Base
+ i
);
645 printf("%s", get_symbol_str((const char*)RVA(funcs
[i
], sizeof(DWORD
))));
647 printf("<by ordinal>");
649 /* check for forwarded function */
650 if ((const char *)RVA(pFunc
[i
],1) >= (const char *)exportDir
&&
651 (const char *)RVA(pFunc
[i
],1) < (const char *)exportDir
+ size
)
652 printf(" (-> %s)", (const char *)RVA(pFunc
[i
],1));
660 struct runtime_function_x86_64
667 struct runtime_function_armnt
674 UINT FunctionLength
: 11;
681 UINT StackAdjust
: 10;
686 struct runtime_function_arm64
695 UINT FunctionLength
: 11;
707 struct runtime_function_x86_64 chain
;
718 struct unwind_info_x86_64
725 BYTE frame_offset
: 4;
726 struct opcode opcodes
[1]; /* count entries */
727 /* followed by union handler_data */
730 struct unwind_info_armnt
732 UINT function_length
: 18;
741 struct unwind_info_ext_armnt
748 struct unwind_info_epilogue_armnt
756 #define UWOP_PUSH_NONVOL 0
757 #define UWOP_ALLOC_LARGE 1
758 #define UWOP_ALLOC_SMALL 2
759 #define UWOP_SET_FPREG 3
760 #define UWOP_SAVE_NONVOL 4
761 #define UWOP_SAVE_NONVOL_FAR 5
762 #define UWOP_SAVE_XMM128 8
763 #define UWOP_SAVE_XMM128_FAR 9
764 #define UWOP_PUSH_MACHFRAME 10
766 #define UNW_FLAG_EHANDLER 1
767 #define UNW_FLAG_UHANDLER 2
768 #define UNW_FLAG_CHAININFO 4
770 static void dump_x86_64_unwind_info( const struct runtime_function_x86_64
*function
)
772 static const char * const reg_names
[16] =
773 { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
774 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" };
776 const union handler_data
*handler_data
;
777 const struct unwind_info_x86_64
*info
;
778 unsigned int i
, count
;
780 printf( "\nFunction %08x-%08x:\n", function
->BeginAddress
, function
->EndAddress
);
781 if (function
->UnwindData
& 1)
783 const struct runtime_function_x86_64
*next
= RVA( function
->UnwindData
& ~1, sizeof(*next
) );
784 printf( " -> function %08x-%08x\n", next
->BeginAddress
, next
->EndAddress
);
787 info
= RVA( function
->UnwindData
, sizeof(*info
) );
789 printf( " unwind info at %08x\n", function
->UnwindData
);
790 if (info
->version
!= 1)
792 printf( " *** unknown version %u\n", info
->version
);
795 printf( " flags %x", info
->flags
);
796 if (info
->flags
& UNW_FLAG_EHANDLER
) printf( " EHANDLER" );
797 if (info
->flags
& UNW_FLAG_UHANDLER
) printf( " UHANDLER" );
798 if (info
->flags
& UNW_FLAG_CHAININFO
) printf( " CHAININFO" );
799 printf( "\n prolog 0x%x bytes\n", info
->prolog
);
802 printf( " frame register %s offset 0x%x(%%rsp)\n",
803 reg_names
[info
->frame_reg
], info
->frame_offset
* 16 );
805 for (i
= 0; i
< info
->count
; i
++)
807 printf( " 0x%02x: ", info
->opcodes
[i
].offset
);
808 switch (info
->opcodes
[i
].code
)
810 case UWOP_PUSH_NONVOL
:
811 printf( "push %%%s\n", reg_names
[info
->opcodes
[i
].info
] );
813 case UWOP_ALLOC_LARGE
:
814 if (info
->opcodes
[i
].info
)
816 count
= *(const UINT
*)&info
->opcodes
[i
+1];
821 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 8;
824 printf( "sub $0x%x,%%rsp\n", count
);
826 case UWOP_ALLOC_SMALL
:
827 count
= (info
->opcodes
[i
].info
+ 1) * 8;
828 printf( "sub $0x%x,%%rsp\n", count
);
831 printf( "lea 0x%x(%%rsp),%s\n",
832 info
->frame_offset
* 16, reg_names
[info
->frame_reg
] );
834 case UWOP_SAVE_NONVOL
:
835 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 8;
836 printf( "mov %%%s,0x%x(%%rsp)\n", reg_names
[info
->opcodes
[i
].info
], count
);
839 case UWOP_SAVE_NONVOL_FAR
:
840 count
= *(const UINT
*)&info
->opcodes
[i
+1];
841 printf( "mov %%%s,0x%x(%%rsp)\n", reg_names
[info
->opcodes
[i
].info
], count
);
844 case UWOP_SAVE_XMM128
:
845 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 16;
846 printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info
->opcodes
[i
].info
, count
);
849 case UWOP_SAVE_XMM128_FAR
:
850 count
= *(const UINT
*)&info
->opcodes
[i
+1];
851 printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info
->opcodes
[i
].info
, count
);
854 case UWOP_PUSH_MACHFRAME
:
855 printf( "PUSH_MACHFRAME %u\n", info
->opcodes
[i
].info
);
858 printf( "*** unknown code %u\n", info
->opcodes
[i
].code
);
863 handler_data
= (const union handler_data
*)&info
->opcodes
[(info
->count
+ 1) & ~1];
864 if (info
->flags
& UNW_FLAG_CHAININFO
)
866 printf( " -> function %08x-%08x\n",
867 handler_data
->chain
.BeginAddress
, handler_data
->chain
.EndAddress
);
870 if (info
->flags
& (UNW_FLAG_EHANDLER
| UNW_FLAG_UHANDLER
))
871 printf( " handler %08x data at %08x\n", handler_data
->handler
,
872 (UINT
)(function
->UnwindData
+ (const char *)(&handler_data
->handler
+ 1) - (const char *)info
));
875 static const BYTE armnt_code_lengths
[256] =
877 /* 00 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
878 /* 20 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
879 /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
880 /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
881 /* 80 */ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
882 /* a0 */ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
883 /* c0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
884 /* e0 */ 1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,3,4,1,1,1,1,1
887 static void dump_armnt_unwind_info( const struct runtime_function_armnt
*fnc
)
889 const struct unwind_info_armnt
*info
;
890 const struct unwind_info_ext_armnt
*infoex
;
891 const struct unwind_info_epilogue_armnt
*infoepi
;
893 WORD i
, count
= 0, words
= 0;
897 char intregs
[32] = {0}, intregspop
[32] = {0}, vfpregs
[32] = {0};
898 WORD pf
= 0, ef
= 0, fpoffset
= 0, stack
= fnc
->StackAdjust
;
900 printf( "\nFunction %08x-%08x:\n", fnc
->BeginAddress
& ~1,
901 (fnc
->BeginAddress
& ~1) + fnc
->FunctionLength
* 2 );
902 printf( " Flag %x\n", fnc
->Flag
);
903 printf( " FunctionLength %x\n", fnc
->FunctionLength
);
904 printf( " Ret %x\n", fnc
->Ret
);
905 printf( " H %x\n", fnc
->H
);
906 printf( " Reg %x\n", fnc
->Reg
);
907 printf( " R %x\n", fnc
->R
);
908 printf( " L %x\n", fnc
->L
);
909 printf( " C %x\n", fnc
->C
);
910 printf( " StackAdjust %x\n", fnc
->StackAdjust
);
912 if (fnc
->StackAdjust
>= 0x03f4)
914 pf
= fnc
->StackAdjust
& 0x04;
915 ef
= fnc
->StackAdjust
& 0x08;
916 stack
= (fnc
->StackAdjust
& 3) + 1;
921 int first
= 4, last
= fnc
->Reg
+ 4;
924 first
= (~fnc
->StackAdjust
) & 3;
929 sprintf(intregs
, "r%u", first
);
931 sprintf(intregs
, "r%u-r%u", first
, last
);
932 fpoffset
= last
+ 1 - first
;
937 int first
= 4, last
= fnc
->Reg
+ 4;
940 first
= (~fnc
->StackAdjust
) & 3;
945 sprintf(intregspop
, "r%u", first
);
947 sprintf(intregspop
, "r%u-r%u", first
, last
);
953 strcat(intregs
, ", ");
955 strcat(intregspop
, ", ");
956 strcat(intregs
, "r11");
957 strcat(intregspop
, "r11");
962 strcat(intregs
, ", ");
963 strcat(intregs
, "lr");
965 if (intregspop
[0] && (fnc
->Ret
!= 0 || !fnc
->H
))
966 strcat(intregspop
, ", ");
968 strcat(intregspop
, "lr");
970 strcat(intregspop
, "pc");
976 sprintf(vfpregs
, "d8-d%u", fnc
->Reg
+ 8);
978 strcpy(vfpregs
, "d8");
981 if (fnc
->Flag
== 1) {
983 printf( " Unwind Code\tpush {r0-r3}\n" );
986 printf( " Unwind Code\tpush {%s}\n", intregs
);
988 if (fnc
->C
&& fpoffset
== 0)
989 printf( " Unwind Code\tmov r11, sp\n" );
991 printf( " Unwind Code\tadd r11, sp, #%d\n", fpoffset
* 4 );
993 if (fnc
->R
&& fnc
->Reg
!= 0x07)
994 printf( " Unwind Code\tvpush {%s}\n", vfpregs
);
997 printf( " Unwind Code\tsub sp, sp, #%d\n", stack
* 4 );
1002 printf( "Epilogue:\n" );
1005 printf( " Unwind Code\tadd sp, sp, #%d\n", stack
* 4 );
1007 if (fnc
->R
&& fnc
->Reg
!= 0x07)
1008 printf( " Unwind Code\tvpop {%s}\n", vfpregs
);
1011 printf( " Unwind Code\tpop {%s}\n", intregspop
);
1013 if (fnc
->H
&& !(fnc
->L
&& fnc
->Ret
== 0))
1014 printf( " Unwind Code\tadd sp, sp, #16\n" );
1015 else if (fnc
->H
&& (fnc
->L
&& fnc
->Ret
== 0))
1016 printf( " Unwind Code\tldr pc, [sp], #20\n" );
1019 printf( " Unwind Code\tbx <reg>\n" );
1020 else if (fnc
->Ret
== 2)
1021 printf( " Unwind Code\tb <address>\n" );
1026 info
= RVA( fnc
->UnwindData
, sizeof(*info
) );
1027 rva
= fnc
->UnwindData
+ sizeof(*info
);
1028 count
= info
->count
;
1029 words
= info
->words
;
1031 printf( "\nFunction %08x-%08x:\n", fnc
->BeginAddress
& ~1,
1032 (fnc
->BeginAddress
& ~1) + info
->function_length
* 2 );
1033 printf( " unwind info at %08x\n", fnc
->UnwindData
);
1034 printf( " Flag %x\n", fnc
->Flag
);
1035 printf( " FunctionLength %x\n", info
->function_length
);
1036 printf( " Version %x\n", info
->version
);
1037 printf( " X %x\n", info
->x
);
1038 printf( " E %x\n", info
->e
);
1039 printf( " F %x\n", info
->f
);
1040 printf( " Count %x\n", count
);
1041 printf( " Words %x\n", words
);
1043 if (!info
->count
&& !info
->words
)
1045 infoex
= RVA( rva
, sizeof(*infoex
) );
1046 rva
= rva
+ sizeof(*infoex
);
1047 count
= infoex
->excount
;
1048 words
= infoex
->exwords
;
1049 printf( " ExtCount %x\n", count
);
1050 printf( " ExtWords %x\n", words
);
1055 infoepi
= RVA( rva
, count
* sizeof(*infoepi
) );
1056 rva
= rva
+ count
* sizeof(*infoepi
);
1058 for (i
= 0; i
< count
; i
++)
1060 printf( " Epilogue Scope %x\n", i
);
1061 printf( " Offset %x\n", infoepi
[i
].offset
);
1062 printf( " Reserved %x\n", infoepi
[i
].res
);
1063 printf( " Condition %x\n", infoepi
[i
].cond
);
1064 printf( " Index %x\n", infoepi
[i
].index
);
1072 const unsigned int *codes
;
1074 BOOL inepilogue
= FALSE
;
1076 codes
= RVA( rva
, words
* sizeof(*codes
) );
1077 rva
= rva
+ words
* sizeof(*codes
);
1078 bytes
= (BYTE
*)codes
;
1080 for (b
= 0; b
< words
* sizeof(*codes
); b
++)
1082 BYTE code
= bytes
[b
];
1083 BYTE len
= armnt_code_lengths
[code
];
1085 if (info
->e
&& b
== count
)
1087 printf( "Epilogue:\n" );
1090 else if (!info
->e
&& infoepi
)
1092 for (i
= 0; i
< count
; i
++)
1093 if (b
== infoepi
[i
].index
)
1095 printf( "Epilogue from Scope %x at %08x:\n", i
,
1096 (fnc
->BeginAddress
& ~1) + infoepi
[i
].offset
* 2 );
1101 printf( " Unwind Code");
1102 for (i
= 0; i
< len
; i
++)
1103 printf( " %02x", bytes
[b
+i
] );
1108 else if (code
<= 0x7f)
1109 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", code
* 4 );
1110 else if (code
<= 0xbf)
1114 BYTE excodes
= bytes
[++b
];
1116 excode
= (code
<< 8) | excodes
;
1117 printf( "%s {", inepilogue
? "pop" : "push" );
1119 for (f
= 0; f
<= 12; f
++)
1121 if ((excode
>> f
) & 1)
1123 printf( "%sr%u", first
? "" : ", ", f
);
1128 if (excode
& 0x2000)
1129 printf( "%s%s", first
? "" : ", ", inepilogue
? "pc" : "lr" );
1133 else if (code
<= 0xcf)
1135 printf( "mov sp, r%u\n", code
& 0x0f );
1137 printf( "mov r%u, sp\n", code
& 0x0f );
1138 else if (code
<= 0xd7)
1140 printf( "pop {r4-r%u%s}\n", (code
& 0x03) + 4, (code
& 0x04) ? ", pc" : "" );
1142 printf( "push {r4-r%u%s}\n", (code
& 0x03) + 4, (code
& 0x04) ? ", lr" : "" );
1143 else if (code
<= 0xdf)
1145 printf( "pop {r4-r%u%s}\n", (code
& 0x03) + 8, (code
& 0x04) ? ", pc" : "" );
1147 printf( "push {r4-r%u%s}\n", (code
& 0x03) + 8, (code
& 0x04) ? ", lr" : "" );
1148 else if (code
<= 0xe7)
1149 printf( "%s {d8-d%u}\n", inepilogue
? "vpop" : "vpush", (code
& 0x07) + 8 );
1150 else if (code
<= 0xeb)
1153 BYTE excodes
= bytes
[++b
];
1155 excode
= (code
<< 8) | excodes
;
1156 printf( "%s sp, sp, #%u\n", inepilogue
? "addw" : "subw", (excode
& 0x03ff) *4 );
1158 else if (code
<= 0xed)
1162 BYTE excodes
= bytes
[++b
];
1164 excode
= (code
<< 8) | excodes
;
1165 printf( "%s {", inepilogue
? "pop" : "push" );
1167 for (f
= 0; f
< 8; f
++)
1169 if ((excode
>> f
) & 1)
1171 printf( "%sr%u", first
? "" : ", ", f
);
1176 if (excode
& 0x0100)
1177 printf( "%s%s", first
? "" : ", ", inepilogue
? "pc" : "lr" );
1181 else if (code
== 0xee)
1182 printf( "unknown 16\n" );
1183 else if (code
== 0xef)
1186 BYTE excodes
= bytes
[++b
];
1188 if (excodes
<= 0x0f)
1190 excode
= (code
<< 8) | excodes
;
1192 printf( "ldr lr, [sp], #%u\n", (excode
& 0x0f) * 4 );
1194 printf( "str lr, [sp, #-%u]!\n", (excode
& 0x0f) * 4 );
1197 printf( "unknown 32\n" );
1199 else if (code
<= 0xf4)
1200 printf( "unknown\n" );
1201 else if (code
<= 0xf6)
1203 WORD excode
, offset
= (code
== 0xf6) ? 16 : 0;
1204 BYTE excodes
= bytes
[++b
];
1206 excode
= (code
<< 8) | excodes
;
1207 printf( "%s {d%u-d%u}\n", inepilogue
? "vpop" : "vpush",
1208 ((excode
& 0x00f0) >> 4) + offset
, (excode
& 0x0f) + offset
);
1210 else if (code
<= 0xf7)
1212 unsigned int excode
;
1215 excodes
[0] = bytes
[++b
];
1216 excodes
[1] = bytes
[++b
];
1217 excode
= (code
<< 16) | (excodes
[0] << 8) | excodes
[1];
1218 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffff) *4 );
1220 else if (code
<= 0xf8)
1222 unsigned int excode
;
1225 excodes
[0] = bytes
[++b
];
1226 excodes
[1] = bytes
[++b
];
1227 excodes
[2] = bytes
[++b
];
1228 excode
= (code
<< 24) | (excodes
[0] << 16) | (excodes
[1] << 8) | excodes
[2];
1229 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffffff) * 4 );
1231 else if (code
<= 0xf9)
1233 unsigned int excode
;
1236 excodes
[0] = bytes
[++b
];
1237 excodes
[1] = bytes
[++b
];
1238 excode
= (code
<< 16) | (excodes
[0] << 8) | excodes
[1];
1239 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffff) *4 );
1241 else if (code
<= 0xfa)
1243 unsigned int excode
;
1246 excodes
[0] = bytes
[++b
];
1247 excodes
[1] = bytes
[++b
];
1248 excodes
[2] = bytes
[++b
];
1249 excode
= (code
<< 24) | (excodes
[0] << 16) | (excodes
[1] << 8) | excodes
[2];
1250 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffffff) * 4 );
1252 else if (code
<= 0xfb)
1254 else if (code
<= 0xfc)
1255 printf( "nop.w\n" );
1256 else if (code
<= 0xfd)
1258 printf( "(end) nop\n" );
1261 else if (code
<= 0xfe)
1263 printf( "(end) nop.w\n" );
1276 const unsigned int *handler
;
1278 handler
= RVA( rva
, sizeof(*handler
) );
1279 rva
= rva
+ sizeof(*handler
);
1281 printf( " handler %08x data at %08x\n", *handler
, rva
);
1285 struct unwind_info_arm64
1287 UINT function_length
: 18;
1295 struct unwind_info_ext_arm64
1302 struct unwind_info_epilog_arm64
1309 static const BYTE code_lengths
[256] =
1311 /* 00 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1312 /* 20 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1313 /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1314 /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1315 /* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1316 /* a0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1317 /* c0 */ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
1318 /* e0 */ 4,1,2,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1321 static void dump_arm64_codes( const BYTE
*ptr
, unsigned int count
)
1325 for (i
= 0; i
< count
; i
+= code_lengths
[ptr
[i
]])
1327 BYTE len
= code_lengths
[ptr
[i
]];
1328 unsigned int val
= ptr
[i
];
1329 if (len
== 2) val
= ptr
[i
] * 0x100 + ptr
[i
+1];
1330 else if (len
== 4) val
= ptr
[i
] * 0x1000000 + ptr
[i
+1] * 0x10000 + ptr
[i
+2] * 0x100 + ptr
[i
+3];
1332 printf( " %04x: ", i
);
1333 for (j
= 0; j
< 4; j
++)
1334 if (j
< len
) printf( "%02x ", ptr
[i
+j
] );
1337 if (ptr
[i
] < 0x20) /* alloc_s */
1339 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0x1f) );
1341 else if (ptr
[i
] < 0x40) /* save_r19r20_x */
1343 printf( "stp r19,r20,[sp,-#%#x]!\n", 8 * (val
& 0x1f) );
1345 else if (ptr
[i
] < 0x80) /* save_fplr */
1347 printf( "stp r29,lr,[sp,#%#x]\n", 8 * (val
& 0x3f) );
1349 else if (ptr
[i
] < 0xc0) /* save_fplr_x */
1351 printf( "stp r29,lr,[sp,-#%#x]!\n", 8 * (val
& 0x3f) + 8 );
1353 else if (ptr
[i
] < 0xc8) /* alloc_m */
1355 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0x7ff) );
1357 else if (ptr
[i
] < 0xcc) /* save_regp */
1359 int reg
= 19 + ((val
>> 6) & 0xf);
1360 printf( "stp r%u,r%u,[sp,#%#x]\n", reg
, reg
+ 1, 8 * (val
& 0x3f) );
1362 else if (ptr
[i
] < 0xd0) /* save_regp_x */
1364 int reg
= 19 + ((val
>> 6) & 0xf);
1365 printf( "stp r%u,r%u,[sp,-#%#x]!\n", reg
, reg
+ 1, 8 * (val
& 0x3f) + 8 );
1367 else if (ptr
[i
] < 0xd4) /* save_reg */
1369 int reg
= 19 + ((val
>> 6) & 0xf);
1370 printf( "str r%u,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1372 else if (ptr
[i
] < 0xd6) /* save_reg_x */
1374 int reg
= 19 + ((val
>> 5) & 0xf);
1375 printf( "str r%u,[sp,-#%#x]!\n", reg
, 8 * (val
& 0x1f) + 8 );
1377 else if (ptr
[i
] < 0xd8) /* save_lrpair */
1379 int reg
= 19 + 2 * ((val
>> 6) & 0x7);
1380 printf( "stp r%u,lr,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1382 else if (ptr
[i
] < 0xda) /* save_fregp */
1384 int reg
= 8 + ((val
>> 6) & 0x7);
1385 printf( "stp d%u,d%u,[sp,#%#x]\n", reg
, reg
+ 1, 8 * (val
& 0x3f) );
1387 else if (ptr
[i
] < 0xdc) /* save_fregp_x */
1389 int reg
= 8 + ((val
>> 6) & 0x7);
1390 printf( "stp d%u,d%u,[sp,-#%#x]!\n", reg
, reg
+ 1, 8 * (val
& 0x3f) + 8 );
1392 else if (ptr
[i
] < 0xde) /* save_freg */
1394 int reg
= 8 + ((val
>> 6) & 0x7);
1395 printf( "str d%u,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1397 else if (ptr
[i
] == 0xde) /* save_freg_x */
1399 int reg
= 8 + ((val
>> 5) & 0x7);
1400 printf( "str d%u,[sp,-#%#x]!\n", reg
, 8 * (val
& 0x3f) + 8 );
1402 else if (ptr
[i
] == 0xe0) /* alloc_l */
1404 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0xffffff) );
1406 else if (ptr
[i
] == 0xe1) /* set_fp */
1408 printf( "mov x29,sp\n" );
1410 else if (ptr
[i
] == 0xe2) /* add_fp */
1412 printf( "add x29,sp,#%#x\n", 8 * (val
& 0xff) );
1414 else if (ptr
[i
] == 0xe3) /* nop */
1418 else if (ptr
[i
] == 0xe4) /* end */
1422 else if (ptr
[i
] == 0xe5) /* end_c */
1424 printf( "end_c\n" );
1426 else if (ptr
[i
] == 0xe6) /* save_next */
1428 printf( "save_next\n" );
1430 else if (ptr
[i
] == 0xe7) /* arithmetic */
1432 switch ((val
>> 4) & 0x0f)
1434 case 0: printf( "add lr,lr,x28\n" ); break;
1435 case 1: printf( "add lr,lr,sp\n" ); break;
1436 case 2: printf( "sub lr,lr,x28\n" ); break;
1437 case 3: printf( "sub lr,lr,sp\n" ); break;
1438 case 4: printf( "eor lr,lr,x28\n" ); break;
1439 case 5: printf( "eor lr,lr,sp\n" ); break;
1440 case 6: printf( "rol lr,lr,neg x28\n" ); break;
1441 case 8: printf( "ror lr,lr,x28\n" ); break;
1442 case 9: printf( "ror lr,lr,sp\n" ); break;
1443 default:printf( "unknown op\n" ); break;
1446 else if (ptr
[i
] == 0xe8) /* MSFT_OP_TRAP_FRAME */
1448 printf( "MSFT_OP_TRAP_FRAME\n" );
1450 else if (ptr
[i
] == 0xe9) /* MSFT_OP_MACHINE_FRAME */
1452 printf( "MSFT_OP_MACHINE_FRAME\n" );
1454 else if (ptr
[i
] == 0xea) /* MSFT_OP_CONTEXT */
1456 printf( "MSFT_OP_CONTEXT\n" );
1458 else if (ptr
[i
] == 0xec) /* MSFT_OP_CLEAR_UNWOUND_TO_CALL */
1460 printf( "MSFT_OP_CLEAR_UNWOUND_TO_CALL\n" );
1462 else printf( "??\n");
1466 static void dump_arm64_packed_info( const struct runtime_function_arm64
*func
)
1468 int i
, pos
= 0, intsz
= func
->RegI
* 8, fpsz
= func
->RegF
* 8, savesz
, locsz
;
1470 if (func
->CR
== 1) intsz
+= 8;
1471 if (func
->RegF
) fpsz
+= 8;
1473 savesz
= ((intsz
+ fpsz
+ 8 * 8 * func
->H
) + 0xf) & ~0xf;
1474 locsz
= func
->FrameSize
* 16 - savesz
;
1479 printf( " %04x: mov x29,sp\n", pos
++ );
1482 printf( " %04x: stp x29,lr,[sp,-#%#x]!\n", pos
++, locsz
);
1485 printf( " %04x: stp x29,lr,[sp,0]\n", pos
++ );
1491 printf( " %04x: sub sp,sp,#%#x\n", pos
++, locsz
);
1495 printf( " %04x: sub sp,sp,#%#x\n", pos
++, locsz
- 4080 );
1496 printf( " %04x: sub sp,sp,#%#x\n", pos
++, 4080 );
1503 printf( " %04x: stp x6,x7,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 48 );
1504 printf( " %04x: stp x4,x5,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 32 );
1505 printf( " %04x: stp x2,x3,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 16 );
1506 printf( " %04x: stp x0,x1,[sp,#%#x]\n", pos
++, intsz
+ fpsz
);
1511 if (func
->RegF
% 2 == 0)
1512 printf( " %04x: str d%u,[sp,#%#x]\n", pos
++, 8 + func
->RegF
, intsz
+ fpsz
- 8 );
1513 for (i
= (func
->RegF
- 1)/ 2; i
>= 0; i
--)
1516 printf( " %04x: stp d8,d9,[sp,-#%#x]!\n", pos
++, savesz
);
1518 printf( " %04x: stp d%u,d%u,[sp,#%#x]\n", pos
++, 8 + 2 * i
, 9 + 2 * i
, intsz
+ 16 * i
);
1526 printf( " %04x: str lr,[sp,-#%#x]!\n", pos
++, savesz
);
1530 printf( " %04x: stp x19,lr,[sp,-#%#x]!\n", pos
++, savesz
);
1532 printf( " %04x: str x19,[sp,-#%#x]!\n", pos
++, savesz
);
1538 printf( " %04x: stp x%u,lr,[sp,#%#x]\n", pos
++, 18 + func
->RegI
, 8 * func
->RegI
- 8 );
1540 printf( " %04x: str x%u,[sp,#%#x]\n", pos
++, 18 + func
->RegI
, 8 * func
->RegI
- 8 );
1542 else if (func
->CR
== 1)
1543 printf( " %04x: str lr,[sp,#%#x]\n", pos
++, intsz
- 8 );
1545 for (i
= func
->RegI
/ 2 - 1; i
>= 0; i
--)
1547 printf( " %04x: stp x%u,x%u,[sp,#%#x]\n", pos
++, 19 + 2 * i
, 20 + 2 * i
, 16 * i
);
1549 printf( " %04x: stp x19,x20,[sp,-#%#x]!\n", pos
++, savesz
);
1552 printf( " %04x: end\n", pos
);
1555 static void dump_arm64_unwind_info( const struct runtime_function_arm64
*func
)
1557 const struct unwind_info_arm64
*info
;
1558 const struct unwind_info_ext_arm64
*infoex
;
1559 const struct unwind_info_epilog_arm64
*infoepi
;
1561 unsigned int i
, rva
, codes
, epilogs
;
1565 printf( "\nFunction %08x-%08x:\n", func
->BeginAddress
,
1566 func
->BeginAddress
+ func
->FunctionLength
* 4 );
1567 printf( " len=%#x flag=%x regF=%u regI=%u H=%u CR=%u frame=%x\n",
1568 func
->FunctionLength
, func
->Flag
, func
->RegF
, func
->RegI
,
1569 func
->H
, func
->CR
, func
->FrameSize
);
1570 dump_arm64_packed_info( func
);
1574 rva
= func
->UnwindData
;
1575 info
= RVA( rva
, sizeof(*info
) );
1576 rva
+= sizeof(*info
);
1577 epilogs
= info
->epilog
;
1578 codes
= info
->codes
;
1582 infoex
= RVA( rva
, sizeof(*infoex
) );
1583 rva
= rva
+ sizeof(*infoex
);
1584 codes
= infoex
->codes
;
1585 epilogs
= infoex
->epilog
;
1587 printf( "\nFunction %08x-%08x:\n",
1588 func
->BeginAddress
, func
->BeginAddress
+ info
->function_length
* 4 );
1589 printf( " len=%#x ver=%u X=%u E=%u epilogs=%u codes=%u\n",
1590 info
->function_length
, info
->version
, info
->x
, info
->e
, epilogs
, codes
* 4 );
1593 printf( " epilog 0: code=%04x\n", info
->epilog
);
1597 infoepi
= RVA( rva
, sizeof(*infoepi
) * epilogs
);
1598 rva
+= sizeof(*infoepi
) * epilogs
;
1599 for (i
= 0; i
< epilogs
; i
++)
1600 printf( " epilog %u: pc=%08x code=%04x\n", i
,
1601 func
->BeginAddress
+ infoepi
[i
].offset
* 4, infoepi
[i
].index
);
1603 ptr
= RVA( rva
, codes
* 4);
1607 const UINT
*handler
= RVA( rva
, sizeof(*handler
) );
1608 rva
+= sizeof(*handler
);
1609 printf( " handler: %08x data %08x\n", *handler
, rva
);
1611 dump_arm64_codes( ptr
, codes
* 4 );
1614 static void dump_dir_exceptions(void)
1616 unsigned int i
, size
= 0;
1617 const void *funcs
= get_dir_and_size(IMAGE_FILE_EXCEPTION_DIRECTORY
, &size
);
1618 const IMAGE_FILE_HEADER
*file_header
= &PE_nt_headers
->FileHeader
;
1622 switch (file_header
->Machine
)
1624 case IMAGE_FILE_MACHINE_AMD64
:
1625 size
/= sizeof(struct runtime_function_x86_64
);
1626 printf( "Exception info (%u functions):\n", size
);
1627 for (i
= 0; i
< size
; i
++) dump_x86_64_unwind_info( (struct runtime_function_x86_64
*)funcs
+ i
);
1629 case IMAGE_FILE_MACHINE_ARMNT
:
1630 size
/= sizeof(struct runtime_function_armnt
);
1631 printf( "Exception info (%u functions):\n", size
);
1632 for (i
= 0; i
< size
; i
++) dump_armnt_unwind_info( (struct runtime_function_armnt
*)funcs
+ i
);
1634 case IMAGE_FILE_MACHINE_ARM64
:
1635 size
/= sizeof(struct runtime_function_arm64
);
1636 printf( "Exception info (%u functions):\n", size
);
1637 for (i
= 0; i
< size
; i
++) dump_arm64_unwind_info( (struct runtime_function_arm64
*)funcs
+ i
);
1640 printf( "Exception information not supported for %s binaries\n",
1641 get_machine_str(file_header
->Machine
));
1647 static void dump_image_thunk_data64(const IMAGE_THUNK_DATA64
*il
, UINT thunk_rva
)
1649 /* FIXME: This does not properly handle large images */
1650 const IMAGE_IMPORT_BY_NAME
* iibn
;
1651 for (; il
->u1
.Ordinal
; il
++, thunk_rva
+= sizeof(LONGLONG
))
1653 if (IMAGE_SNAP_BY_ORDINAL64(il
->u1
.Ordinal
))
1654 printf(" %08x %4u <by ordinal>\n", thunk_rva
, (UINT
)IMAGE_ORDINAL64(il
->u1
.Ordinal
));
1657 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
, sizeof(DWORD
));
1659 printf("Can't grab import by name info, skipping to next ordinal\n");
1661 printf(" %08x %4u %s\n", thunk_rva
, iibn
->Hint
, iibn
->Name
);
1666 static void dump_image_thunk_data32(const IMAGE_THUNK_DATA32
*il
, int offset
, UINT thunk_rva
)
1668 const IMAGE_IMPORT_BY_NAME
* iibn
;
1669 for (; il
->u1
.Ordinal
; il
++, thunk_rva
+= sizeof(UINT
))
1671 if (IMAGE_SNAP_BY_ORDINAL32(il
->u1
.Ordinal
))
1672 printf(" %08x %4u <by ordinal>\n", thunk_rva
, (UINT
)IMAGE_ORDINAL32(il
->u1
.Ordinal
));
1675 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
- offset
, sizeof(DWORD
));
1677 printf("Can't grab import by name info, skipping to next ordinal\n");
1679 printf(" %08x %4u %s\n", thunk_rva
, iibn
->Hint
, iibn
->Name
);
1684 static void dump_dir_imported_functions(void)
1686 unsigned directorySize
;
1687 const IMAGE_IMPORT_DESCRIPTOR
* importDesc
= get_dir_and_size(IMAGE_FILE_IMPORT_DIRECTORY
, &directorySize
);
1689 if (!importDesc
) return;
1691 printf("Import Table size: %08x\n", directorySize
);/* FIXME */
1695 const IMAGE_THUNK_DATA32
* il
;
1697 if (!importDesc
->Name
|| !importDesc
->FirstThunk
) break;
1699 printf(" offset %08lx %s\n", Offset(importDesc
), (const char*)RVA(importDesc
->Name
, sizeof(DWORD
)));
1700 printf(" Hint/Name Table: %08X\n", (UINT
)importDesc
->OriginalFirstThunk
);
1701 printf(" TimeDateStamp: %08X (%s)\n",
1702 (UINT
)importDesc
->TimeDateStamp
, get_time_str(importDesc
->TimeDateStamp
));
1703 printf(" ForwarderChain: %08X\n", (UINT
)importDesc
->ForwarderChain
);
1704 printf(" First thunk RVA: %08X\n", (UINT
)importDesc
->FirstThunk
);
1706 printf(" Thunk Ordn Name\n");
1708 il
= (importDesc
->OriginalFirstThunk
!= 0) ?
1709 RVA((DWORD
)importDesc
->OriginalFirstThunk
, sizeof(DWORD
)) :
1710 RVA((DWORD
)importDesc
->FirstThunk
, sizeof(DWORD
));
1713 printf("Can't grab thunk data, going to next imported DLL\n");
1716 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1717 dump_image_thunk_data64((const IMAGE_THUNK_DATA64
*)il
, importDesc
->FirstThunk
);
1719 dump_image_thunk_data32(il
, 0, importDesc
->FirstThunk
);
1727 static void dump_dir_loadconfig(void)
1729 const IMAGE_LOAD_CONFIG_DIRECTORY32
*loadcfg32
= get_dir(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
);
1730 const IMAGE_LOAD_CONFIG_DIRECTORY64
*loadcfg64
= (void*)loadcfg32
;
1732 if (!loadcfg32
) return;
1734 printf( "Loadconfig\n" );
1735 print_dword( "Size", loadcfg32
->Size
);
1736 print_dword( "TimeDateStamp", loadcfg32
->TimeDateStamp
);
1737 print_word( "MajorVersion", loadcfg32
->MajorVersion
);
1738 print_word( "MinorVersion", loadcfg32
->MinorVersion
);
1739 print_dword( "GlobalFlagsClear", loadcfg32
->GlobalFlagsClear
);
1740 print_dword( "GlobalFlagsSet", loadcfg32
->GlobalFlagsSet
);
1741 print_dword( "CriticalSectionDefaultTimeout", loadcfg32
->CriticalSectionDefaultTimeout
);
1743 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1745 print_longlong( "DeCommitFreeBlockThreshold", loadcfg64
->DeCommitFreeBlockThreshold
);
1746 print_longlong( "DeCommitTotalFreeThreshold", loadcfg64
->DeCommitTotalFreeThreshold
);
1747 print_longlong( "MaximumAllocationSize", loadcfg64
->MaximumAllocationSize
);
1748 print_longlong( "VirtualMemoryThreshold", loadcfg64
->VirtualMemoryThreshold
);
1749 print_dword( "ProcessHeapFlags", loadcfg64
->ProcessHeapFlags
);
1750 print_longlong( "ProcessAffinityMask", loadcfg64
->ProcessAffinityMask
);
1751 print_word( "CSDVersion", loadcfg64
->CSDVersion
);
1752 print_word( "Reserved", loadcfg64
->Reserved1
);
1753 print_longlong( "SecurityCookie", loadcfg64
->SecurityCookie
);
1754 print_longlong( "SEHandlerTable", loadcfg64
->SEHandlerTable
);
1755 print_longlong( "SEHandlerCount", loadcfg64
->SEHandlerCount
);
1759 print_dword( "DeCommitFreeBlockThreshold", loadcfg32
->DeCommitFreeBlockThreshold
);
1760 print_dword( "DeCommitTotalFreeThreshold", loadcfg32
->DeCommitTotalFreeThreshold
);
1761 print_dword( "MaximumAllocationSize", loadcfg32
->MaximumAllocationSize
);
1762 print_dword( "VirtualMemoryThreshold", loadcfg32
->VirtualMemoryThreshold
);
1763 print_dword( "ProcessHeapFlags", loadcfg32
->ProcessHeapFlags
);
1764 print_dword( "ProcessAffinityMask", loadcfg32
->ProcessAffinityMask
);
1765 print_word( "CSDVersion", loadcfg32
->CSDVersion
);
1766 print_word( "Reserved", loadcfg32
->Reserved1
);
1767 print_dword( "SecurityCookie", loadcfg32
->SecurityCookie
);
1768 print_dword( "SEHandlerTable", loadcfg32
->SEHandlerTable
);
1769 print_dword( "SEHandlerCount", loadcfg32
->SEHandlerCount
);
1773 static void dump_dir_delay_imported_functions(void)
1775 unsigned directorySize
;
1776 const IMAGE_DELAYLOAD_DESCRIPTOR
*importDesc
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
, &directorySize
);
1778 if (!importDesc
) return;
1780 printf("Delay Import Table size: %08x\n", directorySize
); /* FIXME */
1784 const IMAGE_THUNK_DATA32
* il
;
1785 int offset
= (importDesc
->Attributes
.AllAttributes
& 1) ? 0 : PE_nt_headers
->OptionalHeader
.ImageBase
;
1787 if (!importDesc
->DllNameRVA
|| !importDesc
->ImportAddressTableRVA
|| !importDesc
->ImportNameTableRVA
) break;
1789 printf(" grAttrs %08x offset %08lx %s\n", (UINT
)importDesc
->Attributes
.AllAttributes
,
1790 Offset(importDesc
), (const char *)RVA(importDesc
->DllNameRVA
- offset
, sizeof(DWORD
)));
1791 printf(" Hint/Name Table: %08x\n", (UINT
)importDesc
->ImportNameTableRVA
);
1792 printf(" Address Table: %08x\n", (UINT
)importDesc
->ImportAddressTableRVA
);
1793 printf(" TimeDateStamp: %08X (%s)\n",
1794 (UINT
)importDesc
->TimeDateStamp
, get_time_str(importDesc
->TimeDateStamp
));
1796 printf(" Thunk Ordn Name\n");
1798 il
= RVA(importDesc
->ImportNameTableRVA
- offset
, sizeof(DWORD
));
1801 printf("Can't grab thunk data, going to next imported DLL\n");
1804 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1805 dump_image_thunk_data64((const IMAGE_THUNK_DATA64
*)il
, importDesc
->ImportAddressTableRVA
);
1807 dump_image_thunk_data32(il
, offset
, importDesc
->ImportAddressTableRVA
);
1815 static void dump_dir_debug_dir(const IMAGE_DEBUG_DIRECTORY
* idd
, int idx
)
1819 printf("Directory %02u\n", idx
+ 1);
1820 printf(" Characteristics: %08X\n", (UINT
)idd
->Characteristics
);
1821 printf(" TimeDateStamp: %08X %s\n",
1822 (UINT
)idd
->TimeDateStamp
, get_time_str(idd
->TimeDateStamp
));
1823 printf(" Version %u.%02u\n", idd
->MajorVersion
, idd
->MinorVersion
);
1827 case IMAGE_DEBUG_TYPE_UNKNOWN
: str
= "UNKNOWN"; break;
1828 case IMAGE_DEBUG_TYPE_COFF
: str
= "COFF"; break;
1829 case IMAGE_DEBUG_TYPE_CODEVIEW
: str
= "CODEVIEW"; break;
1830 case IMAGE_DEBUG_TYPE_FPO
: str
= "FPO"; break;
1831 case IMAGE_DEBUG_TYPE_MISC
: str
= "MISC"; break;
1832 case IMAGE_DEBUG_TYPE_EXCEPTION
: str
= "EXCEPTION"; break;
1833 case IMAGE_DEBUG_TYPE_FIXUP
: str
= "FIXUP"; break;
1834 case IMAGE_DEBUG_TYPE_OMAP_TO_SRC
: str
= "OMAP_TO_SRC"; break;
1835 case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
:str
= "OMAP_FROM_SRC"; break;
1836 case IMAGE_DEBUG_TYPE_BORLAND
: str
= "BORLAND"; break;
1837 case IMAGE_DEBUG_TYPE_RESERVED10
: str
= "RESERVED10"; break;
1838 case IMAGE_DEBUG_TYPE_CLSID
: str
= "CLSID"; break;
1839 case IMAGE_DEBUG_TYPE_VC_FEATURE
: str
= "VC_FEATURE"; break;
1840 case IMAGE_DEBUG_TYPE_POGO
: str
= "POGO"; break;
1841 case IMAGE_DEBUG_TYPE_ILTCG
: str
= "ILTCG"; break;
1842 case IMAGE_DEBUG_TYPE_MPX
: str
= "MPX"; break;
1843 case IMAGE_DEBUG_TYPE_REPRO
: str
= "REPRO"; break;
1845 printf(" Type: %u (%s)\n", (UINT
)idd
->Type
, str
);
1846 printf(" SizeOfData: %u\n", (UINT
)idd
->SizeOfData
);
1847 printf(" AddressOfRawData: %08X\n", (UINT
)idd
->AddressOfRawData
);
1848 printf(" PointerToRawData: %08X\n", (UINT
)idd
->PointerToRawData
);
1852 case IMAGE_DEBUG_TYPE_UNKNOWN
:
1854 case IMAGE_DEBUG_TYPE_COFF
:
1855 dump_coff(idd
->PointerToRawData
, idd
->SizeOfData
,
1856 IMAGE_FIRST_SECTION(PE_nt_headers
));
1858 case IMAGE_DEBUG_TYPE_CODEVIEW
:
1859 dump_codeview(idd
->PointerToRawData
, idd
->SizeOfData
);
1861 case IMAGE_DEBUG_TYPE_FPO
:
1862 dump_frame_pointer_omission(idd
->PointerToRawData
, idd
->SizeOfData
);
1864 case IMAGE_DEBUG_TYPE_MISC
:
1866 const IMAGE_DEBUG_MISC
* misc
= PRD(idd
->PointerToRawData
, idd
->SizeOfData
);
1867 if (!misc
) {printf("Can't get misc debug information\n"); break;}
1868 printf(" DataType: %u (%s)\n",
1869 (UINT
)misc
->DataType
, (misc
->DataType
== IMAGE_DEBUG_MISC_EXENAME
) ? "Exe name" : "Unknown");
1870 printf(" Length: %u\n", (UINT
)misc
->Length
);
1871 printf(" Unicode: %s\n", misc
->Unicode
? "Yes" : "No");
1872 printf(" Data: %s\n", misc
->Data
);
1880 static void dump_dir_debug(void)
1883 const IMAGE_DEBUG_DIRECTORY
*debugDir
= get_dir_and_size(IMAGE_FILE_DEBUG_DIRECTORY
, &nb_dbg
);
1885 nb_dbg
/= sizeof(*debugDir
);
1886 if (!debugDir
|| !nb_dbg
) return;
1888 printf("Debug Table (%u directories)\n", nb_dbg
);
1890 for (i
= 0; i
< nb_dbg
; i
++)
1892 dump_dir_debug_dir(debugDir
, i
);
1898 static inline void print_clrflags(const char *title
, UINT value
)
1900 printf(" %-34s 0x%X\n", title
, value
);
1901 #define X(f,s) if (value & f) printf(" %s\n", s)
1902 X(COMIMAGE_FLAGS_ILONLY
, "ILONLY");
1903 X(COMIMAGE_FLAGS_32BITREQUIRED
, "32BITREQUIRED");
1904 X(COMIMAGE_FLAGS_IL_LIBRARY
, "IL_LIBRARY");
1905 X(COMIMAGE_FLAGS_STRONGNAMESIGNED
, "STRONGNAMESIGNED");
1906 X(COMIMAGE_FLAGS_TRACKDEBUGDATA
, "TRACKDEBUGDATA");
1910 static inline void print_clrdirectory(const char *title
, const IMAGE_DATA_DIRECTORY
*dir
)
1912 printf(" %-23s rva: 0x%-8x size: 0x%-8x\n", title
, (UINT
)dir
->VirtualAddress
, (UINT
)dir
->Size
);
1915 static void dump_dir_clr_header(void)
1917 unsigned int size
= 0;
1918 const IMAGE_COR20_HEADER
*dir
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
, &size
);
1922 printf( "CLR Header\n" );
1923 print_dword( "Header Size", dir
->cb
);
1924 print_ver( "Required runtime version", dir
->MajorRuntimeVersion
, dir
->MinorRuntimeVersion
);
1925 print_clrflags( "Flags", dir
->Flags
);
1926 print_dword( "EntryPointToken", dir
->EntryPointToken
);
1928 printf( "CLR Data Directory\n" );
1929 print_clrdirectory( "MetaData", &dir
->MetaData
);
1930 print_clrdirectory( "Resources", &dir
->Resources
);
1931 print_clrdirectory( "StrongNameSignature", &dir
->StrongNameSignature
);
1932 print_clrdirectory( "CodeManagerTable", &dir
->CodeManagerTable
);
1933 print_clrdirectory( "VTableFixups", &dir
->VTableFixups
);
1934 print_clrdirectory( "ExportAddressTableJumps", &dir
->ExportAddressTableJumps
);
1935 print_clrdirectory( "ManagedNativeHeader", &dir
->ManagedNativeHeader
);
1939 static void dump_dir_reloc(void)
1941 unsigned int i
, size
= 0;
1942 const USHORT
*relocs
;
1943 const IMAGE_BASE_RELOCATION
*rel
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_BASERELOC
, &size
);
1944 const IMAGE_BASE_RELOCATION
*end
= (const IMAGE_BASE_RELOCATION
*)((const char *)rel
+ size
);
1945 static const char * const names
[] =
1952 "BASED_MIPS_JMPADDR",
1967 printf( "Relocations\n" );
1968 while (rel
< end
- 1 && rel
->SizeOfBlock
)
1970 printf( " Page %x\n", (UINT
)rel
->VirtualAddress
);
1971 relocs
= (const USHORT
*)(rel
+ 1);
1972 i
= (rel
->SizeOfBlock
- sizeof(*rel
)) / sizeof(USHORT
);
1975 USHORT offset
= *relocs
& 0xfff;
1976 int type
= *relocs
>> 12;
1977 printf( " off %04x type %s\n", offset
, names
[type
] );
1980 rel
= (const IMAGE_BASE_RELOCATION
*)relocs
;
1985 static void dump_dir_tls(void)
1987 IMAGE_TLS_DIRECTORY64 dir
;
1988 const UINT
*callbacks
;
1989 const IMAGE_TLS_DIRECTORY32
*pdir
= get_dir(IMAGE_FILE_THREAD_LOCAL_STORAGE
);
1993 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1994 memcpy(&dir
, pdir
, sizeof(dir
));
1997 dir
.StartAddressOfRawData
= pdir
->StartAddressOfRawData
;
1998 dir
.EndAddressOfRawData
= pdir
->EndAddressOfRawData
;
1999 dir
.AddressOfIndex
= pdir
->AddressOfIndex
;
2000 dir
.AddressOfCallBacks
= pdir
->AddressOfCallBacks
;
2001 dir
.SizeOfZeroFill
= pdir
->SizeOfZeroFill
;
2002 dir
.Characteristics
= pdir
->Characteristics
;
2005 /* FIXME: This does not properly handle large images */
2006 printf( "Thread Local Storage\n" );
2007 printf( " Raw data %08x-%08x (data size %x zero fill size %x)\n",
2008 (UINT
)dir
.StartAddressOfRawData
, (UINT
)dir
.EndAddressOfRawData
,
2009 (UINT
)(dir
.EndAddressOfRawData
- dir
.StartAddressOfRawData
),
2010 (UINT
)dir
.SizeOfZeroFill
);
2011 printf( " Index address %08x\n", (UINT
)dir
.AddressOfIndex
);
2012 printf( " Characteristics %08x\n", (UINT
)dir
.Characteristics
);
2013 printf( " Callbacks %08x -> {", (UINT
)dir
.AddressOfCallBacks
);
2014 if (dir
.AddressOfCallBacks
)
2016 UINT addr
= (UINT
)dir
.AddressOfCallBacks
- PE_nt_headers
->OptionalHeader
.ImageBase
;
2017 while ((callbacks
= RVA(addr
, sizeof(UINT
))) && *callbacks
)
2019 printf( " %08x", *callbacks
);
2020 addr
+= sizeof(UINT
);
2026 enum FileSig
get_kind_dbg(void)
2030 pw
= PRD(0, sizeof(WORD
));
2031 if (!pw
) {printf("Can't get main signature, aborting\n"); return 0;}
2033 if (*pw
== 0x4944 /* "DI" */) return SIG_DBG
;
2039 const IMAGE_SEPARATE_DEBUG_HEADER
* separateDebugHead
;
2042 const IMAGE_DEBUG_DIRECTORY
* debugDir
;
2044 separateDebugHead
= PRD(0, sizeof(*separateDebugHead
));
2045 if (!separateDebugHead
) {printf("Can't grab the separate header, aborting\n"); return;}
2047 printf ("Signature: %.2s (0x%4X)\n",
2048 (const char*)&separateDebugHead
->Signature
, separateDebugHead
->Signature
);
2049 printf ("Flags: 0x%04X\n", separateDebugHead
->Flags
);
2050 printf ("Machine: 0x%04X (%s)\n",
2051 separateDebugHead
->Machine
, get_machine_str(separateDebugHead
->Machine
));
2052 printf ("Characteristics: 0x%04X\n", separateDebugHead
->Characteristics
);
2053 printf ("TimeDateStamp: 0x%08X (%s)\n",
2054 (UINT
)separateDebugHead
->TimeDateStamp
, get_time_str(separateDebugHead
->TimeDateStamp
));
2055 printf ("CheckSum: 0x%08X\n", (UINT
)separateDebugHead
->CheckSum
);
2056 printf ("ImageBase: 0x%08X\n", (UINT
)separateDebugHead
->ImageBase
);
2057 printf ("SizeOfImage: 0x%08X\n", (UINT
)separateDebugHead
->SizeOfImage
);
2058 printf ("NumberOfSections: 0x%08X\n", (UINT
)separateDebugHead
->NumberOfSections
);
2059 printf ("ExportedNamesSize: 0x%08X\n", (UINT
)separateDebugHead
->ExportedNamesSize
);
2060 printf ("DebugDirectorySize: 0x%08X\n", (UINT
)separateDebugHead
->DebugDirectorySize
);
2062 if (!PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
),
2063 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)))
2064 {printf("Can't get the sections, aborting\n"); return;}
2066 dump_sections(separateDebugHead
, separateDebugHead
+ 1, separateDebugHead
->NumberOfSections
);
2068 nb_dbg
= separateDebugHead
->DebugDirectorySize
/ sizeof(IMAGE_DEBUG_DIRECTORY
);
2069 debugDir
= PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
) +
2070 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
) +
2071 separateDebugHead
->ExportedNamesSize
,
2072 nb_dbg
* sizeof(IMAGE_DEBUG_DIRECTORY
));
2073 if (!debugDir
) {printf("Couldn't get the debug directory info, aborting\n");return;}
2075 printf("Debug Table (%u directories)\n", nb_dbg
);
2077 for (i
= 0; i
< nb_dbg
; i
++)
2079 dump_dir_debug_dir(debugDir
, i
);
2084 static const char *get_resource_type( unsigned int id
)
2086 static const char * const types
[] =
2115 if ((size_t)id
< ARRAY_SIZE(types
)) return types
[id
];
2119 /* dump an ASCII string with proper escaping */
2120 static int dump_strA( const unsigned char *str
, size_t len
)
2122 static const char escapes
[32] = ".......abtnvfr.............e....";
2127 for (; len
; str
++, len
--)
2129 if (pos
> buffer
+ sizeof(buffer
) - 8)
2131 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2132 count
+= pos
- buffer
;
2135 if (*str
> 127) /* hex escape */
2137 pos
+= sprintf( pos
, "\\x%02x", *str
);
2140 if (*str
< 32) /* octal or C escape */
2142 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
2143 if (escapes
[*str
] != '.')
2144 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
2145 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
2146 pos
+= sprintf( pos
, "\\%03o", *str
);
2148 pos
+= sprintf( pos
, "\\%o", *str
);
2151 if (*str
== '\\') *pos
++ = '\\';
2154 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2155 count
+= pos
- buffer
;
2159 /* dump a Unicode string with proper escaping */
2160 static int dump_strW( const WCHAR
*str
, size_t len
)
2162 static const char escapes
[32] = ".......abtnvfr.............e....";
2167 for (; len
; str
++, len
--)
2169 if (pos
> buffer
+ sizeof(buffer
) - 8)
2171 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2172 count
+= pos
- buffer
;
2175 if (*str
> 127) /* hex escape */
2177 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
2178 pos
+= sprintf( pos
, "\\x%04x", *str
);
2180 pos
+= sprintf( pos
, "\\x%x", *str
);
2183 if (*str
< 32) /* octal or C escape */
2185 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
2186 if (escapes
[*str
] != '.')
2187 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
2188 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
2189 pos
+= sprintf( pos
, "\\%03o", *str
);
2191 pos
+= sprintf( pos
, "\\%o", *str
);
2194 if (*str
== '\\') *pos
++ = '\\';
2197 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2198 count
+= pos
- buffer
;
2202 /* dump data for a STRING resource */
2203 static void dump_string_data( const WCHAR
*ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
2207 for (i
= 0; i
< 16 && size
; i
++)
2209 unsigned len
= *ptr
++;
2216 else size
-= len
+ 1;
2220 printf( "%s%04x \"", prefix
, (id
- 1) * 16 + i
);
2221 dump_strW( ptr
, len
);
2228 /* dump data for a MESSAGETABLE resource */
2229 static void dump_msgtable_data( const void *ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
2231 const MESSAGE_RESOURCE_DATA
*data
= ptr
;
2232 const MESSAGE_RESOURCE_BLOCK
*block
= data
->Blocks
;
2235 for (i
= 0; i
< data
->NumberOfBlocks
; i
++, block
++)
2237 const MESSAGE_RESOURCE_ENTRY
*entry
;
2239 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)data
+ block
->OffsetToEntries
);
2240 for (j
= block
->LowId
; j
<= block
->HighId
; j
++)
2242 if (entry
->Flags
& MESSAGE_RESOURCE_UNICODE
)
2244 const WCHAR
*str
= (const WCHAR
*)entry
->Text
;
2245 printf( "%s%08x L\"", prefix
, j
);
2246 dump_strW( str
, strlenW(str
) );
2251 const char *str
= (const char *) entry
->Text
;
2252 printf( "%s%08x \"", prefix
, j
);
2253 dump_strA( entry
->Text
, strlen(str
) );
2256 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)entry
+ entry
->Length
);
2261 static void dump_dir_resource(void)
2263 const IMAGE_RESOURCE_DIRECTORY
*root
= get_dir(IMAGE_FILE_RESOURCE_DIRECTORY
);
2264 const IMAGE_RESOURCE_DIRECTORY
*namedir
;
2265 const IMAGE_RESOURCE_DIRECTORY
*langdir
;
2266 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*e1
, *e2
, *e3
;
2267 const IMAGE_RESOURCE_DIR_STRING_U
*string
;
2268 const IMAGE_RESOURCE_DATA_ENTRY
*data
;
2273 printf( "Resources:" );
2275 for (i
= 0; i
< root
->NumberOfNamedEntries
+ root
->NumberOfIdEntries
; i
++)
2277 e1
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(root
+ 1) + i
;
2278 namedir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e1
->OffsetToDirectory
);
2279 for (j
= 0; j
< namedir
->NumberOfNamedEntries
+ namedir
->NumberOfIdEntries
; j
++)
2281 e2
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(namedir
+ 1) + j
;
2282 langdir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e2
->OffsetToDirectory
);
2283 for (k
= 0; k
< langdir
->NumberOfNamedEntries
+ langdir
->NumberOfIdEntries
; k
++)
2285 e3
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(langdir
+ 1) + k
;
2288 if (e1
->NameIsString
)
2290 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*)((const char *)root
+ e1
->NameOffset
);
2291 dump_unicode_str( string
->NameString
, string
->Length
);
2295 const char *type
= get_resource_type( e1
->Id
);
2296 if (type
) printf( "%s", type
);
2297 else printf( "%04x", e1
->Id
);
2301 if (e2
->NameIsString
)
2303 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*) ((const char *)root
+ e2
->NameOffset
);
2304 dump_unicode_str( string
->NameString
, string
->Length
);
2307 printf( "%04x", e2
->Id
);
2309 printf( " Language=%04x:\n", e3
->Id
);
2310 data
= (const IMAGE_RESOURCE_DATA_ENTRY
*)((const char *)root
+ e3
->OffsetToData
);
2311 if (e1
->NameIsString
)
2313 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
2318 dump_string_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, e2
->Id
, " " );
2321 dump_msgtable_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, e2
->Id
, " " );
2324 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
2333 static void dump_debug(void)
2335 const char* stabs
= NULL
;
2336 unsigned szstabs
= 0;
2337 const char* stabstr
= NULL
;
2340 const IMAGE_SECTION_HEADER
* sectHead
;
2342 sectHead
= IMAGE_FIRST_SECTION(PE_nt_headers
);
2344 for (i
= 0; i
< PE_nt_headers
->FileHeader
.NumberOfSections
; i
++, sectHead
++)
2346 if (!strcmp((const char *)sectHead
->Name
, ".stab"))
2348 stabs
= RVA(sectHead
->VirtualAddress
, sectHead
->Misc
.VirtualSize
);
2349 szstabs
= sectHead
->Misc
.VirtualSize
;
2351 if (!strncmp((const char *)sectHead
->Name
, ".stabstr", 8))
2353 stabstr
= RVA(sectHead
->VirtualAddress
, sectHead
->Misc
.VirtualSize
);
2354 szstr
= sectHead
->Misc
.VirtualSize
;
2357 if (stabs
&& stabstr
)
2358 dump_stabs(stabs
, szstabs
, stabstr
, szstr
);
2361 static void dump_symbol_table(void)
2363 const IMAGE_SYMBOL
* sym
;
2366 numsym
= PE_nt_headers
->FileHeader
.NumberOfSymbols
;
2367 if (!PE_nt_headers
->FileHeader
.PointerToSymbolTable
|| !numsym
)
2369 sym
= PRD(PE_nt_headers
->FileHeader
.PointerToSymbolTable
,
2370 sizeof(*sym
) * numsym
);
2373 dump_coff_symbol_table(sym
, numsym
, IMAGE_FIRST_SECTION(PE_nt_headers
));
2376 enum FileSig
get_kind_exec(void)
2380 const IMAGE_DOS_HEADER
* dh
;
2382 pw
= PRD(0, sizeof(WORD
));
2383 if (!pw
) {printf("Can't get main signature, aborting\n"); return 0;}
2385 if (*pw
!= IMAGE_DOS_SIGNATURE
) return SIG_UNKNOWN
;
2387 if ((dh
= PRD(0, sizeof(IMAGE_DOS_HEADER
))))
2389 /* the signature is the first DWORD */
2390 pdw
= PRD(dh
->e_lfanew
, sizeof(DWORD
));
2393 if (*pdw
== IMAGE_NT_SIGNATURE
) return SIG_PE
;
2394 if (*(const WORD
*)pdw
== IMAGE_OS2_SIGNATURE
) return SIG_NE
;
2395 if (*(const WORD
*)pdw
== IMAGE_VXD_SIGNATURE
) return SIG_LE
;
2404 int all
= (globals
.dumpsect
!= NULL
) && strcmp(globals
.dumpsect
, "ALL") == 0;
2406 PE_nt_headers
= get_nt_header();
2409 if (globals
.do_dumpheader
)
2412 /* FIXME: should check ptr */
2413 dump_sections(PRD(0, 1), IMAGE_FIRST_SECTION(PE_nt_headers
),
2414 PE_nt_headers
->FileHeader
.NumberOfSections
);
2416 else if (!globals
.dumpsect
)
2418 /* show at least something here */
2422 if (globals
.dumpsect
)
2424 if (all
|| !strcmp(globals
.dumpsect
, "import"))
2426 dump_dir_imported_functions();
2427 dump_dir_delay_imported_functions();
2429 if (all
|| !strcmp(globals
.dumpsect
, "export"))
2430 dump_dir_exported_functions();
2431 if (all
|| !strcmp(globals
.dumpsect
, "debug"))
2433 if (all
|| !strcmp(globals
.dumpsect
, "resource"))
2434 dump_dir_resource();
2435 if (all
|| !strcmp(globals
.dumpsect
, "tls"))
2437 if (all
|| !strcmp(globals
.dumpsect
, "loadcfg"))
2438 dump_dir_loadconfig();
2439 if (all
|| !strcmp(globals
.dumpsect
, "clr"))
2440 dump_dir_clr_header();
2441 if (all
|| !strcmp(globals
.dumpsect
, "reloc"))
2443 if (all
|| !strcmp(globals
.dumpsect
, "except"))
2444 dump_dir_exceptions();
2445 if (all
|| !strcmp(globals
.dumpsect
, "apiset"))
2446 dump_section_apiset();
2448 if (globals
.do_symbol_table
)
2449 dump_symbol_table();
2450 if (globals
.do_debug
)
2454 typedef struct _dll_symbol
{
2459 static dll_symbol
*dll_symbols
= NULL
;
2460 static dll_symbol
*dll_current_symbol
= NULL
;
2462 /* Compare symbols by ordinal for qsort */
2463 static int symbol_cmp(const void *left
, const void *right
)
2465 return ((const dll_symbol
*)left
)->ordinal
> ((const dll_symbol
*)right
)->ordinal
;
2468 /*******************************************************************
2471 * Free resources used by DLL
2473 /* FIXME: Not used yet
2474 static void dll_close (void)
2479 fatal("No symbols");
2481 for (ds = dll_symbols; ds->symbol; ds++)
2488 static void do_grab_sym( void )
2490 const IMAGE_EXPORT_DIRECTORY
*exportDir
;
2497 PE_nt_headers
= get_nt_header();
2498 if (!(exportDir
= get_dir(IMAGE_FILE_EXPORT_DIRECTORY
))) return;
2500 pName
= RVA(exportDir
->AddressOfNames
, exportDir
->NumberOfNames
* sizeof(DWORD
));
2501 if (!pName
) {printf("Can't grab functions' name table\n"); return;}
2502 pOrdl
= RVA(exportDir
->AddressOfNameOrdinals
, exportDir
->NumberOfNames
* sizeof(WORD
));
2503 if (!pOrdl
) {printf("Can't grab functions' ordinal table\n"); return;}
2504 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
2505 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
2509 dll_symbols
= xmalloc((exportDir
->NumberOfFunctions
+ 1) * sizeof(dll_symbol
));
2511 /* bit map of used funcs */
2512 map
= calloc(((exportDir
->NumberOfFunctions
+ 31) & ~31) / 32, sizeof(DWORD
));
2513 if (!map
) fatal("no memory");
2515 for (j
= 0; j
< exportDir
->NumberOfNames
; j
++, pOrdl
++)
2517 map
[*pOrdl
/ 32] |= 1 << (*pOrdl
% 32);
2518 ptr
= RVA(*pName
++, sizeof(DWORD
));
2519 if (!ptr
) ptr
= "cant_get_function";
2520 dll_symbols
[j
].symbol
= xstrdup(ptr
);
2521 dll_symbols
[j
].ordinal
= exportDir
->Base
+ *pOrdl
;
2522 assert(dll_symbols
[j
].symbol
);
2525 for (i
= 0; i
< exportDir
->NumberOfFunctions
; i
++)
2527 if (pFunc
[i
] && !(map
[i
/ 32] & (1 << (i
% 32))))
2529 char ordinal_text
[256];
2530 /* Ordinal only entry */
2531 sprintf (ordinal_text
, "%s_%u",
2532 globals
.forward_dll
? globals
.forward_dll
: OUTPUT_UC_DLL_NAME
,
2533 (UINT
)exportDir
->Base
+ i
);
2534 str_toupper(ordinal_text
);
2535 dll_symbols
[j
].symbol
= xstrdup(ordinal_text
);
2536 assert(dll_symbols
[j
].symbol
);
2537 dll_symbols
[j
].ordinal
= exportDir
->Base
+ i
;
2539 assert(j
<= exportDir
->NumberOfFunctions
);
2545 printf("%u named symbols in DLL, %u total, %d unique (ordinal base = %d)\n",
2546 (UINT
)exportDir
->NumberOfNames
, (UINT
)exportDir
->NumberOfFunctions
,
2547 j
, (UINT
)exportDir
->Base
);
2549 qsort( dll_symbols
, j
, sizeof(dll_symbol
), symbol_cmp
);
2551 dll_symbols
[j
].symbol
= NULL
;
2553 dll_current_symbol
= dll_symbols
;
2556 /*******************************************************************
2559 * Open a DLL and read in exported symbols
2561 BOOL
dll_open (const char *dll_name
)
2563 return dump_analysis(dll_name
, do_grab_sym
, SIG_PE
);
2566 /*******************************************************************
2569 * Get next exported symbol from dll
2571 BOOL
dll_next_symbol (parsed_symbol
* sym
)
2573 if (!dll_current_symbol
|| !dll_current_symbol
->symbol
)
2575 assert (dll_symbols
);
2576 sym
->symbol
= xstrdup (dll_current_symbol
->symbol
);
2577 sym
->ordinal
= dll_current_symbol
->ordinal
;
2578 dll_current_symbol
++;