winedump: Build with nameless unions/structs.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-04-22 17:02:09 +02:00
parent fdd0ad5939
commit 4b865129a5
4 changed files with 110 additions and 119 deletions

View File

@ -25,8 +25,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#define NONAMELESSUNION
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winnt.h" #include "winnt.h"
@ -60,7 +58,7 @@ static void dump_import_object(const IMPORT_OBJECT_HEADER *ioh)
printf(" Symbol name : %s\n", name); printf(" Symbol name : %s\n", name);
printf(" Type : %s\n", (ioh->Type < ARRAY_SIZE(obj_type)) ? obj_type[ioh->Type] : "unknown"); printf(" Type : %s\n", (ioh->Type < ARRAY_SIZE(obj_type)) ? obj_type[ioh->Type] : "unknown");
printf(" Name type : %s\n", (ioh->NameType < ARRAY_SIZE(name_type)) ? name_type[ioh->NameType] : "unknown"); printf(" Name type : %s\n", (ioh->NameType < ARRAY_SIZE(name_type)) ? name_type[ioh->NameType] : "unknown");
printf(" %-13s: %u\n", (ioh->NameType == IMPORT_OBJECT_ORDINAL) ? "Ordinal" : "Hint", ioh->u.Ordinal); printf(" %-13s: %u\n", (ioh->NameType == IMPORT_OBJECT_ORDINAL) ? "Ordinal" : "Hint", ioh->Ordinal);
printf("\n"); printf("\n");
} }
} }

View File

