Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winedump/pe.c
4389 views
1
/*
2
* PE dumping utility
3
*
4
* Copyright 2001 Eric Pouech
5
*
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.
10
*
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.
15
*
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
19
*/
20
21
#include "config.h"
22
23
#include <stdlib.h>
24
#include <stdarg.h>
25
#include <stdio.h>
26
#include <time.h>
27
#include <fcntl.h>
28
29
#include "windef.h"
30
#include "winbase.h"
31
#include "verrsrc.h"
32
#include "winedump.h"
33
34
#define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
35
36
static const IMAGE_NT_HEADERS32* PE_nt_headers;
37
38
static const char builtin_signature[] = "Wine builtin DLL";
39
static const char fakedll_signature[] = "Wine placeholder DLL";
40
static int is_builtin;
41
42
const char *get_machine_str(int mach)
43
{
44
switch (mach)
45
{
46
case IMAGE_FILE_MACHINE_UNKNOWN: return "Unknown";
47
case IMAGE_FILE_MACHINE_I386: return "i386";
48
case IMAGE_FILE_MACHINE_R3000: return "R3000";
49
case IMAGE_FILE_MACHINE_R4000: return "R4000";
50
case IMAGE_FILE_MACHINE_R10000: return "R10000";
51
case IMAGE_FILE_MACHINE_ALPHA: return "Alpha";
52
case IMAGE_FILE_MACHINE_POWERPC: return "PowerPC";
53
case IMAGE_FILE_MACHINE_AMD64: return "AMD64";
54
case IMAGE_FILE_MACHINE_IA64: return "IA64";
55
case IMAGE_FILE_MACHINE_ARM64: return "ARM64";
56
case IMAGE_FILE_MACHINE_ARM: return "ARM";
57
case IMAGE_FILE_MACHINE_ARMNT: return "ARMNT";
58
case IMAGE_FILE_MACHINE_THUMB: return "ARM Thumb";
59
case IMAGE_FILE_MACHINE_ALPHA64: return "Alpha64";
60
case IMAGE_FILE_MACHINE_CHPE_X86: return "CHPE-x86";
61
case IMAGE_FILE_MACHINE_ARM64EC: return "ARM64EC";
62
case IMAGE_FILE_MACHINE_ARM64X: return "ARM64X";
63
case IMAGE_FILE_MACHINE_RISCV32: return "RISC-V 32-bit";
64
case IMAGE_FILE_MACHINE_RISCV64: return "RISC-V 64-bit";
65
case IMAGE_FILE_MACHINE_RISCV128: return "RISC-V 128-bit";
66
}
67
return "???";
68
}
69
70
static const void* RVA(unsigned long rva, unsigned long len)
71
{
72
IMAGE_SECTION_HEADER* sectHead;
73
int i;
74
75
if (rva == 0) return NULL;
76
77
sectHead = IMAGE_FIRST_SECTION(PE_nt_headers);
78
for (i = PE_nt_headers->FileHeader.NumberOfSections - 1; i >= 0; i--)
79
{
80
if (sectHead[i].VirtualAddress <= rva &&
81
rva + len <= (DWORD)sectHead[i].VirtualAddress + sectHead[i].SizeOfRawData)
82
{
83
/* return image import directory offset */
84
return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
85
}
86
}
87
88
return NULL;
89
}
90
91
static const IMAGE_NT_HEADERS32 *get_nt_header( void )
92
{
93
const IMAGE_DOS_HEADER *dos;
94
dos = PRD(0, sizeof(*dos));
95
if (!dos) return NULL;
96
is_builtin = (dos->e_lfanew >= sizeof(*dos) + 32 &&
97
!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) ));
98
return PRD(dos->e_lfanew, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER));
99
}
100
101
void print_fake_dll( void )
102
{
103
const IMAGE_DOS_HEADER *dos;
104
105
dos = PRD(0, sizeof(*dos) + 32);
106
if (dos && dos->e_lfanew >= sizeof(*dos) + 32)
107
{
108
if (!memcmp( dos + 1, builtin_signature, sizeof(builtin_signature) ))
109
printf( "*** This is a Wine builtin DLL ***\n\n" );
110
else if (!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) ))
111
printf( "*** This is a Wine fake DLL ***\n\n" );
112
}
113
}
114
115
static const void *get_data_dir(const IMAGE_NT_HEADERS32 *hdr, unsigned int idx, unsigned int *size)
116
{
117
if(hdr->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
118
{
119
const IMAGE_OPTIONAL_HEADER64 *opt = (const IMAGE_OPTIONAL_HEADER64*)&hdr->OptionalHeader;
120
if (idx >= opt->NumberOfRvaAndSizes)
121
return NULL;
122
if(size)
123
*size = opt->DataDirectory[idx].Size;
124
return RVA(opt->DataDirectory[idx].VirtualAddress,
125
opt->DataDirectory[idx].Size);
126
}
127
else
128
{
129
const IMAGE_OPTIONAL_HEADER32 *opt = (const IMAGE_OPTIONAL_HEADER32*)&hdr->OptionalHeader;
130
if (idx >= opt->NumberOfRvaAndSizes)
131
return NULL;
132
if(size)
133
*size = opt->DataDirectory[idx].Size;
134
return RVA(opt->DataDirectory[idx].VirtualAddress,
135
opt->DataDirectory[idx].Size);
136
}
137
}
138
139
static const void *get_dir_and_size(unsigned int idx, unsigned int *size)
140
{
141
return get_data_dir( PE_nt_headers, idx, size );
142
}
143
144
static const void* get_dir(unsigned idx)
145
{
146
return get_dir_and_size(idx, 0);
147
}
148
149
static const char * const DirectoryNames[16] = {
150
"EXPORT", "IMPORT", "RESOURCE", "EXCEPTION",
151
"SECURITY", "BASERELOC", "DEBUG", "ARCHITECTURE",
152
"GLOBALPTR", "TLS", "LOAD_CONFIG", "Bound IAT",
153
"IAT", "Delay IAT", "CLR Header", ""
154
};
155
156
static const char *get_magic_type(WORD magic)
157
{
158
switch(magic) {
159
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
160
return "32bit";
161
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
162
return "64bit";
163
case IMAGE_ROM_OPTIONAL_HDR_MAGIC:
164
return "ROM";
165
}
166
return "???";
167
}
168
169
static const void *get_hybrid_metadata(void)
170
{
171
unsigned int size;
172
173
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
174
{
175
const IMAGE_LOAD_CONFIG_DIRECTORY64 *cfg = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &size);
176
if (!cfg) return 0;
177
size = min( size, cfg->Size );
178
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, CHPEMetadataPointer )) return 0;
179
if (!cfg->CHPEMetadataPointer) return 0;
180
return RVA( cfg->CHPEMetadataPointer - ((const IMAGE_OPTIONAL_HEADER64 *)&PE_nt_headers->OptionalHeader)->ImageBase, 1 );
181
}
182
else
183
{
184
const IMAGE_LOAD_CONFIG_DIRECTORY32 *cfg = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &size);
185
if (!cfg) return 0;
186
size = min( size, cfg->Size );
187
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, CHPEMetadataPointer )) return 0;
188
if (!cfg->CHPEMetadataPointer) return 0;
189
return RVA( cfg->CHPEMetadataPointer - PE_nt_headers->OptionalHeader.ImageBase, 1 );
190
}
191
}
192
193
static inline const char *longlong_str( ULONGLONG value )
194
{
195
static char buffer[20];
196
197
if (sizeof(value) > sizeof(unsigned long) && value >> 32)
198
sprintf(buffer, "%lx%08lx", (unsigned long)(value >> 32), (unsigned long)value);
199
else
200
sprintf(buffer, "%lx", (unsigned long)value);
201
return buffer;
202
}
203
204
static inline void print_word(const char *title, WORD value)
205
{
206
printf(" %-34s 0x%-4X %u\n", title, value, value);
207
}
208
209
static inline void print_dword(const char *title, UINT value)
210
{
211
printf(" %-34s 0x%-8x %u\n", title, value, value);
212
}
213
214
static inline void print_longlong(const char *title, ULONGLONG value)
215
{
216
printf(" %-34s 0x%s\n", title, longlong_str(value));
217
}
218
219
static inline void print_ver(const char *title, BYTE major, BYTE minor)
220
{
221
printf(" %-34s %u.%02u\n", title, major, minor);
222
}
223
224
static inline void print_subsys(const char *title, WORD value)
225
{
226
const char *str;
227
switch (value)
228
{
229
default:
230
case IMAGE_SUBSYSTEM_UNKNOWN: str = "Unknown"; break;
231
case IMAGE_SUBSYSTEM_NATIVE: str = "Native"; break;
232
case IMAGE_SUBSYSTEM_WINDOWS_GUI: str = "Windows GUI"; break;
233
case IMAGE_SUBSYSTEM_WINDOWS_CUI: str = "Windows CUI"; break;
234
case IMAGE_SUBSYSTEM_OS2_CUI: str = "OS/2 CUI"; break;
235
case IMAGE_SUBSYSTEM_POSIX_CUI: str = "Posix CUI"; break;
236
case IMAGE_SUBSYSTEM_NATIVE_WINDOWS: str = "native Win9x driver"; break;
237
case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI: str = "Windows CE GUI"; break;
238
case IMAGE_SUBSYSTEM_EFI_APPLICATION: str = "EFI application"; break;
239
case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER: str = "EFI driver (boot)"; break;
240
case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER: str = "EFI driver (runtime)"; break;
241
case IMAGE_SUBSYSTEM_EFI_ROM: str = "EFI ROM"; break;
242
case IMAGE_SUBSYSTEM_XBOX: str = "Xbox application"; break;
243
case IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION: str = "Boot application"; break;
244
}
245
printf(" %-34s 0x%X (%s)\n", title, value, str);
246
}
247
248
static inline void print_dllflags(const char *title, WORD value)
249
{
250
printf(" %-34s 0x%04X\n", title, value);
251
#define X(f,s) do { if (value & f) printf(" %s\n", s); } while(0)
252
if (is_builtin) X(IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE, "PREFER_NATIVE (Wine extension)");
253
X(IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA, "HIGH_ENTROPY_VA");
254
X(IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE, "DYNAMIC_BASE");
255
X(IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY, "FORCE_INTEGRITY");
256
X(IMAGE_DLLCHARACTERISTICS_NX_COMPAT, "NX_COMPAT");
257
X(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION, "NO_ISOLATION");
258
X(IMAGE_DLLCHARACTERISTICS_NO_SEH, "NO_SEH");
259
X(IMAGE_DLLCHARACTERISTICS_NO_BIND, "NO_BIND");
260
X(IMAGE_DLLCHARACTERISTICS_APPCONTAINER, "APPCONTAINER");
261
X(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER, "WDM_DRIVER");
262
X(IMAGE_DLLCHARACTERISTICS_GUARD_CF, "GUARD_CF");
263
X(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE, "TERMINAL_SERVER_AWARE");
264
#undef X
265
}
266
267
static inline void print_datadirectory(DWORD n, const IMAGE_DATA_DIRECTORY *directory)
268
{
269
unsigned i;
270
printf("Data Directory\n");
271
272
for (i = 0; i < n && i < 16; i++)
273
{
274
printf(" %-12s rva: 0x%-8x size: 0x%-8x\n",
275
DirectoryNames[i], (UINT)directory[i].VirtualAddress,
276
(UINT)directory[i].Size);
277
}
278
}
279
280
static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh)
281
{
282
IMAGE_OPTIONAL_HEADER32 oh;
283
const IMAGE_OPTIONAL_HEADER32 *optionalHeader;
284
285
/* in case optional header is missing or partial */
286
memset(&oh, 0, sizeof(oh));
287
memcpy(&oh, image_oh, min(dump_total_len - ((char *)image_oh - (char *)dump_base), sizeof(oh)));
288
optionalHeader = &oh;
289
290
print_word("Magic", optionalHeader->Magic);
291
print_ver("linker version",
292
optionalHeader->MajorLinkerVersion, optionalHeader->MinorLinkerVersion);
293
print_dword("size of code", optionalHeader->SizeOfCode);
294
print_dword("size of initialized data", optionalHeader->SizeOfInitializedData);
295
print_dword("size of uninitialized data", optionalHeader->SizeOfUninitializedData);
296
print_dword("entrypoint RVA", optionalHeader->AddressOfEntryPoint);
297
print_dword("base of code", optionalHeader->BaseOfCode);
298
print_dword("base of data", optionalHeader->BaseOfData);
299
print_dword("image base", optionalHeader->ImageBase);
300
print_dword("section align", optionalHeader->SectionAlignment);
301
print_dword("file align", optionalHeader->FileAlignment);
302
print_ver("required OS version",
303
optionalHeader->MajorOperatingSystemVersion, optionalHeader->MinorOperatingSystemVersion);
304
print_ver("image version",
305
optionalHeader->MajorImageVersion, optionalHeader->MinorImageVersion);
306
print_ver("subsystem version",
307
optionalHeader->MajorSubsystemVersion, optionalHeader->MinorSubsystemVersion);
308
print_dword("Win32 Version", optionalHeader->Win32VersionValue);
309
print_dword("size of image", optionalHeader->SizeOfImage);
310
print_dword("size of headers", optionalHeader->SizeOfHeaders);
311
print_dword("checksum", optionalHeader->CheckSum);
312
print_subsys("Subsystem", optionalHeader->Subsystem);
313
print_dllflags("DLL characteristics:", optionalHeader->DllCharacteristics);
314
print_dword("stack reserve size", optionalHeader->SizeOfStackReserve);
315
print_dword("stack commit size", optionalHeader->SizeOfStackCommit);
316
print_dword("heap reserve size", optionalHeader->SizeOfHeapReserve);
317
print_dword("heap commit size", optionalHeader->SizeOfHeapCommit);
318
print_dword("loader flags", optionalHeader->LoaderFlags);
319
print_dword("RVAs & sizes", optionalHeader->NumberOfRvaAndSizes);
320
printf("\n");
321
print_datadirectory(optionalHeader->NumberOfRvaAndSizes, optionalHeader->DataDirectory);
322
printf("\n");
323
}
324
325
static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh)
326
{
327
IMAGE_OPTIONAL_HEADER64 oh;
328
const IMAGE_OPTIONAL_HEADER64 *optionalHeader;
329
330
/* in case optional header is missing or partial */
331
memset(&oh, 0, sizeof(oh));
332
memcpy(&oh, image_oh, min(dump_total_len - ((char *)image_oh - (char *)dump_base), sizeof(oh)));
333
optionalHeader = &oh;
334
335
print_word("Magic", optionalHeader->Magic);
336
print_ver("linker version",
337
optionalHeader->MajorLinkerVersion, optionalHeader->MinorLinkerVersion);
338
print_dword("size of code", optionalHeader->SizeOfCode);
339
print_dword("size of initialized data", optionalHeader->SizeOfInitializedData);
340
print_dword("size of uninitialized data", optionalHeader->SizeOfUninitializedData);
341
print_dword("entrypoint RVA", optionalHeader->AddressOfEntryPoint);
342
print_dword("base of code", optionalHeader->BaseOfCode);
343
print_longlong("image base", optionalHeader->ImageBase);
344
print_dword("section align", optionalHeader->SectionAlignment);
345
print_dword("file align", optionalHeader->FileAlignment);
346
print_ver("required OS version",
347
optionalHeader->MajorOperatingSystemVersion, optionalHeader->MinorOperatingSystemVersion);
348
print_ver("image version",
349
optionalHeader->MajorImageVersion, optionalHeader->MinorImageVersion);
350
print_ver("subsystem version",
351
optionalHeader->MajorSubsystemVersion, optionalHeader->MinorSubsystemVersion);
352
print_dword("Win32 Version", optionalHeader->Win32VersionValue);
353
print_dword("size of image", optionalHeader->SizeOfImage);
354
print_dword("size of headers", optionalHeader->SizeOfHeaders);
355
print_dword("checksum", optionalHeader->CheckSum);
356
print_subsys("Subsystem", optionalHeader->Subsystem);
357
print_dllflags("DLL characteristics:", optionalHeader->DllCharacteristics);
358
print_longlong("stack reserve size", optionalHeader->SizeOfStackReserve);
359
print_longlong("stack commit size", optionalHeader->SizeOfStackCommit);
360
print_longlong("heap reserve size", optionalHeader->SizeOfHeapReserve);
361
print_longlong("heap commit size", optionalHeader->SizeOfHeapCommit);
362
print_dword("loader flags", optionalHeader->LoaderFlags);
363
print_dword("RVAs & sizes", optionalHeader->NumberOfRvaAndSizes);
364
printf("\n");
365
print_datadirectory(optionalHeader->NumberOfRvaAndSizes, optionalHeader->DataDirectory);
366
printf("\n");
367
}
368
369
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *optionalHeader)
370
{
371
printf("Optional Header (%s)\n", get_magic_type(optionalHeader->Magic));
372
373
switch(optionalHeader->Magic) {
374
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
375
dump_optional_header32(optionalHeader);
376
break;
377
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
378
dump_optional_header64((const IMAGE_OPTIONAL_HEADER64 *)optionalHeader);
379
break;
380
default:
381
printf(" Unknown optional header magic: 0x%-4X\n", optionalHeader->Magic);
382
break;
383
}
384
}
385
386
void dump_file_header(const IMAGE_FILE_HEADER *fileHeader, BOOL is_hybrid)
387
{
388
const char *name = get_machine_str(fileHeader->Machine);
389
390
printf("File Header\n");
391
392
if (is_hybrid)
393
{
394
switch (fileHeader->Machine)
395
{
396
case IMAGE_FILE_MACHINE_I386: name = "CHPE"; break;
397
case IMAGE_FILE_MACHINE_AMD64: name = "ARM64EC"; break;
398
case IMAGE_FILE_MACHINE_ARM64: name = "ARM64X"; break;
399
}
400
}
401
printf(" Machine: %04X (%s)\n", fileHeader->Machine, name);
402
printf(" Number of Sections: %d\n", fileHeader->NumberOfSections);
403
printf(" TimeDateStamp: %08X (%s)\n",
404
(UINT)fileHeader->TimeDateStamp, get_time_str(fileHeader->TimeDateStamp));
405
printf(" PointerToSymbolTable: %08X\n", (UINT)fileHeader->PointerToSymbolTable);
406
printf(" NumberOfSymbols: %08X\n", (UINT)fileHeader->NumberOfSymbols);
407
printf(" SizeOfOptionalHeader: %04X\n", (UINT)fileHeader->SizeOfOptionalHeader);
408
printf(" Characteristics: %04X\n", (UINT)fileHeader->Characteristics);
409
#define X(f,s) if (fileHeader->Characteristics & f) printf(" %s\n", s)
410
X(IMAGE_FILE_RELOCS_STRIPPED, "RELOCS_STRIPPED");
411
X(IMAGE_FILE_EXECUTABLE_IMAGE, "EXECUTABLE_IMAGE");
412
X(IMAGE_FILE_LINE_NUMS_STRIPPED, "LINE_NUMS_STRIPPED");
413
X(IMAGE_FILE_LOCAL_SYMS_STRIPPED, "LOCAL_SYMS_STRIPPED");
414
X(IMAGE_FILE_AGGRESIVE_WS_TRIM, "AGGRESIVE_WS_TRIM");
415
X(IMAGE_FILE_LARGE_ADDRESS_AWARE, "LARGE_ADDRESS_AWARE");
416
X(IMAGE_FILE_16BIT_MACHINE, "16BIT_MACHINE");
417
X(IMAGE_FILE_BYTES_REVERSED_LO, "BYTES_REVERSED_LO");
418
X(IMAGE_FILE_32BIT_MACHINE, "32BIT_MACHINE");
419
X(IMAGE_FILE_DEBUG_STRIPPED, "DEBUG_STRIPPED");
420
X(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP, "REMOVABLE_RUN_FROM_SWAP");
421
X(IMAGE_FILE_NET_RUN_FROM_SWAP, "NET_RUN_FROM_SWAP");
422
X(IMAGE_FILE_SYSTEM, "SYSTEM");
423
X(IMAGE_FILE_DLL, "DLL");
424
X(IMAGE_FILE_UP_SYSTEM_ONLY, "UP_SYSTEM_ONLY");
425
X(IMAGE_FILE_BYTES_REVERSED_HI, "BYTES_REVERSED_HI");
426
#undef X
427
printf("\n");
428
}
429
430
static void dump_pe_header(void)
431
{
432
dump_file_header(&PE_nt_headers->FileHeader, get_hybrid_metadata() != NULL);
433
dump_optional_header((const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader);
434
}
435
436
void dump_section_characteristics(DWORD characteristics, const char* sep)
437
{
438
#define X(b,s) if (characteristics & b) printf("%s%s", sep, s)
439
/* #define IMAGE_SCN_TYPE_REG 0x00000000 - Reserved */
440
/* #define IMAGE_SCN_TYPE_DSECT 0x00000001 - Reserved */
441
/* #define IMAGE_SCN_TYPE_NOLOAD 0x00000002 - Reserved */
442
/* #define IMAGE_SCN_TYPE_GROUP 0x00000004 - Reserved */
443
/* #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - Reserved */
444
/* #define IMAGE_SCN_TYPE_COPY 0x00000010 - Reserved */
445
446
X(IMAGE_SCN_CNT_CODE, "CODE");
447
X(IMAGE_SCN_CNT_INITIALIZED_DATA, "INITIALIZED_DATA");
448
X(IMAGE_SCN_CNT_UNINITIALIZED_DATA, "UNINITIALIZED_DATA");
449
450
X(IMAGE_SCN_LNK_OTHER, "LNK_OTHER");
451
X(IMAGE_SCN_LNK_INFO, "LNK_INFO");
452
/* #define IMAGE_SCN_TYPE_OVER 0x00000400 - Reserved */
453
X(IMAGE_SCN_LNK_REMOVE, "LNK_REMOVE");
454
X(IMAGE_SCN_LNK_COMDAT, "LNK_COMDAT");
455
456
/* 0x00002000 - Reserved */
457
/* #define IMAGE_SCN_MEM_PROTECTED 0x00004000 - Obsolete */
458
X(IMAGE_SCN_MEM_FARDATA, "MEM_FARDATA");
459
460
/* #define IMAGE_SCN_MEM_SYSHEAP 0x00010000 - Obsolete */
461
X(IMAGE_SCN_MEM_PURGEABLE, "MEM_PURGEABLE");
462
X(IMAGE_SCN_MEM_16BIT, "MEM_16BIT");
463
X(IMAGE_SCN_MEM_LOCKED, "MEM_LOCKED");
464
X(IMAGE_SCN_MEM_PRELOAD, "MEM_PRELOAD");
465
466
switch (characteristics & IMAGE_SCN_ALIGN_MASK)
467
{
468
#define X2(b,s) case b: printf("%s%s", sep, s); break
469
X2(IMAGE_SCN_ALIGN_1BYTES, "ALIGN_1BYTES");
470
X2(IMAGE_SCN_ALIGN_2BYTES, "ALIGN_2BYTES");
471
X2(IMAGE_SCN_ALIGN_4BYTES, "ALIGN_4BYTES");
472
X2(IMAGE_SCN_ALIGN_8BYTES, "ALIGN_8BYTES");
473
X2(IMAGE_SCN_ALIGN_16BYTES, "ALIGN_16BYTES");
474
X2(IMAGE_SCN_ALIGN_32BYTES, "ALIGN_32BYTES");
475
X2(IMAGE_SCN_ALIGN_64BYTES, "ALIGN_64BYTES");
476
X2(IMAGE_SCN_ALIGN_128BYTES, "ALIGN_128BYTES");
477
X2(IMAGE_SCN_ALIGN_256BYTES, "ALIGN_256BYTES");
478
X2(IMAGE_SCN_ALIGN_512BYTES, "ALIGN_512BYTES");
479
X2(IMAGE_SCN_ALIGN_1024BYTES, "ALIGN_1024BYTES");
480
X2(IMAGE_SCN_ALIGN_2048BYTES, "ALIGN_2048BYTES");
481
X2(IMAGE_SCN_ALIGN_4096BYTES, "ALIGN_4096BYTES");
482
X2(IMAGE_SCN_ALIGN_8192BYTES, "ALIGN_8192BYTES");
483
#undef X2
484
}
485
486
X(IMAGE_SCN_LNK_NRELOC_OVFL, "LNK_NRELOC_OVFL");
487
488
X(IMAGE_SCN_MEM_DISCARDABLE, "MEM_DISCARDABLE");
489
X(IMAGE_SCN_MEM_NOT_CACHED, "MEM_NOT_CACHED");
490
X(IMAGE_SCN_MEM_NOT_PAGED, "MEM_NOT_PAGED");
491
X(IMAGE_SCN_MEM_SHARED, "MEM_SHARED");
492
X(IMAGE_SCN_MEM_EXECUTE, "MEM_EXECUTE");
493
X(IMAGE_SCN_MEM_READ, "MEM_READ");
494
X(IMAGE_SCN_MEM_WRITE, "MEM_WRITE");
495
#undef X
496
}
497
498
void dump_section(const IMAGE_SECTION_HEADER *sectHead, const char* strtable)
499
{
500
unsigned offset;
501
502
/* long section name ? */
503
if (strtable && sectHead->Name[0] == '/' &&
504
((offset = atoi((const char*)sectHead->Name + 1)) < *(const DWORD*)strtable))
505
printf(" %.8s (%s)", sectHead->Name, strtable + offset);
506
else
507
printf(" %-8.8s", sectHead->Name);
508
printf(" VirtSize: 0x%08x VirtAddr: 0x%08x\n",
509
(UINT)sectHead->Misc.VirtualSize, (UINT)sectHead->VirtualAddress);
510
printf(" raw data offs: 0x%08x raw data size: 0x%08x\n",
511
(UINT)sectHead->PointerToRawData, (UINT)sectHead->SizeOfRawData);
512
printf(" relocation offs: 0x%08x relocations: 0x%08x\n",
513
(UINT)sectHead->PointerToRelocations, (UINT)sectHead->NumberOfRelocations);
514
printf(" line # offs: %-8u line #'s: %-8u\n",
515
(UINT)sectHead->PointerToLinenumbers, (UINT)sectHead->NumberOfLinenumbers);
516
printf(" characteristics: 0x%08x\n", (UINT)sectHead->Characteristics);
517
printf(" ");
518
dump_section_characteristics(sectHead->Characteristics, " ");
519
520
printf("\n\n");
521
}
522
523
static void dump_sections(const void *base, const void* addr, unsigned num_sect)
524
{
525
const IMAGE_SECTION_HEADER* sectHead = addr;
526
unsigned i;
527
const char* strtable;
528
529
if (PE_nt_headers && PE_nt_headers->FileHeader.PointerToSymbolTable && PE_nt_headers->FileHeader.NumberOfSymbols)
530
{
531
strtable = (const char*)base +
532
PE_nt_headers->FileHeader.PointerToSymbolTable +
533
PE_nt_headers->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL);
534
}
535
else strtable = NULL;
536
537
printf("Section Table\n");
538
for (i = 0; i < num_sect; i++, sectHead++)
539
{
540
dump_section(sectHead, strtable);
541
542
if (globals.do_dump_rawdata)
543
{
544
dump_data_offset((const unsigned char *)base + sectHead->PointerToRawData,
545
sectHead->SizeOfRawData, sectHead->VirtualAddress, " " );
546
printf("\n");
547
}
548
}
549
}
550
551
static char *get_str( char *buffer, unsigned int rva, unsigned int len )
552
{
553
const WCHAR *wstr = PRD( rva, len );
554
char *ret = buffer;
555
556
len /= sizeof(WCHAR);
557
while (len--) *buffer++ = *wstr++;
558
*buffer = 0;
559
return ret;
560
}
561
562
static void dump_section_apiset(void)
563
{
564
const IMAGE_SECTION_HEADER *sect = IMAGE_FIRST_SECTION(PE_nt_headers);
565
const UINT *ptr, *entry, *value, *hash;
566
unsigned int i, j, count, val_count, rva;
567
char buffer[128];
568
569
for (i = 0; i < PE_nt_headers->FileHeader.NumberOfSections; i++, sect++)
570
{
571
if (strncmp( (const char *)sect->Name, ".apiset", 8 )) continue;
572
rva = sect->PointerToRawData;
573
ptr = PRD( rva, sizeof(*ptr) );
574
printf( "ApiSet section:\n" );
575
switch (ptr[0]) /* version */
576
{
577
case 2:
578
printf( " Version: %u\n", ptr[0] );
579
printf( " Count: %08x\n", ptr[1] );
580
count = ptr[1];
581
if (!(entry = PRD( rva + 2 * sizeof(*ptr), count * 3 * sizeof(*entry) ))) break;
582
for (i = 0; i < count; i++, entry += 3)
583
{
584
printf( " %s ->", get_str( buffer, rva + entry[0], entry[1] ));
585
if (!(value = PRD( rva + entry[2], sizeof(*value) ))) break;
586
val_count = *value++;
587
for (j = 0; j < val_count; j++, value += 4)
588
{
589
putchar( ' ' );
590
if (value[1]) printf( "%s:", get_str( buffer, rva + value[0], value[1] ));
591
printf( "%s", get_str( buffer, rva + value[2], value[3] ));
592
}
593
printf( "\n");
594
}
595
break;
596
case 4:
597
printf( " Version: %u\n", ptr[0] );
598
printf( " Size: %08x\n", ptr[1] );
599
printf( " Flags: %08x\n", ptr[2] );
600
printf( " Count: %08x\n", ptr[3] );
601
count = ptr[3];
602
if (!(entry = PRD( rva + 4 * sizeof(*ptr), count * 6 * sizeof(*entry) ))) break;
603
for (i = 0; i < count; i++, entry += 6)
604
{
605
printf( " %08x %s ->", entry[0], get_str( buffer, rva + entry[1], entry[2] ));
606
if (!(value = PRD( rva + entry[5], sizeof(*value) ))) break;
607
value++; /* flags */
608
val_count = *value++;
609
for (j = 0; j < val_count; j++, value += 5)
610
{
611
putchar( ' ' );
612
if (value[1]) printf( "%s:", get_str( buffer, rva + value[1], value[2] ));
613
printf( "%s", get_str( buffer, rva + value[3], value[4] ));
614
}
615
printf( "\n");
616
}
617
break;
618
case 6:
619
printf( " Version: %u\n", ptr[0] );
620
printf( " Size: %08x\n", ptr[1] );
621
printf( " Flags: %08x\n", ptr[2] );
622
printf( " Count: %08x\n", ptr[3] );
623
printf( " EntryOffset: %08x\n", ptr[4] );
624
printf( " HashOffset: %08x\n", ptr[5] );
625
printf( " HashFactor: %08x\n", ptr[6] );
626
count = ptr[3];
627
if (!(entry = PRD( rva + ptr[4], count * 6 * sizeof(*entry) ))) break;
628
for (i = 0; i < count; i++, entry += 6)
629
{
630
printf( " %08x %s ->", entry[0], get_str( buffer, rva + entry[1], entry[2] ));
631
if (!(value = PRD( rva + entry[4], entry[5] * 5 * sizeof(*value) ))) break;
632
for (j = 0; j < entry[5]; j++, value += 5)
633
{
634
putchar( ' ' );
635
if (value[1]) printf( "%s:", get_str( buffer, rva + value[1], value[2] ));
636
printf( "%s", get_str( buffer, rva + value[3], value[4] ));
637
}
638
printf( "\n" );
639
}
640
printf( " Hash table:\n" );
641
if (!(hash = PRD( rva + ptr[5], count * 2 * sizeof(*hash) ))) break;
642
for (i = 0; i < count; i++, hash += 2)
643
{
644
entry = PRD( rva + ptr[4] + hash[1] * 6 * sizeof(*entry), 6 * sizeof(*entry) );
645
printf( " %08x -> %s\n", hash[0], get_str( buffer, rva + entry[1], entry[3] ));
646
}
647
break;
648
default:
649
printf( "*** Unknown version %u\n", ptr[0] );
650
break;
651
}
652
break;
653
}
654
}
655
656
static const char *find_export_from_rva( UINT rva )
657
{
658
UINT i, *func_names;
659
const UINT *funcs;
660
const UINT *names;
661
const WORD *ordinals;
662
const IMAGE_EXPORT_DIRECTORY *dir;
663
const char *ret = NULL;
664
665
if (!(dir = get_dir( IMAGE_FILE_EXPORT_DIRECTORY ))) return "";
666
if (!(funcs = RVA( dir->AddressOfFunctions, dir->NumberOfFunctions * sizeof(DWORD) ))) return "";
667
names = RVA( dir->AddressOfNames, dir->NumberOfNames * sizeof(DWORD) );
668
ordinals = RVA( dir->AddressOfNameOrdinals, dir->NumberOfNames * sizeof(WORD) );
669
func_names = calloc( dir->NumberOfFunctions, sizeof(*func_names) );
670
671
for (i = 0; i < dir->NumberOfNames; i++) func_names[ordinals[i]] = names[i];
672
for (i = 0; i < dir->NumberOfFunctions; i++)
673
{
674
if (funcs[i] != rva) continue;
675
if (func_names[i]) ret = get_symbol_str( RVA( func_names[i], sizeof(DWORD) ));
676
break;
677
}
678
679
free( func_names );
680
if (!ret && rva == PE_nt_headers->OptionalHeader.AddressOfEntryPoint) return " <EntryPoint>";
681
return ret ? strmake( " (%s)", ret ) : "";
682
}
683
684
static const char *find_import_from_rva( UINT rva )
685
{
686
const IMAGE_IMPORT_DESCRIPTOR *imp;
687
688
if (!(imp = get_dir( IMAGE_FILE_IMPORT_DIRECTORY ))) return "";
689
690
/* check for import thunk */
691
switch (PE_nt_headers->FileHeader.Machine)
692
{
693
case IMAGE_FILE_MACHINE_AMD64:
694
{
695
const BYTE *ptr = RVA( rva, 6 );
696
if (!ptr) return "";
697
if (ptr[0] == 0xff && ptr[1] == 0x25)
698
{
699
rva += 6 + *(int *)(ptr + 2);
700
break;
701
}
702
if (ptr[0] == 0x48 && ptr[1] == 0xff && ptr[2] == 0x25)
703
{
704
rva += 7 + *(int *)(ptr + 3);
705
break;
706
}
707
return "";
708
}
709
case IMAGE_FILE_MACHINE_ARM64:
710
{
711
const UINT *ptr = RVA( rva, sizeof(DWORD) );
712
if ((ptr[0] & 0x9f00001f) == 0x90000010 && /* adrp x16, page */
713
(ptr[1] & 0xffc003ff) == 0xf9400210 && /* ldr x16, [x16, #off] */
714
ptr[2] == 0xd61f0200) /* br x16 */
715
{
716
rva &= ~0xfff;
717
rva += ((ptr[0] & 0x00ffffe0) << 9) + ((ptr[0] & 0x60000000) >> 17);
718
rva += (ptr[1] & 0x003ffc00) >> 7;
719
break;
720
}
721
return "";
722
}
723
default:
724
return "";
725
}
726
727
for ( ; imp->Name && imp->FirstThunk; imp++)
728
{
729
UINT imp_rva = imp->OriginalFirstThunk ? imp->OriginalFirstThunk : imp->FirstThunk;
730
UINT thunk_rva = imp->FirstThunk;
731
732
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
733
{
734
const IMAGE_THUNK_DATA64 *il = RVA( imp_rva, sizeof(DWORD) );
735
for ( ; il && il->u1.Ordinal; il++, thunk_rva += sizeof(LONGLONG))
736
{
737
if (thunk_rva != rva) continue;
738
if (IMAGE_SNAP_BY_ORDINAL64(il->u1.Ordinal))
739
return strmake( " (-> #%u)", (WORD)IMAGE_ORDINAL64( il->u1.Ordinal ));
740
else
741
return strmake( " (-> %s)", get_symbol_str( RVA( (DWORD)il->u1.AddressOfData + 2, 1 )));
742
}
743
}
744
else
745
{
746
const IMAGE_THUNK_DATA32 *il = RVA( imp_rva, sizeof(DWORD) );
747
for ( ; il && il->u1.Ordinal; il++, thunk_rva += sizeof(LONG))
748
{
749
if (thunk_rva != rva) continue;
750
if (IMAGE_SNAP_BY_ORDINAL32(il->u1.Ordinal))
751
return strmake( " (-> #%u)", (WORD)IMAGE_ORDINAL32( il->u1.Ordinal ));
752
else
753
return strmake( " (-> %s)", get_symbol_str( RVA( (DWORD)il->u1.AddressOfData + 2, 1 )));
754
}
755
}
756
}
757
return "";
758
}
759
760
static const char *get_function_name( UINT rva )
761
{
762
const char *name = find_export_from_rva( rva );
763
if (!*name) name = find_import_from_rva( rva );
764
return name;
765
}
766
767
static int match_pattern( const BYTE *instr, const BYTE *pattern, int len )
768
{
769
for (int i = 0; i < len; i++) if (pattern[i] && pattern[i] != instr[i]) return 0;
770
return 1;
771
}
772
773
static void dump_export_flags( UINT rva )
774
{
775
switch (PE_nt_headers->FileHeader.Machine)
776
{
777
case IMAGE_FILE_MACHINE_I386:
778
{
779
static const BYTE patterns[][18] =
780
{
781
{ 0xb8, 0, 0, 0, 0, 0xba, 0, 0, 0, 0, 0xff, 0xd2 }, /* >= win10 */
782
{ 0xb8, 0, 0, 0, 0, 0xba, 0, 0, 0, 0, 0xff, 0x12 }, /* winxp */
783
{ 0xb8, 0, 0, 0, 0, 0x64, 0xff, 0x15, 0xc0, 0, 0, 0 }, /* nt */
784
{ 0xb8, 0, 0, 0, 0, 0x8d, 0x54, 0x24, 0x04, 0xcd, 0x2e }, /* nt */
785
{ 0xb8, 0, 0, 0, 0, 0xb9, 0, 0, 0, 0, 0x8d, 0x54, 0x24, 0x04, 0x64, 0xff, 0x15, 0xc0 }, /* vista */
786
{ 0xb8, 0, 0, 0, 0, 0x33, 0xc9, 0x8d, 0x54, 0x24, 0x04, 0x64, 0xff, 0x15, 0xc0 }, /* vista */
787
{ 0xb8, 0, 0, 0, 0, 0xe8, 0, 0, 0, 0, 0x8d, 0x54, 0x24, 0x04, 0x64, 0xff, 0x15, 0xc0 }, /* win8 */
788
{ 0xb8, 0, 0, 0, 0, 0xe8, 0x01, 0, 0, 0, 0xc3, 0x8b, 0xd4, 0x0f, 0x34, 0xc3 }, /* win8 */
789
{ 0xb8, 0, 0, 0, 0, 0xe8, 0x03, 0, 0, 0, 0xc2, 0, 0, 0x8b, 0xd4, 0x0f, 0x34, 0xc3 }, /* win8 */
790
};
791
const BYTE *instr = RVA( rva, 32 );
792
793
if (!instr) break;
794
for (UINT i = 0; i < ARRAY_SIZE(patterns); i++)
795
{
796
if (match_pattern( instr, patterns[i], ARRAY_SIZE(patterns[0]) ))
797
{
798
printf( " [syscall=%04x]", *(UINT *)(instr + 1) );
799
return;
800
}
801
}
802
break;
803
}
804
case IMAGE_FILE_MACHINE_AMD64:
805
{
806
static const BYTE patterns[][20] =
807
{
808
{ 0x4c, 0x8b, 0xd1, 0xb8, 0, 0, 0, 0, 0xf6, 0x04, 0x25, 0x08, 0x03, 0xfe,
809
0x7f, 0x01, 0x75, 0x03, 0x0f, 0x05 }, /* >= win10 */
810
{ 0x4c, 0x8b, 0xd1, 0xb8, 0, 0, 0, 0, 0x0f, 0x05, 0xc3 }, /* < win10 */
811
};
812
const BYTE *instr = RVA( rva, 32 );
813
814
if (!instr) break;
815
for (UINT i = 0; i < ARRAY_SIZE(patterns); i++)
816
{
817
if (match_pattern( instr, patterns[i], ARRAY_SIZE(patterns[0]) ))
818
{
819
printf( " [syscall=%04x]", ((UINT *)instr)[1] );
820
return;
821
}
822
}
823
break;
824
}
825
case IMAGE_FILE_MACHINE_ARM64:
826
{
827
const UINT *instr = RVA( rva, 32 );
828
829
if (!instr) break;
830
if (((instr[0] & 0xffe0001f) == 0xd4000001 && instr[1] == 0xd65f03c0) || /* windows */
831
((instr[0] & 0xffe0001f) == 0xd2800008 && instr[1] == 0xaa1e03e9 && /* wine */
832
instr[3] == 0xf9400210 && instr[4] == 0xd63f0200 && instr[5] == 0xd65f03c0))
833
printf( " [syscall=%04x]", (instr[0] >> 5) & 0xffff );
834
break;
835
}
836
case IMAGE_FILE_MACHINE_ARMNT:
837
{
838
const USHORT *instr = RVA( rva & ~1, 16 );
839
if (!instr) break;
840
if (instr[0] == 0xb40f && (instr[2] & 0x0f00) == 0x0c00 &&
841
((instr[3] == 0xdef8 && instr[4] == 0xb004 && instr[5] == 0x4770) || /* windows */
842
(instr[3] == 0x4673 && instr[6] == 0xb004 && instr[7] == 0x4770))) /* wine */
843
{
844
USHORT imm = ((instr[1] & 0x400) << 1) | (instr[2] & 0xff) | ((instr[2] >> 4) & 0x0700);
845
if ((instr[1] & 0xfbf0) == 0xf240) /* T3 */
846
{
847
imm |= (instr[1] & 0x0f) << 12;
848
printf( " [syscall=%04x]", imm );
849
}
850
else if ((instr[1] & 0xfbf0) == 0xf040) /* T2 */
851
{
852
switch (imm >> 8)
853
{
854
case 0: break;
855
case 1: imm = (imm & 0xff); break;
856
case 2: imm = (imm & 0xff) << 8; break;
857
case 3: imm = (imm & 0xff) | ((imm & 0xff) << 8); break;
858
default: imm = (0x80 | (imm & 0x7f)) << (32 - (imm >> 7)); break;
859
}
860
printf( " [syscall=%04x]", imm );
861
}
862
}
863
break;
864
}
865
default:
866
break;
867
}
868
}
869
870
static void dump_dir_exported_functions(void)
871
{
872
unsigned int size;
873
const IMAGE_EXPORT_DIRECTORY *dir = get_dir_and_size(IMAGE_FILE_EXPORT_DIRECTORY, &size);
874
UINT i, *funcs;
875
const UINT *pFunc;
876
const UINT *pName;
877
const WORD *pOrdl;
878
879
if (!dir) return;
880
881
printf("\n");
882
printf(" Name: %s\n", (const char*)RVA(dir->Name, sizeof(DWORD)));
883
printf(" Characteristics: %08x\n", (UINT)dir->Characteristics);
884
printf(" TimeDateStamp: %08X %s\n",
885
(UINT)dir->TimeDateStamp, get_time_str(dir->TimeDateStamp));
886
printf(" Version: %u.%02u\n", dir->MajorVersion, dir->MinorVersion);
887
printf(" Ordinal base: %u\n", (UINT)dir->Base);
888
printf(" # of functions: %u\n", (UINT)dir->NumberOfFunctions);
889
printf(" # of Names: %u\n", (UINT)dir->NumberOfNames);
890
printf(" Functions RVA: %08X\n", (UINT)dir->AddressOfFunctions);
891
printf(" Ordinals RVA: %08X\n", (UINT)dir->AddressOfNameOrdinals);
892
printf(" Names RVA: %08X\n", (UINT)dir->AddressOfNames);
893
printf("\n");
894
printf(" Entry Pt Ordn Name\n");
895
896
pFunc = RVA(dir->AddressOfFunctions, dir->NumberOfFunctions * sizeof(DWORD));
897
if (!pFunc) {printf("Can't grab functions' address table\n"); return;}
898
pName = RVA(dir->AddressOfNames, dir->NumberOfNames * sizeof(DWORD));
899
pOrdl = RVA(dir->AddressOfNameOrdinals, dir->NumberOfNames * sizeof(WORD));
900
901
funcs = calloc( dir->NumberOfFunctions, sizeof(*funcs) );
902
if (!funcs) fatal("no memory");
903
904
for (i = 0; i < dir->NumberOfNames; i++) funcs[pOrdl[i]] = pName[i];
905
906
for (i = 0; i < dir->NumberOfFunctions; i++)
907
{
908
if (!pFunc[i]) continue;
909
printf(" %08X %5u ", pFunc[i], (UINT)dir->Base + i);
910
if (funcs[i])
911
printf("%s", get_symbol_str((const char*)RVA(funcs[i], sizeof(DWORD))));
912
else
913
printf("<by ordinal>");
914
915
/* check for forwarded function */
916
if ((const char *)RVA(pFunc[i],1) >= (const char *)dir &&
917
(const char *)RVA(pFunc[i],1) < (const char *)dir + size)
918
printf(" (-> %s)", (const char *)RVA(pFunc[i],1));
919
dump_export_flags( pFunc[i] );
920
printf("\n");
921
}
922
free(funcs);
923
printf("\n");
924
}
925
926
927
struct runtime_function_x86_64
928
{
929
UINT BeginAddress;
930
UINT EndAddress;
931
UINT UnwindData;
932
};
933
934
struct runtime_function_armnt
935
{
936
UINT BeginAddress;
937
union {
938
UINT UnwindData;
939
struct {
940
UINT Flag : 2;
941
UINT FunctionLength : 11;
942
UINT Ret : 2;
943
UINT H : 1;
944
UINT Reg : 3;
945
UINT R : 1;
946
UINT L : 1;
947
UINT C : 1;
948
UINT StackAdjust : 10;
949
};
950
};
951
};
952
953
struct runtime_function_arm64
954
{
955
UINT BeginAddress;
956
union
957
{
958
UINT UnwindData;
959
struct
960
{
961
UINT Flag : 2;
962
UINT FunctionLength : 11;
963
UINT RegF : 3;
964
UINT RegI : 4;
965
UINT H : 1;
966
UINT CR : 2;
967
UINT FrameSize : 9;
968
};
969
};
970
};
971
972
union handler_data
973
{
974
struct runtime_function_x86_64 chain;
975
UINT handler;
976
};
977
978
struct opcode
979
{
980
BYTE offset;
981
BYTE code : 4;
982
BYTE info : 4;
983
};
984
985
struct unwind_info_x86_64
986
{
987
BYTE version : 3;
988
BYTE flags : 5;
989
BYTE prolog;
990
BYTE count;
991
BYTE frame_reg : 4;
992
BYTE frame_offset : 4;
993
struct opcode opcodes[1]; /* count entries */
994
/* followed by union handler_data */
995
};
996
997
struct unwind_info_armnt
998
{
999
UINT function_length : 18;
1000
UINT version : 2;
1001
UINT x : 1;
1002
UINT e : 1;
1003
UINT f : 1;
1004
UINT count : 5;
1005
UINT words : 4;
1006
};
1007
1008
struct unwind_info_ext_armnt
1009
{
1010
WORD excount;
1011
BYTE exwords;
1012
BYTE reserved;
1013
};
1014
1015
struct unwind_info_epilogue_armnt
1016
{
1017
UINT offset : 18;
1018
UINT res : 2;
1019
UINT cond : 4;
1020
UINT index : 8;
1021
};
1022
1023
#define UWOP_PUSH_NONVOL 0
1024
#define UWOP_ALLOC_LARGE 1
1025
#define UWOP_ALLOC_SMALL 2
1026
#define UWOP_SET_FPREG 3
1027
#define UWOP_SAVE_NONVOL 4
1028
#define UWOP_SAVE_NONVOL_FAR 5
1029
#define UWOP_EPILOG 6
1030
#define UWOP_SAVE_XMM128 8
1031
#define UWOP_SAVE_XMM128_FAR 9
1032
#define UWOP_PUSH_MACHFRAME 10
1033
1034
#define UNW_FLAG_EHANDLER 1
1035
#define UNW_FLAG_UHANDLER 2
1036
#define UNW_FLAG_CHAININFO 4
1037
1038
static void dump_c_exception_data( unsigned int rva )
1039
{
1040
unsigned int i;
1041
const struct
1042
{
1043
UINT count;
1044
struct
1045
{
1046
UINT begin;
1047
UINT end;
1048
UINT handler;
1049
UINT target;
1050
} rec[];
1051
} *table = RVA( rva, sizeof(*table) );
1052
1053
if (!table) return;
1054
printf( " C exception data at %08x count %u\n", rva, table->count );
1055
for (i = 0; i < table->count; i++)
1056
printf( " %u: %08x-%08x handler %08x target %08x\n", i,
1057
table->rec[i].begin, table->rec[i].end, table->rec[i].handler, table->rec[i].target );
1058
}
1059
1060
static void dump_cxx_exception_data( unsigned int rva, unsigned int func_rva )
1061
{
1062
unsigned int i, j, flags = 0;
1063
const unsigned int *ptr = RVA( rva, sizeof(*ptr) );
1064
1065
const struct
1066
{
1067
int prev;
1068
UINT handler;
1069
} *unwind_info;
1070
1071
const struct
1072
{
1073
int start;
1074
int end;
1075
int catch;
1076
int catchblock_count;
1077
UINT catchblock;
1078
} *tryblock;
1079
1080
const struct
1081
{
1082
UINT flags;
1083
UINT type_info;
1084
int offset;
1085
UINT handler;
1086
UINT frame;
1087
} *catchblock;
1088
1089
const struct
1090
{
1091
UINT flags;
1092
UINT type_info;
1093
int offset;
1094
UINT handler;
1095
} *catchblock32;
1096
1097
const struct
1098
{
1099
UINT ip;
1100
int state;
1101
} *ipmap;
1102
1103
const struct
1104
{
1105
UINT magic;
1106
UINT unwind_count;
1107
UINT unwind_table;
1108
UINT tryblock_count;
1109
UINT tryblock;
1110
UINT ipmap_count;
1111
UINT ipmap;
1112
int unwind_help;
1113
UINT expect_list;
1114
UINT flags;
1115
} *func;
1116
1117
if (!ptr || !*ptr) return;
1118
rva = *ptr;
1119
if (!(func = RVA( rva, sizeof(*func) ))) return;
1120
if (func->magic < 0x19930520 || func->magic > 0x19930522) return;
1121
if (func->magic > 0x19930521) flags = func->flags;
1122
printf( " C++ exception data at %08x magic %08x", rva, func->magic );
1123
if (flags & 1) printf( " sync" );
1124
if (flags & 4) printf( " noexcept" );
1125
printf( "\n" );
1126
printf( " unwind help %+d\n", func->unwind_help );
1127
if (func->magic > 0x19930520 && func->expect_list)
1128
printf( " expect_list %08x\n", func->expect_list );
1129
if (func->unwind_count)
1130
{
1131
printf( " unwind table at %08x count %u\n", func->unwind_table, func->unwind_count );
1132
if ((unwind_info = RVA( func->unwind_table, func->unwind_count * sizeof(*unwind_info) )))
1133
{
1134
for (i = 0; i < func->unwind_count; i++)
1135
printf( " %u: prev %d func %08x\n", i,
1136
unwind_info[i].prev, unwind_info[i].handler );
1137
}
1138
}
1139
if (func->tryblock_count)
1140
{
1141
printf( " try table at %08x count %u\n", func->tryblock, func->tryblock_count );
1142
if ((tryblock = RVA( func->tryblock, func->tryblock_count * sizeof(*tryblock) )))
1143
{
1144
for (i = 0; i < func->tryblock_count; i++)
1145
{
1146
catchblock = RVA( tryblock[i].catchblock, sizeof(*catchblock) );
1147
catchblock32 = RVA( tryblock[i].catchblock, sizeof(*catchblock32) );
1148
printf( " %d: start %d end %d catch %d count %u\n", i,
1149
tryblock[i].start, tryblock[i].end, tryblock[i].catch,
1150
tryblock[i].catchblock_count );
1151
for (j = 0; j < tryblock[i].catchblock_count; j++)
1152
{
1153
const char *type = "<none>";
1154
1155
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
1156
{
1157
if (catchblock[j].type_info) type = RVA( catchblock[j].type_info + 16, 1 );
1158
printf( " %d: flags %x offset %+d handler %08x frame %x type %s\n", j,
1159
catchblock[j].flags, catchblock[j].offset,
1160
catchblock[j].handler, catchblock[j].frame, type );
1161
}
1162
else
1163
{
1164
if (catchblock32[j].type_info) type = RVA( catchblock32[j].type_info + 8, 1 );
1165
printf( " %d: flags %x offset %+d handler %08x type %s\n", j,
1166
catchblock32[j].flags, catchblock32[j].offset,
1167
catchblock32[j].handler, type );
1168
}
1169
}
1170
}
1171
}
1172
}
1173
if (func->ipmap_count)
1174
{
1175
printf( " ip map at %08x count %u\n", func->ipmap, func->ipmap_count );
1176
if ((ipmap = RVA( func->ipmap, func->ipmap_count * sizeof(*ipmap) )))
1177
{
1178
for (i = 0; i < func->ipmap_count; i++)
1179
printf( " %u: ip %08x state %d\n", i, ipmap[i].ip, ipmap[i].state );
1180
}
1181
}
1182
}
1183
1184
static UINT v4_decode_uint( const BYTE **b )
1185
{
1186
UINT ret;
1187
const BYTE *p = *b;
1188
1189
if ((*p & 1) == 0)
1190
{
1191
ret = p[0] >> 1;
1192
p += 1;
1193
}
1194
else if ((*p & 3) == 1)
1195
{
1196
ret = (p[0] >> 2) + (p[1] << 6);
1197
p += 2;
1198
}
1199
else if ((*p & 7) == 3)
1200
{
1201
ret = (p[0] >> 3) + (p[1] << 5) + (p[2] << 13);
1202
p += 3;
1203
}
1204
else if ((*p & 15) == 7)
1205
{
1206
ret = (p[0] >> 4) + (p[1] << 4) + (p[2] << 12) + (p[3] << 20);
1207
p += 4;
1208
}
1209
else
1210
{
1211
ret = 0;
1212
p += 5;
1213
}
1214
1215
*b = p;
1216
return ret;
1217
}
1218
1219
static UINT v4_read_rva( const BYTE **b )
1220
{
1221
UINT ret = *(UINT *)*b;
1222
*b += sizeof(UINT);
1223
return ret;
1224
}
1225
1226
#define FUNC_DESCR_IS_CATCH 0x01
1227
#define FUNC_DESCR_IS_SEPARATED 0x02
1228
#define FUNC_DESCR_BBT 0x04
1229
#define FUNC_DESCR_UNWIND_MAP 0x08
1230
#define FUNC_DESCR_TRYBLOCK_MAP 0x10
1231
#define FUNC_DESCR_EHS 0x20
1232
#define FUNC_DESCR_NO_EXCEPT 0x40
1233
#define FUNC_DESCR_RESERVED 0x80
1234
1235
#define CATCHBLOCK_FLAGS 0x01
1236
#define CATCHBLOCK_TYPE_INFO 0x02
1237
#define CATCHBLOCK_OFFSET 0x04
1238
#define CATCHBLOCK_SEPARATED 0x08
1239
#define CATCHBLOCK_RET_ADDR_MASK 0x30
1240
#define CATCHBLOCK_RET_ADDR 0x10
1241
#define CATCHBLOCK_TWO_RET_ADDRS 0x20
1242
1243
static void dump_cxx_exception_data_v4( unsigned int rva, unsigned int func_rva )
1244
{
1245
const unsigned int *ptr = RVA( rva, sizeof(*ptr) );
1246
const BYTE *p;
1247
BYTE flags;
1248
UINT unwind_map = 0, tryblock_map = 0, ip_map, count, i, j, k;
1249
1250
if (!ptr || !*ptr) return;
1251
rva = *ptr;
1252
if (!(p = RVA( rva, 1 ))) return;
1253
flags = *p++;
1254
printf( " C++ v4 exception data at %08x", rva );
1255
if (flags & FUNC_DESCR_BBT) printf( " bbt %08x", v4_decode_uint( &p ));
1256
if (flags & FUNC_DESCR_UNWIND_MAP) unwind_map = v4_read_rva( &p );
1257
if (flags & FUNC_DESCR_TRYBLOCK_MAP) tryblock_map = v4_read_rva( &p );
1258
ip_map = v4_read_rva(&p);
1259
if (flags & FUNC_DESCR_IS_CATCH) printf( " frame %08x", v4_decode_uint( &p ));
1260
if (flags & FUNC_DESCR_EHS) printf( " sync" );
1261
if (flags & FUNC_DESCR_NO_EXCEPT) printf( " noexcept" );
1262
printf( "\n" );
1263
1264
if (unwind_map)
1265
{
1266
int *offsets;
1267
const BYTE *start, *p = RVA( unwind_map, 1 );
1268
count = v4_decode_uint( &p );
1269
printf( " unwind map at %08x count %u\n", unwind_map, count );
1270
offsets = calloc( count, sizeof(*offsets) );
1271
start = p;
1272
for (i = 0; i < count; i++)
1273
{
1274
UINT handler, object, type;
1275
int offset = p - start, off, prev = -2;
1276
1277
offsets[i] = offset;
1278
type = v4_decode_uint( &p );
1279
off = (type >> 2);
1280
if (off > offset) prev = -1;
1281
else for (j = 0; j < i; j++) if (offsets[j] == offset - off) prev = j;
1282
1283
switch (type & 3)
1284
{
1285
case 0:
1286
printf( " %u: prev %d no handler\n", i, prev );
1287
break;
1288
case 1:
1289
handler = v4_read_rva( &p );
1290
object = v4_decode_uint( &p );
1291
printf( " %u: prev %d dtor obj handler %08x obj %+d\n",
1292
i, prev, handler, (int)object );
1293
break;
1294
case 2:
1295
handler = v4_read_rva( &p );
1296
object = v4_decode_uint( &p );
1297
printf( " %u: prev %d dtor ptr handler %08x obj %+d\n",
1298
i, prev, handler, (int)object );
1299
break;
1300
case 3:
1301
handler = v4_read_rva( &p );
1302
printf( " %u: prev %d handler %08x\n", i, prev, handler );
1303
break;
1304
}
1305
}
1306
free( offsets );
1307
}
1308
1309
if (tryblock_map)
1310
{
1311
const BYTE *p = RVA( tryblock_map, 1 );
1312
count = v4_decode_uint( &p );
1313
printf( " tryblock map at %08x count %u\n", tryblock_map, count );
1314
for (i = 0; i < count; i++)
1315
{
1316
int start = v4_decode_uint( &p );
1317
int end = v4_decode_uint( &p );
1318
int catch = v4_decode_uint( &p );
1319
UINT catchblock = v4_read_rva( &p );
1320
1321
printf( " %u: start %d end %d catch %d\n", i, start, end, catch );
1322
if (catchblock)
1323
{
1324
UINT cont[3];
1325
const BYTE *p = RVA( catchblock, 1 );
1326
UINT count2 = v4_decode_uint( &p );
1327
for (j = 0; j < count2; j++)
1328
{
1329
BYTE flags = *p++;
1330
printf( " %u:", j );
1331
if (flags & CATCHBLOCK_FLAGS)
1332
printf( " flags %08x", v4_decode_uint( &p ));
1333
if (flags & CATCHBLOCK_TYPE_INFO)
1334
printf( " type %08x", v4_read_rva( &p ));
1335
if (flags & CATCHBLOCK_OFFSET)
1336
printf( " offset %08x", v4_decode_uint( &p ));
1337
printf( " handler %08x", v4_read_rva( &p ));
1338
for (k = 0; k < ((flags >> 4) & 3); k++)
1339
if (flags & CATCHBLOCK_SEPARATED) cont[k] = v4_read_rva( &p );
1340
else cont[k] = func_rva + v4_decode_uint( &p );
1341
if (k == 1) printf( " cont %08x", cont[0] );
1342
else if (k == 2) printf( " cont %08x,%08x", cont[0], cont[1] );
1343
printf( "\n" );
1344
}
1345
}
1346
}
1347
}
1348
1349
if (ip_map && (flags & FUNC_DESCR_IS_SEPARATED))
1350
{
1351
const BYTE *p = RVA( ip_map, 1 );
1352
1353
count = v4_decode_uint( &p );
1354
printf( " separated ip map at %08x count %u\n", ip_map, count );
1355
for (i = 0; i < count; i++)
1356
{
1357
UINT ip = v4_read_rva( &p );
1358
UINT map = v4_read_rva( &p );
1359
1360
if (map)
1361
{
1362
UINT state, count2;
1363
const BYTE *p = RVA( map, 1 );
1364
1365
count2 = v4_decode_uint( &p );
1366
printf( " %u: start %08x map %08x\n", i, ip, map );
1367
for (j = 0; j < count2; j++)
1368
{
1369
ip += v4_decode_uint( &p );
1370
state = v4_decode_uint( &p );
1371
printf( " %u: ip %08x state %d\n", i, ip, state );
1372
}
1373
}
1374
}
1375
}
1376
else if (ip_map)
1377
{
1378
UINT ip = func_rva, state;
1379
const BYTE *p = RVA( ip_map, 1 );
1380
1381
count = v4_decode_uint( &p );
1382
printf( " ip map at %08x count %u\n", ip_map, count );
1383
for (i = 0; i < count; i++)
1384
{
1385
ip += v4_decode_uint( &p );
1386
state = v4_decode_uint( &p );
1387
printf( " %u: ip %08x state %d\n", i, ip, state );
1388
}
1389
}
1390
}
1391
1392
static void dump_exception_data( unsigned int rva, unsigned int func_rva, const char *name )
1393
{
1394
if (strstr( name, "__C_specific_handler" )) dump_c_exception_data( rva );
1395
if (strstr( name, "__CxxFrameHandler4" )) dump_cxx_exception_data_v4( rva, func_rva );
1396
else dump_cxx_exception_data( rva, func_rva );
1397
}
1398
1399
static void dump_x86_64_unwind_info( const struct runtime_function_x86_64 *function )
1400
{
1401
static const char * const reg_names[16] =
1402
{ "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
1403
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" };
1404
1405
const union handler_data *handler_data;
1406
const struct unwind_info_x86_64 *info;
1407
unsigned int i, count;
1408
1409
printf( "\nFunction %08x-%08x:%s\n", function->BeginAddress, function->EndAddress,
1410
find_export_from_rva( function->BeginAddress ));
1411
if (function->UnwindData & 1)
1412
{
1413
const struct runtime_function_x86_64 *next = RVA( function->UnwindData & ~1, sizeof(*next) );
1414
printf( " -> function %08x-%08x\n", next->BeginAddress, next->EndAddress );
1415
return;
1416
}
1417
info = RVA( function->UnwindData, sizeof(*info) );
1418
1419
if (!info)
1420
{
1421
printf( " no unwind info (%x)\n", function->UnwindData );
1422
return;
1423
}
1424
printf( " unwind info at %08x\n", function->UnwindData );
1425
if (info->version > 2)
1426
{
1427
printf( " *** unknown version %u\n", info->version );
1428
return;
1429
}
1430
printf( " flags %x", info->flags );
1431
if (info->flags & UNW_FLAG_EHANDLER) printf( " EHANDLER" );
1432
if (info->flags & UNW_FLAG_UHANDLER) printf( " UHANDLER" );
1433
if (info->flags & UNW_FLAG_CHAININFO) printf( " CHAININFO" );
1434
printf( "\n prolog 0x%x bytes\n", info->prolog );
1435
1436
if (info->frame_reg)
1437
printf( " frame register %s offset 0x%x(%%rsp)\n",
1438
reg_names[info->frame_reg], info->frame_offset * 16 );
1439
1440
for (i = 0; i < info->count; i++)
1441
{
1442
if (info->opcodes[i].code == UWOP_EPILOG)
1443
{
1444
i++;
1445
continue;
1446
}
1447
printf( " 0x%02x: ", info->opcodes[i].offset );
1448
switch (info->opcodes[i].code)
1449
{
1450
case UWOP_PUSH_NONVOL:
1451
printf( "push %%%s\n", reg_names[info->opcodes[i].info] );
1452
break;
1453
case UWOP_ALLOC_LARGE:
1454
if (info->opcodes[i].info)
1455
{
1456
count = *(const UINT *)&info->opcodes[i+1];
1457
i += 2;
1458
}
1459
else
1460
{
1461
count = *(const USHORT *)&info->opcodes[i+1] * 8;
1462
i++;
1463
}
1464
printf( "sub $0x%x,%%rsp\n", count );
1465
break;
1466
case UWOP_ALLOC_SMALL:
1467
count = (info->opcodes[i].info + 1) * 8;
1468
printf( "sub $0x%x,%%rsp\n", count );
1469
break;
1470
case UWOP_SET_FPREG:
1471
printf( "lea 0x%x(%%rsp),%s\n",
1472
info->frame_offset * 16, reg_names[info->frame_reg] );
1473
break;
1474
case UWOP_SAVE_NONVOL:
1475
count = *(const USHORT *)&info->opcodes[i+1] * 8;
1476
printf( "mov %%%s,0x%x(%%rsp)\n", reg_names[info->opcodes[i].info], count );
1477
i++;
1478
break;
1479
case UWOP_SAVE_NONVOL_FAR:
1480
count = *(const UINT *)&info->opcodes[i+1];
1481
printf( "mov %%%s,0x%x(%%rsp)\n", reg_names[info->opcodes[i].info], count );
1482
i += 2;
1483
break;
1484
case UWOP_SAVE_XMM128:
1485
count = *(const USHORT *)&info->opcodes[i+1] * 16;
1486
printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info->opcodes[i].info, count );
1487
i++;
1488
break;
1489
case UWOP_SAVE_XMM128_FAR:
1490
count = *(const UINT *)&info->opcodes[i+1];
1491
printf( "movaps %%xmm%u,0x%x(%%rsp)\n", info->opcodes[i].info, count );
1492
i += 2;
1493
break;
1494
case UWOP_PUSH_MACHFRAME:
1495
printf( "PUSH_MACHFRAME %u\n", info->opcodes[i].info );
1496
break;
1497
default:
1498
printf( "*** unknown code %u\n", info->opcodes[i].code );
1499
break;
1500
}
1501
}
1502
1503
if (info->version == 2 && info->opcodes[0].code == UWOP_EPILOG) /* print the epilogs */
1504
{
1505
unsigned int end = function->EndAddress;
1506
unsigned int size = info->opcodes[0].offset;
1507
1508
printf( " epilog 0x%x bytes\n", size );
1509
if (info->opcodes[0].info) printf( " at %08x-%08x\n", end - size, end );
1510
for (i = 1; i < info->count && info->opcodes[i].code == UWOP_EPILOG; i++)
1511
{
1512
unsigned int offset = (info->opcodes[i].info << 8) + info->opcodes[i].offset;
1513
if (!offset) break;
1514
printf( " at %08x-%08x\n", end - offset, end - offset + size );
1515
}
1516
}
1517
1518
handler_data = (const union handler_data *)&info->opcodes[(info->count + 1) & ~1];
1519
if (info->flags & UNW_FLAG_CHAININFO)
1520
{
1521
printf( " -> function %08x-%08x\n",
1522
handler_data->chain.BeginAddress, handler_data->chain.EndAddress );
1523
return;
1524
}
1525
if (info->flags & (UNW_FLAG_EHANDLER | UNW_FLAG_UHANDLER))
1526
{
1527
UINT rva = function->UnwindData + ((const char *)(&handler_data->handler + 1) - (const char *)info);
1528
const char *name = get_function_name( handler_data->handler );
1529
1530
printf( " handler %08x%s data at %08x\n", handler_data->handler, name, rva );
1531
dump_exception_data( rva, function->BeginAddress, name );
1532
}
1533
}
1534
1535
static const BYTE armnt_code_lengths[256] =
1536
{
1537
/* 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,
1538
/* 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,
1539
/* 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,
1540
/* 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,
1541
/* 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,
1542
/* 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,
1543
/* 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,
1544
/* 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
1545
};
1546
1547
static void dump_armnt_unwind_info( const struct runtime_function_armnt *fnc )
1548
{
1549
const struct unwind_info_armnt *info;
1550
const struct unwind_info_ext_armnt *infoex;
1551
const struct unwind_info_epilogue_armnt *infoepi = NULL;
1552
unsigned int rva;
1553
WORD i, count = 0, words = 0;
1554
1555
if (fnc->Flag)
1556
{
1557
char intregs[32] = {0}, intregspop[32] = {0}, vfpregs[32] = {0};
1558
WORD pf = 0, ef = 0, fpoffset = 0, stack = fnc->StackAdjust;
1559
const char *pfx = " ... ";
1560
1561
printf( "\nFunction %08x-%08x: flag=%u ret=%u H=%u reg=%u R=%u L=%u C=%u%s\n",
1562
fnc->BeginAddress & ~1, (fnc->BeginAddress & ~1) + fnc->FunctionLength * 2,
1563
fnc->Flag, fnc->Ret, fnc->H, fnc->Reg, fnc->R, fnc->L, fnc->C,
1564
find_export_from_rva( fnc->BeginAddress ));
1565
1566
if (fnc->StackAdjust >= 0x03f4)
1567
{
1568
pf = fnc->StackAdjust & 0x04;
1569
ef = fnc->StackAdjust & 0x08;
1570
stack = (fnc->StackAdjust & 3) + 1;
1571
}
1572
1573
if (!fnc->R || pf)
1574
{
1575
int first = 4, last = fnc->Reg + 4;
1576
if (pf)
1577
{
1578
first = (~fnc->StackAdjust) & 3;
1579
if (fnc->R)
1580
last = 3;
1581
}
1582
if (first == last)
1583
sprintf(intregs, "r%u", first);
1584
else
1585
sprintf(intregs, "r%u-r%u", first, last);
1586
fpoffset = last + 1 - first;
1587
}
1588
1589
if (!fnc->R || ef)
1590
{
1591
int first = 4, last = fnc->Reg + 4;
1592
if (ef)
1593
{
1594
first = (~fnc->StackAdjust) & 3;
1595
if (fnc->R)
1596
last = 3;
1597
}
1598
if (first == last)
1599
sprintf(intregspop, "r%u", first);
1600
else
1601
sprintf(intregspop, "r%u-r%u", first, last);
1602
}
1603
1604
if (fnc->C)
1605
{
1606
if (intregs[0])
1607
strcat(intregs, ", ");
1608
if (intregspop[0])
1609
strcat(intregspop, ", ");
1610
strcat(intregs, "r11");
1611
strcat(intregspop, "r11");
1612
}
1613
if (fnc->L)
1614
{
1615
if (intregs[0])
1616
strcat(intregs, ", ");
1617
strcat(intregs, "lr");
1618
1619
if (intregspop[0] && (fnc->Ret != 0 || !fnc->H))
1620
strcat(intregspop, ", ");
1621
if (fnc->Ret != 0)
1622
strcat(intregspop, "lr");
1623
else if (!fnc->H)
1624
strcat(intregspop, "pc");
1625
}
1626
1627
if (fnc->R)
1628
{
1629
if (fnc->Reg)
1630
sprintf(vfpregs, "d8-d%u", fnc->Reg + 8);
1631
else
1632
strcpy(vfpregs, "d8");
1633
}
1634
1635
printf( " Prologue:\n" );
1636
if (fnc->Flag == 1) {
1637
if (fnc->H)
1638
printf( "%s push {r0-r3}\n", pfx );
1639
1640
if (intregs[0])
1641
printf( "%s push {%s}\n", pfx, intregs );
1642
1643
if (fnc->C && fpoffset == 0)
1644
printf( "%s mov r11, sp\n", pfx );
1645
else if (fnc->C)
1646
printf( "%s add r11, sp, #%d\n", pfx, fpoffset * 4 );
1647
1648
if (fnc->R && fnc->Reg != 0x07)
1649
printf( "%s vpush {%s}\n", pfx, vfpregs );
1650
1651
if (stack && !pf)
1652
printf( "%s sub sp, sp, #%d\n", pfx, stack * 4 );
1653
}
1654
1655
if (fnc->Ret == 3)
1656
return;
1657
printf( " Epilogue:\n" );
1658
1659
if (stack && !ef)
1660
printf( "%s add sp, sp, #%d\n", pfx, stack * 4 );
1661
1662
if (fnc->R && fnc->Reg != 0x07)
1663
printf( "%s vpop {%s}\n", pfx, vfpregs );
1664
1665
if (intregspop[0])
1666
printf( "%s pop {%s}\n", pfx, intregspop );
1667
1668
if (fnc->H && !(fnc->L && fnc->Ret == 0))
1669
printf( "%s add sp, sp, #16\n", pfx );
1670
else if (fnc->H && (fnc->L && fnc->Ret == 0))
1671
printf( "%s ldr pc, [sp], #20\n", pfx );
1672
1673
if (fnc->Ret == 1)
1674
printf( "%s bx <reg>\n", pfx );
1675
else if (fnc->Ret == 2)
1676
printf( "%s b <address>\n", pfx );
1677
1678
return;
1679
}
1680
1681
info = RVA( fnc->UnwindData, sizeof(*info) );
1682
rva = fnc->UnwindData + sizeof(*info);
1683
count = info->count;
1684
words = info->words;
1685
1686
printf( "\nFunction %08x-%08x: ver=%u X=%u E=%u F=%u%s\n", fnc->BeginAddress & ~1,
1687
(fnc->BeginAddress & ~1) + info->function_length * 2,
1688
info->version, info->x, info->e, info->f, find_export_from_rva( fnc->BeginAddress | 1 ));
1689
1690
if (!info->count && !info->words)
1691
{
1692
infoex = RVA( rva, sizeof(*infoex) );
1693
rva = rva + sizeof(*infoex);
1694
count = infoex->excount;
1695
words = infoex->exwords;
1696
}
1697
1698
if (!info->e)
1699
{
1700
infoepi = RVA( rva, count * sizeof(*infoepi) );
1701
rva = rva + count * sizeof(*infoepi);
1702
}
1703
1704
if (words)
1705
{
1706
const unsigned int *codes;
1707
BYTE b, *bytes;
1708
BOOL inepilogue = FALSE;
1709
1710
codes = RVA( rva, words * sizeof(*codes) );
1711
rva = rva + words * sizeof(*codes);
1712
bytes = (BYTE*)codes;
1713
1714
printf( " Prologue:\n" );
1715
for (b = 0; b < words * sizeof(*codes); b++)
1716
{
1717
BYTE code = bytes[b];
1718
BYTE len = armnt_code_lengths[code];
1719
1720
if (info->e && b == count)
1721
{
1722
printf( " Epilogue:\n" );
1723
inepilogue = TRUE;
1724
}
1725
else if (!info->e && infoepi)
1726
{
1727
for (i = 0; i < count; i++)
1728
if (b == infoepi[i].index)
1729
{
1730
printf( " Epilogue %u at %08x: (res=%x cond=%x)\n", i,
1731
(fnc->BeginAddress & ~1) + infoepi[i].offset * 2,
1732
infoepi[i].res, infoepi[i].cond );
1733
inepilogue = TRUE;
1734
}
1735
}
1736
1737
printf( " ");
1738
for (i = 0; i < len; i++)
1739
printf( " %02x", bytes[b+i] );
1740
printf( " %*s", 3 * (3 - len), "" );
1741
1742
if (code == 0x00)
1743
printf( "\n" );
1744
else if (code <= 0x7f)
1745
printf( "%s sp, sp, #%u\n", inepilogue ? "add" : "sub", code * 4 );
1746
else if (code <= 0xbf)
1747
{
1748
WORD excode, f;
1749
BOOL first = TRUE;
1750
BYTE excodes = bytes[++b];
1751
1752
excode = (code << 8) | excodes;
1753
printf( "%s {", inepilogue ? "pop" : "push" );
1754
1755
for (f = 0; f <= 12; f++)
1756
{
1757
if ((excode >> f) & 1)
1758
{
1759
printf( "%sr%u", first ? "" : ", ", f );
1760
first = FALSE;
1761
}
1762
}
1763
1764
if (excode & 0x2000)
1765
printf( "%s%s", first ? "" : ", ", inepilogue ? "pc" : "lr" );
1766
1767
printf( "}\n" );
1768
}
1769
else if (code <= 0xcf)
1770
if (inepilogue)
1771
printf( "mov sp, r%u\n", code & 0x0f );
1772
else
1773
printf( "mov r%u, sp\n", code & 0x0f );
1774
else if (code <= 0xd3)
1775
printf( "%s {r4-r%u}\n", inepilogue ? "pop" : "push", (code & 0x03) + 4 );
1776
else if (code <= 0xd4)
1777
printf( "%s {r4, %s}\n", inepilogue ? "pop" : "push", inepilogue ? "pc" : "lr" );
1778
else if (code <= 0xd7)
1779
printf( "%s {r4-r%u, %s}\n", inepilogue ? "pop" : "push", (code & 0x03) + 4, inepilogue ? "pc" : "lr" );
1780
else if (code <= 0xdb)
1781
printf( "%s {r4-r%u}\n", inepilogue ? "pop" : "push", (code & 0x03) + 8 );
1782
else if (code <= 0xdf)
1783
printf( "%s {r4-r%u, %s}\n", inepilogue ? "pop" : "push", (code & 0x03) + 8, inepilogue ? "pc" : "lr" );
1784
else if (code <= 0xe7)
1785
printf( "%s {d8-d%u}\n", inepilogue ? "vpop" : "vpush", (code & 0x07) + 8 );
1786
else if (code <= 0xeb)
1787
{
1788
WORD excode;
1789
BYTE excodes = bytes[++b];
1790
1791
excode = (code << 8) | excodes;
1792
printf( "%s sp, sp, #%u\n", inepilogue ? "addw" : "subw", (excode & 0x03ff) *4 );
1793
}
1794
else if (code <= 0xed)
1795
{
1796
WORD excode, f;
1797
BOOL first = TRUE;
1798
BYTE excodes = bytes[++b];
1799
1800
excode = (code << 8) | excodes;
1801
printf( "%s {", inepilogue ? "pop" : "push" );
1802
1803
for (f = 0; f < 8; f++)
1804
{
1805
if ((excode >> f) & 1)
1806
{
1807
printf( "%sr%u", first ? "" : ", ", f );
1808
first = FALSE;
1809
}
1810
}
1811
1812
if (excode & 0x0100)
1813
printf( "%s%s", first ? "" : ", ", inepilogue ? "pc" : "lr" );
1814
1815
printf( "}\n" );
1816
}
1817
else if (code == 0xee)
1818
{
1819
BYTE excodes = bytes[++b];
1820
if (excodes == 0x01)
1821
printf( "MSFT_OP_MACHINE_FRAME\n");
1822
else if (excodes == 0x02)
1823
printf( "MSFT_OP_CONTEXT\n");
1824
else
1825
printf( "MSFT opcode %u\n", excodes );
1826
}
1827
else if (code == 0xef)
1828
{
1829
WORD excode;
1830
BYTE excodes = bytes[++b];
1831
1832
if (excodes <= 0x0f)
1833
{
1834
excode = (code << 8) | excodes;
1835
if (inepilogue)
1836
printf( "ldr lr, [sp], #%u\n", (excode & 0x0f) * 4 );
1837
else
1838
printf( "str lr, [sp, #-%u]!\n", (excode & 0x0f) * 4 );
1839
}
1840
else
1841
printf( "unknown 32\n" );
1842
}
1843
else if (code <= 0xf4)
1844
printf( "unknown\n" );
1845
else if (code <= 0xf6)
1846
{
1847
WORD excode, offset = (code == 0xf6) ? 16 : 0;
1848
BYTE excodes = bytes[++b];
1849
1850
excode = (code << 8) | excodes;
1851
printf( "%s {d%u-d%u}\n", inepilogue ? "vpop" : "vpush",
1852
((excode & 0x00f0) >> 4) + offset, (excode & 0x0f) + offset );
1853
}
1854
else if (code <= 0xf7)
1855
{
1856
unsigned int excode;
1857
BYTE excodes[2];
1858
1859
excodes[0] = bytes[++b];
1860
excodes[1] = bytes[++b];
1861
excode = (code << 16) | (excodes[0] << 8) | excodes[1];
1862
printf( "%s sp, sp, #%u\n", inepilogue ? "add" : "sub", (excode & 0xffff) *4 );
1863
}
1864
else if (code <= 0xf8)
1865
{
1866
unsigned int excode;
1867
BYTE excodes[3];
1868
1869
excodes[0] = bytes[++b];
1870
excodes[1] = bytes[++b];
1871
excodes[2] = bytes[++b];
1872
excode = (code << 24) | (excodes[0] << 16) | (excodes[1] << 8) | excodes[2];
1873
printf( "%s sp, sp, #%u\n", inepilogue ? "add" : "sub", (excode & 0xffffff) * 4 );
1874
}
1875
else if (code <= 0xf9)
1876
{
1877
unsigned int excode;
1878
BYTE excodes[2];
1879
1880
excodes[0] = bytes[++b];
1881
excodes[1] = bytes[++b];
1882
excode = (code << 16) | (excodes[0] << 8) | excodes[1];
1883
printf( "%s sp, sp, #%u\n", inepilogue ? "add" : "sub", (excode & 0xffff) *4 );
1884
}
1885
else if (code <= 0xfa)
1886
{
1887
unsigned int excode;
1888
BYTE excodes[3];
1889
1890
excodes[0] = bytes[++b];
1891
excodes[1] = bytes[++b];
1892
excodes[2] = bytes[++b];
1893
excode = (code << 24) | (excodes[0] << 16) | (excodes[1] << 8) | excodes[2];
1894
printf( "%s sp, sp, #%u\n", inepilogue ? "add" : "sub", (excode & 0xffffff) * 4 );
1895
}
1896
else if (code <= 0xfb)
1897
printf( "nop\n" );
1898
else if (code <= 0xfc)
1899
printf( "nop.w\n" );
1900
else if (code <= 0xfd)
1901
{
1902
printf( "(end) nop\n" );
1903
inepilogue = TRUE;
1904
}
1905
else if (code <= 0xfe)
1906
{
1907
printf( "(end) nop.w\n" );
1908
inepilogue = TRUE;
1909
}
1910
else
1911
{
1912
printf( "end\n" );
1913
inepilogue = TRUE;
1914
}
1915
}
1916
}
1917
1918
if (info->x)
1919
{
1920
const unsigned int *handler;
1921
const char *name;
1922
1923
handler = RVA( rva, sizeof(*handler) );
1924
rva = rva + sizeof(*handler);
1925
name = get_function_name( *handler );
1926
printf( " handler %08x%s data at %08x\n", *handler, name, rva );
1927
dump_exception_data( rva, fnc->BeginAddress & ~1, name );
1928
}
1929
}
1930
1931
struct unwind_info_arm64
1932
{
1933
UINT function_length : 18;
1934
UINT version : 2;
1935
UINT x : 1;
1936
UINT e : 1;
1937
UINT epilog : 5;
1938
UINT codes : 5;
1939
};
1940
1941
struct unwind_info_ext_arm64
1942
{
1943
WORD epilog;
1944
BYTE codes;
1945
BYTE reserved;
1946
};
1947
1948
struct unwind_info_epilog_arm64
1949
{
1950
UINT offset : 18;
1951
UINT res : 4;
1952
UINT index : 10;
1953
};
1954
1955
static const BYTE code_lengths[256] =
1956
{
1957
/* 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,
1958
/* 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,
1959
/* 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,
1960
/* 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,
1961
/* 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,
1962
/* 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,
1963
/* 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,
1964
/* e0 */ 4,1,2,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1965
};
1966
1967
static void dump_arm64_codes( const BYTE *ptr, unsigned int count )
1968
{
1969
unsigned int i, j;
1970
1971
for (i = 0; i < count; i += code_lengths[ptr[i]])
1972
{
1973
BYTE len = code_lengths[ptr[i]];
1974
unsigned int val = ptr[i];
1975
for (j = 1; j < len; j++) val = val * 0x100 + ptr[i + j];
1976
1977
printf( " %04x: ", i );
1978
for (j = 0; j < 4; j++)
1979
if (j < len) printf( "%02x ", ptr[i+j] );
1980
else printf( " " );
1981
1982
if (ptr[i] < 0x20) /* alloc_s */
1983
{
1984
printf( "sub sp,sp,#%#x\n", 16 * (val & 0x1f) );
1985
}
1986
else if (ptr[i] < 0x40) /* save_r19r20_x */
1987
{
1988
printf( "stp x19,x20,[sp,-#%#x]!\n", 8 * (val & 0x1f) );
1989
}
1990
else if (ptr[i] < 0x80) /* save_fplr */
1991
{
1992
printf( "stp x29,lr,[sp,#%#x]\n", 8 * (val & 0x3f) );
1993
}
1994
else if (ptr[i] < 0xc0) /* save_fplr_x */
1995
{
1996
printf( "stp x29,lr,[sp,-#%#x]!\n", 8 * (val & 0x3f) + 8 );
1997
}
1998
else if (ptr[i] < 0xc8) /* alloc_m */
1999
{
2000
printf( "sub sp,sp,#%#x\n", 16 * (val & 0x7ff) );
2001
}
2002
else if (ptr[i] < 0xcc) /* save_regp */
2003
{
2004
int reg = 19 + ((val >> 6) & 0xf);
2005
printf( "stp x%u,x%u,[sp,#%#x]\n", reg, reg + 1, 8 * (val & 0x3f) );
2006
}
2007
else if (ptr[i] < 0xd0) /* save_regp_x */
2008
{
2009
int reg = 19 + ((val >> 6) & 0xf);
2010
printf( "stp x%u,x%u,[sp,-#%#x]!\n", reg, reg + 1, 8 * (val & 0x3f) + 8 );
2011
}
2012
else if (ptr[i] < 0xd4) /* save_reg */
2013
{
2014
int reg = 19 + ((val >> 6) & 0xf);
2015
printf( "str x%u,[sp,#%#x]\n", reg, 8 * (val & 0x3f) );
2016
}
2017
else if (ptr[i] < 0xd6) /* save_reg_x */
2018
{
2019
int reg = 19 + ((val >> 5) & 0xf);
2020
printf( "str x%u,[sp,-#%#x]!\n", reg, 8 * (val & 0x1f) + 8 );
2021
}
2022
else if (ptr[i] < 0xd8) /* save_lrpair */
2023
{
2024
int reg = 19 + 2 * ((val >> 6) & 0x7);
2025
printf( "stp x%u,lr,[sp,#%#x]\n", reg, 8 * (val & 0x3f) );
2026
}
2027
else if (ptr[i] < 0xda) /* save_fregp */
2028
{
2029
int reg = 8 + ((val >> 6) & 0x7);
2030
printf( "stp d%u,d%u,[sp,#%#x]\n", reg, reg + 1, 8 * (val & 0x3f) );
2031
}
2032
else if (ptr[i] < 0xdc) /* save_fregp_x */
2033
{
2034
int reg = 8 + ((val >> 6) & 0x7);
2035
printf( "stp d%u,d%u,[sp,-#%#x]!\n", reg, reg + 1, 8 * (val & 0x3f) + 8 );
2036
}
2037
else if (ptr[i] < 0xde) /* save_freg */
2038
{
2039
int reg = 8 + ((val >> 6) & 0x7);
2040
printf( "str d%u,[sp,#%#x]\n", reg, 8 * (val & 0x3f) );
2041
}
2042
else if (ptr[i] == 0xde) /* save_freg_x */
2043
{
2044
int reg = 8 + ((val >> 5) & 0x7);
2045
printf( "str d%u,[sp,-#%#x]!\n", reg, 8 * (val & 0x3f) + 8 );
2046
}
2047
else if (ptr[i] == 0xe0) /* alloc_l */
2048
{
2049
printf( "sub sp,sp,#%#x\n", 16 * (val & 0xffffff) );
2050
}
2051
else if (ptr[i] == 0xe1) /* set_fp */
2052
{
2053
printf( "mov x29,sp\n" );
2054
}
2055
else if (ptr[i] == 0xe2) /* add_fp */
2056
{
2057
printf( "add x29,sp,#%#x\n", 8 * (val & 0xff) );
2058
}
2059
else if (ptr[i] == 0xe3) /* nop */
2060
{
2061
printf( "nop\n" );
2062
}
2063
else if (ptr[i] == 0xe4) /* end */
2064
{
2065
printf( "end\n" );
2066
}
2067
else if (ptr[i] == 0xe5) /* end_c */
2068
{
2069
printf( "end_c\n" );
2070
}
2071
else if (ptr[i] == 0xe6) /* save_next */
2072
{
2073
printf( "save_next\n" );
2074
}
2075
else if (ptr[i] == 0xe7) /* save_any_reg */
2076
{
2077
char reg = "xdq?"[(val >> 6) & 3];
2078
int num = (val >> 8) & 0x1f;
2079
if (val & 0x4000)
2080
printf( "stp %c%u,%c%u", reg, num, reg, num + 1 );
2081
else
2082
printf( "str %c%u,", reg, num );
2083
if (val & 0x2000)
2084
printf( "[sp,#-%#x]!\n", 16 * (val & 0x3f) + 16 );
2085
else
2086
printf( "[sp,#%#x]\n", (val & 0x3f) * ((val & 0x4080) ? 16 : 8) );
2087
}
2088
else if (ptr[i] == 0xe8) /* MSFT_OP_TRAP_FRAME */
2089
{
2090
printf( "MSFT_OP_TRAP_FRAME\n" );
2091
}
2092
else if (ptr[i] == 0xe9) /* MSFT_OP_MACHINE_FRAME */
2093
{
2094
printf( "MSFT_OP_MACHINE_FRAME\n" );
2095
}
2096
else if (ptr[i] == 0xea) /* MSFT_OP_CONTEXT */
2097
{
2098
printf( "MSFT_OP_CONTEXT\n" );
2099
}
2100
else if (ptr[i] == 0xeb) /* MSFT_OP_EC_CONTEXT */
2101
{
2102
printf( "MSFT_OP_EC_CONTEXT\n" );
2103
}
2104
else if (ptr[i] == 0xec) /* MSFT_OP_CLEAR_UNWOUND_TO_CALL */
2105
{
2106
printf( "MSFT_OP_CLEAR_UNWOUND_TO_CALL\n" );
2107
}
2108
else if (ptr[i] == 0xfc) /* pac_sign_lr */
2109
{
2110
printf( "pac_sign_lr\n" );
2111
}
2112
else printf( "??\n");
2113
}
2114
}
2115
2116
static void dump_arm64_packed_info( const struct runtime_function_arm64 *func )
2117
{
2118
int i, pos = 0, intsz = func->RegI * 8, fpsz = func->RegF * 8, savesz, locsz;
2119
2120
if (func->CR == 1) intsz += 8;
2121
if (func->RegF) fpsz += 8;
2122
2123
savesz = ((intsz + fpsz + 8 * 8 * func->H) + 0xf) & ~0xf;
2124
locsz = func->FrameSize * 16 - savesz;
2125
2126
switch (func->CR)
2127
{
2128
case 3:
2129
printf( " %04x: mov x29,sp\n", pos++ );
2130
if (locsz <= 512)
2131
{
2132
printf( " %04x: stp x29,lr,[sp,-#%#x]!\n", pos++, locsz );
2133
break;
2134
}
2135
printf( " %04x: stp x29,lr,[sp,0]\n", pos++ );
2136
/* fall through */
2137
case 0:
2138
case 1:
2139
if (locsz <= 4080)
2140
{
2141
printf( " %04x: sub sp,sp,#%#x\n", pos++, locsz );
2142
}
2143
else
2144
{
2145
printf( " %04x: sub sp,sp,#%#x\n", pos++, locsz - 4080 );
2146
printf( " %04x: sub sp,sp,#%#x\n", pos++, 4080 );
2147
}
2148
break;
2149
}
2150
2151
if (func->H)
2152
{
2153
printf( " %04x: stp x6,x7,[sp,#%#x]\n", pos++, intsz + fpsz + 48 );
2154
printf( " %04x: stp x4,x5,[sp,#%#x]\n", pos++, intsz + fpsz + 32 );
2155
printf( " %04x: stp x2,x3,[sp,#%#x]\n", pos++, intsz + fpsz + 16 );
2156
printf( " %04x: stp x0,x1,[sp,#%#x]\n", pos++, intsz + fpsz );
2157
}
2158
2159
if (func->RegF)
2160
{
2161
if (func->RegF % 2 == 0)
2162
printf( " %04x: str d%u,[sp,#%#x]\n", pos++, 8 + func->RegF, intsz + fpsz - 8 );
2163
for (i = (func->RegF - 1)/ 2; i >= 0; i--)
2164
{
2165
if (!i && !intsz)
2166
printf( " %04x: stp d8,d9,[sp,-#%#x]!\n", pos++, savesz );
2167
else
2168
printf( " %04x: stp d%u,d%u,[sp,#%#x]\n", pos++, 8 + 2 * i, 9 + 2 * i, intsz + 16 * i );
2169
}
2170
}
2171
2172
switch (func->RegI)
2173
{
2174
case 0:
2175
if (func->CR == 1)
2176
printf( " %04x: str lr,[sp,-#%#x]!\n", pos++, savesz );
2177
break;
2178
case 1:
2179
if (func->CR == 1)
2180
printf( " %04x: stp x19,lr,[sp,-#%#x]!\n", pos++, savesz );
2181
else
2182
printf( " %04x: str x19,[sp,-#%#x]!\n", pos++, savesz );
2183
break;
2184
default:
2185
if (func->RegI % 2)
2186
{
2187
if (func->CR == 1)
2188
printf( " %04x: stp x%u,lr,[sp,#%#x]\n", pos++, 18 + func->RegI, 8 * func->RegI - 8 );
2189
else
2190
printf( " %04x: str x%u,[sp,#%#x]\n", pos++, 18 + func->RegI, 8 * func->RegI - 8 );
2191
}
2192
else if (func->CR == 1)
2193
printf( " %04x: str lr,[sp,#%#x]\n", pos++, intsz - 8 );
2194
2195
for (i = func->RegI / 2 - 1; i >= 0; i--)
2196
if (i)
2197
printf( " %04x: stp x%u,x%u,[sp,#%#x]\n", pos++, 19 + 2 * i, 20 + 2 * i, 16 * i );
2198
else
2199
printf( " %04x: stp x19,x20,[sp,-#%#x]!\n", pos++, savesz );
2200
break;
2201
}
2202
printf( " %04x: end\n", pos );
2203
}
2204
2205
static void dump_arm64_unwind_info( const struct runtime_function_arm64 *func )
2206
{
2207
const struct unwind_info_arm64 *info;
2208
const struct unwind_info_ext_arm64 *infoex;
2209
const struct unwind_info_epilog_arm64 *infoepi;
2210
const struct runtime_function_arm64 *parent_func;
2211
const BYTE *ptr;
2212
unsigned int i, rva, codes, epilogs;
2213
2214
switch (func->Flag)
2215
{
2216
case 1:
2217
case 2:
2218
printf( "\nFunction %08x-%08x:%s\n", func->BeginAddress,
2219
func->BeginAddress + func->FunctionLength * 4, find_export_from_rva( func->BeginAddress ));
2220
printf( " len=%#x flag=%x regF=%u regI=%u H=%u CR=%u frame=%x\n",
2221
func->FunctionLength, func->Flag, func->RegF, func->RegI,
2222
func->H, func->CR, func->FrameSize );
2223
dump_arm64_packed_info( func );
2224
return;
2225
case 3:
2226
rva = func->UnwindData & ~3;
2227
parent_func = RVA( rva, sizeof(*parent_func) );
2228
printf( "\nFunction %08x-%08x:%s\n", func->BeginAddress,
2229
func->BeginAddress + 12 /* adrl x16, <dest>; br x16 */,
2230
find_export_from_rva( func->BeginAddress ));
2231
printf( " forward to parent %08x\n", parent_func->BeginAddress );
2232
return;
2233
}
2234
2235
rva = func->UnwindData;
2236
info = RVA( rva, sizeof(*info) );
2237
rva += sizeof(*info);
2238
epilogs = info->epilog;
2239
codes = info->codes;
2240
2241
if (!codes)
2242
{
2243
infoex = RVA( rva, sizeof(*infoex) );
2244
rva = rva + sizeof(*infoex);
2245
codes = infoex->codes;
2246
epilogs = infoex->epilog;
2247
}
2248
printf( "\nFunction %08x-%08x:\n",
2249
func->BeginAddress, func->BeginAddress + info->function_length * 4 );
2250
printf( " len=%#x ver=%u X=%u E=%u epilogs=%u codes=%u\n",
2251
info->function_length, info->version, info->x, info->e, epilogs, codes * 4 );
2252
if (info->e)
2253
{
2254
printf( " epilog 0: code=%04x\n", info->epilog );
2255
}
2256
else
2257
{
2258
infoepi = RVA( rva, sizeof(*infoepi) * epilogs );
2259
rva += sizeof(*infoepi) * epilogs;
2260
for (i = 0; i < epilogs; i++)
2261
printf( " epilog %u: pc=%08x code=%04x\n", i,
2262
func->BeginAddress + infoepi[i].offset * 4, infoepi[i].index );
2263
}
2264
ptr = RVA( rva, codes * 4);
2265
rva += codes * 4;
2266
dump_arm64_codes( ptr, codes * 4 );
2267
if (info->x)
2268
{
2269
const UINT *handler = RVA( rva, sizeof(*handler) );
2270
const char *name = get_function_name( *handler );
2271
2272
rva += sizeof(*handler);
2273
printf( " handler: %08x%s data %08x\n", *handler, name, rva );
2274
dump_exception_data( rva, func->BeginAddress, name );
2275
}
2276
}
2277
2278
static void dump_dir_exceptions(void)
2279
{
2280
static const void *arm64_funcs;
2281
unsigned int i, size;
2282
const void *funcs;
2283
const IMAGE_FILE_HEADER *file_header = &PE_nt_headers->FileHeader;
2284
const IMAGE_ARM64EC_METADATA *metadata;
2285
2286
funcs = get_dir_and_size(IMAGE_FILE_EXCEPTION_DIRECTORY, &size);
2287
if (!funcs) return;
2288
2289
switch (file_header->Machine)
2290
{
2291
case IMAGE_FILE_MACHINE_AMD64:
2292
size /= sizeof(struct runtime_function_x86_64);
2293
printf( "%s exception info (%u functions):\n", get_machine_str( file_header->Machine ), size );
2294
for (i = 0; i < size; i++) dump_x86_64_unwind_info( (struct runtime_function_x86_64*)funcs + i );
2295
if (!(metadata = get_hybrid_metadata())) break;
2296
if (!(size = metadata->ExtraRFETableSize)) break;
2297
if (!(funcs = RVA( metadata->ExtraRFETable, size ))) break;
2298
if (funcs == arm64_funcs) break; /* already dumped */
2299
printf( "\n" );
2300
/* fall through */
2301
case IMAGE_FILE_MACHINE_ARM64:
2302
arm64_funcs = funcs;
2303
size /= sizeof(struct runtime_function_arm64);
2304
printf( "%s exception info (%u functions):\n", get_machine_str( file_header->Machine ), size );
2305
for (i = 0; i < size; i++) dump_arm64_unwind_info( (struct runtime_function_arm64*)funcs + i );
2306
break;
2307
case IMAGE_FILE_MACHINE_ARMNT:
2308
size /= sizeof(struct runtime_function_armnt);
2309
printf( "%s exception info (%u functions):\n", get_machine_str( file_header->Machine ), size );
2310
for (i = 0; i < size; i++) dump_armnt_unwind_info( (struct runtime_function_armnt*)funcs + i );
2311
break;
2312
default:
2313
printf( "Exception information not supported for %s binaries\n",
2314
get_machine_str(file_header->Machine));
2315
break;
2316
}
2317
printf( "\n" );
2318
}
2319
2320
2321
static void dump_image_thunk_data64(const IMAGE_THUNK_DATA64 *il, UINT thunk_rva)
2322
{
2323
/* FIXME: This does not properly handle large images */
2324
const IMAGE_IMPORT_BY_NAME* iibn;
2325
for (; il->u1.Ordinal; il++, thunk_rva += sizeof(LONGLONG))
2326
{
2327
if (IMAGE_SNAP_BY_ORDINAL64(il->u1.Ordinal))
2328
printf(" %08x %4u <by ordinal>\n", thunk_rva, (UINT)IMAGE_ORDINAL64(il->u1.Ordinal));
2329
else
2330
{
2331
iibn = RVA((DWORD)il->u1.AddressOfData, sizeof(DWORD));
2332
if (!iibn)
2333
printf("Can't grab import by name info, skipping to next ordinal\n");
2334
else
2335
printf(" %08x %4u %s\n", thunk_rva, iibn->Hint, iibn->Name);
2336
}
2337
}
2338
}
2339
2340
static void dump_image_thunk_data32(const IMAGE_THUNK_DATA32 *il, int offset, UINT thunk_rva)
2341
{
2342
const IMAGE_IMPORT_BY_NAME* iibn;
2343
for (; il->u1.Ordinal; il++, thunk_rva += sizeof(UINT))
2344
{
2345
if (IMAGE_SNAP_BY_ORDINAL32(il->u1.Ordinal))
2346
printf(" %08x %4u <by ordinal>\n", thunk_rva, (UINT)IMAGE_ORDINAL32(il->u1.Ordinal));
2347
else
2348
{
2349
iibn = RVA((DWORD)il->u1.AddressOfData - offset, sizeof(DWORD));
2350
if (!iibn)
2351
printf("Can't grab import by name info, skipping to next ordinal\n");
2352
else
2353
printf(" %08x %4u %s\n", thunk_rva, iibn->Hint, iibn->Name);
2354
}
2355
}
2356
}
2357
2358
static void dump_dir_imported_functions(void)
2359
{
2360
unsigned directorySize;
2361
const IMAGE_IMPORT_DESCRIPTOR* importDesc = get_dir_and_size(IMAGE_FILE_IMPORT_DIRECTORY, &directorySize);
2362
2363
if (!importDesc) return;
2364
2365
printf("Import Table size: %08x\n", directorySize);/* FIXME */
2366
2367
for (;;)
2368
{
2369
const IMAGE_THUNK_DATA32* il;
2370
2371
if (!importDesc->Name || !importDesc->FirstThunk) break;
2372
2373
printf(" offset %08lx %s\n", Offset(importDesc), (const char*)RVA(importDesc->Name, sizeof(DWORD)));
2374
printf(" Hint/Name Table: %08X\n", (UINT)importDesc->OriginalFirstThunk);
2375
printf(" TimeDateStamp: %08X (%s)\n",
2376
(UINT)importDesc->TimeDateStamp, get_time_str(importDesc->TimeDateStamp));
2377
printf(" ForwarderChain: %08X\n", (UINT)importDesc->ForwarderChain);
2378
printf(" First thunk RVA: %08X\n", (UINT)importDesc->FirstThunk);
2379
2380
printf(" Thunk Ordn Name\n");
2381
2382
il = (importDesc->OriginalFirstThunk != 0) ?
2383
RVA((DWORD)importDesc->OriginalFirstThunk, sizeof(DWORD)) :
2384
RVA((DWORD)importDesc->FirstThunk, sizeof(DWORD));
2385
2386
if (!il)
2387
printf("Can't grab thunk data, going to next imported DLL\n");
2388
else
2389
{
2390
if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
2391
dump_image_thunk_data64((const IMAGE_THUNK_DATA64*)il, importDesc->FirstThunk);
2392
else
2393
dump_image_thunk_data32(il, 0, importDesc->FirstThunk);
2394
printf("\n");
2395
}
2396
importDesc++;
2397
}
2398
printf("\n");
2399
}
2400
2401
static void dump_hybrid_metadata(void)
2402
{
2403
unsigned int i;
2404
const void *metadata = get_hybrid_metadata();
2405
2406
if (!metadata) return;
2407
printf( "Hybrid metadata\n" );
2408
2409
switch (PE_nt_headers->FileHeader.Machine)
2410
{
2411
case IMAGE_FILE_MACHINE_I386:
2412
{
2413
const IMAGE_CHPE_METADATA_X86 *data = metadata;
2414
2415
printf( " Version %#x\n", (int)data->Version );
2416
printf( " CHPECodeAddressRangeOffset %#x\n", (int)data->CHPECodeAddressRangeOffset );
2417
printf( " CHPECodeAddressRangeCount %#x\n", (int)data->CHPECodeAddressRangeCount );
2418
printf( " WowA64ExceptionHandlerFunctionPointer %#x\n", (int)data->WowA64ExceptionHandlerFunctionPointer );
2419
printf( " WowA64DispatchCallFunctionPointer %#x\n", (int)data->WowA64DispatchCallFunctionPointer );
2420
printf( " WowA64DispatchIndirectCallFunctionPointer %#x\n", (int)data->WowA64DispatchIndirectCallFunctionPointer );
2421
printf( " WowA64DispatchIndirectCallCfgFunctionPointer %#x\n", (int)data->WowA64DispatchIndirectCallCfgFunctionPointer );
2422
printf( " WowA64DispatchRetFunctionPointer %#x\n", (int)data->WowA64DispatchRetFunctionPointer );
2423
printf( " WowA64DispatchRetLeafFunctionPointer %#x\n", (int)data->WowA64DispatchRetLeafFunctionPointer );
2424
printf( " WowA64DispatchJumpFunctionPointer %#x\n", (int)data->WowA64DispatchJumpFunctionPointer );
2425
if (data->Version >= 2)
2426
printf( " CompilerIATPointer %#x\n", (int)data->CompilerIATPointer );
2427
if (data->Version >= 3)
2428
printf( " WowA64RdtscFunctionPointer %#x\n", (int)data->WowA64RdtscFunctionPointer );
2429
if (data->Version >= 4)
2430
{
2431
printf( " unknown[0] %#x\n", (int)data->unknown[0] );
2432
printf( " unknown[1] %#x\n", (int)data->unknown[1] );
2433
printf( " unknown[2] %#x\n", (int)data->unknown[2] );
2434
printf( " unknown[3] %#x\n", (int)data->unknown[3] );
2435
}
2436
2437
if (data->CHPECodeAddressRangeOffset)
2438
{
2439
const IMAGE_CHPE_RANGE_ENTRY *map = RVA( data->CHPECodeAddressRangeOffset,
2440
data->CHPECodeAddressRangeCount * sizeof(*map) );
2441
2442
printf( "\nCode ranges\n" );
2443
for (i = 0; i < data->CHPECodeAddressRangeCount; i++)
2444
{
2445
static const char *types[] = { "x86", "ARM64" };
2446
unsigned int start = map[i].StartOffset & ~1;
2447
unsigned int type = map[i].StartOffset & 1;
2448
printf( " %08x - %08x %s\n", start, start + (int)map[i].Length, types[type] );
2449
}
2450
}
2451
2452
break;
2453
}
2454
2455
case IMAGE_FILE_MACHINE_AMD64:
2456
case IMAGE_FILE_MACHINE_ARM64:
2457
{
2458
const IMAGE_ARM64EC_METADATA *data = metadata;
2459
2460
printf( " Version %#x\n", (int)data->Version );
2461
printf( " CodeMap %#x\n", (int)data->CodeMap );
2462
printf( " CodeMapCount %#x\n", (int)data->CodeMapCount );
2463
printf( " CodeRangesToEntryPoints %#x\n", (int)data->CodeRangesToEntryPoints );
2464
printf( " RedirectionMetadata %#x\n", (int)data->RedirectionMetadata );
2465
printf( " __os_arm64x_dispatch_call_no_redirect %#x\n", (int)data->__os_arm64x_dispatch_call_no_redirect );
2466
printf( " __os_arm64x_dispatch_ret %#x\n", (int)data->__os_arm64x_dispatch_ret );
2467
printf( " __os_arm64x_dispatch_call %#x\n", (int)data->__os_arm64x_dispatch_call );
2468
printf( " __os_arm64x_dispatch_icall %#x\n", (int)data->__os_arm64x_dispatch_icall );
2469
printf( " __os_arm64x_dispatch_icall_cfg %#x\n", (int)data->__os_arm64x_dispatch_icall_cfg );
2470
printf( " AlternateEntryPoint %#x\n", (int)data->AlternateEntryPoint );
2471
printf( " AuxiliaryIAT %#x\n", (int)data->AuxiliaryIAT );
2472
printf( " CodeRangesToEntryPointsCount %#x\n", (int)data->CodeRangesToEntryPointsCount );
2473
printf( " RedirectionMetadataCount %#x\n", (int)data->RedirectionMetadataCount );
2474
printf( " GetX64InformationFunctionPointer %#x\n", (int)data->GetX64InformationFunctionPointer );
2475
printf( " SetX64InformationFunctionPointer %#x\n", (int)data->SetX64InformationFunctionPointer );
2476
printf( " ExtraRFETable %#x\n", (int)data->ExtraRFETable );
2477
printf( " ExtraRFETableSize %#x\n", (int)data->ExtraRFETableSize );
2478
printf( " __os_arm64x_dispatch_fptr %#x\n", (int)data->__os_arm64x_dispatch_fptr );
2479
printf( " AuxiliaryIATCopy %#x\n", (int)data->AuxiliaryIATCopy );
2480
printf( " __os_arm64x_helper0 %#x\n", (int)data->__os_arm64x_helper0 );
2481
printf( " __os_arm64x_helper1 %#x\n", (int)data->__os_arm64x_helper1 );
2482
printf( " __os_arm64x_helper2 %#x\n", (int)data->__os_arm64x_helper2 );
2483
printf( " __os_arm64x_helper3 %#x\n", (int)data->__os_arm64x_helper3 );
2484
printf( " __os_arm64x_helper4 %#x\n", (int)data->__os_arm64x_helper4 );
2485
printf( " __os_arm64x_helper5 %#x\n", (int)data->__os_arm64x_helper5 );
2486
printf( " __os_arm64x_helper6 %#x\n", (int)data->__os_arm64x_helper6 );
2487
printf( " __os_arm64x_helper7 %#x\n", (int)data->__os_arm64x_helper7 );
2488
printf( " __os_arm64x_helper8 %#x\n", (int)data->__os_arm64x_helper8 );
2489
2490
if (data->CodeMap)
2491
{
2492
const IMAGE_CHPE_RANGE_ENTRY *map = RVA( data->CodeMap, data->CodeMapCount * sizeof(*map) );
2493
2494
printf( "\nCode ranges\n" );
2495
for (i = 0; i < data->CodeMapCount; i++)
2496
{
2497
static const char *types[] = { "ARM64", "ARM64EC", "x64", "??" };
2498
unsigned int start = map[i].StartOffset & ~0x3;
2499
unsigned int type = map[i].StartOffset & 0x3;
2500
printf( " %08x - %08x %s\n", start, start + (int)map[i].Length, types[type] );
2501
}
2502
}
2503
2504
if (PE_nt_headers->FileHeader.Machine == IMAGE_FILE_MACHINE_ARM64) break;
2505
2506
if (data->CodeRangesToEntryPoints)
2507
{
2508
const IMAGE_ARM64EC_CODE_RANGE_ENTRY_POINT *map = RVA( data->CodeRangesToEntryPoints,
2509
data->CodeRangesToEntryPointsCount * sizeof(*map) );
2510
2511
printf( "\nCode ranges to entry points\n" );
2512
printf( " Start - End Entry point\n" );
2513
for (i = 0; i < data->CodeRangesToEntryPointsCount; i++)
2514
{
2515
const char *name = find_export_from_rva( map[i].EntryPoint );
2516
printf( " %08x - %08x %08x%s\n",
2517
(int)map[i].StartRva, (int)map[i].EndRva, (int)map[i].EntryPoint, name );
2518
}
2519
}
2520
2521
if (data->RedirectionMetadata)
2522
{
2523
const IMAGE_ARM64EC_REDIRECTION_ENTRY *map = RVA( data->RedirectionMetadata,
2524
data->RedirectionMetadataCount * sizeof(*map) );
2525
2526
printf( "\nEntry point redirection\n" );
2527
for (i = 0; i < data->RedirectionMetadataCount; i++)
2528
{
2529
const char *name = find_export_from_rva( map[i].Source );
2530
printf( " %08x -> %08x%s\n", (int)map[i].Source, (int)map[i].Destination, name );
2531
}
2532
}
2533
break;
2534
}
2535
}
2536
printf( "\n" );
2537
}
2538
2539
static void dump_dir_loadconfig(void)
2540
{
2541
unsigned int size;
2542
const IMAGE_LOAD_CONFIG_DIRECTORY32 *loadcfg32;
2543
2544
loadcfg32 = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &size);
2545
if (!loadcfg32) return;
2546
size = min( size, loadcfg32->Size );
2547
2548
printf( "Loadconfig\n" );
2549
print_dword( "Size", loadcfg32->Size );
2550
print_dword( "TimeDateStamp", loadcfg32->TimeDateStamp );
2551
print_word( "MajorVersion", loadcfg32->MajorVersion );
2552
print_word( "MinorVersion", loadcfg32->MinorVersion );
2553
print_dword( "GlobalFlagsClear", loadcfg32->GlobalFlagsClear );
2554
print_dword( "GlobalFlagsSet", loadcfg32->GlobalFlagsSet );
2555
print_dword( "CriticalSectionDefaultTimeout", loadcfg32->CriticalSectionDefaultTimeout );
2556
2557
if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
2558
{
2559
const IMAGE_LOAD_CONFIG_DIRECTORY64 *loadcfg64 = (void *)loadcfg32;
2560
2561
print_longlong( "DeCommitFreeBlockThreshold", loadcfg64->DeCommitFreeBlockThreshold );
2562
print_longlong( "DeCommitTotalFreeThreshold", loadcfg64->DeCommitTotalFreeThreshold );
2563
print_longlong( "MaximumAllocationSize", loadcfg64->MaximumAllocationSize );
2564
print_longlong( "VirtualMemoryThreshold", loadcfg64->VirtualMemoryThreshold );
2565
print_dword( "ProcessHeapFlags", loadcfg64->ProcessHeapFlags );
2566
print_longlong( "ProcessAffinityMask", loadcfg64->ProcessAffinityMask );
2567
print_word( "CSDVersion", loadcfg64->CSDVersion );
2568
print_word( "DependentLoadFlags", loadcfg64->DependentLoadFlags );
2569
print_longlong( "SecurityCookie", loadcfg64->SecurityCookie );
2570
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, SEHandlerTable )) goto done;
2571
print_longlong( "SEHandlerTable", loadcfg64->SEHandlerTable );
2572
print_longlong( "SEHandlerCount", loadcfg64->SEHandlerCount );
2573
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardCFCheckFunctionPointer )) goto done;
2574
print_longlong( "GuardCFCheckFunctionPointer", loadcfg64->GuardCFCheckFunctionPointer );
2575
print_longlong( "GuardCFDispatchFunctionPointer", loadcfg64->GuardCFDispatchFunctionPointer );
2576
print_longlong( "GuardCFFunctionTable", loadcfg64->GuardCFFunctionTable );
2577
print_longlong( "GuardCFFunctionCount", loadcfg64->GuardCFFunctionCount );
2578
print_dword( "GuardFlags", loadcfg64->GuardFlags );
2579
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, CodeIntegrity )) goto done;
2580
print_word( "CodeIntegrity.Flags", loadcfg64->CodeIntegrity.Flags );
2581
print_word( "CodeIntegrity.Catalog", loadcfg64->CodeIntegrity.Catalog );
2582
print_dword( "CodeIntegrity.CatalogOffset", loadcfg64->CodeIntegrity.CatalogOffset );
2583
print_dword( "CodeIntegrity.Reserved", loadcfg64->CodeIntegrity.Reserved );
2584
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardAddressTakenIatEntryTable )) goto done;
2585
print_longlong( "GuardAddressTakenIatEntryTable", loadcfg64->GuardAddressTakenIatEntryTable );
2586
print_longlong( "GuardAddressTakenIatEntryCount", loadcfg64->GuardAddressTakenIatEntryCount );
2587
print_longlong( "GuardLongJumpTargetTable", loadcfg64->GuardLongJumpTargetTable );
2588
print_longlong( "GuardLongJumpTargetCount", loadcfg64->GuardLongJumpTargetCount );
2589
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, DynamicValueRelocTable )) goto done;
2590
print_longlong( "DynamicValueRelocTable", loadcfg64->DynamicValueRelocTable );
2591
print_longlong( "CHPEMetadataPointer", loadcfg64->CHPEMetadataPointer );
2592
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardRFFailureRoutine )) goto done;
2593
print_longlong( "GuardRFFailureRoutine", loadcfg64->GuardRFFailureRoutine );
2594
print_longlong( "GuardRFFailureRoutineFuncPtr", loadcfg64->GuardRFFailureRoutineFunctionPointer );
2595
print_dword( "DynamicValueRelocTableOffset", loadcfg64->DynamicValueRelocTableOffset );
2596
print_word( "DynamicValueRelocTableSection",loadcfg64->DynamicValueRelocTableSection );
2597
print_word( "Reserved2", loadcfg64->Reserved2 );
2598
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardRFVerifyStackPointerFunctionPointer )) goto done;
2599
print_longlong( "GuardRFVerifyStackPointerFuncPtr", loadcfg64->GuardRFVerifyStackPointerFunctionPointer );
2600
print_dword( "HotPatchTableOffset", loadcfg64->HotPatchTableOffset );
2601
print_dword( "Reserved3", loadcfg64->Reserved3 );
2602
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, EnclaveConfigurationPointer )) goto done;
2603
print_longlong( "EnclaveConfigurationPointer", loadcfg64->EnclaveConfigurationPointer );
2604
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, VolatileMetadataPointer )) goto done;
2605
print_longlong( "VolatileMetadataPointer", loadcfg64->VolatileMetadataPointer );
2606
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardEHContinuationTable )) goto done;
2607
print_longlong( "GuardEHContinuationTable", loadcfg64->GuardEHContinuationTable );
2608
print_longlong( "GuardEHContinuationCount", loadcfg64->GuardEHContinuationCount );
2609
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardXFGCheckFunctionPointer )) goto done;
2610
print_longlong( "GuardXFGCheckFunctionPointer", loadcfg64->GuardXFGCheckFunctionPointer );
2611
print_longlong( "GuardXFGDispatchFunctionPointer", loadcfg64->GuardXFGDispatchFunctionPointer );
2612
print_longlong( "GuardXFGTableDispatchFuncPtr", loadcfg64->GuardXFGTableDispatchFunctionPointer );
2613
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, CastGuardOsDeterminedFailureMode )) goto done;
2614
print_longlong( "CastGuardOsDeterminedFailureMode", loadcfg64->CastGuardOsDeterminedFailureMode );
2615
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, GuardMemcpyFunctionPointer )) goto done;
2616
print_longlong( "GuardMemcpyFunctionPointer", loadcfg64->GuardMemcpyFunctionPointer );
2617
}
2618
else
2619
{
2620
print_dword( "DeCommitFreeBlockThreshold", loadcfg32->DeCommitFreeBlockThreshold );
2621
print_dword( "DeCommitTotalFreeThreshold", loadcfg32->DeCommitTotalFreeThreshold );
2622
print_dword( "MaximumAllocationSize", loadcfg32->MaximumAllocationSize );
2623
print_dword( "VirtualMemoryThreshold", loadcfg32->VirtualMemoryThreshold );
2624
print_dword( "ProcessHeapFlags", loadcfg32->ProcessHeapFlags );
2625
print_dword( "ProcessAffinityMask", loadcfg32->ProcessAffinityMask );
2626
print_word( "CSDVersion", loadcfg32->CSDVersion );
2627
print_word( "DependentLoadFlags", loadcfg32->DependentLoadFlags );
2628
print_dword( "SecurityCookie", loadcfg32->SecurityCookie );
2629
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, SEHandlerTable )) goto done;
2630
print_dword( "SEHandlerTable", loadcfg32->SEHandlerTable );
2631
print_dword( "SEHandlerCount", loadcfg32->SEHandlerCount );
2632
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardCFCheckFunctionPointer )) goto done;
2633
print_dword( "GuardCFCheckFunctionPointer", loadcfg32->GuardCFCheckFunctionPointer );
2634
print_dword( "GuardCFDispatchFunctionPointer", loadcfg32->GuardCFDispatchFunctionPointer );
2635
print_dword( "GuardCFFunctionTable", loadcfg32->GuardCFFunctionTable );
2636
print_dword( "GuardCFFunctionCount", loadcfg32->GuardCFFunctionCount );
2637
print_dword( "GuardFlags", loadcfg32->GuardFlags );
2638
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, CodeIntegrity )) goto done;
2639
print_word( "CodeIntegrity.Flags", loadcfg32->CodeIntegrity.Flags );
2640
print_word( "CodeIntegrity.Catalog", loadcfg32->CodeIntegrity.Catalog );
2641
print_dword( "CodeIntegrity.CatalogOffset", loadcfg32->CodeIntegrity.CatalogOffset );
2642
print_dword( "CodeIntegrity.Reserved", loadcfg32->CodeIntegrity.Reserved );
2643
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardAddressTakenIatEntryTable )) goto done;
2644
print_dword( "GuardAddressTakenIatEntryTable", loadcfg32->GuardAddressTakenIatEntryTable );
2645
print_dword( "GuardAddressTakenIatEntryCount", loadcfg32->GuardAddressTakenIatEntryCount );
2646
print_dword( "GuardLongJumpTargetTable", loadcfg32->GuardLongJumpTargetTable );
2647
print_dword( "GuardLongJumpTargetCount", loadcfg32->GuardLongJumpTargetCount );
2648
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, DynamicValueRelocTable )) goto done;
2649
print_dword( "DynamicValueRelocTable", loadcfg32->DynamicValueRelocTable );
2650
print_dword( "CHPEMetadataPointer", loadcfg32->CHPEMetadataPointer );
2651
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardRFFailureRoutine )) goto done;
2652
print_dword( "GuardRFFailureRoutine", loadcfg32->GuardRFFailureRoutine );
2653
print_dword( "GuardRFFailureRoutineFuncPtr", loadcfg32->GuardRFFailureRoutineFunctionPointer );
2654
print_dword( "DynamicValueRelocTableOffset", loadcfg32->DynamicValueRelocTableOffset );
2655
print_word( "DynamicValueRelocTableSection", loadcfg32->DynamicValueRelocTableSection );
2656
print_word( "Reserved2", loadcfg32->Reserved2 );
2657
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardRFVerifyStackPointerFunctionPointer )) goto done;
2658
print_dword( "GuardRFVerifyStackPointerFuncPtr", loadcfg32->GuardRFVerifyStackPointerFunctionPointer );
2659
print_dword( "HotPatchTableOffset", loadcfg32->HotPatchTableOffset );
2660
print_dword( "Reserved3", loadcfg32->Reserved3 );
2661
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, EnclaveConfigurationPointer )) goto done;
2662
print_dword( "EnclaveConfigurationPointer", loadcfg32->EnclaveConfigurationPointer );
2663
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, VolatileMetadataPointer )) goto done;
2664
print_dword( "VolatileMetadataPointer", loadcfg32->VolatileMetadataPointer );
2665
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardEHContinuationTable )) goto done;
2666
print_dword( "GuardEHContinuationTable", loadcfg32->GuardEHContinuationTable );
2667
print_dword( "GuardEHContinuationCount", loadcfg32->GuardEHContinuationCount );
2668
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardXFGCheckFunctionPointer )) goto done;
2669
print_dword( "GuardXFGCheckFunctionPointer", loadcfg32->GuardXFGCheckFunctionPointer );
2670
print_dword( "GuardXFGDispatchFunctionPointer", loadcfg32->GuardXFGDispatchFunctionPointer );
2671
print_dword( "GuardXFGTableDispatchFuncPtr", loadcfg32->GuardXFGTableDispatchFunctionPointer );
2672
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, CastGuardOsDeterminedFailureMode )) goto done;
2673
print_dword( "CastGuardOsDeterminedFailureMode", loadcfg32->CastGuardOsDeterminedFailureMode );
2674
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, GuardMemcpyFunctionPointer )) goto done;
2675
print_dword( "GuardMemcpyFunctionPointer", loadcfg32->GuardMemcpyFunctionPointer );
2676
}
2677
done:
2678
printf( "\n" );
2679
dump_hybrid_metadata();
2680
}
2681
2682
static void dump_dir_delay_imported_functions(void)
2683
{
2684
unsigned directorySize;
2685
const IMAGE_DELAYLOAD_DESCRIPTOR *importDesc = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, &directorySize);
2686
2687
if (!importDesc) return;
2688
2689
printf("Delay Import Table size: %08x\n", directorySize); /* FIXME */
2690
2691
for (;;)
2692
{
2693
const IMAGE_THUNK_DATA32* il;
2694
int offset = (importDesc->Attributes.AllAttributes & 1) ? 0 : PE_nt_headers->OptionalHeader.ImageBase;
2695
2696
if (!importDesc->DllNameRVA || !importDesc->ImportAddressTableRVA || !importDesc->ImportNameTableRVA) break;
2697
2698
printf(" grAttrs %08x offset %08lx %s\n", (UINT)importDesc->Attributes.AllAttributes,
2699
Offset(importDesc), (const char *)RVA(importDesc->DllNameRVA - offset, sizeof(DWORD)));
2700
printf(" Hint/Name Table: %08x\n", (UINT)importDesc->ImportNameTableRVA);
2701
printf(" Address Table: %08x\n", (UINT)importDesc->ImportAddressTableRVA);
2702
printf(" TimeDateStamp: %08X (%s)\n",
2703
(UINT)importDesc->TimeDateStamp, get_time_str(importDesc->TimeDateStamp));
2704
2705
printf(" Thunk Ordn Name\n");
2706
2707
il = RVA(importDesc->ImportNameTableRVA - offset, sizeof(DWORD));
2708
2709
if (!il)
2710
printf("Can't grab thunk data, going to next imported DLL\n");
2711
else
2712
{
2713
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
2714
dump_image_thunk_data64((const IMAGE_THUNK_DATA64 *)il, importDesc->ImportAddressTableRVA);
2715
else
2716
dump_image_thunk_data32(il, offset, importDesc->ImportAddressTableRVA);
2717
printf("\n");
2718
}
2719
importDesc++;
2720
}
2721
printf("\n");
2722
}
2723
2724
static void dump_dir_debug_dir(const IMAGE_DEBUG_DIRECTORY* idd, int idx, const IMAGE_SECTION_HEADER *first_section)
2725
{
2726
const char* str;
2727
2728
printf("Directory %02u\n", idx + 1);
2729
printf(" Characteristics: %08X\n", (UINT)idd->Characteristics);
2730
printf(" TimeDateStamp: %08X %s\n",
2731
(UINT)idd->TimeDateStamp, get_time_str(idd->TimeDateStamp));
2732
printf(" Version %u.%02u\n", idd->MajorVersion, idd->MinorVersion);
2733
switch (idd->Type)
2734
{
2735
default:
2736
case IMAGE_DEBUG_TYPE_UNKNOWN: str = "UNKNOWN"; break;
2737
case IMAGE_DEBUG_TYPE_COFF: str = "COFF"; break;
2738
case IMAGE_DEBUG_TYPE_CODEVIEW: str = "CODEVIEW"; break;
2739
case IMAGE_DEBUG_TYPE_FPO: str = "FPO"; break;
2740
case IMAGE_DEBUG_TYPE_MISC: str = "MISC"; break;
2741
case IMAGE_DEBUG_TYPE_EXCEPTION: str = "EXCEPTION"; break;
2742
case IMAGE_DEBUG_TYPE_FIXUP: str = "FIXUP"; break;
2743
case IMAGE_DEBUG_TYPE_OMAP_TO_SRC: str = "OMAP_TO_SRC"; break;
2744
case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC:str = "OMAP_FROM_SRC"; break;
2745
case IMAGE_DEBUG_TYPE_BORLAND: str = "BORLAND"; break;
2746
case IMAGE_DEBUG_TYPE_RESERVED10: str = "RESERVED10"; break;
2747
case IMAGE_DEBUG_TYPE_CLSID: str = "CLSID"; break;
2748
case IMAGE_DEBUG_TYPE_VC_FEATURE: str = "VC_FEATURE"; break;
2749
case IMAGE_DEBUG_TYPE_POGO: str = "POGO"; break;
2750
case IMAGE_DEBUG_TYPE_ILTCG: str = "ILTCG"; break;
2751
case IMAGE_DEBUG_TYPE_MPX: str = "MPX"; break;
2752
case IMAGE_DEBUG_TYPE_REPRO: str = "REPRO"; break;
2753
}
2754
printf(" Type: %u (%s)\n", (UINT)idd->Type, str);
2755
printf(" SizeOfData: %u\n", (UINT)idd->SizeOfData);
2756
printf(" AddressOfRawData: %08X\n", (UINT)idd->AddressOfRawData);
2757
printf(" PointerToRawData: %08X\n", (UINT)idd->PointerToRawData);
2758
2759
switch (idd->Type)
2760
{
2761
case IMAGE_DEBUG_TYPE_UNKNOWN:
2762
break;
2763
case IMAGE_DEBUG_TYPE_COFF:
2764
dump_coff(idd->PointerToRawData, idd->SizeOfData, first_section);
2765
break;
2766
case IMAGE_DEBUG_TYPE_CODEVIEW:
2767
dump_codeview(idd->PointerToRawData, idd->SizeOfData);
2768
break;
2769
case IMAGE_DEBUG_TYPE_FPO:
2770
dump_frame_pointer_omission(idd->PointerToRawData, idd->SizeOfData);
2771
break;
2772
case IMAGE_DEBUG_TYPE_MISC:
2773
{
2774
const IMAGE_DEBUG_MISC* misc = PRD(idd->PointerToRawData, idd->SizeOfData);
2775
if (!misc || idd->SizeOfData < sizeof(*misc)) {printf("Can't get MISC debug information\n"); break;}
2776
printf(" DataType: %u (%s)\n",
2777
(UINT)misc->DataType, (misc->DataType == IMAGE_DEBUG_MISC_EXENAME) ? "Exe name" : "Unknown");
2778
printf(" Length: %u\n", (UINT)misc->Length);
2779
printf(" Unicode: %s\n", misc->Unicode ? "Yes" : "No");
2780
printf(" Data: %s\n", misc->Data);
2781
}
2782
break;
2783
case IMAGE_DEBUG_TYPE_POGO:
2784
{
2785
const unsigned* data = PRD(idd->PointerToRawData, idd->SizeOfData);
2786
const unsigned* end = (const unsigned*)((const unsigned char*)data + idd->SizeOfData);
2787
unsigned idx = 0;
2788
2789
if (!data || idd->SizeOfData < sizeof(unsigned)) {printf("Can't get PODO debug information\n"); break;}
2790
printf(" Header: %08x\n", *(const unsigned*)data);
2791
data++;
2792
printf(" Index Name Offset Size\n");
2793
while (data + 2 < end)
2794
{
2795
const char* ptr;
2796
ptrdiff_t s;
2797
2798
if (!(ptr = memchr(&data[2], '\0', (const char*)end - (const char*)&data[2]))) break;
2799
printf(" %-5u %-16s %08x %08x\n", idx, (const char*)&data[2], data[0], data[1]);
2800
s = ptr - (const char*)&data[2] + 1;
2801
data += 2 + ((s + sizeof(unsigned) - 1) / sizeof(unsigned));
2802
idx++;
2803
}
2804
}
2805
break;
2806
case IMAGE_DEBUG_TYPE_REPRO:
2807
{
2808
const IMAGE_DEBUG_REPRO* repro = PRD(idd->PointerToRawData, idd->SizeOfData);
2809
if (!repro || idd->SizeOfData < sizeof(*repro)) {printf("Can't get REPRO debug information\n"); break;}
2810
printf(" Flags: %08X\n", repro->flags);
2811
printf(" Guid: %s\n", get_guid_str(&repro->guid));
2812
printf(" _unk0: %08X %u\n", repro->unk[0], repro->unk[0]);
2813
printf(" _unk1: %08X %u\n", repro->unk[1], repro->unk[1]);
2814
printf(" _unk2: %08X %u\n", repro->unk[2], repro->unk[2]);
2815
printf(" Timestamp: %08X\n", repro->debug_timestamp);
2816
}
2817
break;
2818
default:
2819
{
2820
const unsigned char* data = PRD(idd->PointerToRawData, idd->SizeOfData);
2821
if (!data) {printf("Can't get debug information for %s\n", str); break;}
2822
dump_data(data, idd->SizeOfData, " ");
2823
}
2824
break;
2825
}
2826
printf("\n");
2827
}
2828
2829
static void dump_dir_debug(void)
2830
{
2831
unsigned nb_dbg, i;
2832
const IMAGE_DEBUG_DIRECTORY*debugDir = get_dir_and_size(IMAGE_FILE_DEBUG_DIRECTORY, &nb_dbg);
2833
2834
nb_dbg /= sizeof(*debugDir);
2835
if (!debugDir || !nb_dbg) return;
2836
2837
printf("Debug Table (%u directories)\n", nb_dbg);
2838
2839
for (i = 0; i < nb_dbg; i++)
2840
{
2841
dump_dir_debug_dir(debugDir, i, IMAGE_FIRST_SECTION(PE_nt_headers));
2842
debugDir++;
2843
}
2844
printf("\n");
2845
}
2846
2847
static struct
2848
{
2849
const BYTE *data;
2850
UINT size;
2851
} strings, userstrings, blobs, guids, tables;
2852
2853
static void print_clr_flags( const char *title, UINT value )
2854
{
2855
printf(" %-34s 0x%X\n", title, value);
2856
#define X(f,s) if (value & f) printf(" %s\n", s)
2857
X(COMIMAGE_FLAGS_ILONLY, "ILONLY");
2858
X(COMIMAGE_FLAGS_32BITREQUIRED, "32BITREQUIRED");
2859
X(COMIMAGE_FLAGS_IL_LIBRARY, "IL_LIBRARY");
2860
X(COMIMAGE_FLAGS_STRONGNAMESIGNED, "STRONGNAMESIGNED");
2861
X(COMIMAGE_FLAGS_TRACKDEBUGDATA, "TRACKDEBUGDATA");
2862
#undef X
2863
}
2864
2865
static void print_clr_directory( const char *title, const IMAGE_DATA_DIRECTORY *dir )
2866
{
2867
printf(" %-23s rva: 0x%-8x size: 0x%-8x\n", title, (UINT)dir->VirtualAddress, (UINT)dir->Size);
2868
}
2869
2870
static UINT clr_indent = 4;
2871
2872
static void print_clr_indent( void )
2873
{
2874
UINT i;
2875
for (i = 0; i < clr_indent; i++) printf( " " );
2876
}
2877
2878
static void print_clr( const char *str )
2879
{
2880
print_clr_indent();
2881
printf( "%s", str );
2882
}
2883
2884
static void print_clr_strings( const BYTE *data, UINT data_size )
2885
{
2886
const char *beg = (const char *)data, *end;
2887
UINT count = 0;
2888
2889
if (!data_size) return;
2890
clr_indent += 4;
2891
for (;;)
2892
{
2893
if (!(end = memchr( beg, '\0', data_size - (beg - (const char *)data) ))) break;
2894
print_clr_indent();
2895
printf( "%-10u\"%s\"\n", count, beg );
2896
beg = end + 1;
2897
count++;
2898
}
2899
clr_indent -= 4;
2900
}
2901
2902
static UINT clr_blob_size( const BYTE *data, UINT data_size, UINT *skip )
2903
{
2904
if (!data_size) return 0;
2905
if (!(data[0] & 0x80))
2906
{
2907
*skip = 1;
2908
return data[0];
2909
}
2910
if (data_size < 2) return 0;
2911
if (!(data[0] & 0x40))
2912
{
2913
*skip = 2;
2914
return ((data[0] & ~0xc0) << 8) + data[1];
2915
}
2916
if (data_size < 4) return 0;
2917
if (!(data[0] & 0x20))
2918
{
2919
*skip = 4;
2920
return ((data[0] & ~0xe0) << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
2921
}
2922
return 0;
2923
}
2924
2925
static void print_clr_blobs( const BYTE *data, UINT data_size )
2926
{
2927
const BYTE *blob = data + 1;
2928
UINT i, size, skip;
2929
2930
if (!data_size) return;
2931
2932
clr_indent += 4;
2933
print_clr_indent();
2934
printf( "%-10u %02x\n", 0, data[0] );
2935
data_size--;
2936
for (;;)
2937
{
2938
if (!(size = clr_blob_size( blob, data_size, &skip ))) break;
2939
print_clr_indent();
2940
printf( "%-10u ", (UINT)(blob - data) );
2941
for (i = 0; i < size; i++)
2942
{
2943
printf( "%02x ", blob[i + skip] );
2944
if (i && i < size - 1 && !((i + 1) % 30))
2945
{
2946
printf( "\n" );
2947
print_clr( " " );
2948
}
2949
}
2950
printf( "\n" );
2951
data_size -= size + skip;
2952
blob += size + skip;
2953
}
2954
clr_indent -= 4;
2955
}
2956
2957
static void print_clr_guids( const BYTE *data, UINT data_size )
2958
{
2959
const BYTE *guid = data;
2960
UINT i, j, count = data_size / 16;
2961
2962
clr_indent += 4;
2963
for (i = 0; i < count; i++)
2964
{
2965
print_clr_indent();
2966
printf( "%-10u ", count );
2967
printf( "%08x", *(UINT *)guid );
2968
printf( " %04x", *(UINT *)guid + 4 );
2969
printf( " %04x", *(USHORT *)guid + 6 );
2970
for (j = 0; j < 8; j++) printf( " %02x", guid[j + 8] );
2971
printf( "\n" );
2972
guid += 16;
2973
}
2974
clr_indent -= 4;
2975
}
2976
2977
static UINT str_idx_size = 2;
2978
static UINT guid_idx_size = 2;
2979
static UINT blob_idx_size = 2;
2980
2981
static void print_clr_byte( const BYTE **ptr, UINT *size, BOOL flags )
2982
{
2983
if (*size < 1) return;
2984
printf( flags ? "0x%02x " : "%-16u", **ptr );
2985
(*ptr)++; (*size)--;
2986
}
2987
2988
static void print_clr_ushort( const BYTE **ptr, UINT *size, BOOL flags )
2989
{
2990
if (*size < sizeof(USHORT)) return;
2991
printf( flags ? "0x%04x " : "%-16u", *(const USHORT *)*ptr );
2992
*ptr += sizeof(USHORT); *size -= sizeof(USHORT);
2993
}
2994
2995
static void print_clr_uint( const BYTE **ptr, UINT *size, BOOL flags )
2996
{
2997
if (*size < sizeof(UINT)) return;
2998
printf( flags ? "0x%08x " : "%-16u", *(const UINT *)*ptr );
2999
*ptr += sizeof(UINT); *size -= sizeof(UINT);
3000
}
3001
3002
static void print_clr_uint64( const BYTE **ptr, UINT *size )
3003
{
3004
if (*size < sizeof(UINT64)) return;
3005
printf( "0x%08x%08x", (UINT)(*(const UINT64 *)*ptr >> 32), (UINT)*(const UINT64 *)*ptr );
3006
*ptr += sizeof(UINT64); *size -= sizeof(UINT64);
3007
}
3008
3009
static void print_clr_string_idx( const BYTE **ptr, UINT *size )
3010
{
3011
if (*size < str_idx_size) return;
3012
if (str_idx_size == 2)
3013
{
3014
USHORT idx = *(const USHORT *)*ptr;
3015
printf( "%-16u", idx );
3016
}
3017
else
3018
{
3019
UINT idx = *(const UINT *)*ptr;
3020
printf( "%-16u", idx );
3021
}
3022
*ptr += str_idx_size; *size -= str_idx_size;
3023
}
3024
3025
static void print_clr_blob_idx( const BYTE **ptr, UINT *size )
3026
{
3027
if (*size < blob_idx_size) return;
3028
if (blob_idx_size == 2)
3029
{
3030
USHORT idx = *(const USHORT *)*ptr;
3031
printf( "%-16u", idx );
3032
}
3033
else
3034
{
3035
UINT idx = *(const UINT *)*ptr;
3036
printf( "%-16u", idx );
3037
}
3038
*ptr += blob_idx_size; *size -= blob_idx_size;
3039
}
3040
3041
static void print_clr_guid_idx( const BYTE **ptr, UINT *size )
3042
{
3043
if (*size < guid_idx_size) return;
3044
if (guid_idx_size == 2)
3045
{
3046
USHORT idx = *(const USHORT *)*ptr;
3047
printf( "%-16u", idx );
3048
}
3049
else
3050
{
3051
UINT idx = *(const UINT *)*ptr;
3052
printf( "%-16u", idx );
3053
}
3054
*ptr += guid_idx_size; *size -= guid_idx_size;
3055
}
3056
3057
enum
3058
{
3059
CLR_TABLE_MODULE = 0x00,
3060
CLR_TABLE_TYPEREF = 0x01,
3061
CLR_TABLE_TYPEDEF = 0x02,
3062
CLR_TABLE_FIELD = 0x04,
3063
CLR_TABLE_METHODDEF = 0x06,
3064
CLR_TABLE_PARAM = 0x08,
3065
CLR_TABLE_INTERFACEIMPL = 0x09,
3066
CLR_TABLE_MEMBERREF = 0x0a,
3067
CLR_TABLE_CONSTANT = 0x0b,
3068
CLR_TABLE_CUSTOMATTRIBUTE = 0x0c,
3069
CLR_TABLE_FIELDMARSHAL = 0x0d,
3070
CLR_TABLE_DECLSECURITY = 0x0e,
3071
CLR_TABLE_CLASSLAYOUT = 0x0f,
3072
CLR_TABLE_FIELDLAYOUT = 0x10,
3073
CLR_TABLE_STANDALONESIG = 0x11,
3074
CLR_TABLE_EVENTMAP = 0x12,
3075
CLR_TABLE_EVENT = 0x14,
3076
CLR_TABLE_PROPERTYMAP = 0x15,
3077
CLR_TABLE_PROPERTY = 0x17,
3078
CLR_TABLE_METHODSEMANTICS = 0x18,
3079
CLR_TABLE_METHODIMPL = 0x19,
3080
CLR_TABLE_MODULEREF = 0x1a,
3081
CLR_TABLE_TYPESPEC = 0x1b,
3082
CLR_TABLE_IMPLMAP = 0x1c,
3083
CLR_TABLE_FIELDRVA = 0x1d,
3084
CLR_TABLE_ASSEMBLY = 0x20,
3085
CLR_TABLE_ASSEMBLYPROCESSOR = 0x21,
3086
CLR_TABLE_ASSEMBLYOS = 0x22,
3087
CLR_TABLE_ASSEMBLYREF = 0x23,
3088
CLR_TABLE_ASSEMBLYREFPROCESSOR = 0x24,
3089
CLR_TABLE_ASSEMBLYREFOS = 0x25,
3090
CLR_TABLE_FILE = 0x26,
3091
CLR_TABLE_EXPORTEDTYPE = 0x27,
3092
CLR_TABLE_MANIFESTRESOURCE = 0x28,
3093
CLR_TABLE_NESTEDCLASS = 0x29,
3094
CLR_TABLE_GENERICPARAM = 0x2a,
3095
CLR_TABLE_METHODSPEC = 0x2b,
3096
CLR_TABLE_GENERICPARAMCONSTRAINT = 0x2c,
3097
CLR_TABLE_MAX = 0x2d,
3098
};
3099
3100
static void print_clr_table_idx( const BYTE **ptr, UINT *size )
3101
{
3102
USHORT idx;
3103
if (*size < sizeof(USHORT)) return; /* FIXME should be 4 bytes if the number of rows exceeds 2^16 */
3104
idx = *(const USHORT *)*ptr;
3105
printf( "0x%04x ", idx );
3106
*ptr += sizeof(USHORT); *size -= sizeof(USHORT);
3107
}
3108
3109
static void print_clr_row( UINT row )
3110
{
3111
print_clr_indent();
3112
printf( "%-10u ", row );
3113
}
3114
3115
static void print_clr_table_header( const char * const *header )
3116
{
3117
const char *str;
3118
3119
print_clr_indent();
3120
printf( "%-11s", "#" );
3121
while ((str = *header++)) printf( "%-16s", str );
3122
printf( "\n" );
3123
}
3124
3125
static void print_clr_table_module( const BYTE **ptr, UINT *size, UINT row_count )
3126
{
3127
static const char * const header[] = { "Generation", "Name", "Mvid", "EncId", "EncBaseId", NULL };
3128
UINT i, row = 1;
3129
3130
print_clr( "Module table\n" );
3131
clr_indent += 4;
3132
print_clr_table_header( header );
3133
for (i = 0; i < row_count; i++)
3134
{
3135
print_clr_row( row++ );
3136
print_clr_ushort( ptr, size, FALSE );
3137
print_clr_string_idx( ptr, size );
3138
print_clr_guid_idx( ptr, size );
3139
print_clr_guid_idx( ptr, size );
3140
print_clr_guid_idx( ptr, size );
3141
printf( "\n" );
3142
}
3143
clr_indent -= 4;
3144
}
3145
3146
static void print_clr_table_typeref( const BYTE **ptr, UINT *size, UINT row_count )
3147
{
3148
static const char * const header[] = { "ResolutionScope", "TypeName", "TypeNamespace", NULL };
3149
UINT i, row = 1;
3150
3151
print_clr( "TypeRef table\n" );
3152
clr_indent += 4;
3153
print_clr_table_header( header );
3154
for (i = 0; i < row_count; i++)
3155
{
3156
print_clr_row( row++ );
3157
print_clr_table_idx( ptr, size );
3158
print_clr_string_idx( ptr, size );
3159
print_clr_string_idx( ptr, size );
3160
printf( "\n" );
3161
}
3162
clr_indent -= 4;
3163
}
3164
3165
static void print_clr_table_typedef( const BYTE **ptr, UINT *size, UINT row_count )
3166
{
3167
static const char * const header[] = { "Flags", "TypeName", "TypeNamespace", "Extends", "FieldList",
3168
"MethodList", NULL };
3169
UINT i, row = 1;
3170
3171
print_clr( "TypeDef table\n" );
3172
clr_indent += 4;
3173
print_clr_table_header( header );
3174
for (i = 0; i < row_count; i++)
3175
{
3176
print_clr_row( row++ );
3177
print_clr_uint( ptr, size, TRUE );
3178
print_clr_string_idx( ptr, size );
3179
print_clr_string_idx( ptr, size );
3180
print_clr_table_idx( ptr, size );
3181
print_clr_table_idx( ptr, size );
3182
print_clr_table_idx( ptr, size );
3183
printf( "\n" );
3184
}
3185
clr_indent -= 4;
3186
}
3187
3188
static void print_clr_table_field( const BYTE **ptr, UINT *size, UINT row_count )
3189
{
3190
static const char * const header[] = { "Flags", "Name", "Signature", NULL };
3191
UINT i, row = 1;
3192
3193
print_clr( "Field table\n" );
3194
clr_indent += 4;
3195
print_clr_table_header( header );
3196
for (i = 0; i < row_count; i++)
3197
{
3198
print_clr_row( row++ );
3199
print_clr_ushort( ptr, size, TRUE );
3200
print_clr_string_idx( ptr, size );
3201
print_clr_blob_idx( ptr, size );
3202
printf( "\n" );
3203
}
3204
clr_indent -= 4;
3205
}
3206
3207
static void print_clr_table_methoddef( const BYTE **ptr, UINT *size, UINT row_count )
3208
{
3209
static const char * const header[] = { "RVA", "ImplFlags", "Flags", "Name", "Signature", "ParamList", NULL };
3210
UINT i, row = 1;
3211
3212
print_clr( "MethodDef table\n" );
3213
clr_indent += 4;
3214
print_clr_table_header( header );
3215
for (i = 0; i < row_count; i++)
3216
{
3217
print_clr_row( row++ );
3218
print_clr_uint( ptr, size, TRUE );
3219
print_clr_ushort( ptr, size, TRUE );
3220
print_clr_ushort( ptr, size, TRUE );
3221
print_clr_string_idx( ptr, size );
3222
print_clr_blob_idx( ptr, size );
3223
print_clr_table_idx( ptr, size );
3224
printf( "\n" );
3225
}
3226
clr_indent -= 4;
3227
}
3228
3229
static void print_clr_table_param( const BYTE **ptr, UINT *size, UINT row_count )
3230
{
3231
static const char * const header[] = { "Flags", "Sequence", "Name", NULL };
3232
UINT i, row = 1;
3233
3234
print_clr( "Param table\n" );
3235
clr_indent += 4;
3236
print_clr_table_header( header );
3237
for (i = 0; i < row_count; i++)
3238
{
3239
print_clr_row( row++ );
3240
print_clr_ushort( ptr, size, TRUE );
3241
print_clr_ushort( ptr, size, FALSE );
3242
print_clr_string_idx( ptr, size );
3243
printf( "\n" );
3244
}
3245
clr_indent -= 4;
3246
}
3247
3248
static void print_clr_table_interfaceimpl( const BYTE **ptr, UINT *size, UINT row_count )
3249
{
3250
static const char * const header[] = { "Class", "Interface", NULL };
3251
UINT i, row = 1;
3252
3253
print_clr( "InterfaceImpl table\n" );
3254
clr_indent += 4;
3255
print_clr_table_header( header );
3256
for (i = 0; i < row_count; i++)
3257
{
3258
print_clr_row( row++ );
3259
print_clr_table_idx( ptr, size );
3260
print_clr_table_idx( ptr, size );
3261
printf( "\n" );
3262
}
3263
clr_indent -= 4;
3264
}
3265
3266
static void print_clr_table_memberref( const BYTE **ptr, UINT *size, UINT row_count )
3267
{
3268
static const char * const header[] = { "Class", "Name", "Signature", NULL };
3269
UINT i, row = 1;
3270
3271
print_clr( "MemberRef table\n" );
3272
clr_indent += 4;
3273
print_clr_table_header( header );
3274
for (i = 0; i < row_count; i++)
3275
{
3276
print_clr_row( row++ );
3277
print_clr_table_idx( ptr, size );
3278
print_clr_string_idx( ptr, size );
3279
print_clr_blob_idx( ptr, size );
3280
printf( "\n" );
3281
}
3282
clr_indent -= 4;
3283
}
3284
3285
static void print_clr_table_constant( const BYTE **ptr, UINT *size, UINT row_count )
3286
{
3287
static const char * const header[] = { "Type", "Padding", "Parent", "Value", NULL };
3288
UINT i, row = 1;
3289
3290
print_clr( "Constant table\n" );
3291
clr_indent += 4;
3292
print_clr_table_header( header );
3293
for (i = 0; i < row_count; i++)
3294
{
3295
print_clr_row( row++ );
3296
print_clr_byte( ptr, size, FALSE );
3297
print_clr_byte( ptr, size, FALSE );
3298
print_clr_table_idx( ptr, size );
3299
print_clr_blob_idx( ptr, size );
3300
printf( "\n" );
3301
}
3302
clr_indent -= 4;
3303
}
3304
3305
static void print_clr_table_customattribute( const BYTE **ptr, UINT *size, UINT row_count )
3306
{
3307
static const char * const header[] = { "Parent", "Type", "Value", NULL };
3308
UINT i, row = 1;
3309
3310
print_clr( "CustomAttribute table\n" );
3311
clr_indent += 4;
3312
print_clr_table_header( header );
3313
for (i = 0; i < row_count; i++)
3314
{
3315
print_clr_row( row++ );
3316
print_clr_table_idx( ptr, size );
3317
print_clr_table_idx( ptr, size );
3318
print_clr_blob_idx( ptr, size );
3319
printf( "\n" );
3320
}
3321
clr_indent -= 4;
3322
}
3323
3324
static void print_clr_table_fieldmarshal( const BYTE **ptr, UINT *size, UINT row_count )
3325
{
3326
static const char * const header[] = { "Parent", "NativeType", NULL };
3327
UINT i, row = 1;
3328
3329
print_clr( "FieldMarshal table\n" );
3330
clr_indent += 4;
3331
print_clr_table_header( header );
3332
for (i = 0; i < row_count; i++)
3333
{
3334
print_clr_row( row++ );
3335
print_clr_table_idx( ptr, size );
3336
print_clr_blob_idx( ptr, size );
3337
printf( "\n" );
3338
}
3339
clr_indent -= 4;
3340
}
3341
3342
static void print_clr_table_declsecurity( const BYTE **ptr, UINT *size, UINT row_count )
3343
{
3344
static const char * const header[] = { "Action", "Parent", "PermissionSet", NULL };
3345
UINT i, row = 1;
3346
3347
print_clr( "DeclSecurity table\n" );
3348
clr_indent += 4;
3349
print_clr_table_header( header );
3350
for (i = 0; i < row_count; i++)
3351
{
3352
print_clr_row( row++ );
3353
print_clr_ushort( ptr, size, TRUE );
3354
print_clr_table_idx( ptr, size );
3355
print_clr_blob_idx( ptr, size );
3356
printf( "\n" );
3357
}
3358
clr_indent -= 4;
3359
}
3360
3361
static void print_clr_table_classlayout( const BYTE **ptr, UINT *size, UINT row_count )
3362
{
3363
static const char * const header[] = { "PackingSize", "ClassSize", "Parent", NULL };
3364
UINT i, row = 1;
3365
3366
print_clr( "ClassLayout table\n" );
3367
clr_indent += 4;
3368
print_clr_table_header( header );
3369
for (i = 0; i < row_count; i++)
3370
{
3371
print_clr_row( row++ );
3372
print_clr_ushort( ptr, size, FALSE );
3373
print_clr_uint( ptr, size, FALSE );
3374
print_clr_table_idx( ptr, size );
3375
printf( "\n" );
3376
}
3377
clr_indent -= 4;
3378
}
3379
3380
static void print_clr_table_fieldlayout( const BYTE **ptr, UINT *size, UINT row_count )
3381
{
3382
static const char * const header[] = { "Offset", "Field", NULL };
3383
UINT i, row = 1;
3384
3385
print_clr( "FieldLayout table\n" );
3386
clr_indent += 4;
3387
print_clr_table_header( header );
3388
for (i = 0; i < row_count; i++)
3389
{
3390
print_clr_row( row++ );
3391
print_clr_uint( ptr, size, FALSE );
3392
print_clr_table_idx( ptr, size );
3393
printf( "\n" );
3394
}
3395
clr_indent -= 4;
3396
}
3397
3398
static void print_clr_table_standalonesig( const BYTE **ptr, UINT *size, UINT row_count )
3399
{
3400
static const char * const header[] = { "Signature", NULL };
3401
UINT i, row = 1;
3402
3403
print_clr( "StandAloneSig table\n" );
3404
clr_indent += 4;
3405
print_clr_table_header( header );
3406
for (i = 0; i < row_count; i++)
3407
{
3408
print_clr_row( row++ );
3409
print_clr_blob_idx( ptr, size );
3410
printf( "\n" );
3411
}
3412
clr_indent -= 4;
3413
}
3414
3415
static void print_clr_table_eventmap( const BYTE **ptr, UINT *size, UINT row_count )
3416
{
3417
static const char * const header[] = { "Parent", "EventList", NULL };
3418
UINT i, row = 1;
3419
3420
print_clr( "EventMap table\n" );
3421
clr_indent += 4;
3422
print_clr_table_header( header );
3423
for (i = 0; i < row_count; i++)
3424
{
3425
print_clr_row( row++ );
3426
print_clr_table_idx( ptr, size );
3427
print_clr_table_idx( ptr, size );
3428
printf( "\n" );
3429
}
3430
clr_indent -= 4;
3431
}
3432
3433
static void print_clr_table_event( const BYTE **ptr, UINT *size, UINT row_count )
3434
{
3435
static const char * const header[] = { "EventFlags", "Name", "EventType", NULL };
3436
UINT i, row = 1;
3437
3438
print_clr( "Event table\n" );
3439
clr_indent += 4;
3440
print_clr_table_header( header );
3441
for (i = 0; i < row_count; i++)
3442
{
3443
print_clr_row( row++ );
3444
print_clr_ushort( ptr, size, TRUE );
3445
print_clr_string_idx( ptr, size );
3446
print_clr_table_idx( ptr, size );
3447
printf( "\n" );
3448
}
3449
clr_indent -= 4;
3450
}
3451
3452
static void print_clr_table_propertymap( const BYTE **ptr, UINT *size, UINT row_count )
3453
{
3454
static const char * const header[] = { "Parent", "PropertyList", NULL };
3455
UINT i, row = 1;
3456
3457
print_clr( "PropertyMap table\n" );
3458
clr_indent += 4;
3459
print_clr_table_header( header );
3460
for (i = 0; i < row_count; i++)
3461
{
3462
print_clr_row( row++ );
3463
print_clr_table_idx( ptr, size );
3464
print_clr_table_idx( ptr, size );
3465
printf( "\n" );
3466
}
3467
clr_indent -= 4;
3468
}
3469
3470
static void print_clr_table_property( const BYTE **ptr, UINT *size, UINT row_count )
3471
{
3472
static const char * const header[] = { "Flags", "Name", "Type", NULL };
3473
UINT i, row = 1;
3474
3475
print_clr( "Property table\n" );
3476
clr_indent += 4;
3477
print_clr_table_header( header );
3478
for (i = 0; i < row_count; i++)
3479
{
3480
print_clr_row( row++ );
3481
print_clr_ushort( ptr, size, TRUE );
3482
print_clr_string_idx( ptr, size );
3483
print_clr_blob_idx( ptr, size );
3484
printf( "\n" );
3485
}
3486
clr_indent -= 4;
3487
}
3488
3489
static void print_clr_table_methodsemantics( const BYTE **ptr, UINT *size, UINT row_count )
3490
{
3491
static const char * const header[] = { "Semantics", "Method", "Association", NULL };
3492
UINT i, row = 1;
3493
3494
print_clr( "MethodSemantics table\n" );
3495
clr_indent += 4;
3496
print_clr_table_header( header );
3497
for (i = 0; i < row_count; i++)
3498
{
3499
print_clr_row( row++ );
3500
print_clr_ushort( ptr, size, TRUE );
3501
print_clr_table_idx( ptr, size );
3502
print_clr_table_idx( ptr, size );
3503
printf( "\n" );
3504
}
3505
clr_indent -= 4;
3506
}
3507
3508
static void print_clr_table_methodimpl( const BYTE **ptr, UINT *size, UINT row_count )
3509
{
3510
static const char * const header[] = { "Class", "Body", "Declaration", NULL };
3511
UINT i, row = 1;
3512
3513
print_clr( "MethodImpl table\n" );
3514
clr_indent += 4;
3515
print_clr_table_header( header );
3516
for (i = 0; i < row_count; i++)
3517
{
3518
print_clr_row( row++ );
3519
print_clr_table_idx( ptr, size );
3520
print_clr_table_idx( ptr, size );
3521
print_clr_table_idx( ptr, size );
3522
printf( "\n" );
3523
}
3524
clr_indent -= 4;
3525
}
3526
3527
static void print_clr_table_moduleref( const BYTE **ptr, UINT *size, UINT row_count )
3528
{
3529
static const char * const header[] = { "Name", NULL };
3530
UINT i, row = 1;
3531
3532
print_clr( "ModuleRef table\n" );
3533
clr_indent += 4;
3534
print_clr_table_header( header );
3535
for (i = 0; i < row_count; i++)
3536
{
3537
print_clr_row( row++ );
3538
print_clr_string_idx( ptr, size );
3539
printf( "\n" );
3540
}
3541
clr_indent -= 4;
3542
}
3543
3544
static void print_clr_table_typespec( const BYTE **ptr, UINT *size, UINT row_count )
3545
{
3546
static const char * const header[] = { "Signature", NULL };
3547
UINT i, row = 1;
3548
3549
print_clr( "TypeSpec table\n" );
3550
clr_indent += 4;
3551
print_clr_table_header( header );
3552
for (i = 0; i < row_count; i++)
3553
{
3554
print_clr_row( row++ );
3555
print_clr_blob_idx( ptr, size );
3556
printf( "\n" );
3557
}
3558
clr_indent -= 4;
3559
}
3560
3561
static void print_clr_table_implmap( const BYTE **ptr, UINT *size, UINT row_count )
3562
{
3563
static const char * const header[] = { "MappingFlags", "MemberForwarded", "ImportName", "ImportScope", NULL };
3564
UINT i, row = 1;
3565
3566
print_clr( "ImplMap table\n" );
3567
clr_indent += 4;
3568
print_clr_table_header( header );
3569
for (i = 0; i < row_count; i++)
3570
{
3571
print_clr_row( row++ );
3572
print_clr_ushort( ptr, size, TRUE );
3573
print_clr_table_idx( ptr, size );
3574
print_clr_string_idx( ptr, size );
3575
print_clr_table_idx( ptr, size );
3576
printf( "\n" );
3577
}
3578
clr_indent -= 4;
3579
}
3580
3581
static void print_clr_table_fieldrva( const BYTE **ptr, UINT *size, UINT row_count )
3582
{
3583
static const char * const header[] = { "RVA", "Field", NULL };
3584
UINT i, row = 1;
3585
3586
print_clr( "FieldRVA table\n" );
3587
clr_indent += 4;
3588
print_clr_table_header( header );
3589
for (i = 0; i < row_count; i++)
3590
{
3591
print_clr_row( row++ );
3592
print_clr_uint( ptr, size, TRUE );
3593
print_clr_table_idx( ptr, size );
3594
printf( "\n" );
3595
}
3596
clr_indent -= 4;
3597
}
3598
3599
static void print_clr_table_assembly( const BYTE **ptr, UINT *size, UINT row_count )
3600
{
3601
static const char * const header[] = { "HashAlgId", "MajorVersion", "MinorVersion", "BuildNumber",
3602
"RevisionNumber", "Flags", "PublicKey", "Name", "Culture", NULL };
3603
UINT i, row = 1;
3604
3605
print_clr( "Assembly table\n" );
3606
clr_indent += 4;
3607
print_clr_table_header( header );
3608
for (i = 0; i < row_count; i++)
3609
{
3610
print_clr_row( row++ );
3611
print_clr_uint( ptr, size, TRUE );
3612
print_clr_ushort( ptr, size, FALSE );
3613
print_clr_ushort( ptr, size, FALSE );
3614
print_clr_ushort( ptr, size, FALSE );
3615
print_clr_ushort( ptr, size, FALSE );
3616
print_clr_uint( ptr, size, TRUE );
3617
print_clr_blob_idx( ptr, size );
3618
print_clr_string_idx( ptr, size );
3619
print_clr_string_idx( ptr, size );
3620
printf( "\n" );
3621
}
3622
clr_indent -= 4;
3623
}
3624
3625
static void print_clr_table_assemblyprocessor( const BYTE **ptr, UINT *size, UINT row_count )
3626
{
3627
static const char * const header[] = { "Processor", NULL };
3628
UINT i, row = 1;
3629
3630
print_clr( "AssemblyProcessor table\n" );
3631
clr_indent += 4;
3632
print_clr_table_header( header );
3633
for (i = 0; i < row_count; i++)
3634
{
3635
print_clr_row( row++ );
3636
print_clr_uint( ptr, size, TRUE );
3637
printf( "\n" );
3638
}
3639
clr_indent -= 4;
3640
}
3641
3642
static void print_clr_table_assemblyos( const BYTE **ptr, UINT *size, UINT row_count )
3643
{
3644
static const char * const header[] = { "OSPlatformID", "OSMajorVersion", "OSMinorVersion", NULL };
3645
UINT i, row = 1;
3646
3647
print_clr( "AssemblyOS table\n" );
3648
clr_indent += 4;
3649
print_clr_table_header( header );
3650
for (i = 0; i < row_count; i++)
3651
{
3652
print_clr_row( row++ );
3653
print_clr_uint( ptr, size, TRUE );
3654
print_clr_uint( ptr, size, FALSE );
3655
print_clr_uint( ptr, size, FALSE );
3656
printf( "\n" );
3657
}
3658
clr_indent -= 4;
3659
}
3660
3661
static void print_clr_table_assemblyref( const BYTE **ptr, UINT *size, UINT row_count )
3662
{
3663
static const char * const header[] = { "MajorVersion", "MinorVersion", "BuildNumber", "RevisionNumber", "Flags",
3664
"PublicKey", "Name", "Culture", "HashValue", NULL };
3665
UINT i, row = 1;
3666
3667
print_clr( "AssemblyRef table\n" );
3668
clr_indent += 4;
3669
print_clr_table_header( header );
3670
for (i = 0; i < row_count; i++)
3671
{
3672
print_clr_row( row++ );
3673
print_clr_ushort( ptr, size, FALSE );
3674
print_clr_ushort( ptr, size, FALSE );
3675
print_clr_ushort( ptr, size, FALSE );
3676
print_clr_ushort( ptr, size, FALSE );
3677
print_clr_uint( ptr, size, TRUE );
3678
print_clr_blob_idx( ptr, size );
3679
print_clr_string_idx( ptr, size );
3680
print_clr_string_idx( ptr, size );
3681
print_clr_blob_idx( ptr, size );
3682
printf( "\n" );
3683
}
3684
clr_indent -= 4;
3685
}
3686
3687
static void print_clr_table_assemblyrefprocessor( const BYTE **ptr, UINT *size, UINT row_count )
3688
{
3689
static const char * const header[] = { "Processor", "AssemblyRef", NULL };
3690
UINT i, row = 1;
3691
3692
print_clr( "AssemblyRefProcessor table\n" );
3693
clr_indent += 4;
3694
print_clr_table_header( header );
3695
for (i = 0; i < row_count; i++)
3696
{
3697
print_clr_row( row++ );
3698
print_clr_uint( ptr, size, TRUE );
3699
print_clr_table_idx( ptr, size );
3700
printf( "\n" );
3701
}
3702
clr_indent -= 4;
3703
}
3704
3705
static void print_clr_table_assemblyrefos( const BYTE **ptr, UINT *size, UINT row_count )
3706
{
3707
static const char * const header[] = { "OSPlatformId", "OSMajorVersion", "OSMinorVersion", "AssemblyRef", NULL };
3708
UINT i, row = 1;
3709
3710
print_clr( "AssemblyRefOS table\n" );
3711
clr_indent += 4;
3712
print_clr_table_header( header );
3713
for (i = 0; i < row_count; i++)
3714
{
3715
print_clr_row( row++ );
3716
print_clr_uint( ptr, size, TRUE );
3717
print_clr_uint( ptr, size, FALSE );
3718
print_clr_uint( ptr, size, FALSE );
3719
print_clr_table_idx( ptr, size );
3720
printf( "\n" );
3721
}
3722
clr_indent -= 4;
3723
}
3724
3725
static void print_clr_table_file( const BYTE **ptr, UINT *size, UINT row_count )
3726
{
3727
static const char * const header[] = { "Flags", "Name", "HashValue", NULL };
3728
UINT i, row = 1;
3729
3730
print_clr( "File table\n" );
3731
clr_indent += 4;
3732
print_clr_table_header( header );
3733
for (i = 0; i < row_count; i++)
3734
{
3735
print_clr_row( row++ );
3736
print_clr_uint( ptr, size, TRUE );
3737
print_clr_string_idx( ptr, size );
3738
print_clr_blob_idx( ptr, size );
3739
printf( "\n" );
3740
}
3741
clr_indent -= 4;
3742
}
3743
3744
static void print_clr_table_exportedtype( const BYTE **ptr, UINT *size, UINT row_count )
3745
{
3746
static const char * const header[] = { "Flags", "TypeDefId", "TypeName", "TypeNamespace", "Implementation", NULL };
3747
UINT i, row = 1;
3748
3749
print_clr( "ExportedType table\n" );
3750
clr_indent += 4;
3751
print_clr_table_header( header );
3752
for (i = 0; i < row_count; i++)
3753
{
3754
print_clr_row( row++ );
3755
print_clr_uint( ptr, size, TRUE );
3756
print_clr_uint( ptr, size, TRUE );
3757
print_clr_string_idx( ptr, size );
3758
print_clr_string_idx( ptr, size );
3759
print_clr_table_idx( ptr, size );
3760
printf( "\n" );
3761
}
3762
clr_indent -= 4;
3763
}
3764
3765
static void print_clr_table_manifestresource( const BYTE **ptr, UINT *size, UINT row_count )
3766
{
3767
static const char * const header[] = { "Offset", "Flags", "Name", "Implementation", NULL };
3768
UINT i, row = 1;
3769
3770
print_clr( "ManifestResource table\n" );
3771
clr_indent += 4;
3772
print_clr_table_header( header );
3773
for (i = 0; i < row_count; i++)
3774
{
3775
print_clr_row( row++ );
3776
print_clr_uint( ptr, size, FALSE );
3777
print_clr_uint( ptr, size, TRUE );
3778
print_clr_string_idx( ptr, size );
3779
print_clr_table_idx( ptr, size );
3780
printf( "\n" );
3781
}
3782
clr_indent -= 4;
3783
}
3784
3785
static void print_clr_table_nestedclass( const BYTE **ptr, UINT *size, UINT row_count )
3786
{
3787
static const char * const header[] = { "NestedClass", "EnclosingClass", NULL };
3788
UINT i, row = 1;
3789
3790
print_clr( "NestedClass table\n" );
3791
clr_indent += 4;
3792
print_clr_table_header( header );
3793
for (i = 0; i < row_count; i++)
3794
{
3795
print_clr_row( row++ );
3796
print_clr_table_idx( ptr, size );
3797
print_clr_table_idx( ptr, size );
3798
printf( "\n" );
3799
}
3800
clr_indent -= 4;
3801
}
3802
3803
static void print_clr_table_genericparam( const BYTE **ptr, UINT *size, UINT row_count )
3804
{
3805
static const char * const header[] = { "Number", "Flags", "Owner", "Name", NULL };
3806
UINT i, row = 1;
3807
3808
print_clr( "GenericParam table\n" );
3809
clr_indent += 4;
3810
print_clr_table_header( header );
3811
for (i = 0; i < row_count; i++)
3812
{
3813
print_clr_row( row++ );
3814
print_clr_ushort( ptr, size, FALSE );
3815
print_clr_ushort( ptr, size, TRUE );
3816
print_clr_table_idx( ptr, size );
3817
print_clr_string_idx( ptr, size );
3818
printf( "\n" );
3819
}
3820
clr_indent -= 4;
3821
}
3822
3823
static void print_clr_table_methodspec( const BYTE **ptr, UINT *size, UINT row_count )
3824
{
3825
static const char * const header[] = { "Method", "Instantiation", NULL };
3826
UINT i, row = 1;
3827
3828
print_clr( "MethodSpec table\n" );
3829
clr_indent += 4;
3830
print_clr_table_header( header );
3831
for (i = 0; i < row_count; i++)
3832
{
3833
print_clr_row( row++ );
3834
print_clr_table_idx( ptr, size );
3835
print_clr_blob_idx( ptr, size );
3836
printf( "\n" );
3837
}
3838
clr_indent -= 4;
3839
}
3840
3841
static void print_clr_table_genericparamconstraint( const BYTE **ptr, UINT *size, UINT row_count )
3842
{
3843
static const char * const header[] = { "Owner", "Constraint", NULL };
3844
UINT i, row = 1;
3845
3846
print_clr( "GenericParamConstraint table\n" );
3847
clr_indent += 4;
3848
print_clr_table_header( header );
3849
for (i = 0; i < row_count; i++)
3850
{
3851
print_clr_row( row++ );
3852
print_clr_table_idx( ptr, size );
3853
print_clr_blob_idx( ptr, size );
3854
printf( "\n" );
3855
}
3856
clr_indent -= 4;
3857
}
3858
3859
enum
3860
{
3861
HEAP_SIZE_FLAG_STRING = 0x01,
3862
HEAP_SIZE_FLAG_GUID = 0x02,
3863
HEAP_SIZE_FLAG_BLOB = 0x04,
3864
};
3865
3866
static void print_clr_tables( const BYTE *data, UINT data_size )
3867
{
3868
const BYTE *ptr = data;
3869
BYTE heap_sizes;
3870
UINT i, size = data_size, count = 0;
3871
const UINT *row_count;
3872
UINT64 valid, j;
3873
3874
if (!data_size) return;
3875
3876
clr_indent += 4;
3877
print_clr( "Reserved " );
3878
print_clr_uint( &ptr, &size, FALSE );
3879
printf( "\n" );
3880
print_clr( "MajorVersion " );
3881
print_clr_byte( &ptr, &size, FALSE );
3882
printf( "\n" );
3883
print_clr( "MinorVersion " );
3884
print_clr_byte( &ptr, &size, FALSE );
3885
printf( "\n" );
3886
3887
if (size < 1) return;
3888
heap_sizes = *ptr;
3889
print_clr( "HeapSizes " );
3890
print_clr_byte( &ptr, &size, TRUE );
3891
printf( "\n" );
3892
if (heap_sizes & HEAP_SIZE_FLAG_STRING) str_idx_size = 4;
3893
if (heap_sizes & HEAP_SIZE_FLAG_GUID) guid_idx_size = 4;
3894
if (heap_sizes & HEAP_SIZE_FLAG_BLOB) blob_idx_size = 4;
3895
3896
print_clr( "Reserved " );
3897
print_clr_byte( &ptr, &size, FALSE );
3898
printf( "\n" );
3899
3900
if (size < sizeof(UINT64)) return;
3901
valid = *(UINT64 *)ptr;
3902
print_clr( "Valid " );
3903
print_clr_uint64( &ptr, &size );
3904
printf( "\n" );
3905
for (j = 0; j < sizeof(valid) * 8; j++) if (valid & (1ul << j)) count++;
3906
3907
print_clr( "Sorted " );
3908
print_clr_uint64( &ptr, &size );
3909
printf( "\n" );
3910
clr_indent -= 4;
3911
3912
row_count = (const UINT *)ptr;
3913
if (count) print_clr( "Row counts\n" );
3914
for (i = 0; i < count; i++)
3915
{
3916
clr_indent += 4;
3917
print_clr_indent();
3918
print_clr_uint( &ptr, &size, FALSE );
3919
clr_indent -= 4;
3920
printf( "\n" );
3921
}
3922
3923
for (i = 0, j = 0; j < sizeof(valid) * 8; j++)
3924
{
3925
if (!(valid & (1ul << j))) continue;
3926
3927
if (row_count[i] > 65536)
3928
{
3929
printf( "can't handle number of rows > 65536\n" );
3930
break;
3931
}
3932
3933
switch (j)
3934
{
3935
case CLR_TABLE_MODULE:
3936
print_clr_table_module( &ptr, &size, row_count[i++] );
3937
break;
3938
case CLR_TABLE_TYPEREF:
3939
print_clr_table_typeref( &ptr, &size, row_count[i++] );
3940
break;
3941
case CLR_TABLE_TYPEDEF:
3942
print_clr_table_typedef( &ptr, &size, row_count[i++] );
3943
break;
3944
case CLR_TABLE_FIELD:
3945
print_clr_table_field( &ptr, &size, row_count[i++] );
3946
break;
3947
case CLR_TABLE_METHODDEF:
3948
print_clr_table_methoddef( &ptr, &size, row_count[i++] );
3949
break;
3950
case CLR_TABLE_PARAM:
3951
print_clr_table_param( &ptr, &size, row_count[i++] );
3952
break;
3953
case CLR_TABLE_INTERFACEIMPL:
3954
print_clr_table_interfaceimpl( &ptr, &size, row_count[i++] );
3955
break;
3956
case CLR_TABLE_MEMBERREF:
3957
print_clr_table_memberref( &ptr, &size, row_count[i++] );
3958
break;
3959
case CLR_TABLE_CONSTANT:
3960
print_clr_table_constant( &ptr, &size, row_count[i++] );
3961
break;
3962
case CLR_TABLE_CUSTOMATTRIBUTE:
3963
print_clr_table_customattribute( &ptr, &size, row_count[i++] );
3964
break;
3965
case CLR_TABLE_FIELDMARSHAL:
3966
print_clr_table_fieldmarshal( &ptr, &size, row_count[i++] );
3967
break;
3968
case CLR_TABLE_DECLSECURITY:
3969
print_clr_table_declsecurity( &ptr, &size, row_count[i++] );
3970
break;
3971
case CLR_TABLE_CLASSLAYOUT:
3972
print_clr_table_classlayout( &ptr, &size, row_count[i++] );
3973
break;
3974
case CLR_TABLE_FIELDLAYOUT:
3975
print_clr_table_fieldlayout( &ptr, &size, row_count[i++] );
3976
break;
3977
case CLR_TABLE_STANDALONESIG:
3978
print_clr_table_standalonesig( &ptr, &size, row_count[i++] );
3979
break;
3980
case CLR_TABLE_EVENTMAP:
3981
print_clr_table_eventmap( &ptr, &size, row_count[i++] );
3982
break;
3983
case CLR_TABLE_EVENT:
3984
print_clr_table_event( &ptr, &size, row_count[i++] );
3985
break;
3986
case CLR_TABLE_PROPERTYMAP:
3987
print_clr_table_propertymap( &ptr, &size, row_count[i++] );
3988
break;
3989
case CLR_TABLE_PROPERTY:
3990
print_clr_table_property( &ptr, &size, row_count[i++] );
3991
break;
3992
case CLR_TABLE_METHODSEMANTICS:
3993
print_clr_table_methodsemantics( &ptr, &size, row_count[i++] );
3994
break;
3995
case CLR_TABLE_METHODIMPL:
3996
print_clr_table_methodimpl( &ptr, &size, row_count[i++] );
3997
break;
3998
case CLR_TABLE_MODULEREF:
3999
print_clr_table_moduleref( &ptr, &size, row_count[i++] );
4000
break;
4001
case CLR_TABLE_TYPESPEC:
4002
print_clr_table_typespec( &ptr, &size, row_count[i++] );
4003
break;
4004
case CLR_TABLE_IMPLMAP:
4005
print_clr_table_implmap( &ptr, &size, row_count[i++] );
4006
break;
4007
case CLR_TABLE_FIELDRVA:
4008
print_clr_table_fieldrva( &ptr, &size, row_count[i++] );
4009
break;
4010
case CLR_TABLE_ASSEMBLY:
4011
print_clr_table_assembly( &ptr, &size, row_count[i++] );
4012
break;
4013
case CLR_TABLE_ASSEMBLYPROCESSOR:
4014
print_clr_table_assemblyprocessor( &ptr, &size, row_count[i++] );
4015
break;
4016
case CLR_TABLE_ASSEMBLYOS:
4017
print_clr_table_assemblyos( &ptr, &size, row_count[i++] );
4018
break;
4019
case CLR_TABLE_ASSEMBLYREF:
4020
print_clr_table_assemblyref( &ptr, &size, row_count[i++] );
4021
break;
4022
case CLR_TABLE_ASSEMBLYREFPROCESSOR:
4023
print_clr_table_assemblyrefprocessor( &ptr, &size, row_count[i++] );
4024
break;
4025
case CLR_TABLE_ASSEMBLYREFOS:
4026
print_clr_table_assemblyrefos( &ptr, &size, row_count[i++] );
4027
break;
4028
case CLR_TABLE_FILE:
4029
print_clr_table_file( &ptr, &size, row_count[i++] );
4030
break;
4031
case CLR_TABLE_EXPORTEDTYPE:
4032
print_clr_table_exportedtype( &ptr, &size, row_count[i++] );
4033
break;
4034
case CLR_TABLE_MANIFESTRESOURCE:
4035
print_clr_table_manifestresource( &ptr, &size, row_count[i++] );
4036
break;
4037
case CLR_TABLE_NESTEDCLASS:
4038
print_clr_table_nestedclass( &ptr, &size, row_count[i++] );
4039
break;
4040
case CLR_TABLE_GENERICPARAM:
4041
print_clr_table_genericparam( &ptr, &size, row_count[i++] );
4042
break;
4043
case CLR_TABLE_METHODSPEC:
4044
print_clr_table_methodspec( &ptr, &size, row_count[i++] );
4045
break;
4046
case CLR_TABLE_GENERICPARAMCONSTRAINT:
4047
print_clr_table_genericparamconstraint( &ptr, &size, row_count[i++] );
4048
break;
4049
default:
4050
printf( "unknown table 0x%02x\n", (BYTE)j );
4051
break;
4052
}
4053
}
4054
}
4055
4056
static void print_clr_stream( const BYTE *base, const BYTE **ptr, UINT *size )
4057
{
4058
const char *name;
4059
UINT len, stream_offset, stream_size;
4060
4061
if (*size < sizeof(UINT)) return;
4062
stream_offset = *(const UINT *)*ptr;
4063
print_clr( "Offset " );
4064
print_clr_uint( ptr, size, FALSE );
4065
printf( "\n" );
4066
4067
if (*size < sizeof(UINT)) return;
4068
stream_size = *(const UINT *)*ptr;
4069
print_clr( "Size " );
4070
print_clr_uint( ptr, size, FALSE );
4071
printf( "\n" );
4072
4073
if (!memchr( *ptr, '\0', *size )) return;
4074
name = (const char *)*ptr;
4075
print_clr( "Name " );
4076
printf( "%s\n", name );
4077
len = ((strlen( name ) + 1) + 3) & ~3;
4078
if (*size < len) return;
4079
*ptr += len; *size -= len;
4080
4081
if (!strcmp( name, "#Strings" ))
4082
{
4083
strings.data = base + stream_offset;
4084
strings.size = stream_size;
4085
/* remove padding */
4086
while (strings.size > 1 && !strings.data[strings.size -2] && !strings.data[strings.size - 1])
4087
strings.size--;
4088
}
4089
else if (!strcmp( name, "#US" ))
4090
{
4091
userstrings.data = base + stream_offset;
4092
userstrings.size = stream_size;
4093
}
4094
else if (!strcmp( name, "#Blob" ))
4095
{
4096
blobs.data = base + stream_offset;
4097
blobs.size = stream_size;
4098
}
4099
else if (!strcmp( name, "#GUID" ))
4100
{
4101
guids.data = base + stream_offset;
4102
guids.size = stream_size;
4103
}
4104
else if (!strcmp( name, "#~" ))
4105
{
4106
tables.data = base + stream_offset;
4107
tables.size = stream_size;
4108
}
4109
}
4110
4111
static void print_clr_metadata( const BYTE *data, UINT data_size )
4112
{
4113
const BYTE *ptr = data;
4114
UINT size = data_size, len, nb_streams, i;
4115
const char *version;
4116
4117
print_clr( "Signature " );
4118
print_clr_uint( &ptr, &size, TRUE );
4119
printf( "\n" );
4120
print_clr( "MajorVersion " );
4121
print_clr_ushort( &ptr, &size, FALSE );
4122
printf( "\n" );
4123
print_clr( "MinorVersion " );
4124
print_clr_ushort( &ptr, &size, FALSE );
4125
printf( "\n" );
4126
print_clr( "Reserved " );
4127
print_clr_uint( &ptr, &size, FALSE );
4128
printf( "\n" );
4129
4130
if (size < sizeof(UINT)) return;
4131
len = *(const UINT *)ptr;
4132
print_clr( "Length " );
4133
print_clr_uint( &ptr, &size, FALSE );
4134
printf( "\n" );
4135
4136
if (size < len || !memchr( ptr, '\0', len )) return;
4137
version = (const char *)ptr;
4138
print_clr( "Version " );
4139
printf( "%s\n", version );
4140
len = ((strlen( version ) + 1) + 3) & ~3;
4141
if (size < len) return;
4142
ptr += len; size -= len;
4143
4144
print_clr( "Flags " );
4145
print_clr_ushort( &ptr, &size, TRUE );
4146
printf( "\n" );
4147
4148
if (size < sizeof(USHORT)) return;
4149
nb_streams = *(const USHORT *)ptr;
4150
print_clr( "Streams " );
4151
print_clr_ushort( &ptr, &size, FALSE );
4152
printf( "\n" );
4153
4154
clr_indent += 4;
4155
for (i = 0; i < nb_streams; i++) print_clr_stream( data, &ptr, &size );
4156
clr_indent -= 4;
4157
4158
print_clr( "Tables\n" );
4159
print_clr_tables( tables.data, tables.size );
4160
print_clr( "Strings\n" );
4161
print_clr_strings( strings.data, strings.size );
4162
print_clr( "Userstrings\n" );
4163
print_clr_blobs( userstrings.data, userstrings.size );
4164
print_clr( "GUIDs\n" );
4165
print_clr_guids( guids.data, guids.size );
4166
print_clr( "Blobs\n" );
4167
print_clr_blobs( blobs.data, blobs.size );
4168
}
4169
4170
static void dump_dir_clr_header(void)
4171
{
4172
unsigned int size = 0;
4173
const IMAGE_COR20_HEADER *dir = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, &size);
4174
4175
if (!dir) return;
4176
4177
printf( "CLR Header\n" );
4178
print_dword( "Header Size", dir->cb );
4179
print_ver( "Required runtime version", dir->MajorRuntimeVersion, dir->MinorRuntimeVersion );
4180
print_clr_flags( "Flags", dir->Flags );
4181
print_dword( "EntryPointToken", dir->EntryPointToken );
4182
printf("\n");
4183
printf( "CLR Data Directory\n" );
4184
print_clr_directory( "MetaData", &dir->MetaData );
4185
print_clr_metadata( RVA(dir->MetaData.VirtualAddress, dir->MetaData.Size), dir->MetaData.Size );
4186
print_clr_directory( "Resources", &dir->Resources );
4187
print_clr_directory( "StrongNameSignature", &dir->StrongNameSignature );
4188
print_clr_directory( "CodeManagerTable", &dir->CodeManagerTable );
4189
print_clr_directory( "VTableFixups", &dir->VTableFixups );
4190
print_clr_directory( "ExportAddressTableJumps", &dir->ExportAddressTableJumps );
4191
print_clr_directory( "ManagedNativeHeader", &dir->ManagedNativeHeader );
4192
printf("\n");
4193
}
4194
4195
static void dump_dynamic_relocs_arm64x( const IMAGE_BASE_RELOCATION *base_reloc, unsigned int size )
4196
{
4197
unsigned int i;
4198
const IMAGE_BASE_RELOCATION *base_end = (const IMAGE_BASE_RELOCATION *)((const char *)base_reloc + size);
4199
4200
printf( "Relocations ARM64X\n" );
4201
while (base_reloc < base_end - 1 && base_reloc->SizeOfBlock)
4202
{
4203
const USHORT *rel = (const USHORT *)(base_reloc + 1);
4204
const USHORT *end = (const USHORT *)base_reloc + base_reloc->SizeOfBlock / sizeof(USHORT);
4205
printf( " Page %x\n", (UINT)base_reloc->VirtualAddress );
4206
while (rel < end && *rel)
4207
{
4208
USHORT offset = *rel & 0xfff;
4209
USHORT type = (*rel >> 12) & 3;
4210
USHORT arg = *rel >> 14;
4211
rel++;
4212
switch (type)
4213
{
4214
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL:
4215
printf( " off %04x zero-fill %u bytes\n", offset, 1 << arg );
4216
break;
4217
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
4218
printf( " off %04x set %u bytes value ", offset, 1 << arg );
4219
for (i = (1 << arg ) / sizeof(USHORT); i > 0; i--) printf( "%04x", rel[i - 1] );
4220
rel += (1 << arg) / sizeof(USHORT);
4221
printf( "\n" );
4222
break;
4223
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
4224
printf( " off %04x add offset ", offset );
4225
if (arg & 1) printf( "-" );
4226
printf( "%08x\n", (UINT)*rel++ * ((arg & 2) ? 8 : 4) );
4227
break;
4228
default:
4229
printf( " off %04x unknown (arg %x)\n", offset, arg );
4230
break;
4231
}
4232
}
4233
base_reloc = (const IMAGE_BASE_RELOCATION *)end;
4234
}
4235
}
4236
4237
static void dump_dynamic_relocs( const char *ptr, unsigned int size, ULONGLONG symbol )
4238
{
4239
switch (symbol)
4240
{
4241
case IMAGE_DYNAMIC_RELOCATION_GUARD_RF_PROLOGUE:
4242
printf( "Relocations GUARD_RF_PROLOGUE\n" );
4243
break;
4244
case IMAGE_DYNAMIC_RELOCATION_GUARD_RF_EPILOGUE:
4245
printf( "Relocations GUARD_RF_EPILOGUE\n" );
4246
break;
4247
case IMAGE_DYNAMIC_RELOCATION_GUARD_IMPORT_CONTROL_TRANSFER:
4248
printf( "Relocations GUARD_IMPORT_CONTROL_TRANSFER\n" );
4249
break;
4250
case IMAGE_DYNAMIC_RELOCATION_GUARD_INDIR_CONTROL_TRANSFER:
4251
printf( "Relocations GUARD_INDIR_CONTROL_TRANSFER\n" );
4252
break;
4253
case IMAGE_DYNAMIC_RELOCATION_GUARD_SWITCHTABLE_BRANCH:
4254
printf( "Relocations GUARD_SWITCHTABLE_BRANCH\n" );
4255
break;
4256
case IMAGE_DYNAMIC_RELOCATION_ARM64X:
4257
dump_dynamic_relocs_arm64x( (const IMAGE_BASE_RELOCATION *)ptr, size );
4258
break;
4259
default:
4260
printf( "Unknown relocation symbol %s\n", longlong_str(symbol) );
4261
break;
4262
}
4263
}
4264
4265
static const IMAGE_DYNAMIC_RELOCATION_TABLE *get_dyn_reloc_table(void)
4266
{
4267
unsigned int size, section, offset;
4268
const IMAGE_SECTION_HEADER *sec;
4269
const IMAGE_DYNAMIC_RELOCATION_TABLE *table;
4270
4271
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4272
{
4273
const IMAGE_LOAD_CONFIG_DIRECTORY64 *cfg = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &size);
4274
if (!cfg) return NULL;
4275
size = min( size, cfg->Size );
4276
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY64, DynamicValueRelocTableSection )) return NULL;
4277
offset = cfg->DynamicValueRelocTableOffset;
4278
section = cfg->DynamicValueRelocTableSection;
4279
}
4280
else
4281
{
4282
const IMAGE_LOAD_CONFIG_DIRECTORY32 *cfg = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &size);
4283
if (!cfg) return NULL;
4284
size = min( size, cfg->Size );
4285
if (size <= offsetof( IMAGE_LOAD_CONFIG_DIRECTORY32, DynamicValueRelocTableSection )) return NULL;
4286
offset = cfg->DynamicValueRelocTableOffset;
4287
section = cfg->DynamicValueRelocTableSection;
4288
}
4289
if (!section || section > PE_nt_headers->FileHeader.NumberOfSections) return NULL;
4290
sec = IMAGE_FIRST_SECTION( PE_nt_headers ) + section - 1;
4291
if (offset >= sec->SizeOfRawData) return NULL;
4292
return PRD( sec->PointerToRawData + offset, sizeof(*table) );
4293
}
4294
4295
static void dump_dir_dynamic_reloc(void)
4296
{
4297
const char *ptr, *end;
4298
const IMAGE_DYNAMIC_RELOCATION_TABLE *table = get_dyn_reloc_table();
4299
4300
if (!table) return;
4301
4302
printf( "Dynamic relocations (version %u)\n\n", (UINT)table->Version );
4303
ptr = (const char *)(table + 1);
4304
end = ptr + table->Size;
4305
while (ptr < end)
4306
{
4307
switch (table->Version)
4308
{
4309
case 1:
4310
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4311
{
4312
const IMAGE_DYNAMIC_RELOCATION64 *reloc = (const IMAGE_DYNAMIC_RELOCATION64 *)ptr;
4313
dump_dynamic_relocs( (const char *)(reloc + 1), reloc->BaseRelocSize, reloc->Symbol );
4314
ptr += sizeof(*reloc) + reloc->BaseRelocSize;
4315
}
4316
else
4317
{
4318
const IMAGE_DYNAMIC_RELOCATION32 *reloc = (const IMAGE_DYNAMIC_RELOCATION32 *)ptr;
4319
dump_dynamic_relocs( (const char *)(reloc + 1), reloc->BaseRelocSize, reloc->Symbol );
4320
ptr += sizeof(*reloc) + reloc->BaseRelocSize;
4321
}
4322
break;
4323
case 2:
4324
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4325
{
4326
const IMAGE_DYNAMIC_RELOCATION64_V2 *reloc = (const IMAGE_DYNAMIC_RELOCATION64_V2 *)ptr;
4327
dump_dynamic_relocs( ptr + reloc->HeaderSize, reloc->FixupInfoSize, reloc->Symbol );
4328
ptr += reloc->HeaderSize + reloc->FixupInfoSize;
4329
}
4330
else
4331
{
4332
const IMAGE_DYNAMIC_RELOCATION32_V2 *reloc = (const IMAGE_DYNAMIC_RELOCATION32_V2 *)ptr;
4333
dump_dynamic_relocs( ptr + reloc->HeaderSize, reloc->FixupInfoSize, reloc->Symbol );
4334
ptr += reloc->HeaderSize + reloc->FixupInfoSize;
4335
}
4336
break;
4337
}
4338
}
4339
printf( "\n" );
4340
}
4341
4342
static const IMAGE_BASE_RELOCATION *get_armx_relocs( unsigned int *size )
4343
{
4344
const char *ptr, *end;
4345
const IMAGE_DYNAMIC_RELOCATION_TABLE *table = get_dyn_reloc_table();
4346
4347
if (!table) return NULL;
4348
ptr = (const char *)(table + 1);
4349
end = ptr + table->Size;
4350
while (ptr < end)
4351
{
4352
switch (table->Version)
4353
{
4354
case 1:
4355
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4356
{
4357
const IMAGE_DYNAMIC_RELOCATION64 *reloc = (const IMAGE_DYNAMIC_RELOCATION64 *)ptr;
4358
if (reloc->Symbol == IMAGE_DYNAMIC_RELOCATION_ARM64X)
4359
{
4360
*size = reloc->BaseRelocSize;
4361
return (const IMAGE_BASE_RELOCATION *)(reloc + 1);
4362
}
4363
ptr += sizeof(*reloc) + reloc->BaseRelocSize;
4364
}
4365
else
4366
{
4367
const IMAGE_DYNAMIC_RELOCATION32 *reloc = (const IMAGE_DYNAMIC_RELOCATION32 *)ptr;
4368
if (reloc->Symbol == IMAGE_DYNAMIC_RELOCATION_ARM64X)
4369
{
4370
*size = reloc->BaseRelocSize;
4371
return (const IMAGE_BASE_RELOCATION *)(reloc + 1);
4372
}
4373
ptr += sizeof(*reloc) + reloc->BaseRelocSize;
4374
}
4375
break;
4376
case 2:
4377
if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4378
{
4379
const IMAGE_DYNAMIC_RELOCATION64_V2 *reloc = (const IMAGE_DYNAMIC_RELOCATION64_V2 *)ptr;
4380
if (reloc->Symbol == IMAGE_DYNAMIC_RELOCATION_ARM64X)
4381
{
4382
*size = reloc->FixupInfoSize;
4383
return (const IMAGE_BASE_RELOCATION *)(reloc + 1);
4384
}
4385
ptr += reloc->HeaderSize + reloc->FixupInfoSize;
4386
}
4387
else
4388
{
4389
const IMAGE_DYNAMIC_RELOCATION32_V2 *reloc = (const IMAGE_DYNAMIC_RELOCATION32_V2 *)ptr;
4390
if (reloc->Symbol == IMAGE_DYNAMIC_RELOCATION_ARM64X)
4391
{
4392
*size = reloc->FixupInfoSize;
4393
return (const IMAGE_BASE_RELOCATION *)(reloc + 1);
4394
}
4395
ptr += reloc->HeaderSize + reloc->FixupInfoSize;
4396
}
4397
break;
4398
}
4399
}
4400
return NULL;
4401
}
4402
4403
static BOOL get_alt_header( void )
4404
{
4405
unsigned int size;
4406
const IMAGE_BASE_RELOCATION *end, *reloc = get_armx_relocs( &size );
4407
4408
if (!reloc) return FALSE;
4409
end = (const IMAGE_BASE_RELOCATION *)((const char *)reloc + size);
4410
4411
while (reloc < end - 1 && reloc->SizeOfBlock)
4412
{
4413
const USHORT *rel = (const USHORT *)(reloc + 1);
4414
const USHORT *rel_end = (const USHORT *)reloc + reloc->SizeOfBlock / sizeof(USHORT);
4415
char *page = reloc->VirtualAddress ? (char *)RVA(reloc->VirtualAddress,1) : dump_base;
4416
4417
while (rel < rel_end && *rel)
4418
{
4419
USHORT offset = *rel & 0xfff;
4420
USHORT type = (*rel >> 12) & 3;
4421
USHORT arg = *rel >> 14;
4422
int val;
4423
rel++;
4424
switch (type)
4425
{
4426
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL:
4427
memset( page + offset, 0, 1 << arg );
4428
break;
4429
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
4430
memcpy( page + offset, rel, 1 << arg );
4431
rel += (1 << arg) / sizeof(USHORT);
4432
break;
4433
case IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
4434
val = (unsigned int)*rel++ * ((arg & 2) ? 8 : 4);
4435
if (arg & 1) val = -val;
4436
*(int *)(page + offset) += val;
4437
break;
4438
}
4439
}
4440
reloc = (const IMAGE_BASE_RELOCATION *)rel_end;
4441
}
4442
return TRUE;
4443
}
4444
4445
static void dump_dir_reloc(void)
4446
{
4447
unsigned int i, size = 0;
4448
const USHORT *relocs;
4449
const IMAGE_BASE_RELOCATION *rel = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_BASERELOC, &size);
4450
const IMAGE_BASE_RELOCATION *end = (const IMAGE_BASE_RELOCATION *)((const char *)rel + size);
4451
static const char * const names[] =
4452
{
4453
"BASED_ABSOLUTE",
4454
"BASED_HIGH",
4455
"BASED_LOW",
4456
"BASED_HIGHLOW",
4457
"BASED_HIGHADJ",
4458
"BASED_MIPS_JMPADDR",
4459
"BASED_SECTION",
4460
"BASED_REL",
4461
"unknown 8",
4462
"BASED_IA64_IMM64",
4463
"BASED_DIR64",
4464
"BASED_HIGH3ADJ",
4465
"unknown 12",
4466
"unknown 13",
4467
"unknown 14",
4468
"unknown 15"
4469
};
4470
4471
if (!rel) return;
4472
4473
printf( "Relocations\n" );
4474
while (rel < end - 1 && rel->SizeOfBlock)
4475
{
4476
printf( " Page %x\n", (UINT)rel->VirtualAddress );
4477
relocs = (const USHORT *)(rel + 1);
4478
i = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(USHORT);
4479
while (i--)
4480
{
4481
USHORT offset = *relocs & 0xfff;
4482
int type = *relocs >> 12;
4483
printf( " off %04x type %s\n", offset, names[type] );
4484
relocs++;
4485
}
4486
rel = (const IMAGE_BASE_RELOCATION *)relocs;
4487
}
4488
printf("\n");
4489
}
4490
4491
static void dump_dir_tls(void)
4492
{
4493
IMAGE_TLS_DIRECTORY64 dir;
4494
const UINT *callbacks;
4495
const IMAGE_TLS_DIRECTORY32 *pdir = get_dir(IMAGE_FILE_THREAD_LOCAL_STORAGE);
4496
4497
if (!pdir) return;
4498
4499
if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
4500
memcpy(&dir, pdir, sizeof(dir));
4501
else
4502
{
4503
dir.StartAddressOfRawData = pdir->StartAddressOfRawData;
4504
dir.EndAddressOfRawData = pdir->EndAddressOfRawData;
4505
dir.AddressOfIndex = pdir->AddressOfIndex;
4506
dir.AddressOfCallBacks = pdir->AddressOfCallBacks;
4507
dir.SizeOfZeroFill = pdir->SizeOfZeroFill;
4508
dir.Characteristics = pdir->Characteristics;
4509
}
4510
4511
/* FIXME: This does not properly handle large images */
4512
printf( "Thread Local Storage\n" );
4513
printf( " Raw data %08x-%08x (data size %x zero fill size %x)\n",
4514
(UINT)dir.StartAddressOfRawData, (UINT)dir.EndAddressOfRawData,
4515
(UINT)(dir.EndAddressOfRawData - dir.StartAddressOfRawData),
4516
(UINT)dir.SizeOfZeroFill );
4517
printf( " Index address %08x\n", (UINT)dir.AddressOfIndex );
4518
printf( " Characteristics %08x\n", (UINT)dir.Characteristics );
4519
printf( " Callbacks %08x -> {", (UINT)dir.AddressOfCallBacks );
4520
if (dir.AddressOfCallBacks)
4521
{
4522
UINT addr = (UINT)dir.AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase;
4523
while ((callbacks = RVA(addr, sizeof(UINT))) && *callbacks)
4524
{
4525
printf( " %08x", *callbacks );
4526
addr += sizeof(UINT);
4527
}
4528
}
4529
printf(" }\n\n");
4530
}
4531
4532
enum FileSig get_kind_dbg(void)
4533
{
4534
const WORD* pw;
4535
4536
pw = PRD(0, sizeof(WORD));
4537
if (!pw) {printf("Can't get main signature, aborting\n"); return 0;}
4538
4539
if (*pw == 0x4944 /* "DI" */) return SIG_DBG;
4540
return SIG_UNKNOWN;
4541
}
4542
4543
void dbg_dump(void)
4544
{
4545
const IMAGE_SEPARATE_DEBUG_HEADER* separateDebugHead;
4546
unsigned nb_dbg;
4547
unsigned i;
4548
const IMAGE_DEBUG_DIRECTORY* debugDir;
4549
4550
separateDebugHead = PRD(0, sizeof(*separateDebugHead));
4551
if (!separateDebugHead) {printf("Can't grab the separate header, aborting\n"); return;}
4552
4553
printf ("Signature: %.2s (0x%4X)\n",
4554
(const char*)&separateDebugHead->Signature, separateDebugHead->Signature);
4555
printf ("Flags: 0x%04X\n", separateDebugHead->Flags);
4556
printf ("Machine: 0x%04X (%s)\n",
4557
separateDebugHead->Machine, get_machine_str(separateDebugHead->Machine));
4558
printf ("Characteristics: 0x%04X\n", separateDebugHead->Characteristics);
4559
printf ("TimeDateStamp: 0x%08X (%s)\n",
4560
(UINT)separateDebugHead->TimeDateStamp, get_time_str(separateDebugHead->TimeDateStamp));
4561
printf ("CheckSum: 0x%08X\n", (UINT)separateDebugHead->CheckSum);
4562
printf ("ImageBase: 0x%08X\n", (UINT)separateDebugHead->ImageBase);
4563
printf ("SizeOfImage: 0x%08X\n", (UINT)separateDebugHead->SizeOfImage);
4564
printf ("NumberOfSections: 0x%08X\n", (UINT)separateDebugHead->NumberOfSections);
4565
printf ("ExportedNamesSize: 0x%08X\n", (UINT)separateDebugHead->ExportedNamesSize);
4566
printf ("DebugDirectorySize: 0x%08X\n", (UINT)separateDebugHead->DebugDirectorySize);
4567
4568
if (!PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER),
4569
separateDebugHead->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)))
4570
{printf("Can't get the sections, aborting\n"); return;}
4571
4572
dump_sections(separateDebugHead, separateDebugHead + 1, separateDebugHead->NumberOfSections);
4573
4574
nb_dbg = separateDebugHead->DebugDirectorySize / sizeof(IMAGE_DEBUG_DIRECTORY);
4575
debugDir = PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER) +
4576
separateDebugHead->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
4577
separateDebugHead->ExportedNamesSize,
4578
nb_dbg * sizeof(IMAGE_DEBUG_DIRECTORY));
4579
if (!debugDir) {printf("Couldn't get the debug directory info, aborting\n");return;}
4580
4581
printf("Debug Table (%u directories)\n", nb_dbg);
4582
4583
for (i = 0; i < nb_dbg; i++)
4584
{
4585
dump_dir_debug_dir(debugDir, i, (const IMAGE_SECTION_HEADER*)(separateDebugHead + 1));
4586
debugDir++;
4587
}
4588
}
4589
4590
static const char *get_resource_type( unsigned int id )
4591
{
4592
static const char * const types[] =
4593
{
4594
NULL,
4595
"CURSOR",
4596
"BITMAP",
4597
"ICON",
4598
"MENU",
4599
"DIALOG",
4600
"STRING",
4601
"FONTDIR",
4602
"FONT",
4603
"ACCELERATOR",
4604
"RCDATA",
4605
"MESSAGETABLE",
4606
"GROUP_CURSOR",
4607
NULL,
4608
"GROUP_ICON",
4609
NULL,
4610
"VERSION",
4611
"DLGINCLUDE",
4612
NULL,
4613
"PLUGPLAY",
4614
"VXD",
4615
"ANICURSOR",
4616
"ANIICON",
4617
"HTML",
4618
"MANIFEST"
4619
};
4620
4621
if ((size_t)id < ARRAY_SIZE(types)) return types[id];
4622
return NULL;
4623
}
4624
4625
/* dump an ASCII string with proper escaping */
4626
static int dump_strA( const unsigned char *str, size_t len )
4627
{
4628
static const char escapes[32] = ".......abtnvfr.............e....";
4629
char buffer[256];
4630
char *pos = buffer;
4631
int count = 0;
4632
4633
for (; len; str++, len--)
4634
{
4635
if (pos > buffer + sizeof(buffer) - 8)
4636
{
4637
fwrite( buffer, pos - buffer, 1, stdout );
4638
count += pos - buffer;
4639
pos = buffer;
4640
}
4641
if (*str > 127) /* hex escape */
4642
{
4643
pos += sprintf( pos, "\\x%02x", *str );
4644
continue;
4645
}
4646
if (*str < 32) /* octal or C escape */
4647
{
4648
if (!*str && len == 1) continue; /* do not output terminating NULL */
4649
if (escapes[*str] != '.')
4650
pos += sprintf( pos, "\\%c", escapes[*str] );
4651
else if (len > 1 && str[1] >= '0' && str[1] <= '7')
4652
pos += sprintf( pos, "\\%03o", *str );
4653
else
4654
pos += sprintf( pos, "\\%o", *str );
4655
continue;
4656
}
4657
if (*str == '\\') *pos++ = '\\';
4658
*pos++ = *str;
4659
}
4660
fwrite( buffer, pos - buffer, 1, stdout );
4661
count += pos - buffer;
4662
return count;
4663
}
4664
4665
/* dump a Unicode string with proper escaping */
4666
static int dump_strW( const WCHAR *str, size_t len )
4667
{
4668
static const char escapes[32] = ".......abtnvfr.............e....";
4669
char buffer[256];
4670
char *pos = buffer;
4671
int count = 0;
4672
4673
for (; len; str++, len--)
4674
{
4675
if (pos > buffer + sizeof(buffer) - 8)
4676
{
4677
fwrite( buffer, pos - buffer, 1, stdout );
4678
count += pos - buffer;
4679
pos = buffer;
4680
}
4681
if (*str > 127) /* hex escape */
4682
{
4683
if (len > 1 && str[1] < 128 && isxdigit((char)str[1]))
4684
pos += sprintf( pos, "\\x%04x", *str );
4685
else
4686
pos += sprintf( pos, "\\x%x", *str );
4687
continue;
4688
}
4689
if (*str < 32) /* octal or C escape */
4690
{
4691
if (!*str && len == 1) continue; /* do not output terminating NULL */
4692
if (escapes[*str] != '.')
4693
pos += sprintf( pos, "\\%c", escapes[*str] );
4694
else if (len > 1 && str[1] >= '0' && str[1] <= '7')
4695
pos += sprintf( pos, "\\%03o", *str );
4696
else
4697
pos += sprintf( pos, "\\%o", *str );
4698
continue;
4699
}
4700
if (*str == '\\') *pos++ = '\\';
4701
*pos++ = *str;
4702
}
4703
fwrite( buffer, pos - buffer, 1, stdout );
4704
count += pos - buffer;
4705
return count;
4706
}
4707
4708
/* dump data for a STRING resource */
4709
static void dump_string_data( const WCHAR *ptr, unsigned int size, unsigned int id, const char *prefix )
4710
{
4711
int i;
4712
4713
for (i = 0; i < 16 && size; i++)
4714
{
4715
unsigned len = *ptr++;
4716
4717
if (len >= size)
4718
{
4719
len = size;
4720
size = 0;
4721
}
4722
else size -= len + 1;
4723
4724
if (len)
4725
{
4726
printf( "%s%04x \"", prefix, (id - 1) * 16 + i );
4727
dump_strW( ptr, len );
4728
printf( "\"\n" );
4729
ptr += len;
4730
}
4731
}
4732
}
4733
4734
/* dump data for a MESSAGETABLE resource */
4735
static void dump_msgtable_data( const void *ptr, unsigned int size, const char *prefix )
4736
{
4737
const MESSAGE_RESOURCE_DATA *data = ptr;
4738
const MESSAGE_RESOURCE_BLOCK *block = data->Blocks;
4739
unsigned i, j;
4740
4741
for (i = 0; i < data->NumberOfBlocks; i++, block++)
4742
{
4743
const MESSAGE_RESOURCE_ENTRY *entry;
4744
4745
entry = (const MESSAGE_RESOURCE_ENTRY *)((const char *)data + block->OffsetToEntries);
4746
for (j = block->LowId; j <= block->HighId; j++)
4747
{
4748
if (entry->Flags & MESSAGE_RESOURCE_UNICODE)
4749
{
4750
const WCHAR *str = (const WCHAR *)entry->Text;
4751
printf( "%s%08x L\"", prefix, j );
4752
dump_strW( str, strlenW(str) );
4753
printf( "\"\n" );
4754
}
4755
else
4756
{
4757
const char *str = (const char *) entry->Text;
4758
printf( "%s%08x \"", prefix, j );
4759
dump_strA( entry->Text, strlen(str) );
4760
printf( "\"\n" );
4761
}
4762
entry = (const MESSAGE_RESOURCE_ENTRY *)((const char *)entry + entry->Length);
4763
}
4764
}
4765
}
4766
4767
struct version_info
4768
{
4769
WORD len;
4770
WORD val_len;
4771
WORD type;
4772
WCHAR key[1];
4773
};
4774
#define GET_VALUE(info) ((void *)((char *)info + ((offsetof(struct version_info, key[strlenW(info->key) + 1]) + 3) & ~3)))
4775
#define GET_CHILD(info) ((void *)((char *)GET_VALUE(info) + ((info->val_len * (info->type ? 2 : 1) + 3) & ~3)))
4776
#define GET_NEXT(info) ((void *)((char *)info + ((info->len + 3) & ~3)))
4777
4778
static void dump_version_children( const struct version_info *info, const char *prefix, int indent )
4779
{
4780
const struct version_info *next, *child = GET_CHILD( info );
4781
4782
for ( ; (char *)child < (char *)info + info->len; child = next)
4783
{
4784
next = GET_NEXT( child );
4785
printf( "%s%*s", prefix, indent * 2, "" );
4786
if (child->val_len || GET_VALUE( child ) == next)
4787
{
4788
printf( "VALUE \"" );
4789
dump_strW( child->key, strlenW(child->key) );
4790
if (child->type)
4791
{
4792
printf( "\", \"" );
4793
dump_strW( GET_VALUE(child), child->val_len );
4794
printf( "\"\n" );
4795
}
4796
else
4797
{
4798
const WORD *data = GET_VALUE(child);
4799
unsigned int i;
4800
printf( "\"," );
4801
for (i = 0; i < child->val_len / sizeof(WORD); i++) printf( " %#x", data[i] );
4802
printf( "\n" );
4803
}
4804
}
4805
else
4806
{
4807
printf( "BLOCK \"" );
4808
dump_strW( child->key, strlenW(child->key) );
4809
printf( "\"\n" );
4810
}
4811
dump_version_children( child, prefix, indent + 1 );
4812
}
4813
}
4814
4815
/* dump data for a VERSION resource */
4816
static void dump_version_data( const void *ptr, unsigned int size, const char *prefix )
4817
{
4818
const struct version_info *info = ptr;
4819
const VS_FIXEDFILEINFO *fileinfo = GET_VALUE( info );
4820
4821
printf( "%sSIGNATURE %08x\n", prefix, (UINT)fileinfo->dwSignature );
4822
printf( "%sVERSION %u.%u\n", prefix,
4823
HIWORD(fileinfo->dwStrucVersion), LOWORD(fileinfo->dwStrucVersion) );
4824
printf( "%sFILEVERSION %u.%u.%u.%u\n", prefix,
4825
HIWORD(fileinfo->dwFileVersionMS), LOWORD(fileinfo->dwFileVersionMS),
4826
HIWORD(fileinfo->dwFileVersionLS), LOWORD(fileinfo->dwFileVersionLS) );
4827
printf( "%sPRODUCTVERSION %u.%u.%u.%u\n", prefix,
4828
HIWORD(fileinfo->dwProductVersionMS), LOWORD(fileinfo->dwProductVersionMS),
4829
HIWORD(fileinfo->dwProductVersionLS), LOWORD(fileinfo->dwProductVersionLS) );
4830
printf( "%sFILEFLAGSMASK %08x\n", prefix, (UINT)fileinfo->dwFileFlagsMask );
4831
printf( "%sFILEFLAGS %08x\n", prefix, (UINT)fileinfo->dwFileFlags );
4832
4833
switch (fileinfo->dwFileOS)
4834
{
4835
#define CASE(x) case x: printf( "%sFILEOS %s\n", prefix, #x ); break
4836
CASE(VOS_UNKNOWN);
4837
CASE(VOS_DOS_WINDOWS16);
4838
CASE(VOS_DOS_WINDOWS32);
4839
CASE(VOS_OS216_PM16);
4840
CASE(VOS_OS232_PM32);
4841
CASE(VOS_NT_WINDOWS32);
4842
#undef CASE
4843
default:
4844
printf( "%sFILEOS %u.%u\n", prefix,
4845
(WORD)(fileinfo->dwFileOS >> 16), (WORD)fileinfo->dwFileOS );
4846
break;
4847
}
4848
4849
switch (fileinfo->dwFileType)
4850
{
4851
#define CASE(x) case x: printf( "%sFILETYPE %s\n", prefix, #x ); break
4852
CASE(VFT_UNKNOWN);
4853
CASE(VFT_APP);
4854
CASE(VFT_DLL);
4855
CASE(VFT_DRV);
4856
CASE(VFT_FONT);
4857
CASE(VFT_VXD);
4858
CASE(VFT_STATIC_LIB);
4859
#undef CASE
4860
default:
4861
printf( "%sFILETYPE %08x\n", prefix, (UINT)fileinfo->dwFileType );
4862
break;
4863
}
4864
4865
switch (((ULONGLONG)fileinfo->dwFileType << 32) + fileinfo->dwFileSubtype)
4866
{
4867
#define CASE(t,x) case (((ULONGLONG)t << 32) + x): printf( "%sFILESUBTYPE %s\n", prefix, #x ); break
4868
CASE(VFT_DRV, VFT2_UNKNOWN);
4869
CASE(VFT_DRV, VFT2_DRV_PRINTER);
4870
CASE(VFT_DRV, VFT2_DRV_KEYBOARD);
4871
CASE(VFT_DRV, VFT2_DRV_LANGUAGE);
4872
CASE(VFT_DRV, VFT2_DRV_DISPLAY);
4873
CASE(VFT_DRV, VFT2_DRV_MOUSE);
4874
CASE(VFT_DRV, VFT2_DRV_NETWORK);
4875
CASE(VFT_DRV, VFT2_DRV_SYSTEM);
4876
CASE(VFT_DRV, VFT2_DRV_INSTALLABLE);
4877
CASE(VFT_DRV, VFT2_DRV_SOUND);
4878
CASE(VFT_DRV, VFT2_DRV_COMM);
4879
CASE(VFT_DRV, VFT2_DRV_INPUTMETHOD);
4880
CASE(VFT_DRV, VFT2_DRV_VERSIONED_PRINTER);
4881
CASE(VFT_FONT, VFT2_FONT_RASTER);
4882
CASE(VFT_FONT, VFT2_FONT_VECTOR);
4883
CASE(VFT_FONT, VFT2_FONT_TRUETYPE);
4884
#undef CASE
4885
default:
4886
printf( "%sFILESUBTYPE %08x\n", prefix, (UINT)fileinfo->dwFileSubtype );
4887
break;
4888
}
4889
4890
printf( "%sFILEDATE %08x.%08x\n", prefix,
4891
(UINT)fileinfo->dwFileDateMS, (UINT)fileinfo->dwFileDateLS );
4892
dump_version_children( info, prefix, 0 );
4893
}
4894
4895
/* dump data for a HTML/MANIFEST resource */
4896
static void dump_text_data( const void *ptr, unsigned int size, const char *prefix )
4897
{
4898
const char *p = ptr, *end = p + size;
4899
4900
while (p < end)
4901
{
4902
const char *start = p;
4903
while (p < end && *p != '\r' && *p != '\n') p++;
4904
printf( "%s%.*s\n", prefix, (int)(p - start), start );
4905
while (p < end && (*p == '\r' || *p == '\n')) p++;
4906
}
4907
}
4908
4909
/* dump data for an MUI resource */
4910
static void dump_mui_data( const void *ptr, unsigned int size, const char *prefix )
4911
{
4912
UINT i;
4913
4914
const struct mui_resource
4915
{
4916
UINT signature;
4917
UINT size;
4918
UINT version;
4919
UINT path_type;
4920
UINT file_type;
4921
UINT system_attributes;
4922
UINT fallback_location;
4923
BYTE service_checksum[16];
4924
BYTE checksum[16];
4925
UINT unk1[2];
4926
UINT mui_path_off;
4927
UINT mui_path_size;
4928
UINT unk2[2];
4929
UINT ln_type_name_off;
4930
UINT ln_type_name_size;
4931
UINT ln_type_id_off;
4932
UINT ln_type_id_size;
4933
UINT mui_type_name_off;
4934
UINT mui_type_name_size;
4935
UINT mui_type_id_off;
4936
UINT mui_type_id_size;
4937
UINT lang_off;
4938
UINT lang_size;
4939
UINT fallback_lang_off;
4940
UINT fallback_lang_size;
4941
} *data = ptr;
4942
4943
printf( "%sSignature: %x\n", prefix, data->signature );
4944
printf( "%sVersion: %u.%u\n", prefix, HIWORD(data->version), LOWORD(data->version) );
4945
printf( "%sPath type: %x\n", prefix, data->path_type );
4946
printf( "%sFile type: %x\n", prefix, data->file_type );
4947
printf( "%sAttributes: %x\n", prefix, data->system_attributes );
4948
printf( "%sFallback: %x\n", prefix, data->fallback_location );
4949
printf( "%sChecksum: ", prefix );
4950
for (i = 0; i < sizeof(data->checksum); i++) printf( "%02x", data->checksum[i] );
4951
printf( "\n%sSvc checksum: ", prefix );
4952
for (i = 0; i < sizeof(data->service_checksum); i++) printf( "%02x", data->service_checksum[i] );
4953
printf( "\n" );
4954
printf( "%sUnknown1: %08x %08x\n", prefix, data->unk1[0], data->unk1[1] );
4955
printf( "%sUnknown2: %08x %08x\n", prefix, data->unk2[0], data->unk2[1] );
4956
4957
if (data->mui_path_off)
4958
{
4959
const WCHAR *name = (WCHAR *)((char *)data + data->mui_path_off);
4960
printf( "%sMUI path: ", prefix );
4961
dump_strW( name, strlenW(name) );
4962
printf( "\n" );
4963
}
4964
4965
printf( "%sResources: {", prefix );
4966
if (data->ln_type_name_off)
4967
{
4968
const WCHAR *names = (WCHAR *)((char *)data + data->ln_type_name_off);
4969
while (*names)
4970
{
4971
printf( " " );
4972
dump_strW( names, strlenW(names) );
4973
names += strlenW( names ) + 1;
4974
}
4975
}
4976
if (data->ln_type_id_off)
4977
{
4978
const UINT *types = (UINT *)((char *)data + data->ln_type_id_off);
4979
for (i = 0; i < data->ln_type_id_size / sizeof(*types); i++)
4980
{
4981
const char *type = get_resource_type( types[i] );
4982
if (type) printf( " %s", type );
4983
else printf( " %04x", types[i] );
4984
}
4985
}
4986
printf( " }\n" );
4987
4988
printf( "%sMUI resources: {", prefix );
4989
if (data->mui_type_name_off)
4990
{
4991
const WCHAR *names = (WCHAR *)((char *)data + data->mui_type_name_off);
4992
while (*names)
4993
{
4994
printf( " " );
4995
dump_strW( names, strlenW(names) );
4996
names += strlenW( names ) + 1;
4997
}
4998
}
4999
if (data->mui_type_id_off)
5000
{
5001
const UINT *types = (UINT *)((char *)data + data->mui_type_id_off);
5002
for (i = 0; i < data->mui_type_id_size / sizeof(*types); i++)
5003
{
5004
const char *type = get_resource_type( types[i] );
5005
if (type) printf( " %s", type );
5006
else printf( " %04x", types[i] );
5007
}
5008
}
5009
printf( " }\n" );
5010
5011
if (data->lang_off)
5012
{
5013
const WCHAR *name = (WCHAR *)((char *)data + data->lang_off);
5014
printf( "%sLanguage: ", prefix );
5015
dump_strW( name, strlenW(name) );
5016
printf( "\n" );
5017
}
5018
5019
if (data->fallback_lang_off)
5020
{
5021
const WCHAR *name = (WCHAR *)((char *)data + data->fallback_lang_off);
5022
printf( "%sFallback lang: ", prefix );
5023
dump_strW( name, strlenW(name) );
5024
printf( "\n" );
5025
}
5026
dump_data( ptr, size, prefix );
5027
}
5028
5029
static int cmp_resource_name( const IMAGE_RESOURCE_DIR_STRING_U *str_res, const char *str )
5030
{
5031
unsigned int i;
5032
5033
for (i = 0; i < str_res->Length; i++)
5034
{
5035
int res = str_res->NameString[i] - (WCHAR)str[i];
5036
if (res || !str[i]) return res;
5037
}
5038
return -(WCHAR)str[i];
5039
}
5040
5041
static void dump_dir_resource(void)
5042
{
5043
const IMAGE_RESOURCE_DIRECTORY *root = get_dir(IMAGE_FILE_RESOURCE_DIRECTORY);
5044
const IMAGE_RESOURCE_DIRECTORY *namedir;
5045
const IMAGE_RESOURCE_DIRECTORY *langdir;
5046
const IMAGE_RESOURCE_DIRECTORY_ENTRY *e1, *e2, *e3;
5047
const IMAGE_RESOURCE_DIR_STRING_U *string;
5048
const IMAGE_RESOURCE_DATA_ENTRY *data;
5049
int i, j, k;
5050
5051
if (!root) return;
5052
5053
printf( "Resources:" );
5054
5055
for (i = 0; i< root->NumberOfNamedEntries + root->NumberOfIdEntries; i++)
5056
{
5057
e1 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(root + 1) + i;
5058
namedir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e1->OffsetToDirectory);
5059
for (j = 0; j < namedir->NumberOfNamedEntries + namedir->NumberOfIdEntries; j++)
5060
{
5061
e2 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(namedir + 1) + j;
5062
langdir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e2->OffsetToDirectory);
5063
for (k = 0; k < langdir->NumberOfNamedEntries + langdir->NumberOfIdEntries; k++)
5064
{
5065
e3 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(langdir + 1) + k;
5066
5067
printf( "\n " );
5068
if (e1->NameIsString)
5069
{
5070
string = (const IMAGE_RESOURCE_DIR_STRING_U*)((const char *)root + e1->NameOffset);
5071
dump_unicode_str( string->NameString, string->Length );
5072
}
5073
else
5074
{
5075
const char *type = get_resource_type( e1->Id );
5076
if (type) printf( "%s", type );
5077
else printf( "%04x", e1->Id );
5078
}
5079
5080
printf( " Name=" );
5081
if (e2->NameIsString)
5082
{
5083
string = (const IMAGE_RESOURCE_DIR_STRING_U*) ((const char *)root + e2->NameOffset);
5084
dump_unicode_str( string->NameString, string->Length );
5085
}
5086
else
5087
printf( "%04x", e2->Id );
5088
5089
printf( " Language=%04x:\n", e3->Id );
5090
data = (const IMAGE_RESOURCE_DATA_ENTRY *)((const char *)root + e3->OffsetToData);
5091
if (e1->NameIsString)
5092
{
5093
string = (const IMAGE_RESOURCE_DIR_STRING_U*)((const char *)root + e1->NameOffset);
5094
if (!cmp_resource_name( string, "TYPELIB" ))
5095
tlb_dump_resource( (void *)RVA( data->OffsetToData, data->Size ), data->Size, " | " );
5096
else if (!cmp_resource_name( string, "MUI" ))
5097
dump_mui_data( RVA( data->OffsetToData, data->Size ), data->Size, " | " );
5098
else if (!cmp_resource_name( string, "WINE_REGISTRY" ))
5099
dump_text_data( RVA( data->OffsetToData, data->Size ), data->Size, " | " );
5100
else
5101
dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " );
5102
}
5103
else switch(e1->Id)
5104
{
5105
case 6: /* RT_STRING */
5106
dump_string_data( RVA( data->OffsetToData, data->Size ), data->Size, e2->Id, " " );
5107
break;
5108
case 11: /* RT_MESSAGETABLE */
5109
dump_msgtable_data( RVA( data->OffsetToData, data->Size ), data->Size, " " );
5110
break;
5111
case 16: /* RT_VERSION */
5112
dump_version_data( RVA( data->OffsetToData, data->Size ), data->Size, " | " );
5113
break;
5114
case 23: /* RT_HTML */
5115
case 24: /* RT_MANIFEST */
5116
dump_text_data( RVA( data->OffsetToData, data->Size ), data->Size, " | " );
5117
break;
5118
default:
5119
dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " );
5120
break;
5121
}
5122
}
5123
}
5124
}
5125
printf( "\n\n" );
5126
}
5127
5128
static void dump_debug(void)
5129
{
5130
const char* stabs = NULL;
5131
unsigned szstabs = 0;
5132
const char* stabstr = NULL;
5133
unsigned szstr = 0;
5134
unsigned i;
5135
const IMAGE_SECTION_HEADER* sectHead;
5136
5137
sectHead = IMAGE_FIRST_SECTION(PE_nt_headers);
5138
5139
for (i = 0; i < PE_nt_headers->FileHeader.NumberOfSections; i++, sectHead++)
5140
{
5141
if (!strcmp((const char *)sectHead->Name, ".stab"))
5142
{
5143
stabs = RVA(sectHead->VirtualAddress, sectHead->Misc.VirtualSize);
5144
szstabs = sectHead->Misc.VirtualSize;
5145
}
5146
if (!strncmp((const char *)sectHead->Name, ".stabstr", 8))
5147
{
5148
stabstr = RVA(sectHead->VirtualAddress, sectHead->Misc.VirtualSize);
5149
szstr = sectHead->Misc.VirtualSize;
5150
}
5151
}
5152
if (stabs && stabstr)
5153
dump_stabs(stabs, szstabs, stabstr, szstr);
5154
}
5155
5156
static void dump_symbol_table(void)
5157
{
5158
const IMAGE_SYMBOL* sym;
5159
int numsym;
5160
5161
numsym = PE_nt_headers->FileHeader.NumberOfSymbols;
5162
if (!PE_nt_headers->FileHeader.PointerToSymbolTable || !numsym)
5163
return;
5164
sym = PRD(PE_nt_headers->FileHeader.PointerToSymbolTable,
5165
sizeof(*sym) * numsym);
5166
if (!sym) return;
5167
5168
dump_coff_symbol_table(sym, numsym, IMAGE_FIRST_SECTION(PE_nt_headers));
5169
}
5170
5171
enum FileSig get_kind_exec(void)
5172
{
5173
const WORD* pw;
5174
const DWORD* pdw;
5175
const IMAGE_DOS_HEADER* dh;
5176
5177
pw = PRD(0, sizeof(WORD));
5178
if (!pw) {printf("Can't get main signature, aborting\n"); return 0;}
5179
5180
if (*pw != IMAGE_DOS_SIGNATURE) return SIG_UNKNOWN;
5181
5182
if ((dh = PRD(0, sizeof(IMAGE_DOS_HEADER))))
5183
{
5184
/* the signature is the first DWORD */
5185
pdw = PRD(dh->e_lfanew, sizeof(DWORD));
5186
if (pdw)
5187
{
5188
if (*pdw == IMAGE_NT_SIGNATURE) return SIG_PE;
5189
if (*(const WORD *)pdw == IMAGE_OS2_SIGNATURE) return SIG_NE;
5190
if (*(const WORD *)pdw == IMAGE_VXD_SIGNATURE) return SIG_LE;
5191
}
5192
return SIG_DOS;
5193
}
5194
return SIG_UNKNOWN;
5195
}
5196
5197
void pe_dump(void)
5198
{
5199
int alt = 0;
5200
5201
PE_nt_headers = get_nt_header();
5202
print_fake_dll();
5203
5204
for (;;)
5205
{
5206
if (alt)
5207
printf( "\n**** Alternate (%s) data ****\n\n",
5208
get_machine_str(PE_nt_headers->FileHeader.Machine));
5209
else if (get_dyn_reloc_table())
5210
printf( "**** Native (%s) data ****\n\n",
5211
get_machine_str(PE_nt_headers->FileHeader.Machine));
5212
5213
if (globals.do_dumpheader)
5214
{
5215
dump_pe_header();
5216
/* FIXME: should check ptr */
5217
dump_sections(PRD(0, 1), IMAGE_FIRST_SECTION(PE_nt_headers),
5218
PE_nt_headers->FileHeader.NumberOfSections);
5219
}
5220
else if (!globals.dumpsect)
5221
{
5222
/* show at least something here */
5223
dump_pe_header();
5224
}
5225
5226
if (globals_dump_sect("import"))
5227
{
5228
dump_dir_imported_functions();
5229
dump_dir_delay_imported_functions();
5230
}
5231
if (globals_dump_sect("export"))
5232
dump_dir_exported_functions();
5233
if (globals_dump_sect("debug"))
5234
dump_dir_debug();
5235
if (globals_dump_sect("resource"))
5236
dump_dir_resource();
5237
if (globals_dump_sect("tls"))
5238
dump_dir_tls();
5239
if (globals_dump_sect("loadcfg"))
5240
dump_dir_loadconfig();
5241
if (globals_dump_sect("clr"))
5242
dump_dir_clr_header();
5243
if (globals_dump_sect("reloc"))
5244
dump_dir_reloc();
5245
if (globals_dump_sect("dynreloc"))
5246
dump_dir_dynamic_reloc();
5247
if (globals_dump_sect("except"))
5248
dump_dir_exceptions();
5249
if (globals_dump_sect("apiset"))
5250
dump_section_apiset();
5251
5252
if (globals.do_symbol_table)
5253
dump_symbol_table();
5254
if (globals.do_debug)
5255
dump_debug();
5256
if (alt++) break;
5257
if (!get_alt_header()) break;
5258
}
5259
}
5260
5261
typedef struct _dll_symbol {
5262
size_t ordinal;
5263
char *symbol;
5264
} dll_symbol;
5265
5266
static dll_symbol *dll_symbols = NULL;
5267
static dll_symbol *dll_current_symbol = NULL;
5268
5269
/* Compare symbols by ordinal for qsort */
5270
static int symbol_cmp(const void *left, const void *right)
5271
{
5272
return ((const dll_symbol *)left)->ordinal > ((const dll_symbol *)right)->ordinal;
5273
}
5274
5275
/*******************************************************************
5276
* dll_close
5277
*
5278
* Free resources used by DLL
5279
*/
5280
/* FIXME: Not used yet
5281
static void dll_close (void)
5282
{
5283
dll_symbol* ds;
5284
5285
if (!dll_symbols) {
5286
fatal("No symbols");
5287
}
5288
for (ds = dll_symbols; ds->symbol; ds++)
5289
free(ds->symbol);
5290
free (dll_symbols);
5291
dll_symbols = NULL;
5292
}
5293
*/
5294
5295
static void do_grab_sym( void )
5296
{
5297
const IMAGE_EXPORT_DIRECTORY*exportDir;
5298
UINT i, j, *map;
5299
const UINT *pName;
5300
const UINT *pFunc;
5301
const WORD *pOrdl;
5302
const char *ptr;
5303
5304
PE_nt_headers = get_nt_header();
5305
if (!(exportDir = get_dir(IMAGE_FILE_EXPORT_DIRECTORY))) return;
5306
5307
pName = RVA(exportDir->AddressOfNames, exportDir->NumberOfNames * sizeof(DWORD));
5308
if (!pName) {printf("Can't grab functions' name table\n"); return;}
5309
pOrdl = RVA(exportDir->AddressOfNameOrdinals, exportDir->NumberOfNames * sizeof(WORD));
5310
if (!pOrdl) {printf("Can't grab functions' ordinal table\n"); return;}
5311
pFunc = RVA(exportDir->AddressOfFunctions, exportDir->NumberOfFunctions * sizeof(DWORD));
5312
if (!pFunc) {printf("Can't grab functions' address table\n"); return;}
5313
5314
/* dll_close(); */
5315
5316
dll_symbols = xmalloc((exportDir->NumberOfFunctions + 1) * sizeof(dll_symbol));
5317
5318
/* bit map of used funcs */
5319
map = calloc(((exportDir->NumberOfFunctions + 31) & ~31) / 32, sizeof(DWORD));
5320
if (!map) fatal("no memory");
5321
5322
for (j = 0; j < exportDir->NumberOfNames; j++, pOrdl++)
5323
{
5324
map[*pOrdl / 32] |= 1 << (*pOrdl % 32);
5325
ptr = RVA(*pName++, sizeof(DWORD));
5326
if (!ptr) ptr = "cant_get_function";
5327
dll_symbols[j].symbol = xstrdup(ptr);
5328
dll_symbols[j].ordinal = exportDir->Base + *pOrdl;
5329
assert(dll_symbols[j].symbol);
5330
}
5331
5332
for (i = 0; i < exportDir->NumberOfFunctions; i++)
5333
{
5334
if (pFunc[i] && !(map[i / 32] & (1 << (i % 32))))
5335
{
5336
char ordinal_text[256];
5337
/* Ordinal only entry */
5338
sprintf (ordinal_text, "%s_%u",
5339
globals.forward_dll ? globals.forward_dll : OUTPUT_UC_DLL_NAME,
5340
(UINT)exportDir->Base + i);
5341
str_toupper(ordinal_text);
5342
dll_symbols[j].symbol = xstrdup(ordinal_text);
5343
assert(dll_symbols[j].symbol);
5344
dll_symbols[j].ordinal = exportDir->Base + i;
5345
j++;
5346
assert(j <= exportDir->NumberOfFunctions);
5347
}
5348
}
5349
free(map);
5350
5351
if (NORMAL)
5352
printf("%u named symbols in DLL, %u total, %d unique (ordinal base = %d)\n",
5353
(UINT)exportDir->NumberOfNames, (UINT)exportDir->NumberOfFunctions,
5354
j, (UINT)exportDir->Base);
5355
5356
qsort( dll_symbols, j, sizeof(dll_symbol), symbol_cmp );
5357
5358
dll_symbols[j].symbol = NULL;
5359
5360
dll_current_symbol = dll_symbols;
5361
}
5362
5363
/*******************************************************************
5364
* dll_open
5365
*
5366
* Open a DLL and read in exported symbols
5367
*/
5368
BOOL dll_open (const char *dll_name)
5369
{
5370
return dump_analysis(dll_name, do_grab_sym, SIG_PE);
5371
}
5372
5373
/*******************************************************************
5374
* dll_next_symbol
5375
*
5376
* Get next exported symbol from dll
5377
*/
5378
BOOL dll_next_symbol (parsed_symbol * sym)
5379
{
5380
if (!dll_current_symbol || !dll_current_symbol->symbol)
5381
return FALSE;
5382
assert (dll_symbols);
5383
sym->symbol = xstrdup (dll_current_symbol->symbol);
5384
sym->ordinal = dll_current_symbol->ordinal;
5385
dll_current_symbol++;
5386
return TRUE;
5387
}
5388
5389