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_I386
: return "i386";
47 case IMAGE_FILE_MACHINE_R3000
: return "R3000";
48 case IMAGE_FILE_MACHINE_R4000
: return "R4000";
49 case IMAGE_FILE_MACHINE_R10000
: return "R10000";
50 case IMAGE_FILE_MACHINE_ALPHA
: return "Alpha";
51 case IMAGE_FILE_MACHINE_POWERPC
: return "PowerPC";
52 case IMAGE_FILE_MACHINE_AMD64
: return "AMD64";
53 case IMAGE_FILE_MACHINE_IA64
: return "IA64";
54 case IMAGE_FILE_MACHINE_ARM64
: return "ARM64";
55 case IMAGE_FILE_MACHINE_ARM
: return "ARM";
56 case IMAGE_FILE_MACHINE_ARMNT
: return "ARMNT";
57 case IMAGE_FILE_MACHINE_THUMB
: return "ARM Thumb";
58 case IMAGE_FILE_MACHINE_ALPHA64
: return "Alpha64";
59 case IMAGE_FILE_MACHINE_CHPE_X86
: return "CHPE-x86";
60 case IMAGE_FILE_MACHINE_ARM64EC
: return "ARM64EC";
61 case IMAGE_FILE_MACHINE_ARM64X
: return "ARM64X";
62 case IMAGE_FILE_MACHINE_RISCV32
: return "RISC-V 32-bit";
63 case IMAGE_FILE_MACHINE_RISCV64
: return "RISC-V 64-bit";
64 case IMAGE_FILE_MACHINE_RISCV128
: return "RISC-V 128-bit";
69 static const 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 const IMAGE_NT_HEADERS32
*get_nt_header( void )
92 const IMAGE_DOS_HEADER
*dos
;
93 dos
= PRD(0, sizeof(*dos
));
94 if (!dos
) return NULL
;
95 is_builtin
= (dos
->e_lfanew
>= sizeof(*dos
) + 32 &&
96 !memcmp( dos
+ 1, builtin_signature
, sizeof(builtin_signature
) ));
97 return PRD(dos
->e_lfanew
, sizeof(DWORD
) + sizeof(IMAGE_FILE_HEADER
));
100 void print_fake_dll( void )
102 const IMAGE_DOS_HEADER
*dos
;
104 dos
= PRD(0, sizeof(*dos
) + 32);
105 if (dos
&& dos
->e_lfanew
>= sizeof(*dos
) + 32)
107 if (!memcmp( dos
+ 1, builtin_signature
, sizeof(builtin_signature
) ))
108 printf( "*** This is a Wine builtin DLL ***\n\n" );
109 else if (!memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) ))
110 printf( "*** This is a Wine fake DLL ***\n\n" );
114 static const void *get_data_dir(const IMAGE_NT_HEADERS32
*hdr
, unsigned int idx
, unsigned int *size
)
116 if(hdr
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
118 const IMAGE_OPTIONAL_HEADER64
*opt
= (const IMAGE_OPTIONAL_HEADER64
*)&hdr
->OptionalHeader
;
119 if (idx
>= opt
->NumberOfRvaAndSizes
)
122 *size
= opt
->DataDirectory
[idx
].Size
;
123 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
124 opt
->DataDirectory
[idx
].Size
);
128 const IMAGE_OPTIONAL_HEADER32
*opt
= (const IMAGE_OPTIONAL_HEADER32
*)&hdr
->OptionalHeader
;
129 if (idx
>= opt
->NumberOfRvaAndSizes
)
132 *size
= opt
->DataDirectory
[idx
].Size
;
133 return RVA(opt
->DataDirectory
[idx
].VirtualAddress
,
134 opt
->DataDirectory
[idx
].Size
);
138 static const void *get_dir_and_size(unsigned int idx
, unsigned int *size
)
140 return get_data_dir( PE_nt_headers
, idx
, size
);
143 static const void* get_dir(unsigned idx
)
145 return get_dir_and_size(idx
, 0);
148 static const char * const DirectoryNames
[16] = {
149 "EXPORT", "IMPORT", "RESOURCE", "EXCEPTION",
150 "SECURITY", "BASERELOC", "DEBUG", "ARCHITECTURE",
151 "GLOBALPTR", "TLS", "LOAD_CONFIG", "Bound IAT",
152 "IAT", "Delay IAT", "CLR Header", ""
155 static const char *get_magic_type(WORD magic
)
158 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
160 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
162 case IMAGE_ROM_OPTIONAL_HDR_MAGIC
:
168 static const void *get_hybrid_metadata(void)
172 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
174 const IMAGE_LOAD_CONFIG_DIRECTORY64
*cfg
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
, &size
);
176 size
= min( size
, cfg
->Size
);
177 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, CHPEMetadataPointer
)) return 0;
178 return RVA( cfg
->CHPEMetadataPointer
- ((const IMAGE_OPTIONAL_HEADER64
*)&PE_nt_headers
->OptionalHeader
)->ImageBase
, 1 );
182 const IMAGE_LOAD_CONFIG_DIRECTORY32
*cfg
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
, &size
);
184 size
= min( size
, cfg
->Size
);
185 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, CHPEMetadataPointer
)) return 0;
186 return RVA( cfg
->CHPEMetadataPointer
- PE_nt_headers
->OptionalHeader
.ImageBase
, 1 );
190 static inline const char *longlong_str( ULONGLONG value
)
192 static char buffer
[20];
194 if (sizeof(value
) > sizeof(unsigned long) && value
>> 32)
195 sprintf(buffer
, "%lx%08lx", (unsigned long)(value
>> 32), (unsigned long)value
);
197 sprintf(buffer
, "%lx", (unsigned long)value
);
201 static inline void print_word(const char *title
, WORD value
)
203 printf(" %-34s 0x%-4X %u\n", title
, value
, value
);
206 static inline void print_dword(const char *title
, UINT value
)
208 printf(" %-34s 0x%-8x %u\n", title
, value
, value
);
211 static inline void print_longlong(const char *title
, ULONGLONG value
)
213 printf(" %-34s 0x%s\n", title
, longlong_str(value
));
216 static inline void print_ver(const char *title
, BYTE major
, BYTE minor
)
218 printf(" %-34s %u.%02u\n", title
, major
, minor
);
221 static inline void print_subsys(const char *title
, WORD value
)
227 case IMAGE_SUBSYSTEM_UNKNOWN
: str
= "Unknown"; break;
228 case IMAGE_SUBSYSTEM_NATIVE
: str
= "Native"; break;
229 case IMAGE_SUBSYSTEM_WINDOWS_GUI
: str
= "Windows GUI"; break;
230 case IMAGE_SUBSYSTEM_WINDOWS_CUI
: str
= "Windows CUI"; break;
231 case IMAGE_SUBSYSTEM_OS2_CUI
: str
= "OS/2 CUI"; break;
232 case IMAGE_SUBSYSTEM_POSIX_CUI
: str
= "Posix CUI"; break;
233 case IMAGE_SUBSYSTEM_NATIVE_WINDOWS
: str
= "native Win9x driver"; break;
234 case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
: str
= "Windows CE GUI"; break;
235 case IMAGE_SUBSYSTEM_EFI_APPLICATION
: str
= "EFI application"; break;
236 case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
: str
= "EFI driver (boot)"; break;
237 case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
: str
= "EFI driver (runtime)"; break;
238 case IMAGE_SUBSYSTEM_EFI_ROM
: str
= "EFI ROM"; break;
239 case IMAGE_SUBSYSTEM_XBOX
: str
= "Xbox application"; break;
240 case IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION
: str
= "Boot application"; break;
242 printf(" %-34s 0x%X (%s)\n", title
, value
, str
);
245 static inline void print_dllflags(const char *title
, WORD value
)
247 printf(" %-34s 0x%04X\n", title
, value
);
248 #define X(f,s) do { if (value & f) printf(" %s\n", s); } while(0)
249 if (is_builtin
) X(IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE
, "PREFER_NATIVE (Wine extension)");
250 X(IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
, "HIGH_ENTROPY_VA");
251 X(IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
, "DYNAMIC_BASE");
252 X(IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
, "FORCE_INTEGRITY");
253 X(IMAGE_DLLCHARACTERISTICS_NX_COMPAT
, "NX_COMPAT");
254 X(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
, "NO_ISOLATION");
255 X(IMAGE_DLLCHARACTERISTICS_NO_SEH
, "NO_SEH");
256 X(IMAGE_DLLCHARACTERISTICS_NO_BIND
, "NO_BIND");
257 X(IMAGE_DLLCHARACTERISTICS_APPCONTAINER
, "APPCONTAINER");
258 X(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
, "WDM_DRIVER");
259 X(IMAGE_DLLCHARACTERISTICS_GUARD_CF
, "GUARD_CF");
260 X(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
, "TERMINAL_SERVER_AWARE");
264 static inline void print_datadirectory(DWORD n
, const IMAGE_DATA_DIRECTORY
*directory
)
267 printf("Data Directory\n");
269 for (i
= 0; i
< n
&& i
< 16; i
++)
271 printf(" %-12s rva: 0x%-8x size: 0x%-8x\n",
272 DirectoryNames
[i
], (UINT
)directory
[i
].VirtualAddress
,
273 (UINT
)directory
[i
].Size
);
277 static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32
*image_oh
, UINT header_size
)
279 IMAGE_OPTIONAL_HEADER32 oh
;
280 const IMAGE_OPTIONAL_HEADER32
*optionalHeader
;
282 /* in case optional header is missing or partial */
283 memset(&oh
, 0, sizeof(oh
));
284 memcpy(&oh
, image_oh
, min(header_size
, sizeof(oh
)));
285 optionalHeader
= &oh
;
287 print_word("Magic", optionalHeader
->Magic
);
288 print_ver("linker version",
289 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
290 print_dword("size of code", optionalHeader
->SizeOfCode
);
291 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
292 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
293 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
294 print_dword("base of code", optionalHeader
->BaseOfCode
);
295 print_dword("base of data", optionalHeader
->BaseOfData
);
296 print_dword("image base", optionalHeader
->ImageBase
);
297 print_dword("section align", optionalHeader
->SectionAlignment
);
298 print_dword("file align", optionalHeader
->FileAlignment
);
299 print_ver("required OS version",
300 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
301 print_ver("image version",
302 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
303 print_ver("subsystem version",
304 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
305 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
306 print_dword("size of image", optionalHeader
->SizeOfImage
);
307 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
308 print_dword("checksum", optionalHeader
->CheckSum
);
309 print_subsys("Subsystem", optionalHeader
->Subsystem
);
310 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
311 print_dword("stack reserve size", optionalHeader
->SizeOfStackReserve
);
312 print_dword("stack commit size", optionalHeader
->SizeOfStackCommit
);
313 print_dword("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
314 print_dword("heap commit size", optionalHeader
->SizeOfHeapCommit
);
315 print_dword("loader flags", optionalHeader
->LoaderFlags
);
316 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
318 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
322 static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64
*image_oh
, UINT header_size
)
324 IMAGE_OPTIONAL_HEADER64 oh
;
325 const IMAGE_OPTIONAL_HEADER64
*optionalHeader
;
327 /* in case optional header is missing or partial */
328 memset(&oh
, 0, sizeof(oh
));
329 memcpy(&oh
, image_oh
, min(header_size
, sizeof(oh
)));
330 optionalHeader
= &oh
;
332 print_word("Magic", optionalHeader
->Magic
);
333 print_ver("linker version",
334 optionalHeader
->MajorLinkerVersion
, optionalHeader
->MinorLinkerVersion
);
335 print_dword("size of code", optionalHeader
->SizeOfCode
);
336 print_dword("size of initialized data", optionalHeader
->SizeOfInitializedData
);
337 print_dword("size of uninitialized data", optionalHeader
->SizeOfUninitializedData
);
338 print_dword("entrypoint RVA", optionalHeader
->AddressOfEntryPoint
);
339 print_dword("base of code", optionalHeader
->BaseOfCode
);
340 print_longlong("image base", optionalHeader
->ImageBase
);
341 print_dword("section align", optionalHeader
->SectionAlignment
);
342 print_dword("file align", optionalHeader
->FileAlignment
);
343 print_ver("required OS version",
344 optionalHeader
->MajorOperatingSystemVersion
, optionalHeader
->MinorOperatingSystemVersion
);
345 print_ver("image version",
346 optionalHeader
->MajorImageVersion
, optionalHeader
->MinorImageVersion
);
347 print_ver("subsystem version",
348 optionalHeader
->MajorSubsystemVersion
, optionalHeader
->MinorSubsystemVersion
);
349 print_dword("Win32 Version", optionalHeader
->Win32VersionValue
);
350 print_dword("size of image", optionalHeader
->SizeOfImage
);
351 print_dword("size of headers", optionalHeader
->SizeOfHeaders
);
352 print_dword("checksum", optionalHeader
->CheckSum
);
353 print_subsys("Subsystem", optionalHeader
->Subsystem
);
354 print_dllflags("DLL characteristics:", optionalHeader
->DllCharacteristics
);
355 print_longlong("stack reserve size", optionalHeader
->SizeOfStackReserve
);
356 print_longlong("stack commit size", optionalHeader
->SizeOfStackCommit
);
357 print_longlong("heap reserve size", optionalHeader
->SizeOfHeapReserve
);
358 print_longlong("heap commit size", optionalHeader
->SizeOfHeapCommit
);
359 print_dword("loader flags", optionalHeader
->LoaderFlags
);
360 print_dword("RVAs & sizes", optionalHeader
->NumberOfRvaAndSizes
);
362 print_datadirectory(optionalHeader
->NumberOfRvaAndSizes
, optionalHeader
->DataDirectory
);
366 void dump_optional_header(const IMAGE_OPTIONAL_HEADER32
*optionalHeader
, UINT header_size
)
368 printf("Optional Header (%s)\n", get_magic_type(optionalHeader
->Magic
));
370 switch(optionalHeader
->Magic
) {
371 case IMAGE_NT_OPTIONAL_HDR32_MAGIC
:
372 dump_optional_header32(optionalHeader
, header_size
);
374 case IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
375 dump_optional_header64((const IMAGE_OPTIONAL_HEADER64
*)optionalHeader
, header_size
);
378 printf(" Unknown optional header magic: 0x%-4X\n", optionalHeader
->Magic
);
383 void dump_file_header(const IMAGE_FILE_HEADER
*fileHeader
, BOOL is_hybrid
)
385 const char *name
= get_machine_str(fileHeader
->Machine
);
387 printf("File Header\n");
391 switch (fileHeader
->Machine
)
393 case IMAGE_FILE_MACHINE_I386
: name
= "CHPE"; break;
394 case IMAGE_FILE_MACHINE_AMD64
: name
= "ARM64EC"; break;
395 case IMAGE_FILE_MACHINE_ARM64
: name
= "ARM64X"; break;
398 printf(" Machine: %04X (%s)\n", fileHeader
->Machine
, name
);
399 printf(" Number of Sections: %d\n", fileHeader
->NumberOfSections
);
400 printf(" TimeDateStamp: %08X (%s)\n",
401 (UINT
)fileHeader
->TimeDateStamp
, get_time_str(fileHeader
->TimeDateStamp
));
402 printf(" PointerToSymbolTable: %08X\n", (UINT
)fileHeader
->PointerToSymbolTable
);
403 printf(" NumberOfSymbols: %08X\n", (UINT
)fileHeader
->NumberOfSymbols
);
404 printf(" SizeOfOptionalHeader: %04X\n", (UINT
)fileHeader
->SizeOfOptionalHeader
);
405 printf(" Characteristics: %04X\n", (UINT
)fileHeader
->Characteristics
);
406 #define X(f,s) if (fileHeader->Characteristics & f) printf(" %s\n", s)
407 X(IMAGE_FILE_RELOCS_STRIPPED
, "RELOCS_STRIPPED");
408 X(IMAGE_FILE_EXECUTABLE_IMAGE
, "EXECUTABLE_IMAGE");
409 X(IMAGE_FILE_LINE_NUMS_STRIPPED
, "LINE_NUMS_STRIPPED");
410 X(IMAGE_FILE_LOCAL_SYMS_STRIPPED
, "LOCAL_SYMS_STRIPPED");
411 X(IMAGE_FILE_AGGRESIVE_WS_TRIM
, "AGGRESIVE_WS_TRIM");
412 X(IMAGE_FILE_LARGE_ADDRESS_AWARE
, "LARGE_ADDRESS_AWARE");
413 X(IMAGE_FILE_16BIT_MACHINE
, "16BIT_MACHINE");
414 X(IMAGE_FILE_BYTES_REVERSED_LO
, "BYTES_REVERSED_LO");
415 X(IMAGE_FILE_32BIT_MACHINE
, "32BIT_MACHINE");
416 X(IMAGE_FILE_DEBUG_STRIPPED
, "DEBUG_STRIPPED");
417 X(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
, "REMOVABLE_RUN_FROM_SWAP");
418 X(IMAGE_FILE_NET_RUN_FROM_SWAP
, "NET_RUN_FROM_SWAP");
419 X(IMAGE_FILE_SYSTEM
, "SYSTEM");
420 X(IMAGE_FILE_DLL
, "DLL");
421 X(IMAGE_FILE_UP_SYSTEM_ONLY
, "UP_SYSTEM_ONLY");
422 X(IMAGE_FILE_BYTES_REVERSED_HI
, "BYTES_REVERSED_HI");
427 static void dump_pe_header(void)
429 dump_file_header(&PE_nt_headers
->FileHeader
, get_hybrid_metadata() != NULL
);
430 dump_optional_header((const IMAGE_OPTIONAL_HEADER32
*)&PE_nt_headers
->OptionalHeader
,
431 PE_nt_headers
->FileHeader
.SizeOfOptionalHeader
);
434 void dump_section_characteristics(DWORD characteristics
, const char* sep
)
436 #define X(b,s) if (characteristics & b) printf("%s%s", sep, s)
437 /* #define IMAGE_SCN_TYPE_REG 0x00000000 - Reserved */
438 /* #define IMAGE_SCN_TYPE_DSECT 0x00000001 - Reserved */
439 /* #define IMAGE_SCN_TYPE_NOLOAD 0x00000002 - Reserved */
440 /* #define IMAGE_SCN_TYPE_GROUP 0x00000004 - Reserved */
441 /* #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - Reserved */
442 /* #define IMAGE_SCN_TYPE_COPY 0x00000010 - Reserved */
444 X(IMAGE_SCN_CNT_CODE
, "CODE");
445 X(IMAGE_SCN_CNT_INITIALIZED_DATA
, "INITIALIZED_DATA");
446 X(IMAGE_SCN_CNT_UNINITIALIZED_DATA
, "UNINITIALIZED_DATA");
448 X(IMAGE_SCN_LNK_OTHER
, "LNK_OTHER");
449 X(IMAGE_SCN_LNK_INFO
, "LNK_INFO");
450 /* #define IMAGE_SCN_TYPE_OVER 0x00000400 - Reserved */
451 X(IMAGE_SCN_LNK_REMOVE
, "LNK_REMOVE");
452 X(IMAGE_SCN_LNK_COMDAT
, "LNK_COMDAT");
454 /* 0x00002000 - Reserved */
455 /* #define IMAGE_SCN_MEM_PROTECTED 0x00004000 - Obsolete */
456 X(IMAGE_SCN_MEM_FARDATA
, "MEM_FARDATA");
458 /* #define IMAGE_SCN_MEM_SYSHEAP 0x00010000 - Obsolete */
459 X(IMAGE_SCN_MEM_PURGEABLE
, "MEM_PURGEABLE");
460 X(IMAGE_SCN_MEM_16BIT
, "MEM_16BIT");
461 X(IMAGE_SCN_MEM_LOCKED
, "MEM_LOCKED");
462 X(IMAGE_SCN_MEM_PRELOAD
, "MEM_PRELOAD");
464 switch (characteristics
& IMAGE_SCN_ALIGN_MASK
)
466 #define X2(b,s) case b: printf("%s%s", sep, s); break
467 X2(IMAGE_SCN_ALIGN_1BYTES
, "ALIGN_1BYTES");
468 X2(IMAGE_SCN_ALIGN_2BYTES
, "ALIGN_2BYTES");
469 X2(IMAGE_SCN_ALIGN_4BYTES
, "ALIGN_4BYTES");
470 X2(IMAGE_SCN_ALIGN_8BYTES
, "ALIGN_8BYTES");
471 X2(IMAGE_SCN_ALIGN_16BYTES
, "ALIGN_16BYTES");
472 X2(IMAGE_SCN_ALIGN_32BYTES
, "ALIGN_32BYTES");
473 X2(IMAGE_SCN_ALIGN_64BYTES
, "ALIGN_64BYTES");
474 X2(IMAGE_SCN_ALIGN_128BYTES
, "ALIGN_128BYTES");
475 X2(IMAGE_SCN_ALIGN_256BYTES
, "ALIGN_256BYTES");
476 X2(IMAGE_SCN_ALIGN_512BYTES
, "ALIGN_512BYTES");
477 X2(IMAGE_SCN_ALIGN_1024BYTES
, "ALIGN_1024BYTES");
478 X2(IMAGE_SCN_ALIGN_2048BYTES
, "ALIGN_2048BYTES");
479 X2(IMAGE_SCN_ALIGN_4096BYTES
, "ALIGN_4096BYTES");
480 X2(IMAGE_SCN_ALIGN_8192BYTES
, "ALIGN_8192BYTES");
484 X(IMAGE_SCN_LNK_NRELOC_OVFL
, "LNK_NRELOC_OVFL");
486 X(IMAGE_SCN_MEM_DISCARDABLE
, "MEM_DISCARDABLE");
487 X(IMAGE_SCN_MEM_NOT_CACHED
, "MEM_NOT_CACHED");
488 X(IMAGE_SCN_MEM_NOT_PAGED
, "MEM_NOT_PAGED");
489 X(IMAGE_SCN_MEM_SHARED
, "MEM_SHARED");
490 X(IMAGE_SCN_MEM_EXECUTE
, "MEM_EXECUTE");
491 X(IMAGE_SCN_MEM_READ
, "MEM_READ");
492 X(IMAGE_SCN_MEM_WRITE
, "MEM_WRITE");
496 void dump_section(const IMAGE_SECTION_HEADER
*sectHead
, const char* strtable
)
500 /* long section name ? */
501 if (strtable
&& sectHead
->Name
[0] == '/' &&
502 ((offset
= atoi((const char*)sectHead
->Name
+ 1)) < *(const DWORD
*)strtable
))
503 printf(" %.8s (%s)", sectHead
->Name
, strtable
+ offset
);
505 printf(" %-8.8s", sectHead
->Name
);
506 printf(" VirtSize: 0x%08x VirtAddr: 0x%08x\n",
507 (UINT
)sectHead
->Misc
.VirtualSize
, (UINT
)sectHead
->VirtualAddress
);
508 printf(" raw data offs: 0x%08x raw data size: 0x%08x\n",
509 (UINT
)sectHead
->PointerToRawData
, (UINT
)sectHead
->SizeOfRawData
);
510 printf(" relocation offs: 0x%08x relocations: 0x%08x\n",
511 (UINT
)sectHead
->PointerToRelocations
, (UINT
)sectHead
->NumberOfRelocations
);
512 printf(" line # offs: %-8u line #'s: %-8u\n",
513 (UINT
)sectHead
->PointerToLinenumbers
, (UINT
)sectHead
->NumberOfLinenumbers
);
514 printf(" characteristics: 0x%08x\n", (UINT
)sectHead
->Characteristics
);
516 dump_section_characteristics(sectHead
->Characteristics
, " ");
521 static void dump_sections(const void *base
, const void* addr
, unsigned num_sect
)
523 const IMAGE_SECTION_HEADER
* sectHead
= addr
;
525 const char* strtable
;
527 if (PE_nt_headers
&& PE_nt_headers
->FileHeader
.PointerToSymbolTable
&& PE_nt_headers
->FileHeader
.NumberOfSymbols
)
529 strtable
= (const char*)base
+
530 PE_nt_headers
->FileHeader
.PointerToSymbolTable
+
531 PE_nt_headers
->FileHeader
.NumberOfSymbols
* sizeof(IMAGE_SYMBOL
);
533 else strtable
= NULL
;
535 printf("Section Table\n");
536 for (i
= 0; i
< num_sect
; i
++, sectHead
++)
538 dump_section(sectHead
, strtable
);
540 if (globals
.do_dump_rawdata
)
542 dump_data((const unsigned char *)base
+ sectHead
->PointerToRawData
, sectHead
->SizeOfRawData
, " " );
548 static char *get_str( char *buffer
, unsigned int rva
, unsigned int len
)
550 const WCHAR
*wstr
= PRD( rva
, len
);
553 len
/= sizeof(WCHAR
);
554 while (len
--) *buffer
++ = *wstr
++;
559 static void dump_section_apiset(void)
561 const IMAGE_SECTION_HEADER
*sect
= IMAGE_FIRST_SECTION(PE_nt_headers
);
562 const UINT
*ptr
, *entry
, *value
, *hash
;
563 unsigned int i
, j
, count
, val_count
, rva
;
566 for (i
= 0; i
< PE_nt_headers
->FileHeader
.NumberOfSections
; i
++, sect
++)
568 if (strncmp( (const char *)sect
->Name
, ".apiset", 8 )) continue;
569 rva
= sect
->PointerToRawData
;
570 ptr
= PRD( rva
, sizeof(*ptr
) );
571 printf( "ApiSet section:\n" );
572 switch (ptr
[0]) /* version */
575 printf( " Version: %u\n", ptr
[0] );
576 printf( " Count: %08x\n", ptr
[1] );
578 if (!(entry
= PRD( rva
+ 2 * sizeof(*ptr
), count
* 3 * sizeof(*entry
) ))) break;
579 for (i
= 0; i
< count
; i
++, entry
+= 3)
581 printf( " %s ->", get_str( buffer
, rva
+ entry
[0], entry
[1] ));
582 if (!(value
= PRD( rva
+ entry
[2], sizeof(*value
) ))) break;
583 val_count
= *value
++;
584 for (j
= 0; j
< val_count
; j
++, value
+= 4)
587 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[0], value
[1] ));
588 printf( "%s", get_str( buffer
, rva
+ value
[2], value
[3] ));
594 printf( " Version: %u\n", ptr
[0] );
595 printf( " Size: %08x\n", ptr
[1] );
596 printf( " Flags: %08x\n", ptr
[2] );
597 printf( " Count: %08x\n", ptr
[3] );
599 if (!(entry
= PRD( rva
+ 4 * sizeof(*ptr
), count
* 6 * sizeof(*entry
) ))) break;
600 for (i
= 0; i
< count
; i
++, entry
+= 6)
602 printf( " %08x %s ->", entry
[0], get_str( buffer
, rva
+ entry
[1], entry
[2] ));
603 if (!(value
= PRD( rva
+ entry
[5], sizeof(*value
) ))) break;
605 val_count
= *value
++;
606 for (j
= 0; j
< val_count
; j
++, value
+= 5)
609 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[1], value
[2] ));
610 printf( "%s", get_str( buffer
, rva
+ value
[3], value
[4] ));
616 printf( " Version: %u\n", ptr
[0] );
617 printf( " Size: %08x\n", ptr
[1] );
618 printf( " Flags: %08x\n", ptr
[2] );
619 printf( " Count: %08x\n", ptr
[3] );
620 printf( " EntryOffset: %08x\n", ptr
[4] );
621 printf( " HashOffset: %08x\n", ptr
[5] );
622 printf( " HashFactor: %08x\n", ptr
[6] );
624 if (!(entry
= PRD( rva
+ ptr
[4], count
* 6 * sizeof(*entry
) ))) break;
625 for (i
= 0; i
< count
; i
++, entry
+= 6)
627 printf( " %08x %s ->", entry
[0], get_str( buffer
, rva
+ entry
[1], entry
[2] ));
628 if (!(value
= PRD( rva
+ entry
[4], entry
[5] * 5 * sizeof(*value
) ))) break;
629 for (j
= 0; j
< entry
[5]; j
++, value
+= 5)
632 if (value
[1]) printf( "%s:", get_str( buffer
, rva
+ value
[1], value
[2] ));
633 printf( "%s", get_str( buffer
, rva
+ value
[3], value
[4] ));
637 printf( " Hash table:\n" );
638 if (!(hash
= PRD( rva
+ ptr
[5], count
* 2 * sizeof(*hash
) ))) break;
639 for (i
= 0; i
< count
; i
++, hash
+= 2)
641 entry
= PRD( rva
+ ptr
[4] + hash
[1] * 6 * sizeof(*entry
), 6 * sizeof(*entry
) );
642 printf( " %08x -> %s\n", hash
[0], get_str( buffer
, rva
+ entry
[1], entry
[3] ));
646 printf( "*** Unknown version %u\n", ptr
[0] );
653 static const char *find_export_from_rva( UINT rva
)
658 const WORD
*ordinals
;
659 const IMAGE_EXPORT_DIRECTORY
*dir
;
660 const char *ret
= NULL
;
662 if (!(dir
= get_dir( IMAGE_FILE_EXPORT_DIRECTORY
))) return NULL
;
663 if (!(funcs
= RVA( dir
->AddressOfFunctions
, dir
->NumberOfFunctions
* sizeof(DWORD
) ))) return NULL
;
664 names
= RVA( dir
->AddressOfNames
, dir
->NumberOfNames
* sizeof(DWORD
) );
665 ordinals
= RVA( dir
->AddressOfNameOrdinals
, dir
->NumberOfNames
* sizeof(WORD
) );
666 func_names
= calloc( dir
->NumberOfFunctions
, sizeof(*func_names
) );
668 for (i
= 0; i
< dir
->NumberOfNames
; i
++) func_names
[ordinals
[i
]] = names
[i
];
669 for (i
= 0; i
< dir
->NumberOfFunctions
&& !ret
; i
++)
670 if (funcs
[i
] == rva
) ret
= get_symbol_str( RVA( func_names
[i
], sizeof(DWORD
) ));
673 if (!ret
&& rva
== PE_nt_headers
->OptionalHeader
.AddressOfEntryPoint
) return "<EntryPoint>";
677 static void dump_dir_exported_functions(void)
680 const IMAGE_EXPORT_DIRECTORY
*dir
= get_dir_and_size(IMAGE_FILE_EXPORT_DIRECTORY
, &size
);
689 printf(" Name: %s\n", (const char*)RVA(dir
->Name
, sizeof(DWORD
)));
690 printf(" Characteristics: %08x\n", (UINT
)dir
->Characteristics
);
691 printf(" TimeDateStamp: %08X %s\n",
692 (UINT
)dir
->TimeDateStamp
, get_time_str(dir
->TimeDateStamp
));
693 printf(" Version: %u.%02u\n", dir
->MajorVersion
, dir
->MinorVersion
);
694 printf(" Ordinal base: %u\n", (UINT
)dir
->Base
);
695 printf(" # of functions: %u\n", (UINT
)dir
->NumberOfFunctions
);
696 printf(" # of Names: %u\n", (UINT
)dir
->NumberOfNames
);
697 printf("Addresses of functions: %08X\n", (UINT
)dir
->AddressOfFunctions
);
698 printf("Addresses of name ordinals: %08X\n", (UINT
)dir
->AddressOfNameOrdinals
);
699 printf("Addresses of names: %08X\n", (UINT
)dir
->AddressOfNames
);
701 printf(" Entry Pt Ordn Name\n");
703 pFunc
= RVA(dir
->AddressOfFunctions
, dir
->NumberOfFunctions
* sizeof(DWORD
));
704 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
705 pName
= RVA(dir
->AddressOfNames
, dir
->NumberOfNames
* sizeof(DWORD
));
706 pOrdl
= RVA(dir
->AddressOfNameOrdinals
, dir
->NumberOfNames
* sizeof(WORD
));
708 funcs
= calloc( dir
->NumberOfFunctions
, sizeof(*funcs
) );
709 if (!funcs
) fatal("no memory");
711 for (i
= 0; i
< dir
->NumberOfNames
; i
++) funcs
[pOrdl
[i
]] = pName
[i
];
713 for (i
= 0; i
< dir
->NumberOfFunctions
; i
++)
715 if (!pFunc
[i
]) continue;
716 printf(" %08X %5u ", pFunc
[i
], (UINT
)dir
->Base
+ i
);
718 printf("%s", get_symbol_str((const char*)RVA(funcs
[i
], sizeof(DWORD
))));
720 printf("<by ordinal>");
722 /* check for forwarded function */
723 if ((const char *)RVA(pFunc
[i
],1) >= (const char *)dir
&&
724 (const char *)RVA(pFunc
[i
],1) < (const char *)dir
+ size
)
725 printf(" (-> %s)", (const char *)RVA(pFunc
[i
],1));
733 struct runtime_function_x86_64
740 struct runtime_function_armnt
747 UINT FunctionLength
: 11;
754 UINT StackAdjust
: 10;
759 struct runtime_function_arm64
768 UINT FunctionLength
: 11;
780 struct runtime_function_x86_64 chain
;
791 struct unwind_info_x86_64
798 BYTE frame_offset
: 4;
799 struct opcode opcodes
[1]; /* count entries */
800 /* followed by union handler_data */
803 struct unwind_info_armnt
805 UINT function_length
: 18;
814 struct unwind_info_ext_armnt
821 struct unwind_info_epilogue_armnt
829 #define UWOP_PUSH_NONVOL 0
830 #define UWOP_ALLOC_LARGE 1
831 #define UWOP_ALLOC_SMALL 2
832 #define UWOP_SET_FPREG 3
833 #define UWOP_SAVE_NONVOL 4
834 #define UWOP_SAVE_NONVOL_FAR 5
835 #define UWOP_SAVE_XMM128 8
836 #define UWOP_SAVE_XMM128_FAR 9
837 #define UWOP_PUSH_MACHFRAME 10
839 #define UNW_FLAG_EHANDLER 1
840 #define UNW_FLAG_UHANDLER 2
841 #define UNW_FLAG_CHAININFO 4
843 static void dump_x86_64_unwind_info( const struct runtime_function_x86_64
*function
)
845 static const char * const reg_names
[16] =
846 { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
847 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" };
849 const union handler_data
*handler_data
;
850 const struct unwind_info_x86_64
*info
;
851 unsigned int i
, count
;
853 printf( "\nFunction %08x-%08x:\n", function
->BeginAddress
, function
->EndAddress
);
854 if (function
->UnwindData
& 1)
856 const struct runtime_function_x86_64
*next
= RVA( function
->UnwindData
& ~1, sizeof(*next
) );
857 printf( " -> function %08x-%08x\n", next
->BeginAddress
, next
->EndAddress
);
860 info
= RVA( function
->UnwindData
, sizeof(*info
) );
862 printf( " unwind info at %08x\n", function
->UnwindData
);
863 if (info
->version
!= 1)
865 printf( " *** unknown version %u\n", info
->version
);
868 printf( " flags %x", info
->flags
);
869 if (info
->flags
& UNW_FLAG_EHANDLER
) printf( " EHANDLER" );
870 if (info
->flags
& UNW_FLAG_UHANDLER
) printf( " UHANDLER" );
871 if (info
->flags
& UNW_FLAG_CHAININFO
) printf( " CHAININFO" );
872 printf( "\n prolog 0x%x bytes\n", info
->prolog
);
875 printf( " frame register %s offset 0x%x(%%rsp)\n",
876 reg_names
[info
->frame_reg
], info
->frame_offset
* 16 );
878 for (i
= 0; i
< info
->count
; i
++)
880 printf( " 0x%02x: ", info
->opcodes
[i
].offset
);
881 switch (info
->opcodes
[i
].code
)
883 case UWOP_PUSH_NONVOL
:
884 printf( "push %%%s\n", reg_names
[info
->opcodes
[i
].info
] );
886 case UWOP_ALLOC_LARGE
:
887 if (info
->opcodes
[i
].info
)
889 count
= *(const UINT
*)&info
->opcodes
[i
+1];
894 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 8;
897 printf( "sub $0x%x,%%rsp\n", count
);
899 case UWOP_ALLOC_SMALL
:
900 count
= (info
->opcodes
[i
].info
+ 1) * 8;
901 printf( "sub $0x%x,%%rsp\n", count
);
904 printf( "lea 0x%x(%%rsp),%s\n",
905 info
->frame_offset
* 16, reg_names
[info
->frame_reg
] );
907 case UWOP_SAVE_NONVOL
:
908 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 8;
909 printf( "mov %%%s,0x%x(%%rsp)\n", reg_names
[info
->opcodes
[i
].info
], count
);
912 case UWOP_SAVE_NONVOL_FAR
:
913 count
= *(const UINT
*)&info
->opcodes
[i
+1];
914 printf( "mov %%%s,0x%x(%%rsp)\n", reg_names
[info
->opcodes
[i
].info
], count
);
917 case UWOP_SAVE_XMM128
:
918 count
= *(const USHORT
*)&info
->opcodes
[i
+1] * 16;
919 printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info
->opcodes
[i
].info
, count
);
922 case UWOP_SAVE_XMM128_FAR
:
923 count
= *(const UINT
*)&info
->opcodes
[i
+1];
924 printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info
->opcodes
[i
].info
, count
);
927 case UWOP_PUSH_MACHFRAME
:
928 printf( "PUSH_MACHFRAME %u\n", info
->opcodes
[i
].info
);
931 printf( "*** unknown code %u\n", info
->opcodes
[i
].code
);
936 handler_data
= (const union handler_data
*)&info
->opcodes
[(info
->count
+ 1) & ~1];
937 if (info
->flags
& UNW_FLAG_CHAININFO
)
939 printf( " -> function %08x-%08x\n",
940 handler_data
->chain
.BeginAddress
, handler_data
->chain
.EndAddress
);
943 if (info
->flags
& (UNW_FLAG_EHANDLER
| UNW_FLAG_UHANDLER
))
944 printf( " handler %08x data at %08x\n", handler_data
->handler
,
945 (UINT
)(function
->UnwindData
+ (const char *)(&handler_data
->handler
+ 1) - (const char *)info
));
948 static const BYTE armnt_code_lengths
[256] =
950 /* 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,
951 /* 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,
952 /* 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,
953 /* 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,
954 /* 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,
955 /* 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,
956 /* 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,
957 /* 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
960 static void dump_armnt_unwind_info( const struct runtime_function_armnt
*fnc
)
962 const struct unwind_info_armnt
*info
;
963 const struct unwind_info_ext_armnt
*infoex
;
964 const struct unwind_info_epilogue_armnt
*infoepi
;
966 WORD i
, count
= 0, words
= 0;
970 char intregs
[32] = {0}, intregspop
[32] = {0}, vfpregs
[32] = {0};
971 WORD pf
= 0, ef
= 0, fpoffset
= 0, stack
= fnc
->StackAdjust
;
973 printf( "\nFunction %08x-%08x:\n", fnc
->BeginAddress
& ~1,
974 (fnc
->BeginAddress
& ~1) + fnc
->FunctionLength
* 2 );
975 printf( " Flag %x\n", fnc
->Flag
);
976 printf( " FunctionLength %x\n", fnc
->FunctionLength
);
977 printf( " Ret %x\n", fnc
->Ret
);
978 printf( " H %x\n", fnc
->H
);
979 printf( " Reg %x\n", fnc
->Reg
);
980 printf( " R %x\n", fnc
->R
);
981 printf( " L %x\n", fnc
->L
);
982 printf( " C %x\n", fnc
->C
);
983 printf( " StackAdjust %x\n", fnc
->StackAdjust
);
985 if (fnc
->StackAdjust
>= 0x03f4)
987 pf
= fnc
->StackAdjust
& 0x04;
988 ef
= fnc
->StackAdjust
& 0x08;
989 stack
= (fnc
->StackAdjust
& 3) + 1;
994 int first
= 4, last
= fnc
->Reg
+ 4;
997 first
= (~fnc
->StackAdjust
) & 3;
1002 sprintf(intregs
, "r%u", first
);
1004 sprintf(intregs
, "r%u-r%u", first
, last
);
1005 fpoffset
= last
+ 1 - first
;
1010 int first
= 4, last
= fnc
->Reg
+ 4;
1013 first
= (~fnc
->StackAdjust
) & 3;
1018 sprintf(intregspop
, "r%u", first
);
1020 sprintf(intregspop
, "r%u-r%u", first
, last
);
1026 strcat(intregs
, ", ");
1028 strcat(intregspop
, ", ");
1029 strcat(intregs
, "r11");
1030 strcat(intregspop
, "r11");
1035 strcat(intregs
, ", ");
1036 strcat(intregs
, "lr");
1038 if (intregspop
[0] && (fnc
->Ret
!= 0 || !fnc
->H
))
1039 strcat(intregspop
, ", ");
1041 strcat(intregspop
, "lr");
1043 strcat(intregspop
, "pc");
1049 sprintf(vfpregs
, "d8-d%u", fnc
->Reg
+ 8);
1051 strcpy(vfpregs
, "d8");
1054 if (fnc
->Flag
== 1) {
1056 printf( " Unwind Code\tpush {r0-r3}\n" );
1059 printf( " Unwind Code\tpush {%s}\n", intregs
);
1061 if (fnc
->C
&& fpoffset
== 0)
1062 printf( " Unwind Code\tmov r11, sp\n" );
1064 printf( " Unwind Code\tadd r11, sp, #%d\n", fpoffset
* 4 );
1066 if (fnc
->R
&& fnc
->Reg
!= 0x07)
1067 printf( " Unwind Code\tvpush {%s}\n", vfpregs
);
1070 printf( " Unwind Code\tsub sp, sp, #%d\n", stack
* 4 );
1075 printf( "Epilogue:\n" );
1078 printf( " Unwind Code\tadd sp, sp, #%d\n", stack
* 4 );
1080 if (fnc
->R
&& fnc
->Reg
!= 0x07)
1081 printf( " Unwind Code\tvpop {%s}\n", vfpregs
);
1084 printf( " Unwind Code\tpop {%s}\n", intregspop
);
1086 if (fnc
->H
&& !(fnc
->L
&& fnc
->Ret
== 0))
1087 printf( " Unwind Code\tadd sp, sp, #16\n" );
1088 else if (fnc
->H
&& (fnc
->L
&& fnc
->Ret
== 0))
1089 printf( " Unwind Code\tldr pc, [sp], #20\n" );
1092 printf( " Unwind Code\tbx <reg>\n" );
1093 else if (fnc
->Ret
== 2)
1094 printf( " Unwind Code\tb <address>\n" );
1099 info
= RVA( fnc
->UnwindData
, sizeof(*info
) );
1100 rva
= fnc
->UnwindData
+ sizeof(*info
);
1101 count
= info
->count
;
1102 words
= info
->words
;
1104 printf( "\nFunction %08x-%08x:\n", fnc
->BeginAddress
& ~1,
1105 (fnc
->BeginAddress
& ~1) + info
->function_length
* 2 );
1106 printf( " unwind info at %08x\n", fnc
->UnwindData
);
1107 printf( " Flag %x\n", fnc
->Flag
);
1108 printf( " FunctionLength %x\n", info
->function_length
);
1109 printf( " Version %x\n", info
->version
);
1110 printf( " X %x\n", info
->x
);
1111 printf( " E %x\n", info
->e
);
1112 printf( " F %x\n", info
->f
);
1113 printf( " Count %x\n", count
);
1114 printf( " Words %x\n", words
);
1116 if (!info
->count
&& !info
->words
)
1118 infoex
= RVA( rva
, sizeof(*infoex
) );
1119 rva
= rva
+ sizeof(*infoex
);
1120 count
= infoex
->excount
;
1121 words
= infoex
->exwords
;
1122 printf( " ExtCount %x\n", count
);
1123 printf( " ExtWords %x\n", words
);
1128 infoepi
= RVA( rva
, count
* sizeof(*infoepi
) );
1129 rva
= rva
+ count
* sizeof(*infoepi
);
1131 for (i
= 0; i
< count
; i
++)
1133 printf( " Epilogue Scope %x\n", i
);
1134 printf( " Offset %x\n", infoepi
[i
].offset
);
1135 printf( " Reserved %x\n", infoepi
[i
].res
);
1136 printf( " Condition %x\n", infoepi
[i
].cond
);
1137 printf( " Index %x\n", infoepi
[i
].index
);
1145 const unsigned int *codes
;
1147 BOOL inepilogue
= FALSE
;
1149 codes
= RVA( rva
, words
* sizeof(*codes
) );
1150 rva
= rva
+ words
* sizeof(*codes
);
1151 bytes
= (BYTE
*)codes
;
1153 for (b
= 0; b
< words
* sizeof(*codes
); b
++)
1155 BYTE code
= bytes
[b
];
1156 BYTE len
= armnt_code_lengths
[code
];
1158 if (info
->e
&& b
== count
)
1160 printf( "Epilogue:\n" );
1163 else if (!info
->e
&& infoepi
)
1165 for (i
= 0; i
< count
; i
++)
1166 if (b
== infoepi
[i
].index
)
1168 printf( "Epilogue from Scope %x at %08x:\n", i
,
1169 (fnc
->BeginAddress
& ~1) + infoepi
[i
].offset
* 2 );
1174 printf( " Unwind Code");
1175 for (i
= 0; i
< len
; i
++)
1176 printf( " %02x", bytes
[b
+i
] );
1181 else if (code
<= 0x7f)
1182 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", code
* 4 );
1183 else if (code
<= 0xbf)
1187 BYTE excodes
= bytes
[++b
];
1189 excode
= (code
<< 8) | excodes
;
1190 printf( "%s {", inepilogue
? "pop" : "push" );
1192 for (f
= 0; f
<= 12; f
++)
1194 if ((excode
>> f
) & 1)
1196 printf( "%sr%u", first
? "" : ", ", f
);
1201 if (excode
& 0x2000)
1202 printf( "%s%s", first
? "" : ", ", inepilogue
? "pc" : "lr" );
1206 else if (code
<= 0xcf)
1208 printf( "mov sp, r%u\n", code
& 0x0f );
1210 printf( "mov r%u, sp\n", code
& 0x0f );
1211 else if (code
<= 0xd7)
1213 printf( "pop {r4-r%u%s}\n", (code
& 0x03) + 4, (code
& 0x04) ? ", pc" : "" );
1215 printf( "push {r4-r%u%s}\n", (code
& 0x03) + 4, (code
& 0x04) ? ", lr" : "" );
1216 else if (code
<= 0xdf)
1218 printf( "pop {r4-r%u%s}\n", (code
& 0x03) + 8, (code
& 0x04) ? ", pc" : "" );
1220 printf( "push {r4-r%u%s}\n", (code
& 0x03) + 8, (code
& 0x04) ? ", lr" : "" );
1221 else if (code
<= 0xe7)
1222 printf( "%s {d8-d%u}\n", inepilogue
? "vpop" : "vpush", (code
& 0x07) + 8 );
1223 else if (code
<= 0xeb)
1226 BYTE excodes
= bytes
[++b
];
1228 excode
= (code
<< 8) | excodes
;
1229 printf( "%s sp, sp, #%u\n", inepilogue
? "addw" : "subw", (excode
& 0x03ff) *4 );
1231 else if (code
<= 0xed)
1235 BYTE excodes
= bytes
[++b
];
1237 excode
= (code
<< 8) | excodes
;
1238 printf( "%s {", inepilogue
? "pop" : "push" );
1240 for (f
= 0; f
< 8; f
++)
1242 if ((excode
>> f
) & 1)
1244 printf( "%sr%u", first
? "" : ", ", f
);
1249 if (excode
& 0x0100)
1250 printf( "%s%s", first
? "" : ", ", inepilogue
? "pc" : "lr" );
1254 else if (code
== 0xee)
1255 printf( "unknown 16\n" );
1256 else if (code
== 0xef)
1259 BYTE excodes
= bytes
[++b
];
1261 if (excodes
<= 0x0f)
1263 excode
= (code
<< 8) | excodes
;
1265 printf( "ldr lr, [sp], #%u\n", (excode
& 0x0f) * 4 );
1267 printf( "str lr, [sp, #-%u]!\n", (excode
& 0x0f) * 4 );
1270 printf( "unknown 32\n" );
1272 else if (code
<= 0xf4)
1273 printf( "unknown\n" );
1274 else if (code
<= 0xf6)
1276 WORD excode
, offset
= (code
== 0xf6) ? 16 : 0;
1277 BYTE excodes
= bytes
[++b
];
1279 excode
= (code
<< 8) | excodes
;
1280 printf( "%s {d%u-d%u}\n", inepilogue
? "vpop" : "vpush",
1281 ((excode
& 0x00f0) >> 4) + offset
, (excode
& 0x0f) + offset
);
1283 else if (code
<= 0xf7)
1285 unsigned int excode
;
1288 excodes
[0] = bytes
[++b
];
1289 excodes
[1] = bytes
[++b
];
1290 excode
= (code
<< 16) | (excodes
[0] << 8) | excodes
[1];
1291 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffff) *4 );
1293 else if (code
<= 0xf8)
1295 unsigned int excode
;
1298 excodes
[0] = bytes
[++b
];
1299 excodes
[1] = bytes
[++b
];
1300 excodes
[2] = bytes
[++b
];
1301 excode
= (code
<< 24) | (excodes
[0] << 16) | (excodes
[1] << 8) | excodes
[2];
1302 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffffff) * 4 );
1304 else if (code
<= 0xf9)
1306 unsigned int excode
;
1309 excodes
[0] = bytes
[++b
];
1310 excodes
[1] = bytes
[++b
];
1311 excode
= (code
<< 16) | (excodes
[0] << 8) | excodes
[1];
1312 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffff) *4 );
1314 else if (code
<= 0xfa)
1316 unsigned int excode
;
1319 excodes
[0] = bytes
[++b
];
1320 excodes
[1] = bytes
[++b
];
1321 excodes
[2] = bytes
[++b
];
1322 excode
= (code
<< 24) | (excodes
[0] << 16) | (excodes
[1] << 8) | excodes
[2];
1323 printf( "%s sp, sp, #%u\n", inepilogue
? "add" : "sub", (excode
& 0xffffff) * 4 );
1325 else if (code
<= 0xfb)
1327 else if (code
<= 0xfc)
1328 printf( "nop.w\n" );
1329 else if (code
<= 0xfd)
1331 printf( "(end) nop\n" );
1334 else if (code
<= 0xfe)
1336 printf( "(end) nop.w\n" );
1349 const unsigned int *handler
;
1351 handler
= RVA( rva
, sizeof(*handler
) );
1352 rva
= rva
+ sizeof(*handler
);
1354 printf( " handler %08x data at %08x\n", *handler
, rva
);
1358 struct unwind_info_arm64
1360 UINT function_length
: 18;
1368 struct unwind_info_ext_arm64
1375 struct unwind_info_epilog_arm64
1382 static const BYTE code_lengths
[256] =
1384 /* 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,
1385 /* 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,
1386 /* 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,
1387 /* 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,
1388 /* 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,
1389 /* 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,
1390 /* 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,
1391 /* 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
1394 static void dump_arm64_codes( const BYTE
*ptr
, unsigned int count
)
1398 for (i
= 0; i
< count
; i
+= code_lengths
[ptr
[i
]])
1400 BYTE len
= code_lengths
[ptr
[i
]];
1401 unsigned int val
= ptr
[i
];
1402 if (len
== 2) val
= ptr
[i
] * 0x100 + ptr
[i
+1];
1403 else if (len
== 4) val
= ptr
[i
] * 0x1000000 + ptr
[i
+1] * 0x10000 + ptr
[i
+2] * 0x100 + ptr
[i
+3];
1405 printf( " %04x: ", i
);
1406 for (j
= 0; j
< 4; j
++)
1407 if (j
< len
) printf( "%02x ", ptr
[i
+j
] );
1410 if (ptr
[i
] < 0x20) /* alloc_s */
1412 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0x1f) );
1414 else if (ptr
[i
] < 0x40) /* save_r19r20_x */
1416 printf( "stp r19,r20,[sp,-#%#x]!\n", 8 * (val
& 0x1f) );
1418 else if (ptr
[i
] < 0x80) /* save_fplr */
1420 printf( "stp r29,lr,[sp,#%#x]\n", 8 * (val
& 0x3f) );
1422 else if (ptr
[i
] < 0xc0) /* save_fplr_x */
1424 printf( "stp r29,lr,[sp,-#%#x]!\n", 8 * (val
& 0x3f) + 8 );
1426 else if (ptr
[i
] < 0xc8) /* alloc_m */
1428 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0x7ff) );
1430 else if (ptr
[i
] < 0xcc) /* save_regp */
1432 int reg
= 19 + ((val
>> 6) & 0xf);
1433 printf( "stp r%u,r%u,[sp,#%#x]\n", reg
, reg
+ 1, 8 * (val
& 0x3f) );
1435 else if (ptr
[i
] < 0xd0) /* save_regp_x */
1437 int reg
= 19 + ((val
>> 6) & 0xf);
1438 printf( "stp r%u,r%u,[sp,-#%#x]!\n", reg
, reg
+ 1, 8 * (val
& 0x3f) + 8 );
1440 else if (ptr
[i
] < 0xd4) /* save_reg */
1442 int reg
= 19 + ((val
>> 6) & 0xf);
1443 printf( "str r%u,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1445 else if (ptr
[i
] < 0xd6) /* save_reg_x */
1447 int reg
= 19 + ((val
>> 5) & 0xf);
1448 printf( "str r%u,[sp,-#%#x]!\n", reg
, 8 * (val
& 0x1f) + 8 );
1450 else if (ptr
[i
] < 0xd8) /* save_lrpair */
1452 int reg
= 19 + 2 * ((val
>> 6) & 0x7);
1453 printf( "stp r%u,lr,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1455 else if (ptr
[i
] < 0xda) /* save_fregp */
1457 int reg
= 8 + ((val
>> 6) & 0x7);
1458 printf( "stp d%u,d%u,[sp,#%#x]\n", reg
, reg
+ 1, 8 * (val
& 0x3f) );
1460 else if (ptr
[i
] < 0xdc) /* save_fregp_x */
1462 int reg
= 8 + ((val
>> 6) & 0x7);
1463 printf( "stp d%u,d%u,[sp,-#%#x]!\n", reg
, reg
+ 1, 8 * (val
& 0x3f) + 8 );
1465 else if (ptr
[i
] < 0xde) /* save_freg */
1467 int reg
= 8 + ((val
>> 6) & 0x7);
1468 printf( "str d%u,[sp,#%#x]\n", reg
, 8 * (val
& 0x3f) );
1470 else if (ptr
[i
] == 0xde) /* save_freg_x */
1472 int reg
= 8 + ((val
>> 5) & 0x7);
1473 printf( "str d%u,[sp,-#%#x]!\n", reg
, 8 * (val
& 0x3f) + 8 );
1475 else if (ptr
[i
] == 0xe0) /* alloc_l */
1477 printf( "sub sp,sp,#%#x\n", 16 * (val
& 0xffffff) );
1479 else if (ptr
[i
] == 0xe1) /* set_fp */
1481 printf( "mov x29,sp\n" );
1483 else if (ptr
[i
] == 0xe2) /* add_fp */
1485 printf( "add x29,sp,#%#x\n", 8 * (val
& 0xff) );
1487 else if (ptr
[i
] == 0xe3) /* nop */
1491 else if (ptr
[i
] == 0xe4) /* end */
1495 else if (ptr
[i
] == 0xe5) /* end_c */
1497 printf( "end_c\n" );
1499 else if (ptr
[i
] == 0xe6) /* save_next */
1501 printf( "save_next\n" );
1503 else if (ptr
[i
] == 0xe7) /* arithmetic */
1505 switch ((val
>> 4) & 0x0f)
1507 case 0: printf( "add lr,lr,x28\n" ); break;
1508 case 1: printf( "add lr,lr,sp\n" ); break;
1509 case 2: printf( "sub lr,lr,x28\n" ); break;
1510 case 3: printf( "sub lr,lr,sp\n" ); break;
1511 case 4: printf( "eor lr,lr,x28\n" ); break;
1512 case 5: printf( "eor lr,lr,sp\n" ); break;
1513 case 6: printf( "rol lr,lr,neg x28\n" ); break;
1514 case 8: printf( "ror lr,lr,x28\n" ); break;
1515 case 9: printf( "ror lr,lr,sp\n" ); break;
1516 default:printf( "unknown op\n" ); break;
1519 else if (ptr
[i
] == 0xe8) /* MSFT_OP_TRAP_FRAME */
1521 printf( "MSFT_OP_TRAP_FRAME\n" );
1523 else if (ptr
[i
] == 0xe9) /* MSFT_OP_MACHINE_FRAME */
1525 printf( "MSFT_OP_MACHINE_FRAME\n" );
1527 else if (ptr
[i
] == 0xea) /* MSFT_OP_CONTEXT */
1529 printf( "MSFT_OP_CONTEXT\n" );
1531 else if (ptr
[i
] == 0xec) /* MSFT_OP_CLEAR_UNWOUND_TO_CALL */
1533 printf( "MSFT_OP_CLEAR_UNWOUND_TO_CALL\n" );
1535 else printf( "??\n");
1539 static void dump_arm64_packed_info( const struct runtime_function_arm64
*func
)
1541 int i
, pos
= 0, intsz
= func
->RegI
* 8, fpsz
= func
->RegF
* 8, savesz
, locsz
;
1543 if (func
->CR
== 1) intsz
+= 8;
1544 if (func
->RegF
) fpsz
+= 8;
1546 savesz
= ((intsz
+ fpsz
+ 8 * 8 * func
->H
) + 0xf) & ~0xf;
1547 locsz
= func
->FrameSize
* 16 - savesz
;
1552 printf( " %04x: mov x29,sp\n", pos
++ );
1555 printf( " %04x: stp x29,lr,[sp,-#%#x]!\n", pos
++, locsz
);
1558 printf( " %04x: stp x29,lr,[sp,0]\n", pos
++ );
1564 printf( " %04x: sub sp,sp,#%#x\n", pos
++, locsz
);
1568 printf( " %04x: sub sp,sp,#%#x\n", pos
++, locsz
- 4080 );
1569 printf( " %04x: sub sp,sp,#%#x\n", pos
++, 4080 );
1576 printf( " %04x: stp x6,x7,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 48 );
1577 printf( " %04x: stp x4,x5,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 32 );
1578 printf( " %04x: stp x2,x3,[sp,#%#x]\n", pos
++, intsz
+ fpsz
+ 16 );
1579 printf( " %04x: stp x0,x1,[sp,#%#x]\n", pos
++, intsz
+ fpsz
);
1584 if (func
->RegF
% 2 == 0)
1585 printf( " %04x: str d%u,[sp,#%#x]\n", pos
++, 8 + func
->RegF
, intsz
+ fpsz
- 8 );
1586 for (i
= (func
->RegF
- 1)/ 2; i
>= 0; i
--)
1589 printf( " %04x: stp d8,d9,[sp,-#%#x]!\n", pos
++, savesz
);
1591 printf( " %04x: stp d%u,d%u,[sp,#%#x]\n", pos
++, 8 + 2 * i
, 9 + 2 * i
, intsz
+ 16 * i
);
1599 printf( " %04x: str lr,[sp,-#%#x]!\n", pos
++, savesz
);
1603 printf( " %04x: stp x19,lr,[sp,-#%#x]!\n", pos
++, savesz
);
1605 printf( " %04x: str x19,[sp,-#%#x]!\n", pos
++, savesz
);
1611 printf( " %04x: stp x%u,lr,[sp,#%#x]\n", pos
++, 18 + func
->RegI
, 8 * func
->RegI
- 8 );
1613 printf( " %04x: str x%u,[sp,#%#x]\n", pos
++, 18 + func
->RegI
, 8 * func
->RegI
- 8 );
1615 else if (func
->CR
== 1)
1616 printf( " %04x: str lr,[sp,#%#x]\n", pos
++, intsz
- 8 );
1618 for (i
= func
->RegI
/ 2 - 1; i
>= 0; i
--)
1620 printf( " %04x: stp x%u,x%u,[sp,#%#x]\n", pos
++, 19 + 2 * i
, 20 + 2 * i
, 16 * i
);
1622 printf( " %04x: stp x19,x20,[sp,-#%#x]!\n", pos
++, savesz
);
1625 printf( " %04x: end\n", pos
);
1628 static void dump_arm64_unwind_info( const struct runtime_function_arm64
*func
)
1630 const struct unwind_info_arm64
*info
;
1631 const struct unwind_info_ext_arm64
*infoex
;
1632 const struct unwind_info_epilog_arm64
*infoepi
;
1634 unsigned int i
, rva
, codes
, epilogs
;
1638 printf( "\nFunction %08x-%08x:\n", func
->BeginAddress
,
1639 func
->BeginAddress
+ func
->FunctionLength
* 4 );
1640 printf( " len=%#x flag=%x regF=%u regI=%u H=%u CR=%u frame=%x\n",
1641 func
->FunctionLength
, func
->Flag
, func
->RegF
, func
->RegI
,
1642 func
->H
, func
->CR
, func
->FrameSize
);
1643 dump_arm64_packed_info( func
);
1647 rva
= func
->UnwindData
;
1648 info
= RVA( rva
, sizeof(*info
) );
1649 rva
+= sizeof(*info
);
1650 epilogs
= info
->epilog
;
1651 codes
= info
->codes
;
1655 infoex
= RVA( rva
, sizeof(*infoex
) );
1656 rva
= rva
+ sizeof(*infoex
);
1657 codes
= infoex
->codes
;
1658 epilogs
= infoex
->epilog
;
1660 printf( "\nFunction %08x-%08x:\n",
1661 func
->BeginAddress
, func
->BeginAddress
+ info
->function_length
* 4 );
1662 printf( " len=%#x ver=%u X=%u E=%u epilogs=%u codes=%u\n",
1663 info
->function_length
, info
->version
, info
->x
, info
->e
, epilogs
, codes
* 4 );
1666 printf( " epilog 0: code=%04x\n", info
->epilog
);
1670 infoepi
= RVA( rva
, sizeof(*infoepi
) * epilogs
);
1671 rva
+= sizeof(*infoepi
) * epilogs
;
1672 for (i
= 0; i
< epilogs
; i
++)
1673 printf( " epilog %u: pc=%08x code=%04x\n", i
,
1674 func
->BeginAddress
+ infoepi
[i
].offset
* 4, infoepi
[i
].index
);
1676 ptr
= RVA( rva
, codes
* 4);
1680 const UINT
*handler
= RVA( rva
, sizeof(*handler
) );
1681 rva
+= sizeof(*handler
);
1682 printf( " handler: %08x data %08x\n", *handler
, rva
);
1684 dump_arm64_codes( ptr
, codes
* 4 );
1687 static void dump_dir_exceptions(void)
1689 unsigned int i
, size
;
1691 const IMAGE_FILE_HEADER
*file_header
;
1693 funcs
= get_dir_and_size(IMAGE_FILE_EXCEPTION_DIRECTORY
, &size
);
1696 file_header
= &PE_nt_headers
->FileHeader
;
1698 switch (file_header
->Machine
)
1700 case IMAGE_FILE_MACHINE_AMD64
:
1701 size
/= sizeof(struct runtime_function_x86_64
);
1702 printf( "%s exception info (%u functions):\n", get_machine_str( file_header
->Machine
), size
);
1703 for (i
= 0; i
< size
; i
++) dump_x86_64_unwind_info( (struct runtime_function_x86_64
*)funcs
+ i
);
1705 case IMAGE_FILE_MACHINE_ARMNT
:
1706 size
/= sizeof(struct runtime_function_armnt
);
1707 printf( "%s exception info (%u functions):\n", get_machine_str( file_header
->Machine
), size
);
1708 for (i
= 0; i
< size
; i
++) dump_armnt_unwind_info( (struct runtime_function_armnt
*)funcs
+ i
);
1710 case IMAGE_FILE_MACHINE_ARM64
:
1711 size
/= sizeof(struct runtime_function_arm64
);
1712 printf( "%s exception info (%u functions):\n", get_machine_str( file_header
->Machine
), size
);
1713 for (i
= 0; i
< size
; i
++) dump_arm64_unwind_info( (struct runtime_function_arm64
*)funcs
+ i
);
1716 printf( "Exception information not supported for %s binaries\n",
1717 get_machine_str(file_header
->Machine
));
1724 static void dump_image_thunk_data64(const IMAGE_THUNK_DATA64
*il
, UINT thunk_rva
)
1726 /* FIXME: This does not properly handle large images */
1727 const IMAGE_IMPORT_BY_NAME
* iibn
;
1728 for (; il
->u1
.Ordinal
; il
++, thunk_rva
+= sizeof(LONGLONG
))
1730 if (IMAGE_SNAP_BY_ORDINAL64(il
->u1
.Ordinal
))
1731 printf(" %08x %4u <by ordinal>\n", thunk_rva
, (UINT
)IMAGE_ORDINAL64(il
->u1
.Ordinal
));
1734 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
, sizeof(DWORD
));
1736 printf("Can't grab import by name info, skipping to next ordinal\n");
1738 printf(" %08x %4u %s\n", thunk_rva
, iibn
->Hint
, iibn
->Name
);
1743 static void dump_image_thunk_data32(const IMAGE_THUNK_DATA32
*il
, int offset
, UINT thunk_rva
)
1745 const IMAGE_IMPORT_BY_NAME
* iibn
;
1746 for (; il
->u1
.Ordinal
; il
++, thunk_rva
+= sizeof(UINT
))
1748 if (IMAGE_SNAP_BY_ORDINAL32(il
->u1
.Ordinal
))
1749 printf(" %08x %4u <by ordinal>\n", thunk_rva
, (UINT
)IMAGE_ORDINAL32(il
->u1
.Ordinal
));
1752 iibn
= RVA((DWORD
)il
->u1
.AddressOfData
- offset
, sizeof(DWORD
));
1754 printf("Can't grab import by name info, skipping to next ordinal\n");
1756 printf(" %08x %4u %s\n", thunk_rva
, iibn
->Hint
, iibn
->Name
);
1761 static void dump_dir_imported_functions(void)
1763 unsigned directorySize
;
1764 const IMAGE_IMPORT_DESCRIPTOR
* importDesc
= get_dir_and_size(IMAGE_FILE_IMPORT_DIRECTORY
, &directorySize
);
1766 if (!importDesc
) return;
1768 printf("Import Table size: %08x\n", directorySize
);/* FIXME */
1772 const IMAGE_THUNK_DATA32
* il
;
1774 if (!importDesc
->Name
|| !importDesc
->FirstThunk
) break;
1776 printf(" offset %08lx %s\n", Offset(importDesc
), (const char*)RVA(importDesc
->Name
, sizeof(DWORD
)));
1777 printf(" Hint/Name Table: %08X\n", (UINT
)importDesc
->OriginalFirstThunk
);
1778 printf(" TimeDateStamp: %08X (%s)\n",
1779 (UINT
)importDesc
->TimeDateStamp
, get_time_str(importDesc
->TimeDateStamp
));
1780 printf(" ForwarderChain: %08X\n", (UINT
)importDesc
->ForwarderChain
);
1781 printf(" First thunk RVA: %08X\n", (UINT
)importDesc
->FirstThunk
);
1783 printf(" Thunk Ordn Name\n");
1785 il
= (importDesc
->OriginalFirstThunk
!= 0) ?
1786 RVA((DWORD
)importDesc
->OriginalFirstThunk
, sizeof(DWORD
)) :
1787 RVA((DWORD
)importDesc
->FirstThunk
, sizeof(DWORD
));
1790 printf("Can't grab thunk data, going to next imported DLL\n");
1793 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1794 dump_image_thunk_data64((const IMAGE_THUNK_DATA64
*)il
, importDesc
->FirstThunk
);
1796 dump_image_thunk_data32(il
, 0, importDesc
->FirstThunk
);
1804 static void dump_hybrid_metadata(void)
1807 const void *metadata
= get_hybrid_metadata();
1809 if (!metadata
) return;
1810 printf( "Hybrid metadata\n" );
1812 switch (PE_nt_headers
->FileHeader
.Machine
)
1814 case IMAGE_FILE_MACHINE_I386
:
1816 const IMAGE_CHPE_METADATA_X86
*data
= metadata
;
1818 printf( " Version %#x\n", (int)data
->Version
);
1819 printf( " CHPECodeAddressRangeOffset %#x\n", (int)data
->CHPECodeAddressRangeOffset
);
1820 printf( " CHPECodeAddressRangeCount %#x\n", (int)data
->CHPECodeAddressRangeCount
);
1821 printf( " WowA64ExceptionHandlerFunctionPointer %#x\n", (int)data
->WowA64ExceptionHandlerFunctionPointer
);
1822 printf( " WowA64DispatchCallFunctionPointer %#x\n", (int)data
->WowA64DispatchCallFunctionPointer
);
1823 printf( " WowA64DispatchIndirectCallFunctionPointer %#x\n", (int)data
->WowA64DispatchIndirectCallFunctionPointer
);
1824 printf( " WowA64DispatchIndirectCallCfgFunctionPointer %#x\n", (int)data
->WowA64DispatchIndirectCallCfgFunctionPointer
);
1825 printf( " WowA64DispatchRetFunctionPointer %#x\n", (int)data
->WowA64DispatchRetFunctionPointer
);
1826 printf( " WowA64DispatchRetLeafFunctionPointer %#x\n", (int)data
->WowA64DispatchRetLeafFunctionPointer
);
1827 printf( " WowA64DispatchJumpFunctionPointer %#x\n", (int)data
->WowA64DispatchJumpFunctionPointer
);
1828 if (data
->Version
>= 2)
1829 printf( " CompilerIATPointer %#x\n", (int)data
->CompilerIATPointer
);
1830 if (data
->Version
>= 3)
1831 printf( " WowA64RdtscFunctionPointer %#x\n", (int)data
->WowA64RdtscFunctionPointer
);
1832 if (data
->Version
>= 4)
1834 printf( " unknown[0] %#x\n", (int)data
->unknown
[0] );
1835 printf( " unknown[1] %#x\n", (int)data
->unknown
[1] );
1836 printf( " unknown[2] %#x\n", (int)data
->unknown
[2] );
1837 printf( " unknown[3] %#x\n", (int)data
->unknown
[3] );
1840 if (data
->CHPECodeAddressRangeOffset
)
1842 const IMAGE_CHPE_RANGE_ENTRY
*map
= RVA( data
->CHPECodeAddressRangeOffset
,
1843 data
->CHPECodeAddressRangeCount
* sizeof(*map
) );
1845 printf( "\nCode ranges\n" );
1846 for (i
= 0; i
< data
->CHPECodeAddressRangeCount
; i
++)
1848 static const char *types
[] = { "x86", "ARM64" };
1849 unsigned int start
= map
[i
].StartOffset
& ~1;
1850 unsigned int type
= map
[i
].StartOffset
& 1;
1851 printf( " %08x - %08x %s\n", start
, start
+ (int)map
[i
].Length
, types
[type
] );
1858 case IMAGE_FILE_MACHINE_AMD64
:
1859 case IMAGE_FILE_MACHINE_ARM64
:
1861 const IMAGE_ARM64EC_METADATA
*data
= metadata
;
1863 printf( " Version %#x\n", (int)data
->Version
);
1864 printf( " CodeMap %#x\n", (int)data
->CodeMap
);
1865 printf( " CodeMapCount %#x\n", (int)data
->CodeMapCount
);
1866 printf( " CodeRangesToEntryPoints %#x\n", (int)data
->CodeRangesToEntryPoints
);
1867 printf( " RedirectionMetadata %#x\n", (int)data
->RedirectionMetadata
);
1868 printf( " __os_arm64x_dispatch_call_no_redirect %#x\n", (int)data
->__os_arm64x_dispatch_call_no_redirect
);
1869 printf( " __os_arm64x_dispatch_ret %#x\n", (int)data
->__os_arm64x_dispatch_ret
);
1870 printf( " __os_arm64x_dispatch_call %#x\n", (int)data
->__os_arm64x_dispatch_call
);
1871 printf( " __os_arm64x_dispatch_icall %#x\n", (int)data
->__os_arm64x_dispatch_icall
);
1872 printf( " __os_arm64x_dispatch_icall_cfg %#x\n", (int)data
->__os_arm64x_dispatch_icall_cfg
);
1873 printf( " AlternateEntryPoint %#x\n", (int)data
->AlternateEntryPoint
);
1874 printf( " AuxiliaryIAT %#x\n", (int)data
->AuxiliaryIAT
);
1875 printf( " CodeRangesToEntryPointsCount %#x\n", (int)data
->CodeRangesToEntryPointsCount
);
1876 printf( " RedirectionMetadataCount %#x\n", (int)data
->RedirectionMetadataCount
);
1877 printf( " GetX64InformationFunctionPointer %#x\n", (int)data
->GetX64InformationFunctionPointer
);
1878 printf( " SetX64InformationFunctionPointer %#x\n", (int)data
->SetX64InformationFunctionPointer
);
1879 printf( " ExtraRFETable %#x\n", (int)data
->ExtraRFETable
);
1880 printf( " ExtraRFETableSize %#x\n", (int)data
->ExtraRFETableSize
);
1881 printf( " __os_arm64x_dispatch_fptr %#x\n", (int)data
->__os_arm64x_dispatch_fptr
);
1882 printf( " AuxiliaryIATCopy %#x\n", (int)data
->AuxiliaryIATCopy
);
1886 const IMAGE_CHPE_RANGE_ENTRY
*map
= RVA( data
->CodeMap
, data
->CodeMapCount
* sizeof(*map
) );
1888 printf( "\nCode ranges\n" );
1889 for (i
= 0; i
< data
->CodeMapCount
; i
++)
1891 static const char *types
[] = { "ARM64", "ARM64EC", "x64", "??" };
1892 unsigned int start
= map
[i
].StartOffset
& ~0x3;
1893 unsigned int type
= map
[i
].StartOffset
& 0x3;
1894 printf( " %08x - %08x %s\n", start
, start
+ (int)map
[i
].Length
, types
[type
] );
1898 if (PE_nt_headers
->FileHeader
.Machine
== IMAGE_FILE_MACHINE_ARM64
) break;
1900 if (data
->CodeRangesToEntryPoints
)
1902 const IMAGE_ARM64EC_CODE_RANGE_ENTRY_POINT
*map
= RVA( data
->CodeRangesToEntryPoints
,
1903 data
->CodeRangesToEntryPointsCount
* sizeof(*map
) );
1905 printf( "\nCode ranges to entry points\n" );
1906 printf( " Start - End Entry point\n" );
1907 for (i
= 0; i
< data
->CodeRangesToEntryPointsCount
; i
++)
1909 const char *name
= find_export_from_rva( map
[i
].EntryPoint
);
1910 printf( " %08x - %08x %08x",
1911 (int)map
[i
].StartRva
, (int)map
[i
].EndRva
, (int)map
[i
].EntryPoint
);
1912 if (name
) printf( " %s", name
);
1917 if (data
->RedirectionMetadata
)
1919 const IMAGE_ARM64EC_REDIRECTION_ENTRY
*map
= RVA( data
->RedirectionMetadata
,
1920 data
->RedirectionMetadataCount
* sizeof(*map
) );
1922 printf( "\nEntry point redirection\n" );
1923 for (i
= 0; i
< data
->RedirectionMetadataCount
; i
++)
1925 const char *name
= find_export_from_rva( map
[i
].Source
);
1926 printf( " %08x -> %08x", (int)map
[i
].Source
, (int)map
[i
].Destination
);
1927 if (name
) printf( " (%s)", name
);
1937 static void dump_dir_loadconfig(void)
1940 const IMAGE_LOAD_CONFIG_DIRECTORY32
*loadcfg32
;
1942 loadcfg32
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
, &size
);
1943 if (!loadcfg32
) return;
1944 size
= min( size
, loadcfg32
->Size
);
1946 printf( "Loadconfig\n" );
1947 print_dword( "Size", loadcfg32
->Size
);
1948 print_dword( "TimeDateStamp", loadcfg32
->TimeDateStamp
);
1949 print_word( "MajorVersion", loadcfg32
->MajorVersion
);
1950 print_word( "MinorVersion", loadcfg32
->MinorVersion
);
1951 print_dword( "GlobalFlagsClear", loadcfg32
->GlobalFlagsClear
);
1952 print_dword( "GlobalFlagsSet", loadcfg32
->GlobalFlagsSet
);
1953 print_dword( "CriticalSectionDefaultTimeout", loadcfg32
->CriticalSectionDefaultTimeout
);
1955 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
1957 const IMAGE_LOAD_CONFIG_DIRECTORY64
*loadcfg64
= (void *)loadcfg32
;
1959 print_longlong( "DeCommitFreeBlockThreshold", loadcfg64
->DeCommitFreeBlockThreshold
);
1960 print_longlong( "DeCommitTotalFreeThreshold", loadcfg64
->DeCommitTotalFreeThreshold
);
1961 print_longlong( "MaximumAllocationSize", loadcfg64
->MaximumAllocationSize
);
1962 print_longlong( "VirtualMemoryThreshold", loadcfg64
->VirtualMemoryThreshold
);
1963 print_dword( "ProcessHeapFlags", loadcfg64
->ProcessHeapFlags
);
1964 print_longlong( "ProcessAffinityMask", loadcfg64
->ProcessAffinityMask
);
1965 print_word( "CSDVersion", loadcfg64
->CSDVersion
);
1966 print_word( "DependentLoadFlags", loadcfg64
->DependentLoadFlags
);
1967 print_longlong( "SecurityCookie", loadcfg64
->SecurityCookie
);
1968 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, SEHandlerTable
)) goto done
;
1969 print_longlong( "SEHandlerTable", loadcfg64
->SEHandlerTable
);
1970 print_longlong( "SEHandlerCount", loadcfg64
->SEHandlerCount
);
1971 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardCFCheckFunctionPointer
)) goto done
;
1972 print_longlong( "GuardCFCheckFunctionPointer", loadcfg64
->GuardCFCheckFunctionPointer
);
1973 print_longlong( "GuardCFDispatchFunctionPointer", loadcfg64
->GuardCFDispatchFunctionPointer
);
1974 print_longlong( "GuardCFFunctionTable", loadcfg64
->GuardCFFunctionTable
);
1975 print_longlong( "GuardCFFunctionCount", loadcfg64
->GuardCFFunctionCount
);
1976 print_dword( "GuardFlags", loadcfg64
->GuardFlags
);
1977 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, CodeIntegrity
)) goto done
;
1978 print_word( "CodeIntegrity.Flags", loadcfg64
->CodeIntegrity
.Flags
);
1979 print_word( "CodeIntegrity.Catalog", loadcfg64
->CodeIntegrity
.Catalog
);
1980 print_dword( "CodeIntegrity.CatalogOffset", loadcfg64
->CodeIntegrity
.CatalogOffset
);
1981 print_dword( "CodeIntegrity.Reserved", loadcfg64
->CodeIntegrity
.Reserved
);
1982 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardAddressTakenIatEntryTable
)) goto done
;
1983 print_longlong( "GuardAddressTakenIatEntryTable", loadcfg64
->GuardAddressTakenIatEntryTable
);
1984 print_longlong( "GuardAddressTakenIatEntryCount", loadcfg64
->GuardAddressTakenIatEntryCount
);
1985 print_longlong( "GuardLongJumpTargetTable", loadcfg64
->GuardLongJumpTargetTable
);
1986 print_longlong( "GuardLongJumpTargetCount", loadcfg64
->GuardLongJumpTargetCount
);
1987 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, DynamicValueRelocTable
)) goto done
;
1988 print_longlong( "DynamicValueRelocTable", loadcfg64
->DynamicValueRelocTable
);
1989 print_longlong( "CHPEMetadataPointer", loadcfg64
->CHPEMetadataPointer
);
1990 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardRFFailureRoutine
)) goto done
;
1991 print_longlong( "GuardRFFailureRoutine", loadcfg64
->GuardRFFailureRoutine
);
1992 print_longlong( "GuardRFFailureRoutineFuncPtr", loadcfg64
->GuardRFFailureRoutineFunctionPointer
);
1993 print_dword( "DynamicValueRelocTableOffset", loadcfg64
->DynamicValueRelocTableOffset
);
1994 print_word( "DynamicValueRelocTableSection",loadcfg64
->DynamicValueRelocTableSection
);
1995 print_word( "Reserved2", loadcfg64
->Reserved2
);
1996 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardRFVerifyStackPointerFunctionPointer
)) goto done
;
1997 print_longlong( "GuardRFVerifyStackPointerFuncPtr", loadcfg64
->GuardRFVerifyStackPointerFunctionPointer
);
1998 print_dword( "HotPatchTableOffset", loadcfg64
->HotPatchTableOffset
);
1999 print_dword( "Reserved3", loadcfg64
->Reserved3
);
2000 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, EnclaveConfigurationPointer
)) goto done
;
2001 print_longlong( "EnclaveConfigurationPointer", loadcfg64
->EnclaveConfigurationPointer
);
2002 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, VolatileMetadataPointer
)) goto done
;
2003 print_longlong( "VolatileMetadataPointer", loadcfg64
->VolatileMetadataPointer
);
2004 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardEHContinuationTable
)) goto done
;
2005 print_longlong( "GuardEHContinuationTable", loadcfg64
->GuardEHContinuationTable
);
2006 print_longlong( "GuardEHContinuationCount", loadcfg64
->GuardEHContinuationCount
);
2007 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardXFGCheckFunctionPointer
)) goto done
;
2008 print_longlong( "GuardXFGCheckFunctionPointer", loadcfg64
->GuardXFGCheckFunctionPointer
);
2009 print_longlong( "GuardXFGDispatchFunctionPointer", loadcfg64
->GuardXFGDispatchFunctionPointer
);
2010 print_longlong( "GuardXFGTableDispatchFuncPtr", loadcfg64
->GuardXFGTableDispatchFunctionPointer
);
2011 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, CastGuardOsDeterminedFailureMode
)) goto done
;
2012 print_longlong( "CastGuardOsDeterminedFailureMode", loadcfg64
->CastGuardOsDeterminedFailureMode
);
2013 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, GuardMemcpyFunctionPointer
)) goto done
;
2014 print_longlong( "GuardMemcpyFunctionPointer", loadcfg64
->GuardMemcpyFunctionPointer
);
2018 print_dword( "DeCommitFreeBlockThreshold", loadcfg32
->DeCommitFreeBlockThreshold
);
2019 print_dword( "DeCommitTotalFreeThreshold", loadcfg32
->DeCommitTotalFreeThreshold
);
2020 print_dword( "MaximumAllocationSize", loadcfg32
->MaximumAllocationSize
);
2021 print_dword( "VirtualMemoryThreshold", loadcfg32
->VirtualMemoryThreshold
);
2022 print_dword( "ProcessHeapFlags", loadcfg32
->ProcessHeapFlags
);
2023 print_dword( "ProcessAffinityMask", loadcfg32
->ProcessAffinityMask
);
2024 print_word( "CSDVersion", loadcfg32
->CSDVersion
);
2025 print_word( "DependentLoadFlags", loadcfg32
->DependentLoadFlags
);
2026 print_dword( "SecurityCookie", loadcfg32
->SecurityCookie
);
2027 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, SEHandlerTable
)) goto done
;
2028 print_dword( "SEHandlerTable", loadcfg32
->SEHandlerTable
);
2029 print_dword( "SEHandlerCount", loadcfg32
->SEHandlerCount
);
2030 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardCFCheckFunctionPointer
)) goto done
;
2031 print_dword( "GuardCFCheckFunctionPointer", loadcfg32
->GuardCFCheckFunctionPointer
);
2032 print_dword( "GuardCFDispatchFunctionPointer", loadcfg32
->GuardCFDispatchFunctionPointer
);
2033 print_dword( "GuardCFFunctionTable", loadcfg32
->GuardCFFunctionTable
);
2034 print_dword( "GuardCFFunctionCount", loadcfg32
->GuardCFFunctionCount
);
2035 print_dword( "GuardFlags", loadcfg32
->GuardFlags
);
2036 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, CodeIntegrity
)) goto done
;
2037 print_word( "CodeIntegrity.Flags", loadcfg32
->CodeIntegrity
.Flags
);
2038 print_word( "CodeIntegrity.Catalog", loadcfg32
->CodeIntegrity
.Catalog
);
2039 print_dword( "CodeIntegrity.CatalogOffset", loadcfg32
->CodeIntegrity
.CatalogOffset
);
2040 print_dword( "CodeIntegrity.Reserved", loadcfg32
->CodeIntegrity
.Reserved
);
2041 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardAddressTakenIatEntryTable
)) goto done
;
2042 print_dword( "GuardAddressTakenIatEntryTable", loadcfg32
->GuardAddressTakenIatEntryTable
);
2043 print_dword( "GuardAddressTakenIatEntryCount", loadcfg32
->GuardAddressTakenIatEntryCount
);
2044 print_dword( "GuardLongJumpTargetTable", loadcfg32
->GuardLongJumpTargetTable
);
2045 print_dword( "GuardLongJumpTargetCount", loadcfg32
->GuardLongJumpTargetCount
);
2046 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, DynamicValueRelocTable
)) goto done
;
2047 print_dword( "DynamicValueRelocTable", loadcfg32
->DynamicValueRelocTable
);
2048 print_dword( "CHPEMetadataPointer", loadcfg32
->CHPEMetadataPointer
);
2049 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardRFFailureRoutine
)) goto done
;
2050 print_dword( "GuardRFFailureRoutine", loadcfg32
->GuardRFFailureRoutine
);
2051 print_dword( "GuardRFFailureRoutineFuncPtr", loadcfg32
->GuardRFFailureRoutineFunctionPointer
);
2052 print_dword( "DynamicValueRelocTableOffset", loadcfg32
->DynamicValueRelocTableOffset
);
2053 print_word( "DynamicValueRelocTableSection", loadcfg32
->DynamicValueRelocTableSection
);
2054 print_word( "Reserved2", loadcfg32
->Reserved2
);
2055 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardRFVerifyStackPointerFunctionPointer
)) goto done
;
2056 print_dword( "GuardRFVerifyStackPointerFuncPtr", loadcfg32
->GuardRFVerifyStackPointerFunctionPointer
);
2057 print_dword( "HotPatchTableOffset", loadcfg32
->HotPatchTableOffset
);
2058 print_dword( "Reserved3", loadcfg32
->Reserved3
);
2059 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, EnclaveConfigurationPointer
)) goto done
;
2060 print_dword( "EnclaveConfigurationPointer", loadcfg32
->EnclaveConfigurationPointer
);
2061 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, VolatileMetadataPointer
)) goto done
;
2062 print_dword( "VolatileMetadataPointer", loadcfg32
->VolatileMetadataPointer
);
2063 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardEHContinuationTable
)) goto done
;
2064 print_dword( "GuardEHContinuationTable", loadcfg32
->GuardEHContinuationTable
);
2065 print_dword( "GuardEHContinuationCount", loadcfg32
->GuardEHContinuationCount
);
2066 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardXFGCheckFunctionPointer
)) goto done
;
2067 print_dword( "GuardXFGCheckFunctionPointer", loadcfg32
->GuardXFGCheckFunctionPointer
);
2068 print_dword( "GuardXFGDispatchFunctionPointer", loadcfg32
->GuardXFGDispatchFunctionPointer
);
2069 print_dword( "GuardXFGTableDispatchFuncPtr", loadcfg32
->GuardXFGTableDispatchFunctionPointer
);
2070 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, CastGuardOsDeterminedFailureMode
)) goto done
;
2071 print_dword( "CastGuardOsDeterminedFailureMode", loadcfg32
->CastGuardOsDeterminedFailureMode
);
2072 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, GuardMemcpyFunctionPointer
)) goto done
;
2073 print_dword( "GuardMemcpyFunctionPointer", loadcfg32
->GuardMemcpyFunctionPointer
);
2077 dump_hybrid_metadata();
2080 static void dump_dir_delay_imported_functions(void)
2082 unsigned directorySize
;
2083 const IMAGE_DELAYLOAD_DESCRIPTOR
*importDesc
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
, &directorySize
);
2085 if (!importDesc
) return;
2087 printf("Delay Import Table size: %08x\n", directorySize
); /* FIXME */
2091 const IMAGE_THUNK_DATA32
* il
;
2092 int offset
= (importDesc
->Attributes
.AllAttributes
& 1) ? 0 : PE_nt_headers
->OptionalHeader
.ImageBase
;
2094 if (!importDesc
->DllNameRVA
|| !importDesc
->ImportAddressTableRVA
|| !importDesc
->ImportNameTableRVA
) break;
2096 printf(" grAttrs %08x offset %08lx %s\n", (UINT
)importDesc
->Attributes
.AllAttributes
,
2097 Offset(importDesc
), (const char *)RVA(importDesc
->DllNameRVA
- offset
, sizeof(DWORD
)));
2098 printf(" Hint/Name Table: %08x\n", (UINT
)importDesc
->ImportNameTableRVA
);
2099 printf(" Address Table: %08x\n", (UINT
)importDesc
->ImportAddressTableRVA
);
2100 printf(" TimeDateStamp: %08X (%s)\n",
2101 (UINT
)importDesc
->TimeDateStamp
, get_time_str(importDesc
->TimeDateStamp
));
2103 printf(" Thunk Ordn Name\n");
2105 il
= RVA(importDesc
->ImportNameTableRVA
- offset
, sizeof(DWORD
));
2108 printf("Can't grab thunk data, going to next imported DLL\n");
2111 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2112 dump_image_thunk_data64((const IMAGE_THUNK_DATA64
*)il
, importDesc
->ImportAddressTableRVA
);
2114 dump_image_thunk_data32(il
, offset
, importDesc
->ImportAddressTableRVA
);
2122 static void dump_dir_debug_dir(const IMAGE_DEBUG_DIRECTORY
* idd
, int idx
)
2126 printf("Directory %02u\n", idx
+ 1);
2127 printf(" Characteristics: %08X\n", (UINT
)idd
->Characteristics
);
2128 printf(" TimeDateStamp: %08X %s\n",
2129 (UINT
)idd
->TimeDateStamp
, get_time_str(idd
->TimeDateStamp
));
2130 printf(" Version %u.%02u\n", idd
->MajorVersion
, idd
->MinorVersion
);
2134 case IMAGE_DEBUG_TYPE_UNKNOWN
: str
= "UNKNOWN"; break;
2135 case IMAGE_DEBUG_TYPE_COFF
: str
= "COFF"; break;
2136 case IMAGE_DEBUG_TYPE_CODEVIEW
: str
= "CODEVIEW"; break;
2137 case IMAGE_DEBUG_TYPE_FPO
: str
= "FPO"; break;
2138 case IMAGE_DEBUG_TYPE_MISC
: str
= "MISC"; break;
2139 case IMAGE_DEBUG_TYPE_EXCEPTION
: str
= "EXCEPTION"; break;
2140 case IMAGE_DEBUG_TYPE_FIXUP
: str
= "FIXUP"; break;
2141 case IMAGE_DEBUG_TYPE_OMAP_TO_SRC
: str
= "OMAP_TO_SRC"; break;
2142 case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
:str
= "OMAP_FROM_SRC"; break;
2143 case IMAGE_DEBUG_TYPE_BORLAND
: str
= "BORLAND"; break;
2144 case IMAGE_DEBUG_TYPE_RESERVED10
: str
= "RESERVED10"; break;
2145 case IMAGE_DEBUG_TYPE_CLSID
: str
= "CLSID"; break;
2146 case IMAGE_DEBUG_TYPE_VC_FEATURE
: str
= "VC_FEATURE"; break;
2147 case IMAGE_DEBUG_TYPE_POGO
: str
= "POGO"; break;
2148 case IMAGE_DEBUG_TYPE_ILTCG
: str
= "ILTCG"; break;
2149 case IMAGE_DEBUG_TYPE_MPX
: str
= "MPX"; break;
2150 case IMAGE_DEBUG_TYPE_REPRO
: str
= "REPRO"; break;
2152 printf(" Type: %u (%s)\n", (UINT
)idd
->Type
, str
);
2153 printf(" SizeOfData: %u\n", (UINT
)idd
->SizeOfData
);
2154 printf(" AddressOfRawData: %08X\n", (UINT
)idd
->AddressOfRawData
);
2155 printf(" PointerToRawData: %08X\n", (UINT
)idd
->PointerToRawData
);
2159 case IMAGE_DEBUG_TYPE_UNKNOWN
:
2161 case IMAGE_DEBUG_TYPE_COFF
:
2162 dump_coff(idd
->PointerToRawData
, idd
->SizeOfData
,
2163 IMAGE_FIRST_SECTION(PE_nt_headers
));
2165 case IMAGE_DEBUG_TYPE_CODEVIEW
:
2166 dump_codeview(idd
->PointerToRawData
, idd
->SizeOfData
);
2168 case IMAGE_DEBUG_TYPE_FPO
:
2169 dump_frame_pointer_omission(idd
->PointerToRawData
, idd
->SizeOfData
);
2171 case IMAGE_DEBUG_TYPE_MISC
:
2173 const IMAGE_DEBUG_MISC
* misc
= PRD(idd
->PointerToRawData
, idd
->SizeOfData
);
2174 if (!misc
) {printf("Can't get misc debug information\n"); break;}
2175 printf(" DataType: %u (%s)\n",
2176 (UINT
)misc
->DataType
, (misc
->DataType
== IMAGE_DEBUG_MISC_EXENAME
) ? "Exe name" : "Unknown");
2177 printf(" Length: %u\n", (UINT
)misc
->Length
);
2178 printf(" Unicode: %s\n", misc
->Unicode
? "Yes" : "No");
2179 printf(" Data: %s\n", misc
->Data
);
2187 static void dump_dir_debug(void)
2190 const IMAGE_DEBUG_DIRECTORY
*debugDir
= get_dir_and_size(IMAGE_FILE_DEBUG_DIRECTORY
, &nb_dbg
);
2192 nb_dbg
/= sizeof(*debugDir
);
2193 if (!debugDir
|| !nb_dbg
) return;
2195 printf("Debug Table (%u directories)\n", nb_dbg
);
2197 for (i
= 0; i
< nb_dbg
; i
++)
2199 dump_dir_debug_dir(debugDir
, i
);
2205 static inline void print_clrflags(const char *title
, UINT value
)
2207 printf(" %-34s 0x%X\n", title
, value
);
2208 #define X(f,s) if (value & f) printf(" %s\n", s)
2209 X(COMIMAGE_FLAGS_ILONLY
, "ILONLY");
2210 X(COMIMAGE_FLAGS_32BITREQUIRED
, "32BITREQUIRED");
2211 X(COMIMAGE_FLAGS_IL_LIBRARY
, "IL_LIBRARY");
2212 X(COMIMAGE_FLAGS_STRONGNAMESIGNED
, "STRONGNAMESIGNED");
2213 X(COMIMAGE_FLAGS_TRACKDEBUGDATA
, "TRACKDEBUGDATA");
2217 static inline void print_clrdirectory(const char *title
, const IMAGE_DATA_DIRECTORY
*dir
)
2219 printf(" %-23s rva: 0x%-8x size: 0x%-8x\n", title
, (UINT
)dir
->VirtualAddress
, (UINT
)dir
->Size
);
2222 static void dump_dir_clr_header(void)
2224 unsigned int size
= 0;
2225 const IMAGE_COR20_HEADER
*dir
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
, &size
);
2229 printf( "CLR Header\n" );
2230 print_dword( "Header Size", dir
->cb
);
2231 print_ver( "Required runtime version", dir
->MajorRuntimeVersion
, dir
->MinorRuntimeVersion
);
2232 print_clrflags( "Flags", dir
->Flags
);
2233 print_dword( "EntryPointToken", dir
->EntryPointToken
);
2235 printf( "CLR Data Directory\n" );
2236 print_clrdirectory( "MetaData", &dir
->MetaData
);
2237 print_clrdirectory( "Resources", &dir
->Resources
);
2238 print_clrdirectory( "StrongNameSignature", &dir
->StrongNameSignature
);
2239 print_clrdirectory( "CodeManagerTable", &dir
->CodeManagerTable
);
2240 print_clrdirectory( "VTableFixups", &dir
->VTableFixups
);
2241 print_clrdirectory( "ExportAddressTableJumps", &dir
->ExportAddressTableJumps
);
2242 print_clrdirectory( "ManagedNativeHeader", &dir
->ManagedNativeHeader
);
2246 static void dump_dynamic_relocs_arm64x( const IMAGE_BASE_RELOCATION
*base_reloc
, unsigned int size
)
2249 const IMAGE_BASE_RELOCATION
*base_end
= (const IMAGE_BASE_RELOCATION
*)((const char *)base_reloc
+ size
);
2251 printf( "Relocations ARM64X\n" );
2252 while (base_reloc
< base_end
- 1 && base_reloc
->SizeOfBlock
)
2254 const USHORT
*rel
= (const USHORT
*)(base_reloc
+ 1);
2255 const USHORT
*end
= (const USHORT
*)base_reloc
+ base_reloc
->SizeOfBlock
/ sizeof(USHORT
);
2256 printf( " Page %x\n", (UINT
)base_reloc
->VirtualAddress
);
2257 while (rel
< end
&& *rel
)
2259 USHORT offset
= *rel
& 0xfff;
2260 USHORT type
= (*rel
>> 12) & 3;
2261 USHORT arg
= *rel
>> 14;
2265 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL
:
2266 printf( " off %04x zero-fill %u bytes\n", offset
, 1 << arg
);
2268 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE
:
2269 printf( " off %04x set %u bytes value ", offset
, 1 << arg
);
2270 for (i
= (1 << arg
) / sizeof(USHORT
); i
> 0; i
--) printf( "%04x", rel
[i
- 1] );
2271 rel
+= (1 << arg
) / sizeof(USHORT
);
2274 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA
:
2275 printf( " off %04x add offset ", offset
);
2276 if (arg
& 1) printf( "-" );
2277 printf( "%08x\n", (UINT
)*rel
++ * ((arg
& 2) ? 8 : 4) );
2280 printf( " off %04x unknown (arg %x)\n", offset
, arg
);
2284 base_reloc
= (const IMAGE_BASE_RELOCATION
*)end
;
2288 static void dump_dynamic_relocs( const char *ptr
, unsigned int size
, ULONGLONG symbol
)
2292 case IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE
:
2293 printf( "Relocations GUARD_RF_PROLOGUE\n" );
2295 case IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE
:
2296 printf( "Relocations GUARD_RF_EPILOGUE\n" );
2298 case IMAGE_DYNAMIC_RELOCATION_GUARD_IMPORT_CONTROL_TRANSFER
:
2299 printf( "Relocations GUARD_IMPORT_CONTROL_TRANSFER\n" );
2301 case IMAGE_DYNAMIC_RELOCATION_GUARD_INDIR_CONTROL_TRANSFER
:
2302 printf( "Relocations GUARD_INDIR_CONTROL_TRANSFER\n" );
2304 case IMAGE_DYNAMIC_RELOCATION_GUARD_SWITCHTABLE_BRANCH
:
2305 printf( "Relocations GUARD_SWITCHTABLE_BRANCH\n" );
2307 case IMAGE_DYNAMIC_RELOCATION_ARM64X
:
2308 dump_dynamic_relocs_arm64x( (const IMAGE_BASE_RELOCATION
*)ptr
, size
);
2311 printf( "Unknown relocation symbol %s\n", longlong_str(symbol
) );
2316 static const IMAGE_DYNAMIC_RELOCATION_TABLE
*get_dyn_reloc_table(void)
2318 unsigned int size
, section
, offset
;
2319 const IMAGE_SECTION_HEADER
*sec
;
2320 const IMAGE_DYNAMIC_RELOCATION_TABLE
*table
;
2322 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2324 const IMAGE_LOAD_CONFIG_DIRECTORY64
*cfg
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
, &size
);
2325 if (!cfg
) return NULL
;
2326 size
= min( size
, cfg
->Size
);
2327 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64
, DynamicValueRelocTableSection
)) return NULL
;
2328 offset
= cfg
->DynamicValueRelocTableOffset
;
2329 section
= cfg
->DynamicValueRelocTableSection
;
2333 const IMAGE_LOAD_CONFIG_DIRECTORY32
*cfg
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
, &size
);
2334 if (!cfg
) return NULL
;
2335 size
= min( size
, cfg
->Size
);
2336 if (size
<= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32
, DynamicValueRelocTableSection
)) return NULL
;
2337 offset
= cfg
->DynamicValueRelocTableOffset
;
2338 section
= cfg
->DynamicValueRelocTableSection
;
2340 if (!section
|| section
> PE_nt_headers
->FileHeader
.NumberOfSections
) return NULL
;
2341 sec
= IMAGE_FIRST_SECTION( PE_nt_headers
) + section
- 1;
2342 if (offset
>= sec
->SizeOfRawData
) return NULL
;
2343 return PRD( sec
->PointerToRawData
+ offset
, sizeof(*table
) );
2346 static void dump_dir_dynamic_reloc(void)
2348 const char *ptr
, *end
;
2349 const IMAGE_DYNAMIC_RELOCATION_TABLE
*table
= get_dyn_reloc_table();
2353 printf( "Dynamic relocations (version %u)\n\n", (UINT
)table
->Version
);
2354 ptr
= (const char *)(table
+ 1);
2355 end
= ptr
+ table
->Size
;
2358 switch (table
->Version
)
2361 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2363 const IMAGE_DYNAMIC_RELOCATION64
*reloc
= (const IMAGE_DYNAMIC_RELOCATION64
*)ptr
;
2364 dump_dynamic_relocs( (const char *)(reloc
+ 1), reloc
->BaseRelocSize
, reloc
->Symbol
);
2365 ptr
+= sizeof(*reloc
) + reloc
->BaseRelocSize
;
2369 const IMAGE_DYNAMIC_RELOCATION32
*reloc
= (const IMAGE_DYNAMIC_RELOCATION32
*)ptr
;
2370 dump_dynamic_relocs( (const char *)(reloc
+ 1), reloc
->BaseRelocSize
, reloc
->Symbol
);
2371 ptr
+= sizeof(*reloc
) + reloc
->BaseRelocSize
;
2375 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2377 const IMAGE_DYNAMIC_RELOCATION64_V2
*reloc
= (const IMAGE_DYNAMIC_RELOCATION64_V2
*)ptr
;
2378 dump_dynamic_relocs( ptr
+ reloc
->HeaderSize
, reloc
->FixupInfoSize
, reloc
->Symbol
);
2379 ptr
+= reloc
->HeaderSize
+ reloc
->FixupInfoSize
;
2383 const IMAGE_DYNAMIC_RELOCATION32_V2
*reloc
= (const IMAGE_DYNAMIC_RELOCATION32_V2
*)ptr
;
2384 dump_dynamic_relocs( ptr
+ reloc
->HeaderSize
, reloc
->FixupInfoSize
, reloc
->Symbol
);
2385 ptr
+= reloc
->HeaderSize
+ reloc
->FixupInfoSize
;
2393 static const IMAGE_BASE_RELOCATION
*get_armx_relocs( unsigned int *size
)
2395 const char *ptr
, *end
;
2396 const IMAGE_DYNAMIC_RELOCATION_TABLE
*table
= get_dyn_reloc_table();
2398 if (!table
) return NULL
;
2399 ptr
= (const char *)(table
+ 1);
2400 end
= ptr
+ table
->Size
;
2403 switch (table
->Version
)
2406 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2408 const IMAGE_DYNAMIC_RELOCATION64
*reloc
= (const IMAGE_DYNAMIC_RELOCATION64
*)ptr
;
2409 if (reloc
->Symbol
== IMAGE_DYNAMIC_RELOCATION_ARM64X
)
2411 *size
= reloc
->BaseRelocSize
;
2412 return (const IMAGE_BASE_RELOCATION
*)(reloc
+ 1);
2414 ptr
+= sizeof(*reloc
) + reloc
->BaseRelocSize
;
2418 const IMAGE_DYNAMIC_RELOCATION32
*reloc
= (const IMAGE_DYNAMIC_RELOCATION32
*)ptr
;
2419 if (reloc
->Symbol
== IMAGE_DYNAMIC_RELOCATION_ARM64X
)
2421 *size
= reloc
->BaseRelocSize
;
2422 return (const IMAGE_BASE_RELOCATION
*)(reloc
+ 1);
2424 ptr
+= sizeof(*reloc
) + reloc
->BaseRelocSize
;
2428 if (PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2430 const IMAGE_DYNAMIC_RELOCATION64_V2
*reloc
= (const IMAGE_DYNAMIC_RELOCATION64_V2
*)ptr
;
2431 if (reloc
->Symbol
== IMAGE_DYNAMIC_RELOCATION_ARM64X
)
2433 *size
= reloc
->FixupInfoSize
;
2434 return (const IMAGE_BASE_RELOCATION
*)(reloc
+ 1);
2436 ptr
+= reloc
->HeaderSize
+ reloc
->FixupInfoSize
;
2440 const IMAGE_DYNAMIC_RELOCATION32_V2
*reloc
= (const IMAGE_DYNAMIC_RELOCATION32_V2
*)ptr
;
2441 if (reloc
->Symbol
== IMAGE_DYNAMIC_RELOCATION_ARM64X
)
2443 *size
= reloc
->FixupInfoSize
;
2444 return (const IMAGE_BASE_RELOCATION
*)(reloc
+ 1);
2446 ptr
+= reloc
->HeaderSize
+ reloc
->FixupInfoSize
;
2454 static BOOL
get_alt_header( void )
2457 const IMAGE_BASE_RELOCATION
*end
, *reloc
= get_armx_relocs( &size
);
2459 if (!reloc
) return FALSE
;
2460 end
= (const IMAGE_BASE_RELOCATION
*)((const char *)reloc
+ size
);
2462 while (reloc
< end
- 1 && reloc
->SizeOfBlock
)
2464 const USHORT
*rel
= (const USHORT
*)(reloc
+ 1);
2465 const USHORT
*rel_end
= (const USHORT
*)reloc
+ reloc
->SizeOfBlock
/ sizeof(USHORT
);
2466 char *page
= reloc
->VirtualAddress
? (char *)RVA(reloc
->VirtualAddress
,1) : dump_base
;
2468 while (rel
< rel_end
&& *rel
)
2470 USHORT offset
= *rel
& 0xfff;
2471 USHORT type
= (*rel
>> 12) & 3;
2472 USHORT arg
= *rel
>> 14;
2477 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL
:
2478 memset( page
+ offset
, 0, 1 << arg
);
2480 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE
:
2481 memcpy( page
+ offset
, rel
, 1 << arg
);
2482 rel
+= (1 << arg
) / sizeof(USHORT
);
2484 case IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA
:
2485 val
= (unsigned int)*rel
++ * ((arg
& 2) ? 8 : 4);
2486 if (arg
& 1) val
= -val
;
2487 *(int *)(page
+ offset
) += val
;
2491 reloc
= (const IMAGE_BASE_RELOCATION
*)rel_end
;
2496 static void dump_dir_reloc(void)
2498 unsigned int i
, size
= 0;
2499 const USHORT
*relocs
;
2500 const IMAGE_BASE_RELOCATION
*rel
= get_dir_and_size(IMAGE_DIRECTORY_ENTRY_BASERELOC
, &size
);
2501 const IMAGE_BASE_RELOCATION
*end
= (const IMAGE_BASE_RELOCATION
*)((const char *)rel
+ size
);
2502 static const char * const names
[] =
2509 "BASED_MIPS_JMPADDR",
2524 printf( "Relocations\n" );
2525 while (rel
< end
- 1 && rel
->SizeOfBlock
)
2527 printf( " Page %x\n", (UINT
)rel
->VirtualAddress
);
2528 relocs
= (const USHORT
*)(rel
+ 1);
2529 i
= (rel
->SizeOfBlock
- sizeof(*rel
)) / sizeof(USHORT
);
2532 USHORT offset
= *relocs
& 0xfff;
2533 int type
= *relocs
>> 12;
2534 printf( " off %04x type %s\n", offset
, names
[type
] );
2537 rel
= (const IMAGE_BASE_RELOCATION
*)relocs
;
2542 static void dump_dir_tls(void)
2544 IMAGE_TLS_DIRECTORY64 dir
;
2545 const UINT
*callbacks
;
2546 const IMAGE_TLS_DIRECTORY32
*pdir
= get_dir(IMAGE_FILE_THREAD_LOCAL_STORAGE
);
2550 if(PE_nt_headers
->OptionalHeader
.Magic
== IMAGE_NT_OPTIONAL_HDR64_MAGIC
)
2551 memcpy(&dir
, pdir
, sizeof(dir
));
2554 dir
.StartAddressOfRawData
= pdir
->StartAddressOfRawData
;
2555 dir
.EndAddressOfRawData
= pdir
->EndAddressOfRawData
;
2556 dir
.AddressOfIndex
= pdir
->AddressOfIndex
;
2557 dir
.AddressOfCallBacks
= pdir
->AddressOfCallBacks
;
2558 dir
.SizeOfZeroFill
= pdir
->SizeOfZeroFill
;
2559 dir
.Characteristics
= pdir
->Characteristics
;
2562 /* FIXME: This does not properly handle large images */
2563 printf( "Thread Local Storage\n" );
2564 printf( " Raw data %08x-%08x (data size %x zero fill size %x)\n",
2565 (UINT
)dir
.StartAddressOfRawData
, (UINT
)dir
.EndAddressOfRawData
,
2566 (UINT
)(dir
.EndAddressOfRawData
- dir
.StartAddressOfRawData
),
2567 (UINT
)dir
.SizeOfZeroFill
);
2568 printf( " Index address %08x\n", (UINT
)dir
.AddressOfIndex
);
2569 printf( " Characteristics %08x\n", (UINT
)dir
.Characteristics
);
2570 printf( " Callbacks %08x -> {", (UINT
)dir
.AddressOfCallBacks
);
2571 if (dir
.AddressOfCallBacks
)
2573 UINT addr
= (UINT
)dir
.AddressOfCallBacks
- PE_nt_headers
->OptionalHeader
.ImageBase
;
2574 while ((callbacks
= RVA(addr
, sizeof(UINT
))) && *callbacks
)
2576 printf( " %08x", *callbacks
);
2577 addr
+= sizeof(UINT
);
2583 enum FileSig
get_kind_dbg(void)
2587 pw
= PRD(0, sizeof(WORD
));
2588 if (!pw
) {printf("Can't get main signature, aborting\n"); return 0;}
2590 if (*pw
== 0x4944 /* "DI" */) return SIG_DBG
;
2596 const IMAGE_SEPARATE_DEBUG_HEADER
* separateDebugHead
;
2599 const IMAGE_DEBUG_DIRECTORY
* debugDir
;
2601 separateDebugHead
= PRD(0, sizeof(*separateDebugHead
));
2602 if (!separateDebugHead
) {printf("Can't grab the separate header, aborting\n"); return;}
2604 printf ("Signature: %.2s (0x%4X)\n",
2605 (const char*)&separateDebugHead
->Signature
, separateDebugHead
->Signature
);
2606 printf ("Flags: 0x%04X\n", separateDebugHead
->Flags
);
2607 printf ("Machine: 0x%04X (%s)\n",
2608 separateDebugHead
->Machine
, get_machine_str(separateDebugHead
->Machine
));
2609 printf ("Characteristics: 0x%04X\n", separateDebugHead
->Characteristics
);
2610 printf ("TimeDateStamp: 0x%08X (%s)\n",
2611 (UINT
)separateDebugHead
->TimeDateStamp
, get_time_str(separateDebugHead
->TimeDateStamp
));
2612 printf ("CheckSum: 0x%08X\n", (UINT
)separateDebugHead
->CheckSum
);
2613 printf ("ImageBase: 0x%08X\n", (UINT
)separateDebugHead
->ImageBase
);
2614 printf ("SizeOfImage: 0x%08X\n", (UINT
)separateDebugHead
->SizeOfImage
);
2615 printf ("NumberOfSections: 0x%08X\n", (UINT
)separateDebugHead
->NumberOfSections
);
2616 printf ("ExportedNamesSize: 0x%08X\n", (UINT
)separateDebugHead
->ExportedNamesSize
);
2617 printf ("DebugDirectorySize: 0x%08X\n", (UINT
)separateDebugHead
->DebugDirectorySize
);
2619 if (!PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
),
2620 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)))
2621 {printf("Can't get the sections, aborting\n"); return;}
2623 dump_sections(separateDebugHead
, separateDebugHead
+ 1, separateDebugHead
->NumberOfSections
);
2625 nb_dbg
= separateDebugHead
->DebugDirectorySize
/ sizeof(IMAGE_DEBUG_DIRECTORY
);
2626 debugDir
= PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER
) +
2627 separateDebugHead
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
) +
2628 separateDebugHead
->ExportedNamesSize
,
2629 nb_dbg
* sizeof(IMAGE_DEBUG_DIRECTORY
));
2630 if (!debugDir
) {printf("Couldn't get the debug directory info, aborting\n");return;}
2632 printf("Debug Table (%u directories)\n", nb_dbg
);
2634 for (i
= 0; i
< nb_dbg
; i
++)
2636 dump_dir_debug_dir(debugDir
, i
);
2641 static const char *get_resource_type( unsigned int id
)
2643 static const char * const types
[] =
2672 if ((size_t)id
< ARRAY_SIZE(types
)) return types
[id
];
2676 /* dump an ASCII string with proper escaping */
2677 static int dump_strA( const unsigned char *str
, size_t len
)
2679 static const char escapes
[32] = ".......abtnvfr.............e....";
2684 for (; len
; str
++, len
--)
2686 if (pos
> buffer
+ sizeof(buffer
) - 8)
2688 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2689 count
+= pos
- buffer
;
2692 if (*str
> 127) /* hex escape */
2694 pos
+= sprintf( pos
, "\\x%02x", *str
);
2697 if (*str
< 32) /* octal or C escape */
2699 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
2700 if (escapes
[*str
] != '.')
2701 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
2702 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
2703 pos
+= sprintf( pos
, "\\%03o", *str
);
2705 pos
+= sprintf( pos
, "\\%o", *str
);
2708 if (*str
== '\\') *pos
++ = '\\';
2711 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2712 count
+= pos
- buffer
;
2716 /* dump a Unicode string with proper escaping */
2717 static int dump_strW( const WCHAR
*str
, size_t len
)
2719 static const char escapes
[32] = ".......abtnvfr.............e....";
2724 for (; len
; str
++, len
--)
2726 if (pos
> buffer
+ sizeof(buffer
) - 8)
2728 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2729 count
+= pos
- buffer
;
2732 if (*str
> 127) /* hex escape */
2734 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
2735 pos
+= sprintf( pos
, "\\x%04x", *str
);
2737 pos
+= sprintf( pos
, "\\x%x", *str
);
2740 if (*str
< 32) /* octal or C escape */
2742 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
2743 if (escapes
[*str
] != '.')
2744 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
2745 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
2746 pos
+= sprintf( pos
, "\\%03o", *str
);
2748 pos
+= sprintf( pos
, "\\%o", *str
);
2751 if (*str
== '\\') *pos
++ = '\\';
2754 fwrite( buffer
, pos
- buffer
, 1, stdout
);
2755 count
+= pos
- buffer
;
2759 /* dump data for a STRING resource */
2760 static void dump_string_data( const WCHAR
*ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
2764 for (i
= 0; i
< 16 && size
; i
++)
2766 unsigned len
= *ptr
++;
2773 else size
-= len
+ 1;
2777 printf( "%s%04x \"", prefix
, (id
- 1) * 16 + i
);
2778 dump_strW( ptr
, len
);
2785 /* dump data for a MESSAGETABLE resource */
2786 static void dump_msgtable_data( const void *ptr
, unsigned int size
, unsigned int id
, const char *prefix
)
2788 const MESSAGE_RESOURCE_DATA
*data
= ptr
;
2789 const MESSAGE_RESOURCE_BLOCK
*block
= data
->Blocks
;
2792 for (i
= 0; i
< data
->NumberOfBlocks
; i
++, block
++)
2794 const MESSAGE_RESOURCE_ENTRY
*entry
;
2796 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)data
+ block
->OffsetToEntries
);
2797 for (j
= block
->LowId
; j
<= block
->HighId
; j
++)
2799 if (entry
->Flags
& MESSAGE_RESOURCE_UNICODE
)
2801 const WCHAR
*str
= (const WCHAR
*)entry
->Text
;
2802 printf( "%s%08x L\"", prefix
, j
);
2803 dump_strW( str
, strlenW(str
) );
2808 const char *str
= (const char *) entry
->Text
;
2809 printf( "%s%08x \"", prefix
, j
);
2810 dump_strA( entry
->Text
, strlen(str
) );
2813 entry
= (const MESSAGE_RESOURCE_ENTRY
*)((const char *)entry
+ entry
->Length
);
2818 static void dump_dir_resource(void)
2820 const IMAGE_RESOURCE_DIRECTORY
*root
= get_dir(IMAGE_FILE_RESOURCE_DIRECTORY
);
2821 const IMAGE_RESOURCE_DIRECTORY
*namedir
;
2822 const IMAGE_RESOURCE_DIRECTORY
*langdir
;
2823 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*e1
, *e2
, *e3
;
2824 const IMAGE_RESOURCE_DIR_STRING_U
*string
;
2825 const IMAGE_RESOURCE_DATA_ENTRY
*data
;
2830 printf( "Resources:" );
2832 for (i
= 0; i
< root
->NumberOfNamedEntries
+ root
->NumberOfIdEntries
; i
++)
2834 e1
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(root
+ 1) + i
;
2835 namedir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e1
->OffsetToDirectory
);
2836 for (j
= 0; j
< namedir
->NumberOfNamedEntries
+ namedir
->NumberOfIdEntries
; j
++)
2838 e2
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(namedir
+ 1) + j
;
2839 langdir
= (const IMAGE_RESOURCE_DIRECTORY
*)((const char *)root
+ e2
->OffsetToDirectory
);
2840 for (k
= 0; k
< langdir
->NumberOfNamedEntries
+ langdir
->NumberOfIdEntries
; k
++)
2842 e3
= (const IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(langdir
+ 1) + k
;
2845 if (e1
->NameIsString
)
2847 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*)((const char *)root
+ e1
->NameOffset
);
2848 dump_unicode_str( string
->NameString
, string
->Length
);
2852 const char *type
= get_resource_type( e1
->Id
);
2853 if (type
) printf( "%s", type
);
2854 else printf( "%04x", e1
->Id
);
2858 if (e2
->NameIsString
)
2860 string
= (const IMAGE_RESOURCE_DIR_STRING_U
*) ((const char *)root
+ e2
->NameOffset
);
2861 dump_unicode_str( string
->NameString
, string
->Length
);
2864 printf( "%04x", e2
->Id
);
2866 printf( " Language=%04x:\n", e3
->Id
);
2867 data
= (const IMAGE_RESOURCE_DATA_ENTRY
*)((const char *)root
+ e3
->OffsetToData
);
2868 if (e1
->NameIsString
)
2870 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
2875 dump_string_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, e2
->Id
, " " );
2878 dump_msgtable_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, e2
->Id
, " " );
2881 dump_data( RVA( data
->OffsetToData
, data
->Size
), data
->Size
, " " );
2890 static void dump_debug(void)
2892 const char* stabs
= NULL
;
2893 unsigned szstabs
= 0;
2894 const char* stabstr
= NULL
;
2897 const IMAGE_SECTION_HEADER
* sectHead
;
2899 sectHead
= IMAGE_FIRST_SECTION(PE_nt_headers
);
2901 for (i
= 0; i
< PE_nt_headers
->FileHeader
.NumberOfSections
; i
++, sectHead
++)
2903 if (!strcmp((const char *)sectHead
->Name
, ".stab"))
2905 stabs
= RVA(sectHead
->VirtualAddress
, sectHead
->Misc
.VirtualSize
);
2906 szstabs
= sectHead
->Misc
.VirtualSize
;
2908 if (!strncmp((const char *)sectHead
->Name
, ".stabstr", 8))
2910 stabstr
= RVA(sectHead
->VirtualAddress
, sectHead
->Misc
.VirtualSize
);
2911 szstr
= sectHead
->Misc
.VirtualSize
;
2914 if (stabs
&& stabstr
)
2915 dump_stabs(stabs
, szstabs
, stabstr
, szstr
);
2918 static void dump_symbol_table(void)
2920 const IMAGE_SYMBOL
* sym
;
2923 numsym
= PE_nt_headers
->FileHeader
.NumberOfSymbols
;
2924 if (!PE_nt_headers
->FileHeader
.PointerToSymbolTable
|| !numsym
)
2926 sym
= PRD(PE_nt_headers
->FileHeader
.PointerToSymbolTable
,
2927 sizeof(*sym
) * numsym
);
2930 dump_coff_symbol_table(sym
, numsym
, IMAGE_FIRST_SECTION(PE_nt_headers
));
2933 enum FileSig
get_kind_exec(void)
2937 const IMAGE_DOS_HEADER
* dh
;
2939 pw
= PRD(0, sizeof(WORD
));
2940 if (!pw
) {printf("Can't get main signature, aborting\n"); return 0;}
2942 if (*pw
!= IMAGE_DOS_SIGNATURE
) return SIG_UNKNOWN
;
2944 if ((dh
= PRD(0, sizeof(IMAGE_DOS_HEADER
))))
2946 /* the signature is the first DWORD */
2947 pdw
= PRD(dh
->e_lfanew
, sizeof(DWORD
));
2950 if (*pdw
== IMAGE_NT_SIGNATURE
) return SIG_PE
;
2951 if (*(const WORD
*)pdw
== IMAGE_OS2_SIGNATURE
) return SIG_NE
;
2952 if (*(const WORD
*)pdw
== IMAGE_VXD_SIGNATURE
) return SIG_LE
;
2963 PE_nt_headers
= get_nt_header();
2969 printf( "\n**** Alternate (%s) data ****\n\n",
2970 get_machine_str(PE_nt_headers
->FileHeader
.Machine
));
2971 else if (get_dyn_reloc_table())
2972 printf( "**** Native (%s) data ****\n\n",
2973 get_machine_str(PE_nt_headers
->FileHeader
.Machine
));
2975 if (globals
.do_dumpheader
)
2978 /* FIXME: should check ptr */
2979 dump_sections(PRD(0, 1), IMAGE_FIRST_SECTION(PE_nt_headers
),
2980 PE_nt_headers
->FileHeader
.NumberOfSections
);
2982 else if (!globals
.dumpsect
)
2984 /* show at least something here */
2988 if (globals_dump_sect("import"))
2990 dump_dir_imported_functions();
2991 dump_dir_delay_imported_functions();
2993 if (globals_dump_sect("export"))
2994 dump_dir_exported_functions();
2995 if (globals_dump_sect("debug"))
2997 if (globals_dump_sect("resource"))
2998 dump_dir_resource();
2999 if (globals_dump_sect("tls"))
3001 if (globals_dump_sect("loadcfg"))
3002 dump_dir_loadconfig();
3003 if (globals_dump_sect("clr"))
3004 dump_dir_clr_header();
3005 if (globals_dump_sect("reloc"))
3007 if (globals_dump_sect("dynreloc"))
3008 dump_dir_dynamic_reloc();
3009 if (globals_dump_sect("except"))
3010 dump_dir_exceptions();
3011 if (globals_dump_sect("apiset"))
3012 dump_section_apiset();
3014 if (globals
.do_symbol_table
)
3015 dump_symbol_table();
3016 if (globals
.do_debug
)
3019 if (!get_alt_header()) break;
3023 typedef struct _dll_symbol
{
3028 static dll_symbol
*dll_symbols
= NULL
;
3029 static dll_symbol
*dll_current_symbol
= NULL
;
3031 /* Compare symbols by ordinal for qsort */
3032 static int symbol_cmp(const void *left
, const void *right
)
3034 return ((const dll_symbol
*)left
)->ordinal
> ((const dll_symbol
*)right
)->ordinal
;
3037 /*******************************************************************
3040 * Free resources used by DLL
3042 /* FIXME: Not used yet
3043 static void dll_close (void)
3048 fatal("No symbols");
3050 for (ds = dll_symbols; ds->symbol; ds++)
3057 static void do_grab_sym( void )
3059 const IMAGE_EXPORT_DIRECTORY
*exportDir
;
3066 PE_nt_headers
= get_nt_header();
3067 if (!(exportDir
= get_dir(IMAGE_FILE_EXPORT_DIRECTORY
))) return;
3069 pName
= RVA(exportDir
->AddressOfNames
, exportDir
->NumberOfNames
* sizeof(DWORD
));
3070 if (!pName
) {printf("Can't grab functions' name table\n"); return;}
3071 pOrdl
= RVA(exportDir
->AddressOfNameOrdinals
, exportDir
->NumberOfNames
* sizeof(WORD
));
3072 if (!pOrdl
) {printf("Can't grab functions' ordinal table\n"); return;}
3073 pFunc
= RVA(exportDir
->AddressOfFunctions
, exportDir
->NumberOfFunctions
* sizeof(DWORD
));
3074 if (!pFunc
) {printf("Can't grab functions' address table\n"); return;}
3078 dll_symbols
= xmalloc((exportDir
->NumberOfFunctions
+ 1) * sizeof(dll_symbol
));
3080 /* bit map of used funcs */
3081 map
= calloc(((exportDir
->NumberOfFunctions
+ 31) & ~31) / 32, sizeof(DWORD
));
3082 if (!map
) fatal("no memory");
3084 for (j
= 0; j
< exportDir
->NumberOfNames
; j
++, pOrdl
++)
3086 map
[*pOrdl
/ 32] |= 1 << (*pOrdl
% 32);
3087 ptr
= RVA(*pName
++, sizeof(DWORD
));
3088 if (!ptr
) ptr
= "cant_get_function";
3089 dll_symbols
[j
].symbol
= xstrdup(ptr
);
3090 dll_symbols
[j
].ordinal
= exportDir
->Base
+ *pOrdl
;
3091 assert(dll_symbols
[j
].symbol
);
3094 for (i
= 0; i
< exportDir
->NumberOfFunctions
; i
++)
3096 if (pFunc
[i
] && !(map
[i
/ 32] & (1 << (i
% 32))))
3098 char ordinal_text
[256];
3099 /* Ordinal only entry */
3100 sprintf (ordinal_text
, "%s_%u",
3101 globals
.forward_dll
? globals
.forward_dll
: OUTPUT_UC_DLL_NAME
,
3102 (UINT
)exportDir
->Base
+ i
);
3103 str_toupper(ordinal_text
);
3104 dll_symbols
[j
].symbol
= xstrdup(ordinal_text
);
3105 assert(dll_symbols
[j
].symbol
);
3106 dll_symbols
[j
].ordinal
= exportDir
->Base
+ i
;
3108 assert(j
<= exportDir
->NumberOfFunctions
);
3114 printf("%u named symbols in DLL, %u total, %d unique (ordinal base = %d)\n",
3115 (UINT
)exportDir
->NumberOfNames
, (UINT
)exportDir
->NumberOfFunctions
,
3116 j
, (UINT
)exportDir
->Base
);
3118 qsort( dll_symbols
, j
, sizeof(dll_symbol
), symbol_cmp
);
3120 dll_symbols
[j
].symbol
= NULL
;
3122 dll_current_symbol
= dll_symbols
;
3125 /*******************************************************************
3128 * Open a DLL and read in exported symbols
3130 BOOL
dll_open (const char *dll_name
)
3132 return dump_analysis(dll_name
, do_grab_sym
, SIG_PE
);
3135 /*******************************************************************
3138 * Get next exported symbol from dll
3140 BOOL
dll_next_symbol (parsed_symbol
* sym
)
3142 if (!dll_current_symbol
|| !dll_current_symbol
->symbol
)
3144 assert (dll_symbols
);
3145 sym
->symbol
= xstrdup (dll_current_symbol
->symbol
);
3146 sym
->ordinal
= dll_current_symbol
->ordinal
;
3147 dll_current_symbol
++;