~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/tools/winedump/pe.c

Version: ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  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 #include "wine/port.h"
 23 
 24 #include <stdlib.h>
 25 #include <stdarg.h>
 26 #include <stdio.h>
 27 #ifdef HAVE_UNISTD_H
 28 # include <unistd.h>
 29 #endif
 30 #include <time.h>
 31 #ifdef HAVE_SYS_TYPES_H
 32 # include <sys/types.h>
 33 #endif
 34 #ifdef HAVE_SYS_STAT_H
 35 # include <sys/stat.h>
 36 #endif
 37 #ifdef HAVE_SYS_MMAN_H
 38 #include <sys/mman.h>
 39 #endif
 40 #include <fcntl.h>
 41 
 42 #define NONAMELESSUNION
 43 #define NONAMELESSSTRUCT
 44 #include "windef.h"
 45 #include "winbase.h"
 46 #include "winedump.h"
 47 
 48 static const IMAGE_NT_HEADERS32*        PE_nt_headers;
 49 
 50 const char *get_machine_str(int mach)
 51 {
 52     switch (mach)
 53     {
 54     case IMAGE_FILE_MACHINE_UNKNOWN:    return "Unknown";
 55     case IMAGE_FILE_MACHINE_I860:       return "i860";
 56     case IMAGE_FILE_MACHINE_I386:       return "i386";
 57     case IMAGE_FILE_MACHINE_R3000:      return "R3000";
 58     case IMAGE_FILE_MACHINE_R4000:      return "R4000";
 59     case IMAGE_FILE_MACHINE_R10000:     return "R10000";
 60     case IMAGE_FILE_MACHINE_ALPHA:      return "Alpha";
 61     case IMAGE_FILE_MACHINE_POWERPC:    return "PowerPC";
 62     case IMAGE_FILE_MACHINE_AMD64:      return "AMD64";
 63     case IMAGE_FILE_MACHINE_IA64:       return "IA64";
 64     }
 65     return "???";
 66 }
 67 
 68 static const void*      RVA(unsigned long rva, unsigned long len)
 69 {
 70     IMAGE_SECTION_HEADER*       sectHead;
 71     int                         i;
 72 
 73     if (rva == 0) return NULL;
 74 
 75     sectHead = IMAGE_FIRST_SECTION(PE_nt_headers);
 76     for (i = PE_nt_headers->FileHeader.NumberOfSections - 1; i >= 0; i--)
 77     {
 78         if (sectHead[i].VirtualAddress <= rva &&
 79             rva + len <= (DWORD)sectHead[i].VirtualAddress + sectHead[i].SizeOfRawData)
 80         {
 81             /* return image import directory offset */
 82             return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
 83         }
 84     }
 85 
 86     return NULL;
 87 }
 88 
 89 static const IMAGE_NT_HEADERS32 *get_nt_header( void )
 90 {
 91     const IMAGE_DOS_HEADER *dos;
 92     dos = PRD(0, sizeof(*dos));
 93     if (!dos) return NULL;
 94     return PRD(dos->e_lfanew, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER));
 95 }
 96 
 97 static int is_fake_dll( void )
 98 {
 99     static const char fakedll_signature[] = "Wine placeholder DLL";
100     const IMAGE_DOS_HEADER *dos;
101 
102     dos = PRD(0, sizeof(*dos) + sizeof(fakedll_signature));
103 
104     if (dos && dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
105         !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return TRUE;
106     return FALSE;
107 }
108 
109 static const void *get_dir_and_size(unsigned int idx, unsigned int *size)
110 {
111     if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
112     {
113         const IMAGE_OPTIONAL_HEADER64 *opt = (const IMAGE_OPTIONAL_HEADER64*)&PE_nt_headers->OptionalHeader;
114         if (idx >= opt->NumberOfRvaAndSizes)
115             return NULL;
116         if(size)
117             *size = opt->DataDirectory[idx].Size;
118         return RVA(opt->DataDirectory[idx].VirtualAddress,
119                    opt->DataDirectory[idx].Size);
120     }
121     else
122     {
123         const IMAGE_OPTIONAL_HEADER32 *opt = (const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader;
124         if (idx >= opt->NumberOfRvaAndSizes)
125             return NULL;
126         if(size)
127             *size = opt->DataDirectory[idx].Size;
128         return RVA(opt->DataDirectory[idx].VirtualAddress,
129                    opt->DataDirectory[idx].Size);
130     }
131 }
132 
133 static  const void*     get_dir(unsigned idx)
134 {
135     return get_dir_and_size(idx, 0);
136 }
137 
138 static const char * const DirectoryNames[16] = {
139     "EXPORT",           "IMPORT",       "RESOURCE",     "EXCEPTION",
140     "SECURITY",         "BASERELOC",    "DEBUG",        "ARCHITECTURE",
141     "GLOBALPTR",        "TLS",          "LOAD_CONFIG",  "Bound IAT",
142     "IAT",              "Delay IAT",    "CLR Header", ""
143 };
144 
145 static const char *get_magic_type(WORD magic)
146 {
147     switch(magic) {
148         case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
149             return "32bit";
150         case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
151             return "64bit";
152         case IMAGE_ROM_OPTIONAL_HDR_MAGIC:
153             return "ROM";
154     }
155     return "???";
156 }
157 
158 static inline void print_word(const char *title, WORD value)
159 {
160     printf("  %-34s 0x%-4X         %u\n", title, value, value);
161 }
162 
163 static inline void print_dword(const char *title, DWORD value)
164 {
165     printf("  %-34s 0x%-8x     %u\n", title, value, value);
166 }
167 
168 static inline void print_longlong(const char *title, ULONGLONG value)
169 {
170     printf("  %-34s 0x", title);
171     if(value >> 32)
172         printf("%lx%08lx\n", (unsigned long)(value >> 32), (unsigned long)value);
173     else
174         printf("%lx\n", (unsigned long)value);
175 }
176 
177 static inline void print_ver(const char *title, BYTE major, BYTE minor)
178 {
179     printf("  %-34s %u.%02u\n", title, major, minor);
180 }
181 
182 static inline void print_subsys(const char *title, WORD value)
183 {
184     const char *str;
185     switch (value)
186     {
187         default:
188         case IMAGE_SUBSYSTEM_UNKNOWN:       str = "Unknown";        break;
189         case IMAGE_SUBSYSTEM_NATIVE:        str = "Native";         break;
190         case IMAGE_SUBSYSTEM_WINDOWS_GUI:   str = "Windows GUI";    break;
191         case IMAGE_SUBSYSTEM_WINDOWS_CUI:   str = "Windows CUI";    break;
192         case IMAGE_SUBSYSTEM_OS2_CUI:       str = "OS/2 CUI";       break;
193         case IMAGE_SUBSYSTEM_POSIX_CUI:     str = "Posix CUI";      break;
194     }
195     printf("  %-34s 0x%X (%s)\n", title, value, str);
196 }
197 
198 static inline void print_dllflags(const char *title, WORD value)
199 {
200     printf("  %-34s 0x%X\n", title, value);
201 #define X(f,s) if (value & f) printf("    %s\n", s)
202     X(IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE,          "DYNAMIC_BASE");
203     X(IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY,       "FORCE_INTEGRITY");
204     X(IMAGE_DLLCHARACTERISTICS_NX_COMPAT,             "NX_COMPAT");
205     X(IMAGE_DLLCHARACTERISTICS_NO_ISOLATION,          "NO_ISOLATION");
206     X(IMAGE_DLLCHARACTERISTICS_NO_SEH,                "NO_SEH");
207     X(IMAGE_DLLCHARACTERISTICS_NO_BIND,               "NO_BIND");
208     X(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER,            "WDM_DRIVER");
209     X(IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE, "TERMINAL_SERVER_AWARE");
210 #undef X
211 }
212 
213 static inline void print_datadirectory(DWORD n, const IMAGE_DATA_DIRECTORY *directory)
214 {
215     unsigned i;
216     printf("Data Directory\n");
217 
218     for (i = 0; i < n && i < 16; i++)
219     {
220         printf("  %-12s rva: 0x%-8x  size: 0x%-8x\n",
221                DirectoryNames[i], directory[i].VirtualAddress,
222                directory[i].Size);
223     }
224 }
225 
226 static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh, UINT header_size)
227 {
228     IMAGE_OPTIONAL_HEADER32 oh;
229     const IMAGE_OPTIONAL_HEADER32 *optionalHeader;
230 
231     /* in case optional header is missing or partial */
232     memset(&oh, 0, sizeof(oh));
233     memcpy(&oh, image_oh, min(header_size, sizeof(oh)));
234     optionalHeader = &oh;
235 
236     print_word("Magic", optionalHeader->Magic);
237     print_ver("linker version",
238               optionalHeader->MajorLinkerVersion, optionalHeader->MinorLinkerVersion);
239     print_dword("size of code", optionalHeader->SizeOfCode);
240     print_dword("size of initialized data", optionalHeader->SizeOfInitializedData);
241     print_dword("size of uninitialized data", optionalHeader->SizeOfUninitializedData);
242     print_dword("entrypoint RVA", optionalHeader->AddressOfEntryPoint);
243     print_dword("base of code", optionalHeader->BaseOfCode);
244     print_dword("base of data", optionalHeader->BaseOfData);
245     print_dword("image base", optionalHeader->ImageBase);
246     print_dword("section align", optionalHeader->SectionAlignment);
247     print_dword("file align", optionalHeader->FileAlignment);
248     print_ver("required OS version",
249               optionalHeader->MajorOperatingSystemVersion, optionalHeader->MinorOperatingSystemVersion);
250     print_ver("image version",
251               optionalHeader->MajorImageVersion, optionalHeader->MinorImageVersion);
252     print_ver("subsystem version",
253               optionalHeader->MajorSubsystemVersion, optionalHeader->MinorSubsystemVersion);
254     print_dword("Win32 Version", optionalHeader->Win32VersionValue);
255     print_dword("size of image", optionalHeader->SizeOfImage);
256     print_dword("size of headers", optionalHeader->SizeOfHeaders);
257     print_dword("checksum", optionalHeader->CheckSum);
258     print_subsys("Subsystem", optionalHeader->Subsystem);
259     print_dllflags("DLL characteristics:", optionalHeader->DllCharacteristics);
260     print_dword("stack reserve size", optionalHeader->SizeOfStackReserve);
261     print_dword("stack commit size", optionalHeader->SizeOfStackCommit);
262     print_dword("heap reserve size", optionalHeader->SizeOfHeapReserve);
263     print_dword("heap commit size", optionalHeader->SizeOfHeapCommit);
264     print_dword("loader flags", optionalHeader->LoaderFlags);
265     print_dword("RVAs & sizes", optionalHeader->NumberOfRvaAndSizes);
266     printf("\n");
267     print_datadirectory(optionalHeader->NumberOfRvaAndSizes, optionalHeader->DataDirectory);
268     printf("\n");
269 }
270 
271 static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh, UINT header_size)
272 {
273     IMAGE_OPTIONAL_HEADER64 oh;
274     const IMAGE_OPTIONAL_HEADER64 *optionalHeader;
275 
276     /* in case optional header is missing or partial */
277     memset(&oh, 0, sizeof(oh));
278     memcpy(&oh, image_oh, min(header_size, sizeof(oh)));
279     optionalHeader = &oh;
280 
281     print_word("Magic", optionalHeader->Magic);
282     print_ver("linker version",
283               optionalHeader->MajorLinkerVersion, optionalHeader->MinorLinkerVersion);
284     print_dword("size of code", optionalHeader->SizeOfCode);
285     print_dword("size of initialized data", optionalHeader->SizeOfInitializedData);
286     print_dword("size of uninitialized data", optionalHeader->SizeOfUninitializedData);
287     print_dword("entrypoint RVA", optionalHeader->AddressOfEntryPoint);
288     print_dword("base of code", optionalHeader->BaseOfCode);
289     print_longlong("image base", optionalHeader->ImageBase);
290     print_dword("section align", optionalHeader->SectionAlignment);
291     print_dword("file align", optionalHeader->FileAlignment);
292     print_ver("required OS version",
293               optionalHeader->MajorOperatingSystemVersion, optionalHeader->MinorOperatingSystemVersion);
294     print_ver("image version",
295               optionalHeader->MajorImageVersion, optionalHeader->MinorImageVersion);
296     print_ver("subsystem version",
297               optionalHeader->MajorSubsystemVersion, optionalHeader->MinorSubsystemVersion);
298     print_dword("Win32 Version", optionalHeader->Win32VersionValue);
299     print_dword("size of image", optionalHeader->SizeOfImage);
300     print_dword("size of headers", optionalHeader->SizeOfHeaders);
301     print_dword("checksum", optionalHeader->CheckSum);
302     print_subsys("Subsystem", optionalHeader->Subsystem);
303     print_dllflags("DLL characteristics:", optionalHeader->DllCharacteristics);
304     print_longlong("stack reserve size", optionalHeader->SizeOfStackReserve);
305     print_longlong("stack commit size", optionalHeader->SizeOfStackCommit);
306     print_longlong("heap reserve size", optionalHeader->SizeOfHeapReserve);
307     print_longlong("heap commit size", optionalHeader->SizeOfHeapCommit);
308     print_dword("loader flags", optionalHeader->LoaderFlags);
309     print_dword("RVAs & sizes", optionalHeader->NumberOfRvaAndSizes);
310     printf("\n");
311     print_datadirectory(optionalHeader->NumberOfRvaAndSizes, optionalHeader->DataDirectory);
312     printf("\n");
313 }
314 
315 void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *optionalHeader, UINT header_size)
316 {
317     printf("Optional Header (%s)\n", get_magic_type(optionalHeader->Magic));
318 
319     switch(optionalHeader->Magic) {
320         case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
321             dump_optional_header32(optionalHeader, header_size);
322             break;
323         case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
324             dump_optional_header64((const IMAGE_OPTIONAL_HEADER64 *)optionalHeader, header_size);
325             break;
326         default:
327             printf("  Unknown optional header magic: 0x%-4X\n", optionalHeader->Magic);
328             break;
329     }
330 }
331 
332 void dump_file_header(const IMAGE_FILE_HEADER *fileHeader)
333 {
334     printf("File Header\n");
335 
336     printf("  Machine:                      %04X (%s)\n",
337            fileHeader->Machine, get_machine_str(fileHeader->Machine));
338     printf("  Number of Sections:           %d\n", fileHeader->NumberOfSections);
339     printf("  TimeDateStamp:                %08X (%s) offset %lu\n",
340            fileHeader->TimeDateStamp, get_time_str(fileHeader->TimeDateStamp),
341            Offset(&(fileHeader->TimeDateStamp)));
342     printf("  PointerToSymbolTable:         %08X\n", fileHeader->PointerToSymbolTable);
343     printf("  NumberOfSymbols:              %08X\n", fileHeader->NumberOfSymbols);
344     printf("  SizeOfOptionalHeader:         %04X\n", fileHeader->SizeOfOptionalHeader);
345     printf("  Characteristics:              %04X\n", fileHeader->Characteristics);
346 #define X(f,s)  if (fileHeader->Characteristics & f) printf("    %s\n", s)
347     X(IMAGE_FILE_RELOCS_STRIPPED,       "RELOCS_STRIPPED");
348     X(IMAGE_FILE_EXECUTABLE_IMAGE,      "EXECUTABLE_IMAGE");
349     X(IMAGE_FILE_LINE_NUMS_STRIPPED,    "LINE_NUMS_STRIPPED");
350     X(IMAGE_FILE_LOCAL_SYMS_STRIPPED,   "LOCAL_SYMS_STRIPPED");
351     X(IMAGE_FILE_AGGRESIVE_WS_TRIM,     "AGGRESIVE_WS_TRIM");
352     X(IMAGE_FILE_LARGE_ADDRESS_AWARE,   "LARGE_ADDRESS_AWARE");
353     X(IMAGE_FILE_16BIT_MACHINE,         "16BIT_MACHINE");
354     X(IMAGE_FILE_BYTES_REVERSED_LO,     "BYTES_REVERSED_LO");
355     X(IMAGE_FILE_32BIT_MACHINE,         "32BIT_MACHINE");
356     X(IMAGE_FILE_DEBUG_STRIPPED,        "DEBUG_STRIPPED");
357     X(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP,       "REMOVABLE_RUN_FROM_SWAP");
358     X(IMAGE_FILE_NET_RUN_FROM_SWAP,     "NET_RUN_FROM_SWAP");
359     X(IMAGE_FILE_SYSTEM,                "SYSTEM");
360     X(IMAGE_FILE_DLL,                   "DLL");
361     X(IMAGE_FILE_UP_SYSTEM_ONLY,        "UP_SYSTEM_ONLY");
362     X(IMAGE_FILE_BYTES_REVERSED_HI,     "BYTES_REVERSED_HI");
363 #undef X
364     printf("\n");
365 }
366 
367 static  void    dump_pe_header(void)
368 {
369     dump_file_header(&PE_nt_headers->FileHeader);
370     dump_optional_header((const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader, PE_nt_headers->FileHeader.SizeOfOptionalHeader);
371 }
372 
373 void dump_section(const IMAGE_SECTION_HEADER *sectHead)
374 {
375         printf("  %-8.8s   VirtSize: 0x%08x  VirtAddr:  0x%08x\n",
376                sectHead->Name, sectHead->Misc.VirtualSize, sectHead->VirtualAddress);
377         printf("    raw data offs:   0x%08x  raw data size: 0x%08x\n",
378                sectHead->PointerToRawData, sectHead->SizeOfRawData);
379         printf("    relocation offs: 0x%08x  relocations:   0x%08x\n",
380                sectHead->PointerToRelocations, sectHead->NumberOfRelocations);
381         printf("    line # offs:     %-8u  line #'s:      %-8u\n",
382                sectHead->PointerToLinenumbers, sectHead->NumberOfLinenumbers);
383         printf("    characteristics: 0x%08x\n", sectHead->Characteristics);
384         printf("    ");
385 #define X(b,s)  if (sectHead->Characteristics & b) printf("  " s)
386 /* #define IMAGE_SCN_TYPE_REG                   0x00000000 - Reserved */
387 /* #define IMAGE_SCN_TYPE_DSECT                 0x00000001 - Reserved */
388 /* #define IMAGE_SCN_TYPE_NOLOAD                0x00000002 - Reserved */
389 /* #define IMAGE_SCN_TYPE_GROUP                 0x00000004 - Reserved */
390 /* #define IMAGE_SCN_TYPE_NO_PAD                0x00000008 - Reserved */
391 /* #define IMAGE_SCN_TYPE_COPY                  0x00000010 - Reserved */
392 
393         X(IMAGE_SCN_CNT_CODE,                   "CODE");
394         X(IMAGE_SCN_CNT_INITIALIZED_DATA,       "INITIALIZED_DATA");
395         X(IMAGE_SCN_CNT_UNINITIALIZED_DATA,     "UNINITIALIZED_DATA");
396 
397         X(IMAGE_SCN_LNK_OTHER,                  "LNK_OTHER");
398         X(IMAGE_SCN_LNK_INFO,                   "LNK_INFO");
399 /* #define      IMAGE_SCN_TYPE_OVER             0x00000400 - Reserved */
400         X(IMAGE_SCN_LNK_REMOVE,                 "LNK_REMOVE");
401         X(IMAGE_SCN_LNK_COMDAT,                 "LNK_COMDAT");
402 
403 /*                                              0x00002000 - Reserved */
404 /* #define IMAGE_SCN_MEM_PROTECTED              0x00004000 - Obsolete */
405         X(IMAGE_SCN_MEM_FARDATA,                "MEM_FARDATA");
406 
407 /* #define IMAGE_SCN_MEM_SYSHEAP                0x00010000 - Obsolete */
408         X(IMAGE_SCN_MEM_PURGEABLE,              "MEM_PURGEABLE");
409         X(IMAGE_SCN_MEM_16BIT,                  "MEM_16BIT");
410         X(IMAGE_SCN_MEM_LOCKED,                 "MEM_LOCKED");
411         X(IMAGE_SCN_MEM_PRELOAD,                "MEM_PRELOAD");
412 
413         switch (sectHead->Characteristics & IMAGE_SCN_ALIGN_MASK)
414         {
415 #define X2(b,s) case b: printf("  " s); break
416         X2(IMAGE_SCN_ALIGN_1BYTES,              "ALIGN_1BYTES");
417         X2(IMAGE_SCN_ALIGN_2BYTES,              "ALIGN_2BYTES");
418         X2(IMAGE_SCN_ALIGN_4BYTES,              "ALIGN_4BYTES");
419         X2(IMAGE_SCN_ALIGN_8BYTES,              "ALIGN_8BYTES");
420         X2(IMAGE_SCN_ALIGN_16BYTES,             "ALIGN_16BYTES");
421         X2(IMAGE_SCN_ALIGN_32BYTES,             "ALIGN_32BYTES");
422         X2(IMAGE_SCN_ALIGN_64BYTES,             "ALIGN_64BYTES");
423         X2(IMAGE_SCN_ALIGN_128BYTES,            "ALIGN_128BYTES");
424         X2(IMAGE_SCN_ALIGN_256BYTES,            "ALIGN_256BYTES");
425         X2(IMAGE_SCN_ALIGN_512BYTES,            "ALIGN_512BYTES");
426         X2(IMAGE_SCN_ALIGN_1024BYTES,           "ALIGN_1024BYTES");
427         X2(IMAGE_SCN_ALIGN_2048BYTES,           "ALIGN_2048BYTES");
428         X2(IMAGE_SCN_ALIGN_4096BYTES,           "ALIGN_4096BYTES");
429         X2(IMAGE_SCN_ALIGN_8192BYTES,           "ALIGN_8192BYTES");
430 #undef X2
431         }
432 
433         X(IMAGE_SCN_LNK_NRELOC_OVFL,            "LNK_NRELOC_OVFL");
434 
435         X(IMAGE_SCN_MEM_DISCARDABLE,            "MEM_DISCARDABLE");
436         X(IMAGE_SCN_MEM_NOT_CACHED,             "MEM_NOT_CACHED");
437         X(IMAGE_SCN_MEM_NOT_PAGED,              "MEM_NOT_PAGED");
438         X(IMAGE_SCN_MEM_SHARED,                 "MEM_SHARED");
439         X(IMAGE_SCN_MEM_EXECUTE,                "MEM_EXECUTE");
440         X(IMAGE_SCN_MEM_READ,                   "MEM_READ");
441         X(IMAGE_SCN_MEM_WRITE,                  "MEM_WRITE");
442 #undef X
443         printf("\n\n");
444 }
445 
446 static void dump_sections(const void *base, const void* addr, unsigned num_sect)
447 {
448     const IMAGE_SECTION_HEADER* sectHead = addr;
449     unsigned                    i;
450 
451     printf("Section Table\n");
452     for (i = 0; i < num_sect; i++, sectHead++)
453     {
454         dump_section(sectHead);
455 
456         if (globals.do_dump_rawdata)
457         {
458             dump_data((const unsigned char *)base + sectHead->PointerToRawData, sectHead->SizeOfRawData, "    " );
459             printf("\n");
460         }
461     }
462 }
463 
464 static  void    dump_dir_exported_functions(void)
465 {
466     unsigned int size = 0;
467     const IMAGE_EXPORT_DIRECTORY*exportDir = get_dir_and_size(IMAGE_FILE_EXPORT_DIRECTORY, &size);
468     unsigned int                i;
469     const DWORD*                pFunc;
470     const DWORD*                pName;
471     const WORD*                 pOrdl;
472     DWORD*                      map;
473 
474     if (!exportDir) return;
475 
476     printf("Exports table:\n");
477     printf("\n");
478     printf("  Name:            %s\n", (const char*)RVA(exportDir->Name, sizeof(DWORD)));
479     printf("  Characteristics: %08x\n", exportDir->Characteristics);
480     printf("  TimeDateStamp:   %08X %s\n",
481            exportDir->TimeDateStamp, get_time_str(exportDir->TimeDateStamp));
482     printf("  Version:         %u.%02u\n", exportDir->MajorVersion, exportDir->MinorVersion);
483     printf("  Ordinal base:    %u\n", exportDir->Base);
484     printf("  # of functions:  %u\n", exportDir->NumberOfFunctions);
485     printf("  # of Names:      %u\n", exportDir->NumberOfNames);
486     printf("Addresses of functions: %08X\n", exportDir->AddressOfFunctions);
487     printf("Addresses of name ordinals: %08X\n", exportDir->AddressOfNameOrdinals);
488     printf("Addresses of names: %08X\n", exportDir->AddressOfNames);
489     printf("\n");
490     printf("  Entry Pt  Ordn  Name\n");
491 
492     pFunc = RVA(exportDir->AddressOfFunctions, exportDir->NumberOfFunctions * sizeof(DWORD));
493     if (!pFunc) {printf("Can't grab functions' address table\n"); return;}
494     pName = RVA(exportDir->AddressOfNames, exportDir->NumberOfNames * sizeof(DWORD));
495     if (!pName) {printf("Can't grab functions' name table\n"); return;}
496     pOrdl = RVA(exportDir->AddressOfNameOrdinals, exportDir->NumberOfNames * sizeof(WORD));
497     if (!pOrdl) {printf("Can't grab functions' ordinal table\n"); return;}
498 
499     /* bit map of used funcs */
500     map = calloc(((exportDir->NumberOfFunctions + 31) & ~31) / 32, sizeof(DWORD));
501     if (!map) fatal("no memory");
502 
503     for (i = 0; i < exportDir->NumberOfNames; i++, pName++, pOrdl++)
504     {
505         map[*pOrdl / 32] |= 1 << (*pOrdl % 32);
506 
507         printf("  %08X  %4u %s", pFunc[*pOrdl], exportDir->Base + *pOrdl,
508                get_symbol_str((const char*)RVA(*pName, sizeof(DWORD))));
509         /* check for forwarded function */
510         if ((const char *)RVA(pFunc[*pOrdl],sizeof(void*)) >= (const char *)exportDir &&
511             (const char *)RVA(pFunc[*pOrdl],sizeof(void*)) < (const char *)exportDir + size)
512             printf( " (-> %s)", (const char *)RVA(pFunc[*pOrdl],1));
513         printf("\n");
514     }
515     pFunc = RVA(exportDir->AddressOfFunctions, exportDir->NumberOfFunctions * sizeof(DWORD));
516     if (!pFunc)
517     {
518         printf("Can't grab functions' address table\n");
519         free(map);
520         return;
521     }
522     for (i = 0; i < exportDir->NumberOfFunctions; i++)
523     {
524         if (pFunc[i] && !(map[i / 32] & (1 << (i % 32))))
525         {
526             printf("  %08X  %4u <by ordinal>\n", pFunc[i], exportDir->Base + i);
527         }
528     }
529     free(map);
530     printf("\n");
531 }
532 
533 static void dump_image_thunk_data64(const IMAGE_THUNK_DATA64 *il)
534 {
535     /* FIXME: This does not properly handle large images */
536     const IMAGE_IMPORT_BY_NAME* iibn;
537     for (; il->u1.Ordinal; il++)
538     {
539         if (IMAGE_SNAP_BY_ORDINAL64(il->u1.Ordinal))
540             printf("  %4u  <by ordinal>\n", (DWORD)IMAGE_ORDINAL64(il->u1.Ordinal));
541         else
542         {
543             iibn = RVA((DWORD)il->u1.AddressOfData, sizeof(DWORD));
544             if (!iibn)
545                 printf("Can't grab import by name info, skipping to next ordinal\n");
546             else
547                 printf("  %4u  %s %x\n", iibn->Hint, iibn->Name, (DWORD)il->u1.AddressOfData);
548         }
549     }
550 }
551 
552 static void dump_image_thunk_data32(const IMAGE_THUNK_DATA32 *il, int offset)
553 {
554     const IMAGE_IMPORT_BY_NAME* iibn;
555     for (; il->u1.Ordinal; il++)
556     {
557         if (IMAGE_SNAP_BY_ORDINAL32(il->u1.Ordinal))
558             printf("  %4u  <by ordinal>\n", IMAGE_ORDINAL32(il->u1.Ordinal));
559         else
560         {
561             iibn = RVA((DWORD)il->u1.AddressOfData - offset, sizeof(DWORD));
562             if (!iibn)
563                 printf("Can't grab import by name info, skipping to next ordinal\n");
564             else
565                 printf("  %4u  %s %x\n", iibn->Hint, iibn->Name, (DWORD)il->u1.AddressOfData);
566         }
567     }
568 }
569 
570 static  void    dump_dir_imported_functions(void)
571 {
572     const IMAGE_IMPORT_DESCRIPTOR       *importDesc = get_dir(IMAGE_FILE_IMPORT_DIRECTORY);
573     DWORD directorySize;
574 
575     if (!importDesc)    return;
576     if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
577     {
578         const IMAGE_OPTIONAL_HEADER64 *opt = (const IMAGE_OPTIONAL_HEADER64*)&PE_nt_headers->OptionalHeader;
579         directorySize = opt->DataDirectory[IMAGE_FILE_IMPORT_DIRECTORY].Size;
580     }
581     else
582     {
583         const IMAGE_OPTIONAL_HEADER32 *opt = (const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader;
584         directorySize = opt->DataDirectory[IMAGE_FILE_IMPORT_DIRECTORY].Size;
585     }
586 
587     printf("Import Table size: %08x\n", directorySize);/* FIXME */
588 
589     for (;;)
590     {
591         const IMAGE_THUNK_DATA32*       il;
592 
593         if (!importDesc->Name || !importDesc->FirstThunk) break;
594 
595         printf("  offset %08lx %s\n", Offset(importDesc), (const char*)RVA(importDesc->Name, sizeof(DWORD)));
596         printf("  Hint/Name Table: %08X\n", (DWORD)importDesc->u.OriginalFirstThunk);
597         printf("  TimeDateStamp:   %08X (%s)\n",
598                importDesc->TimeDateStamp, get_time_str(importDesc->TimeDateStamp));
599         printf("  ForwarderChain:  %08X\n", importDesc->ForwarderChain);
600         printf("  First thunk RVA: %08X\n", (DWORD)importDesc->FirstThunk);
601 
602         printf("  Ordn  Name\n");
603 
604         il = (importDesc->u.OriginalFirstThunk != 0) ?
605             RVA((DWORD)importDesc->u.OriginalFirstThunk, sizeof(DWORD)) :
606             RVA((DWORD)importDesc->FirstThunk, sizeof(DWORD));
607 
608         if (!il)
609             printf("Can't grab thunk data, going to next imported DLL\n");
610         else
611         {
612             if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
613                 dump_image_thunk_data64((const IMAGE_THUNK_DATA64*)il);
614             else
615                 dump_image_thunk_data32(il, 0);
616             printf("\n");
617         }
618         importDesc++;
619     }
620     printf("\n");
621 }
622 
623 static void dump_dir_delay_imported_functions(void)
624 {
625     const struct ImgDelayDescr
626     {
627         DWORD grAttrs;
628         DWORD szName;
629         DWORD phmod;
630         DWORD pIAT;
631         DWORD pINT;
632         DWORD pBoundIAT;
633         DWORD pUnloadIAT;
634         DWORD dwTimeStamp;
635     } *importDesc = get_dir(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT);
636     DWORD directorySize;
637 
638     if (!importDesc) return;
639     if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
640     {
641         const IMAGE_OPTIONAL_HEADER64 *opt = (const IMAGE_OPTIONAL_HEADER64 *)&PE_nt_headers->OptionalHeader;
642         directorySize = opt->DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size;
643     }
644     else
645     {
646         const IMAGE_OPTIONAL_HEADER32 *opt = (const IMAGE_OPTIONAL_HEADER32 *)&PE_nt_headers->OptionalHeader;
647         directorySize = opt->DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size;
648     }
649 
650     printf("Delay Import Table size: %08x\n", directorySize); /* FIXME */
651 
652     for (;;)
653     {
654         const IMAGE_THUNK_DATA32*       il;
655         int                             offset = (importDesc->grAttrs & 1) ? 0 : PE_nt_headers->OptionalHeader.ImageBase;
656 
657         if (!importDesc->szName || !importDesc->pIAT || !importDesc->pINT) break;
658 
659         printf("  grAttrs %08x offset %08lx %s\n", importDesc->grAttrs, Offset(importDesc),
660                (const char *)RVA(importDesc->szName - offset, sizeof(DWORD)));
661         printf("  Hint/Name Table: %08x\n", importDesc->pINT);
662         printf("  TimeDateStamp:   %08X (%s)\n",
663                importDesc->dwTimeStamp, get_time_str(importDesc->dwTimeStamp));
664 
665         printf("  Ordn  Name\n");
666 
667         il = (const IMAGE_THUNK_DATA32 *)RVA(importDesc->pINT - offset, sizeof(DWORD));
668 
669         if (!il)
670             printf("Can't grab thunk data, going to next imported DLL\n");
671         else
672         {
673             if (PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
674                 dump_image_thunk_data64((const IMAGE_THUNK_DATA64 *)il);
675             else
676                 dump_image_thunk_data32(il, offset);
677             printf("\n");
678         }
679         importDesc++;
680     }
681     printf("\n");
682 }
683 
684 static  void    dump_dir_debug_dir(const IMAGE_DEBUG_DIRECTORY* idd, int idx)
685 {
686     const       char*   str;
687 
688     printf("Directory %02u\n", idx + 1);
689     printf("  Characteristics:   %08X\n", idd->Characteristics);
690     printf("  TimeDateStamp:     %08X %s\n",
691            idd->TimeDateStamp, get_time_str(idd->TimeDateStamp));
692     printf("  Version            %u.%02u\n", idd->MajorVersion, idd->MinorVersion);
693     switch (idd->Type)
694     {
695     default:
696     case IMAGE_DEBUG_TYPE_UNKNOWN:      str = "UNKNOWN";        break;
697     case IMAGE_DEBUG_TYPE_COFF:         str = "COFF";           break;
698     case IMAGE_DEBUG_TYPE_CODEVIEW:     str = "CODEVIEW";       break;
699     case IMAGE_DEBUG_TYPE_FPO:          str = "FPO";            break;
700     case IMAGE_DEBUG_TYPE_MISC:         str = "MISC";           break;
701     case IMAGE_DEBUG_TYPE_EXCEPTION:    str = "EXCEPTION";      break;
702     case IMAGE_DEBUG_TYPE_FIXUP:        str = "FIXUP";          break;
703     case IMAGE_DEBUG_TYPE_OMAP_TO_SRC:  str = "OMAP_TO_SRC";    break;
704     case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC:str = "OMAP_FROM_SRC";  break;
705     case IMAGE_DEBUG_TYPE_BORLAND:      str = "BORLAND";        break;
706     case IMAGE_DEBUG_TYPE_RESERVED10:   str = "RESERVED10";     break;
707     }
708     printf("  Type:              %u (%s)\n", idd->Type, str);
709     printf("  SizeOfData:        %u\n", idd->SizeOfData);
710     printf("  AddressOfRawData:  %08X\n", idd->AddressOfRawData);
711     printf("  PointerToRawData:  %08X\n", idd->PointerToRawData);
712 
713     switch (idd->Type)
714     {
715     case IMAGE_DEBUG_TYPE_UNKNOWN:
716         break;
717     case IMAGE_DEBUG_TYPE_COFF:
718         dump_coff(idd->PointerToRawData, idd->SizeOfData, 
719                   (const char*)PE_nt_headers + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + PE_nt_headers->FileHeader.SizeOfOptionalHeader);
720         break;
721     case IMAGE_DEBUG_TYPE_CODEVIEW:
722         dump_codeview(idd->PointerToRawData, idd->SizeOfData);
723         break;
724     case IMAGE_DEBUG_TYPE_FPO:
725         dump_frame_pointer_omission(idd->PointerToRawData, idd->SizeOfData);
726         break;
727     case IMAGE_DEBUG_TYPE_MISC:
728     {
729         const IMAGE_DEBUG_MISC* misc = PRD(idd->PointerToRawData, idd->SizeOfData);
730         if (!misc) {printf("Can't get misc debug information\n"); break;}
731         printf("    DataType:          %u (%s)\n",
732                misc->DataType,
733                (misc->DataType == IMAGE_DEBUG_MISC_EXENAME) ? "Exe name" : "Unknown");
734         printf("    Length:            %u\n", misc->Length);
735         printf("    Unicode:           %s\n", misc->Unicode ? "Yes" : "No");
736         printf("    Data:              %s\n", misc->Data);
737     }
738     break;
739     case IMAGE_DEBUG_TYPE_EXCEPTION:
740         break;
741     case IMAGE_DEBUG_TYPE_FIXUP:
742         break;
743     case IMAGE_DEBUG_TYPE_OMAP_TO_SRC:
744         break;
745     case IMAGE_DEBUG_TYPE_OMAP_FROM_SRC:
746         break;
747     case IMAGE_DEBUG_TYPE_BORLAND:
748         break;
749     case IMAGE_DEBUG_TYPE_RESERVED10:
750         break;
751     }
752     printf("\n");
753 }
754 
755 static void     dump_dir_debug(void)
756 {
757     const IMAGE_DEBUG_DIRECTORY*debugDir = get_dir(IMAGE_FILE_DEBUG_DIRECTORY);
758     unsigned                    nb_dbg, i;
759 
760     if (!debugDir) return;
761     nb_dbg = PE_nt_headers->OptionalHeader.DataDirectory[IMAGE_FILE_DEBUG_DIRECTORY].Size /
762         sizeof(*debugDir);
763     if (!nb_dbg) return;
764 
765     printf("Debug Table (%u directories)\n", nb_dbg);
766 
767     for (i = 0; i < nb_dbg; i++)
768     {
769         dump_dir_debug_dir(debugDir, i);
770         debugDir++;
771     }
772     printf("\n");
773 }
774 
775 static inline void print_clrflags(const char *title, WORD value)
776 {
777     printf("  %-34s 0x%X\n", title, value);
778 #define X(f,s) if (value & f) printf("    %s\n", s)
779     X(COMIMAGE_FLAGS_ILONLY,           "ILONLY");
780     X(COMIMAGE_FLAGS_32BITREQUIRED,    "32BITREQUIRED");
781     X(COMIMAGE_FLAGS_IL_LIBRARY,       "IL_LIBRARY");
782     X(COMIMAGE_FLAGS_STRONGNAMESIGNED, "STRONGNAMESIGNED");
783     X(COMIMAGE_FLAGS_TRACKDEBUGDATA,   "TRACKDEBUGDATA");
784 #undef X
785 }
786 
787 static inline void print_clrdirectory(const char *title, const IMAGE_DATA_DIRECTORY *dir)
788 {
789     printf("  %-23s rva: 0x%-8x  size: 0x%-8x\n", title, dir->VirtualAddress, dir->Size);
790 }
791 
792 static void dump_dir_clr_header(void)
793 {
794     unsigned int size = 0;
795     const IMAGE_COR20_HEADER *dir = get_dir_and_size(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, &size);
796 
797     if (!dir) return;
798 
799     printf( "CLR Header\n" );
800     print_dword( "Header Size", dir->cb );
801     print_ver( "Required runtime version", dir->MajorRuntimeVersion, dir->MinorRuntimeVersion );
802     print_clrflags( "Flags", dir->Flags );
803     print_dword( "EntryPointToken", dir->EntryPointToken );
804     printf("\n");
805     printf( "CLR Data Directory\n" );
806     print_clrdirectory( "MetaData", &dir->MetaData );
807     print_clrdirectory( "Resources", &dir->Resources );
808     print_clrdirectory( "StrongNameSignature", &dir->StrongNameSignature );
809     print_clrdirectory( "CodeManagerTable", &dir->CodeManagerTable );
810     print_clrdirectory( "VTableFixups", &dir->VTableFixups );
811     print_clrdirectory( "ExportAddressTableJumps", &dir->ExportAddressTableJumps );
812     print_clrdirectory( "ManagedNativeHeader", &dir->ManagedNativeHeader );
813     printf("\n");
814 }
815 
816 static void dump_dir_tls(void)
817 {
818     IMAGE_TLS_DIRECTORY64 dir;
819     const DWORD *callbacks;
820     const IMAGE_TLS_DIRECTORY32 *pdir = get_dir(IMAGE_FILE_THREAD_LOCAL_STORAGE);
821 
822     if (!pdir) return;
823 
824     if(PE_nt_headers->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
825         memcpy(&dir, pdir, sizeof(dir));
826     else
827     {
828         dir.StartAddressOfRawData = pdir->StartAddressOfRawData;
829         dir.EndAddressOfRawData = pdir->EndAddressOfRawData;
830         dir.AddressOfIndex = pdir->AddressOfIndex;
831         dir.AddressOfCallBacks = pdir->AddressOfCallBacks;
832         dir.SizeOfZeroFill = pdir->SizeOfZeroFill;
833         dir.Characteristics = pdir->Characteristics;
834     }
835 
836     /* FIXME: This does not properly handle large images */
837     printf( "Thread Local Storage\n" );
838     printf( "  Raw data        %08x-%08x (data size %x zero fill size %x)\n",
839             (DWORD)dir.StartAddressOfRawData, (DWORD)dir.EndAddressOfRawData,
840             (DWORD)(dir.EndAddressOfRawData - dir.StartAddressOfRawData),
841             (DWORD)dir.SizeOfZeroFill );
842     printf( "  Index address   %08x\n", (DWORD)dir.AddressOfIndex );
843     printf( "  Characteristics %08x\n", dir.Characteristics );
844     printf( "  Callbacks       %08x -> {", (DWORD)dir.AddressOfCallBacks );
845     if (dir.AddressOfCallBacks)
846     {
847         DWORD   addr = (DWORD)dir.AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase;
848         while ((callbacks = RVA(addr, sizeof(DWORD))) && *callbacks)
849         {
850             printf( " %08x", *callbacks );
851             addr += sizeof(DWORD);
852         }
853     }
854     printf(" }\n\n");
855 }
856 
857 enum FileSig get_kind_dbg(void)
858 {
859     const WORD*                pw;
860 
861     pw = PRD(0, sizeof(WORD));
862     if (!pw) {printf("Can't get main signature, aborting\n"); return 0;}
863 
864     if (*pw == 0x4944 /* "DI" */) return SIG_DBG;
865     return SIG_UNKNOWN;
866 }
867 
868 void    dbg_dump(void)
869 {
870     const IMAGE_SEPARATE_DEBUG_HEADER*  separateDebugHead;
871     unsigned                            nb_dbg;
872     unsigned                            i;
873     const IMAGE_DEBUG_DIRECTORY*        debugDir;
874 
875     separateDebugHead = PRD(0, sizeof(separateDebugHead));
876     if (!separateDebugHead) {printf("Can't grab the separate header, aborting\n"); return;}
877 
878     printf ("Signature:          %.2s (0x%4X)\n",
879             (const char*)&separateDebugHead->Signature, separateDebugHead->Signature);
880     printf ("Flags:              0x%04X\n", separateDebugHead->Flags);
881     printf ("Machine:            0x%04X (%s)\n",
882             separateDebugHead->Machine, get_machine_str(separateDebugHead->Machine));
883     printf ("Characteristics:    0x%04X\n", separateDebugHead->Characteristics);
884     printf ("TimeDateStamp:      0x%08X (%s)\n",
885             separateDebugHead->TimeDateStamp, get_time_str(separateDebugHead->TimeDateStamp));
886     printf ("CheckSum:           0x%08X\n", separateDebugHead->CheckSum);
887     printf ("ImageBase:          0x%08X\n", separateDebugHead->ImageBase);
888     printf ("SizeOfImage:        0x%08X\n", separateDebugHead->SizeOfImage);
889     printf ("NumberOfSections:   0x%08X\n", separateDebugHead->NumberOfSections);
890     printf ("ExportedNamesSize:  0x%08X\n", separateDebugHead->ExportedNamesSize);
891     printf ("DebugDirectorySize: 0x%08X\n", separateDebugHead->DebugDirectorySize);
892 
893     if (!PRD(sizeof(IMAGE_SEPARATE_DEBUG_HEADER),
894              separateDebugHead->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)))
895     {printf("Can't get the sec