@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <stdarg.h> #include <stdarg.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "winedump.h" #include "winedump.h"
#include "winver.h" #include "winver.h"
#include "dbghelp.h" #include "dbghelp.h"
@ -86,7 +84,7 @@ void mdmp_dump(void)
printf("NumberOfStreams: %u\n", (UINT)hdr->NumberOfStreams); printf("NumberOfStreams: %u\n", (UINT)hdr->NumberOfStreams);
printf("StreamDirectoryRva: %u\n", (UINT)hdr->StreamDirectoryRva); printf("StreamDirectoryRva: %u\n", (UINT)hdr->StreamDirectoryRva);
printf("CheckSum: %u\n", (UINT)hdr->CheckSum); printf("CheckSum: %u\n", (UINT)hdr->CheckSum);
printf("TimeDateStamp: %s\n", get_time_str(hdr->u.TimeDateStamp)); printf("TimeDateStamp: %s\n", get_time_str(hdr->TimeDateStamp));
printf("Flags: %x%08x\n", (UINT)(hdr->Flags >> 32), (UINT)hdr->Flags); printf("Flags: %x%08x\n", (UINT)(hdr->Flags >> 32), (UINT)hdr->Flags);
for (idx = 0; idx <= LastReservedStream; idx++) for (idx = 0; idx <= LastReservedStream; idx++)
@ -298,7 +296,7 @@ void mdmp_dump(void)
str = "???"; str = "???";
break; break;
} }
printf(" Processor: %s (#%d CPUs)\n", str, msi->u.s.NumberOfProcessors); printf(" Processor: %s (#%d CPUs)\n", str, msi->NumberOfProcessors);
switch (msi->MajorVersion) switch (msi->MajorVersion)
{ {
case 3: case 3:
@ -323,8 +321,8 @@ void mdmp_dump(void)
case 0: str = "2000"; break; case 0: str = "2000"; break;
case 1: str = "XP"; break; case 1: str = "XP"; break;
case 2: case 2:
if (msi->u.s.ProductType == 1) str = "XP"; if (msi->ProductType == 1) str = "XP";
else if (msi->u.s.ProductType == 3) str = "Server 2003"; else if (msi->ProductType == 3) str = "Server 2003";
else str = "5-????"; else str = "5-????";
break; break;
default: str = "5-????"; break; default: str = "5-????"; break;
@ -334,23 +332,23 @@ void mdmp_dump(void)
switch (msi->MinorVersion) switch (msi->MinorVersion)
{ {
case 0: case 0:
if (msi->u.s.ProductType == 1) str = "Vista"; if (msi->ProductType == 1) str = "Vista";
else if (msi->u.s.ProductType == 3) str = "Server 2008"; else if (msi->ProductType == 3) str = "Server 2008";
else str = "6-????"; else str = "6-????";
break; break;
case 1: case 1:
if (msi->u.s.ProductType == 1) str = "Win7"; if (msi->ProductType == 1) str = "Win7";
else if (msi->u.s.ProductType == 3) str = "Server 2008 R2"; else if (msi->ProductType == 3) str = "Server 2008 R2";
else str = "6-????"; else str = "6-????";
break; break;
case 2: case 2:
if (msi->u.s.ProductType == 1) str = "Win8"; if (msi->ProductType == 1) str = "Win8";
else if (msi->u.s.ProductType == 3) str = "Server 2012"; else if (msi->ProductType == 3) str = "Server 2012";
else str = "6-????"; else str = "6-????";
break; break;
case 3: case 3:
if (msi->u.s.ProductType == 1) str = "Win8.1"; if (msi->ProductType == 1) str = "Win8.1";
else if (msi->u.s.ProductType == 3) str = "Server 2012 R2"; else if (msi->ProductType == 3) str = "Server 2012 R2";
else str = "6-????"; else str = "6-????";
break; break;
default: str = "6-????"; break; default: str = "6-????"; break;
@ -360,7 +358,7 @@ void mdmp_dump(void)
switch (msi->MinorVersion) switch (msi->MinorVersion)
{ {
case 0: case 0:
if (msi->u.s.ProductType == 1) str = "Win10"; if (msi->ProductType == 1) str = "Win10";
else str = "10-????"; else str = "10-????";
break; break;
default: str = "10-????"; break; default: str = "10-????"; break;
@ -373,7 +371,7 @@ void mdmp_dump(void)
printf(" CSD: "); printf(" CSD: ");
dump_mdmp_string(msi->CSDVersionRva); dump_mdmp_string(msi->CSDVersionRva);
printf("\n"); printf("\n");
printf(" Reserved1: %u\n", (UINT)msi->u1.Reserved1); printf(" Reserved1: %u\n", (UINT)msi->Reserved1);
if (msi->ProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) if (msi->ProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
{ {
printf(" x86.VendorId: %.12s\n", printf(" x86.VendorId: %.12s\n",

View File

@ -26,8 +26,6 @@
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
#define NONAMELESSUNION
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winedump.h" #include "winedump.h"

View File

@ -26,8 +26,6 @@
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winedump.h" #include "winedump.h"
@ -675,8 +673,8 @@ struct runtime_function_armnt
UINT L : 1; UINT L : 1;
UINT C : 1; UINT C : 1;
UINT StackAdjust : 10; UINT StackAdjust : 10;
} DUMMYSTRUCTNAME; };
} DUMMYUNIONNAME; };
}; };
struct runtime_function_arm64 struct runtime_function_arm64
@ -694,8 +692,8 @@ struct runtime_function_arm64
UINT H : 1; UINT H : 1;
UINT CR : 2; UINT CR : 2;
UINT FrameSize : 9; UINT FrameSize : 9;
} DUMMYSTRUCTNAME; };
} DUMMYUNIONNAME; };
}; };
union handler_data union handler_data
@ -888,37 +886,37 @@ static void dump_armnt_unwind_info( const struct runtime_function_armnt *fnc )
unsigned int rva; unsigned int rva;
WORD i, count = 0, words = 0; WORD i, count = 0, words = 0;
if (fnc->u.s.Flag) if (fnc->Flag)
{ {
char intregs[32] = {0}, intregspop[32] = {0}, vfpregs[32] = {0}; char intregs[32] = {0}, intregspop[32] = {0}, vfpregs[32] = {0};
WORD pf = 0, ef = 0, fpoffset = 0, stack = fnc->u.s.StackAdjust; WORD pf = 0, ef = 0, fpoffset = 0, stack = fnc->StackAdjust;
printf( "\nFunction %08x-%08x:\n", fnc->BeginAddress & ~1, printf( "\nFunction %08x-%08x:\n", fnc->BeginAddress & ~1,
(fnc->BeginAddress & ~1) + fnc->u.s.FunctionLength * 2 ); (fnc->BeginAddress & ~1) + fnc->FunctionLength * 2 );
printf( " Flag %x\n", fnc->u.s.Flag ); printf( " Flag %x\n", fnc->Flag );
printf( " FunctionLength %x\n", fnc->u.s.FunctionLength ); printf( " FunctionLength %x\n", fnc->FunctionLength );
printf( " Ret %x\n", fnc->u.s.Ret ); printf( " Ret %x\n", fnc->Ret );
printf( " H %x\n", fnc->u.s.H ); printf( " H %x\n", fnc->H );
printf( " Reg %x\n", fnc->u.s.Reg ); printf( " Reg %x\n", fnc->Reg );
printf( " R %x\n", fnc->u.s.R ); printf( " R %x\n", fnc->R );
printf( " L %x\n", fnc->u.s.L ); printf( " L %x\n", fnc->L );
printf( " C %x\n", fnc->u.s.C ); printf( " C %x\n", fnc->C );
printf( " StackAdjust %x\n", fnc->u.s.StackAdjust ); printf( " StackAdjust %x\n", fnc->StackAdjust );
if (fnc->u.s.StackAdjust >= 0x03f4) if (fnc->StackAdjust >= 0x03f4)
{ {
pf = fnc->u.s.StackAdjust & 0x04; pf = fnc->StackAdjust & 0x04;
ef = fnc->u.s.StackAdjust & 0x08; ef = fnc->StackAdjust & 0x08;
stack = (fnc->u.s.StackAdjust & 3) + 1; stack = (fnc->StackAdjust & 3) + 1;
} }
if (!fnc->u.s.R || pf) if (!fnc->R || pf)
{ {
int first = 4, last = fnc->u.s.Reg + 4; int first = 4, last = fnc->Reg + 4;
if (pf) if (pf)
{ {
first = (~fnc->u.s.StackAdjust) & 3; first = (~fnc->StackAdjust) & 3;
if (fnc->u.s.R) if (fnc->R)
last = 3; last = 3;
} }
if (first == last) if (first == last)
@ -928,13 +926,13 @@ static void dump_armnt_unwind_info( const struct runtime_function_armnt *fnc )
fpoffset = last + 1 - first; fpoffset = last + 1 - first;
} }
if (!fnc->u.s.R || ef) if (!fnc->R || ef)
{ {
int first = 4, last = fnc->u.s.Reg + 4; int first = 4, last = fnc->Reg + 4;
if (ef) if (ef)
{ {
first = (~fnc->u.s.StackAdjust) & 3; first = (~fnc->StackAdjust) & 3;
if (fnc->u.s.R) if (fnc->R)
last = 3; last = 3;
} }
if (first == last) if (first == last)
@ -943,7 +941,7 @@ static void dump_armnt_unwind_info( const struct runtime_function_armnt *fnc )
sprintf(intregspop, "r%u-r%u", first, last); sprintf(intregspop, "r%u-r%u", first, last);
} }
if (fnc->u.s.C) if (fnc->C)
{ {
if (intregs[0]) if (intregs[0])
strcat(intregs, ", "); strcat(intregs, ", ");
@ -952,82 +950,82 @@ static void dump_armnt_unwind_info( const struct runtime_function_armnt *fnc )
strcat(intregs, "r11"); strcat(intregs, "r11");
strcat(intregspop, "r11"); strcat(intregspop, "r11");
} }
if (fnc->u.s.L) if (fnc->L)
{ {
if (intregs[0]) if (intregs[0])
strcat(intregs, ", "); strcat(intregs, ", ");
strcat(intregs, "lr"); strcat(intregs, "lr");
if (intregspop[0] && (fnc->u.s.Ret != 0 || !fnc->u.s.H)) if (intregspop[0] && (fnc->Ret != 0 || !fnc->H))
strcat(intregspop, ", "); strcat(intregspop, ", ");
if (fnc->u.s.Ret != 0) if (fnc->Ret != 0)
strcat(intregspop, "lr"); strcat(intregspop, "lr");
else if (!fnc->u.s.H) else if (!fnc->H)
strcat(intregspop, "pc"); strcat(intregspop, "pc");
} }
if (fnc->u.s.R) if (fnc->R)
{ {
if (fnc->u.s.Reg) if (fnc->Reg)
sprintf(vfpregs, "d8-d%u", fnc->u.s.Reg + 8); sprintf(vfpregs, "d8-d%u", fnc->Reg + 8);
else else
strcpy(vfpregs, "d8"); strcpy(vfpregs, "d8");
} }
if (fnc->u.s.Flag == 1) { if (fnc->Flag == 1) {
if (fnc->u.s.H) if (fnc->H)
printf( " Unwind Code\tpush {r0-r3}\n" ); printf( " Unwind Code\tpush {r0-r3}\n" );
if (intregs[0]) if (intregs[0])
printf( " Unwind Code\tpush {%s}\n", intregs ); printf( " Unwind Code\tpush {%s}\n", intregs );
if (fnc->u.s.C && fpoffset == 0) if (fnc->C && fpoffset == 0)
printf( " Unwind Code\tmov r11, sp\n" ); printf( " Unwind Code\tmov r11, sp\n" );
else if (fnc->u.s.C) else if (fnc->C)
printf( " Unwind Code\tadd r11, sp, #%d\n", fpoffset * 4 ); printf( " Unwind Code\tadd r11, sp, #%d\n", fpoffset * 4 );
if (fnc->u.s.R && fnc->u.s.Reg != 0x07) if (fnc->R && fnc->Reg != 0x07)
printf( " Unwind Code\tvpush {%s}\n", vfpregs ); printf( " Unwind Code\tvpush {%s}\n", vfpregs );
if (stack && !pf) if (stack && !pf)
printf( " Unwind Code\tsub sp, sp, #%d\n", stack * 4 ); printf( " Unwind Code\tsub sp, sp, #%d\n", stack * 4 );
} }
if (fnc->u.s.Ret == 3) if (fnc->Ret == 3)
return; return;
printf( "Epilogue:\n" ); printf( "Epilogue:\n" );
if (stack && !ef) if (stack && !ef)
printf( " Unwind Code\tadd sp, sp, #%d\n", stack * 4 ); printf( " Unwind Code\tadd sp, sp, #%d\n", stack * 4 );
if (fnc->u.s.R && fnc->u.s.Reg != 0x07) if (fnc->R && fnc->Reg != 0x07)
printf( " Unwind Code\tvpop {%s}\n", vfpregs ); printf( " Unwind Code\tvpop {%s}\n", vfpregs );
if (intregspop[0]) if (intregspop[0])
printf( " Unwind Code\tpop {%s}\n", intregspop ); printf( " Unwind Code\tpop {%s}\n", intregspop );
if (fnc->u.s.H && !(fnc->u.s.L && fnc->u.s.Ret == 0)) if (fnc->H && !(fnc->L && fnc->Ret == 0))
printf( " Unwind Code\tadd sp, sp, #16\n" ); printf( " Unwind Code\tadd sp, sp, #16\n" );
else if (fnc->u.s.H && (fnc->u.s.L && fnc->u.s.Ret == 0)) else if (fnc->H && (fnc->L && fnc->Ret == 0))
printf( " Unwind Code\tldr pc, [sp], #20\n" ); printf( " Unwind Code\tldr pc, [sp], #20\n" );
if (fnc->u.s.Ret == 1) if (fnc->Ret == 1)
printf( " Unwind Code\tbx <reg>\n" ); printf( " Unwind Code\tbx <reg>\n" );
else if (fnc->u.s.Ret == 2) else if (fnc->Ret == 2)
printf( " Unwind Code\tb <address>\n" ); printf( " Unwind Code\tb <address>\n" );
return; return;
} }
info = RVA( fnc->u.UnwindData, sizeof(*info) ); info = RVA( fnc->UnwindData, sizeof(*info) );
rva = fnc->u.UnwindData + sizeof(*info); rva = fnc->UnwindData + sizeof(*info);
count = info->count; count = info->count;
words = info->words; words = info->words;
printf( "\nFunction %08x-%08x:\n", fnc->BeginAddress & ~1, printf( "\nFunction %08x-%08x:\n", fnc->BeginAddress & ~1,
(fnc->BeginAddress & ~1) + info->function_length * 2 ); (fnc->BeginAddress & ~1) + info->function_length * 2 );
printf( " unwind info at %08x\n", fnc->u.UnwindData ); printf( " unwind info at %08x\n", fnc->UnwindData );
printf( " Flag %x\n", fnc->u.s.Flag ); printf( " Flag %x\n", fnc->Flag );
printf( " FunctionLength %x\n", info->function_length ); printf( " FunctionLength %x\n", info->function_length );
printf( " Version %x\n", info->version ); printf( " Version %x\n", info->version );
printf( " X %x\n", info->x ); printf( " X %x\n", info->x );
@ -1461,15 +1459,15 @@ static void dump_arm64_codes( const BYTE *ptr, unsigned int count )
static void dump_arm64_packed_info( const struct runtime_function_arm64 *func ) static void dump_arm64_packed_info( const struct runtime_function_arm64 *func )
{ {
int i, pos = 0, intsz = func->u.s.RegI * 8, fpsz = func->u.s.RegF * 8, savesz, locsz; int i, pos = 0, intsz = func->RegI * 8, fpsz = func->RegF * 8, savesz, locsz;
if (func->u.s.CR == 1) intsz += 8; if (func->CR == 1) intsz += 8;
if (func->u.s.RegF) fpsz += 8; if (func->RegF) fpsz += 8;
savesz = ((intsz + fpsz + 8 * 8 * func->u.s.H) + 0xf) & ~0xf; savesz = ((intsz + fpsz + 8 * 8 * func->H) + 0xf) & ~0xf;
locsz = func->u.s.FrameSize * 16 - savesz; locsz = func->FrameSize * 16 - savesz;
switch (func->u.s.CR) switch (func->CR)
{ {
case 3: case 3:
printf( " %04x: mov x29,sp\n", pos++ ); printf( " %04x: mov x29,sp\n", pos++ );
@ -1494,7 +1492,7 @@ static void dump_arm64_packed_info( const struct runtime_function_arm64 *func )
break; break;
} }
if (func->u.s.H) if (func->H)
{ {
printf( " %04x: stp x6,x7,[sp,#%#x]\n", pos++, intsz + fpsz + 48 ); printf( " %04x: stp x6,x7,[sp,#%#x]\n", pos++, intsz + fpsz + 48 );
printf( " %04x: stp x4,x5,[sp,#%#x]\n", pos++, intsz + fpsz + 32 ); printf( " %04x: stp x4,x5,[sp,#%#x]\n", pos++, intsz + fpsz + 32 );
@ -1502,11 +1500,11 @@ static void dump_arm64_packed_info( const struct runtime_function_arm64 *func )
printf( " %04x: stp x0,x1,[sp,#%#x]\n", pos++, intsz + fpsz ); printf( " %04x: stp x0,x1,[sp,#%#x]\n", pos++, intsz + fpsz );
} }
if (func->u.s.RegF) if (func->RegF)
{ {
if (func->u.s.RegF % 2 == 0) if (func->RegF % 2 == 0)
printf( " %04x: str d%u,[sp,#%#x]\n", pos++, 8 + func->u.s.RegF, intsz + fpsz - 8 ); printf( " %04x: str d%u,[sp,#%#x]\n", pos++, 8 + func->RegF, intsz + fpsz - 8 );
for (i = (func->u.s.RegF - 1)/ 2; i >= 0; i--) for (i = (func->RegF - 1)/ 2; i >= 0; i--)
{ {
if (!i && !intsz) if (!i && !intsz)
printf( " %04x: stp d8,d9,[sp,-#%#x]!\n", pos++, savesz ); printf( " %04x: stp d8,d9,[sp,-#%#x]!\n", pos++, savesz );
@ -1515,30 +1513,30 @@ static void dump_arm64_packed_info( const struct runtime_function_arm64 *func )
} }
} }
switch (func->u.s.RegI) switch (func->RegI)
{ {
case 0: case 0:
if (func->u.s.CR == 1) if (func->CR == 1)
printf( " %04x: str lr,[sp,-#%#x]!\n", pos++, savesz ); printf( " %04x: str lr,[sp,-#%#x]!\n", pos++, savesz );
break; break;
case 1: case 1:
if (func->u.s.CR == 1) if (func->CR == 1)
printf( " %04x: stp x19,lr,[sp,-#%#x]!\n", pos++, savesz ); printf( " %04x: stp x19,lr,[sp,-#%#x]!\n", pos++, savesz );
else else
printf( " %04x: str x19,[sp,-#%#x]!\n", pos++, savesz ); printf( " %04x: str x19,[sp,-#%#x]!\n", pos++, savesz );
break; break;
default: default:
if (func->u.s.RegI % 2) if (func->RegI % 2)
{ {
if (func->u.s.CR == 1) if (func->CR == 1)
printf( " %04x: stp x%u,lr,[sp,#%#x]\n", pos++, 18 + func->u.s.RegI, 8 * func->u.s.RegI - 8 ); printf( " %04x: stp x%u,lr,[sp,#%#x]\n", pos++, 18 + func->RegI, 8 * func->RegI - 8 );
else else
printf( " %04x: str x%u,[sp,#%#x]\n", pos++, 18 + func->u.s.RegI, 8 * func->u.s.RegI - 8 ); printf( " %04x: str x%u,[sp,#%#x]\n", pos++, 18 + func->RegI, 8 * func->RegI - 8 );
} }
else if (func->u.s.CR == 1) else if (func->CR == 1)
printf( " %04x: str lr,[sp,#%#x]\n", pos++, intsz - 8 ); printf( " %04x: str lr,[sp,#%#x]\n", pos++, intsz - 8 );
for (i = func->u.s.RegI / 2 - 1; i >= 0; i--) for (i = func->RegI / 2 - 1; i >= 0; i--)
if (i) if (i)
printf( " %04x: stp x%u,x%u,[sp,#%#x]\n", pos++, 19 + 2 * i, 20 + 2 * i, 16 * i ); printf( " %04x: stp x%u,x%u,[sp,#%#x]\n", pos++, 19 + 2 * i, 20 + 2 * i, 16 * i );
else else
@ -1556,18 +1554,18 @@ static void dump_arm64_unwind_info( const struct runtime_function_arm64 *func )
const BYTE *ptr; const BYTE *ptr;
unsigned int i, rva, codes, epilogs; unsigned int i, rva, codes, epilogs;
if (func->u.s.Flag) if (func->Flag)
{ {
printf( "\nFunction %08x-%08x:\n", func->BeginAddress, printf( "\nFunction %08x-%08x:\n", func->BeginAddress,
func->BeginAddress + func->u.s.FunctionLength * 4 ); func->BeginAddress + func->FunctionLength * 4 );
printf( " len=%#x flag=%x regF=%u regI=%u H=%u CR=%u frame=%x\n", printf( " len=%#x flag=%x regF=%u regI=%u H=%u CR=%u frame=%x\n",
func->u.s.FunctionLength, func->u.s.Flag, func->u.s.RegF, func->u.s.RegI, func->FunctionLength, func->Flag, func->RegF, func->RegI,
func->u.s.H, func->u.s.CR, func->u.s.FrameSize ); func->H, func->CR, func->FrameSize );
dump_arm64_packed_info( func ); dump_arm64_packed_info( func );
return; return;
} }
rva = func->u.UnwindData; rva = func->UnwindData;
info = RVA( rva, sizeof(*info) ); info = RVA( rva, sizeof(*info) );
rva += sizeof(*info); rva += sizeof(*info);
epilogs = info->epilog; epilogs = info->epilog;
@ -1693,7 +1691,7 @@ static void dump_dir_imported_functions(void)
if (!importDesc->Name || !importDesc->FirstThunk) break; if (!importDesc->Name || !importDesc->FirstThunk) break;
printf(" offset %08lx %s\n", Offset(importDesc), (const char*)RVA(importDesc->Name, sizeof(DWORD))); printf(" offset %08lx %s\n", Offset(importDesc), (const char*)RVA(importDesc->Name, sizeof(DWORD)));
printf(" Hint/Name Table: %08X\n", (UINT)importDesc->u.OriginalFirstThunk); printf(" Hint/Name Table: %08X\n", (UINT)importDesc->OriginalFirstThunk);
printf(" TimeDateStamp: %08X (%s)\n", printf(" TimeDateStamp: %08X (%s)\n",
(UINT)importDesc->TimeDateStamp, get_time_str(importDesc->TimeDateStamp)); (UINT)importDesc->TimeDateStamp, get_time_str(importDesc->TimeDateStamp));
printf(" ForwarderChain: %08X\n", (UINT)importDesc->ForwarderChain); printf(" ForwarderChain: %08X\n", (UINT)importDesc->ForwarderChain);
@ -1701,8 +1699,8 @@ static void dump_dir_imported_functions(void)
printf(" Thunk Ordn Name\n"); printf(" Thunk Ordn Name\n");
il = (importDesc->u.OriginalFirstThunk != 0) ? il = (importDesc->OriginalFirstThunk != 0) ?
RVA((DWORD)importDesc->u.OriginalFirstThunk, sizeof(DWORD)) : RVA((DWORD)importDesc->OriginalFirstThunk, sizeof(DWORD)) :
RVA((DWORD)importDesc->FirstThunk, sizeof(DWORD)); RVA((DWORD)importDesc->FirstThunk, sizeof(DWORD));
if (!il) if (!il)
@ -1919,7 +1917,7 @@ static void dump_dir_clr_header(void)
print_dword( "Header Size", dir->cb ); print_dword( "Header Size", dir->cb );
print_ver( "Required runtime version", dir->MajorRuntimeVersion, dir->MinorRuntimeVersion ); print_ver( "Required runtime version", dir->MajorRuntimeVersion, dir->MinorRuntimeVersion );
print_clrflags( "Flags", dir->Flags ); print_clrflags( "Flags", dir->Flags );
print_dword( "EntryPointToken", dir->u.EntryPointToken ); print_dword( "EntryPointToken", dir->EntryPointToken );
printf("\n"); printf("\n");
printf( "CLR Data Directory\n" ); printf( "CLR Data Directory\n" );
print_clrdirectory( "MetaData", &dir->MetaData ); print_clrdirectory( "MetaData", &dir->MetaData );
@ -2271,51 +2269,50 @@ static void dump_dir_resource(void)
for (i = 0; i< root->NumberOfNamedEntries + root->NumberOfIdEntries; i++) for (i = 0; i< root->NumberOfNamedEntries + root->NumberOfIdEntries; i++)
{ {
e1 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(root + 1) + i; e1 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(root + 1) + i;
namedir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e1->u2.s2.OffsetToDirectory); namedir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e1->OffsetToDirectory);
for (j = 0; j < namedir->NumberOfNamedEntries + namedir->NumberOfIdEntries; j++) for (j = 0; j < namedir->NumberOfNamedEntries + namedir->NumberOfIdEntries; j++)
{ {
e2 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(namedir + 1) + j; e2 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(namedir + 1) + j;
langdir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e2->u2.s2.OffsetToDirectory); langdir = (const IMAGE_RESOURCE_DIRECTORY *)((const char *)root + e2->OffsetToDirectory);
for (k = 0; k < langdir->NumberOfNamedEntries + langdir->NumberOfIdEntries; k++) for (k = 0; k < langdir->NumberOfNamedEntries + langdir->NumberOfIdEntries; k++)
{ {
e3 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(langdir + 1) + k; e3 = (const IMAGE_RESOURCE_DIRECTORY_ENTRY*)(langdir + 1) + k;
printf( "\n " ); printf( "\n " );
if (e1->u.s.NameIsString) if (e1->NameIsString)
{ {
string = (const IMAGE_RESOURCE_DIR_STRING_U*)((const char *)root + e1->u.s.NameOffset); string = (const IMAGE_RESOURCE_DIR_STRING_U*)((const char *)root + e1->NameOffset);
dump_unicode_str( string->NameString, string->Length ); dump_unicode_str( string->NameString, string->Length );
} }
else else
{ {
const char *type = get_resource_type( e1->u.Id ); const char *type = get_resource_type( e1->Id );
if (type) printf( "%s", type ); if (type) printf( "%s", type );
else printf( "%04x", e1->u.Id ); else printf( "%04x", e1->Id );
} }
printf( " Name=" ); printf( " Name=" );
if (e2->u.s.NameIsString) if (e2->NameIsString)
{ {
string = (const IMAGE_RESOURCE_DIR_STRING_U*) ((const char *)root + e2->u.s.NameOffset); string = (const IMAGE_RESOURCE_DIR_STRING_U*) ((const char *)root + e2->NameOffset);
dump_unicode_str( string->NameString, string->Length ); dump_unicode_str( string->NameString, string->Length );
} }
else else
printf( "%04x", e2->u.Id ); printf( "%04x", e2->Id );
printf( " Language=%04x:\n", e3->u.Id ); printf( " Language=%04x:\n", e3->Id );
data = (const IMAGE_RESOURCE_DATA_ENTRY *)((const char *)root + e3->u2.OffsetToData); data = (const IMAGE_RESOURCE_DATA_ENTRY *)((const char *)root + e3->OffsetToData);
if (e1->u.s.NameIsString) if (e1->NameIsString)
{ {
dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " ); dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " );
} }
else switch(e1->u.Id) else switch(e1->Id)
{ {
case 6: case 6:
dump_string_data( RVA( data->OffsetToData, data->Size ), data->Size, e2->u.Id, " " ); dump_string_data( RVA( data->OffsetToData, data->Size ), data->Size, e2->Id, " " );
break; break;
case 11: case 11:
dump_msgtable_data( RVA( data->OffsetToData, data->Size ), data->Size, dump_msgtable_data( RVA( data->OffsetToData, data->Size ), data->Size, e2->Id, " " );
e2->u.Id, " " );
break; break;
default: default:
dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " ); dump_data( RVA( data->OffsetToData, data->Size ), data->Size, " " );