Initial revision
[reactos.git] / freeldr / freeldr / pe.h
1
2 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
3
4 #define IMAGE_SECTION_CHAR_CODE 0x00000020
5 #define IMAGE_SECTION_CHAR_DATA 0x00000040
6 #define IMAGE_SECTION_CHAR_BSS 0x00000080
7 #define IMAGE_SECTION_CHAR_NON_CACHABLE 0x04000000
8 #define IMAGE_SECTION_CHAR_NON_PAGEABLE 0x08000000
9 #define IMAGE_SECTION_CHAR_SHARED 0x10000000
10 #define IMAGE_SECTION_CHAR_EXECUTABLE 0x20000000
11 #define IMAGE_SECTION_CHAR_READABLE 0x40000000
12 #define IMAGE_SECTION_CHAR_WRITABLE 0x80000000
13
14
15 #define IMAGE_DOS_MAGIC 0x5a4d
16 #define IMAGE_PE_MAGIC 0x00004550
17
18 typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
19 WORD e_magic; // Magic number
20 WORD e_cblp; // Bytes on last page of file
21 WORD e_cp; // Pages in file
22 WORD e_crlc; // Relocations
23 WORD e_cparhdr; // Size of header in paragraphs
24 WORD e_minalloc; // Minimum extra paragraphs needed
25 WORD e_maxalloc; // Maximum extra paragraphs needed
26 WORD e_ss; // Initial (relative) SS value
27 WORD e_sp; // Initial SP value
28 WORD e_csum; // Checksum
29 WORD e_ip; // Initial IP value
30 WORD e_cs; // Initial (relative) CS value
31 WORD e_lfarlc; // File address of relocation table
32 WORD e_ovno; // Overlay number
33 WORD e_res[4]; // Reserved words
34 WORD e_oemid; // OEM identifier (for e_oeminfo)
35 WORD e_oeminfo; // OEM information; e_oemid specific
36 WORD e_res2[10]; // Reserved words
37 LONG e_lfanew; // File address of new exe header
38 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
39
40 typedef struct _IMAGE_FILE_HEADER {
41 WORD Machine;
42 WORD NumberOfSections;
43 DWORD TimeDateStamp;
44 DWORD PointerToSymbolTable;
45 DWORD NumberOfSymbols;
46 WORD SizeOfOptionalHeader;
47 WORD Characteristics;
48 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
49
50 #define IMAGE_SIZEOF_FILE_HEADER 20
51
52 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
53 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
54 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
55 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
56 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
57 #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
58 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
59 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
60 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
61 #define IMAGE_FILE_SYSTEM 0x1000 // System File.
62 #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
63 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
64 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
65
66 #define IMAGE_FILE_MACHINE_UNKNOWN 0
67 #define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
68 #define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0x160 big-endian
69 #define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
70 #define IMAGE_FILE_MACHINE_R10000 0x168 // MIPS little-endian
71 #define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
72 #define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian
73
74
75 //
76 // Directory format.
77 //
78
79 typedef struct _IMAGE_DATA_DIRECTORY {
80 DWORD VirtualAddress;
81 DWORD Size;
82 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
83
84 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
85
86 //
87 // Optional header format.
88 //
89
90 typedef struct _IMAGE_OPTIONAL_HEADER {
91 //
92 // Standard fields.
93 //
94
95 WORD Magic;
96 BYTE MajorLinkerVersion;
97 BYTE MinorLinkerVersion;
98 DWORD SizeOfCode;
99 DWORD SizeOfInitializedData;
100 DWORD SizeOfUninitializedData;
101 DWORD AddressOfEntryPoint;
102 DWORD BaseOfCode;
103 DWORD BaseOfData;
104
105 //
106 // NT additional fields.
107 //
108
109 DWORD ImageBase;
110 DWORD SectionAlignment;
111 DWORD FileAlignment;
112 WORD MajorOperatingSystemVersion;
113 WORD MinorOperatingSystemVersion;
114 WORD MajorImageVersion;
115 WORD MinorImageVersion;
116 WORD MajorSubsystemVersion;
117 WORD MinorSubsystemVersion;
118 DWORD Win32VersionValue;
119 DWORD SizeOfImage;
120 DWORD SizeOfHeaders;
121 DWORD CheckSum;
122 WORD Subsystem;
123 WORD DllCharacteristics;
124 DWORD SizeOfStackReserve;
125 DWORD SizeOfStackCommit;
126 DWORD SizeOfHeapReserve;
127 DWORD SizeOfHeapCommit;
128 DWORD LoaderFlags;
129 DWORD NumberOfRvaAndSizes;
130 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
131 } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
132
133 #define IMAGE_SUBSYSTEM_UNKNOWN 0
134 #define IMAGE_SUBSYSTEM_NATIVE 1
135 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
136 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
137 #define IMAGE_SUBSYSTEM_OS2_GUI 4
138 #define IMAGE_SUBSYSTEM_OS2_CUI 5
139 #define IMAGE_SUBSYSTEM_POSIX_GUI 6
140 #define IMAGE_SUBSYSTEM_POSIX_CUI 7
141 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
142
143 typedef struct _IMAGE_NT_HEADERS {
144 DWORD Signature;
145 IMAGE_FILE_HEADER FileHeader;
146 IMAGE_OPTIONAL_HEADER OptionalHeader;
147 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
148
149
150 // Directory Entries
151
152 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
153 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
154 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
155 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
156 #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
157 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
158 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
159 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
160 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
161 #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
162 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
163 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
164 #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address
165 //
166 // Section header format.
167 //
168
169 #define IMAGE_SIZEOF_SHORT_NAME 8
170
171 typedef struct _IMAGE_SECTION_HEADER {
172 BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
173 union {
174 DWORD PhysicalAddress;
175 DWORD VirtualSize;
176 } Misc;
177 DWORD VirtualAddress;
178 DWORD SizeOfRawData;
179 DWORD PointerToRawData;
180 DWORD PointerToRelocations;
181 DWORD PointerToLinenumbers;
182 WORD NumberOfRelocations;
183 WORD NumberOfLinenumbers;
184 DWORD Characteristics;
185 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
186
187 #define IMAGE_SIZEOF_SECTION_HEADER 40
188
189 #define IMAGE_SECTION_CODE (0x20)
190 #define IMAGE_SECTION_INITIALIZED_DATA (0x40)
191 #define IMAGE_SECTION_UNINITIALIZED_DATA (0x80)
192
193 //
194 // Export Format
195 //
196
197 typedef struct _IMAGE_EXPORT_DIRECTORY {
198 DWORD Characteristics;
199 DWORD TimeDateStamp;
200 WORD MajorVersion;
201 WORD MinorVersion;
202 DWORD Name;
203 DWORD Base;
204 DWORD NumberOfFunctions;
205 DWORD NumberOfNames;
206 PDWORD *AddressOfFunctions;
207 PDWORD *AddressOfNames;
208 PWORD *AddressOfNameOrdinals;
209 } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
210
211 //
212 // Import Format
213 //
214
215 typedef struct _IMAGE_IMPORT_BY_NAME {
216 WORD Hint;
217 BYTE Name[1];
218 } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
219
220 #define IMAGE_ORDINAL_FLAG 0x80000000
221 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
222
223
224 // Predefined resource types ... there may be some more, but I don't have
225 // the information yet. .....sang cho.....
226
227 #define RT_NEWRESOURCE 0x2000
228 #define RT_ERROR 0x7fff
229 #define NEWBITMAP (RT_BITMAP|RT_NEWRESOURCE)
230 #define NEWMENU (RT_MENU|RT_NEWRESOURCE)
231 #define NEWDIALOG (RT_DIALOG|RT_NEWRESOURCE)
232
233
234 //
235 // Resource Format.
236 //
237
238 //
239 // Resource directory consists of two counts, following by a variable length
240 // array of directory entries. The first count is the number of entries at
241 // beginning of the array that have actual names associated with each entry.
242 // The entries are in ascending order, case insensitive strings. The second
243 // count is the number of entries that immediately follow the named entries.
244 // This second count identifies the number of entries that have 16-bit integer
245 // Ids as their name. These entries are also sorted in ascending order.
246 //
247 // This structure allows fast lookup by either name or number, but for any
248 // given resource entry only one form of lookup is supported, not both.
249 // This is consistant with the syntax of the .RC file and the .RES file.
250 //
251
252
253 //
254 // Each directory contains the 32-bit Name of the entry and an offset,
255 // relative to the beginning of the resource directory of the data associated
256 // with this directory entry. If the name of the entry is an actual text
257 // string instead of an integer Id, then the high order bit of the name field
258 // is set to one and the low order 31-bits are an offset, relative to the
259 // beginning of the resource directory of the string, which is of type
260 // IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
261 // low-order 16-bits are the integer Id that identify this resource directory
262 // entry. If the directory entry is yet another resource directory (i.e. a
263 // subdirectory), then the high order bit of the offset field will be
264 // set to indicate this. Otherwise the high bit is clear and the offset
265 // field points to a resource data entry.
266 //
267
268 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
269 DWORD Name;
270 DWORD OffsetToData;
271 } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
272
273
274 typedef struct _IMAGE_RESOURCE_DIRECTORY {
275 DWORD Characteristics;
276 DWORD TimeDateStamp;
277 WORD MajorVersion;
278 WORD MinorVersion;
279 WORD NumberOfNamedEntries;
280 WORD NumberOfIdEntries;
281 IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[0];
282 } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
283
284 #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
285 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
286
287
288
289 //
290 // For resource directory entries that have actual string names, the Name
291 // field of the directory entry points to an object of the following type.
292 // All of these string objects are stored together after the last resource
293 // directory entry and before the first resource data object. This minimizes
294 // the impact of these variable length objects on the alignment of the fixed
295 // size directory entry objects.
296 //
297
298 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
299 WORD Length;
300 CHAR NameString[ 1 ];
301 } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
302
303
304 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
305 WORD Length;
306 WCHAR NameString[ 1 ];
307 } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
308
309
310 //
311 // Each resource data entry describes a leaf node in the resource directory
312 // tree. It contains an offset, relative to the beginning of the resource
313 // directory of the data for the resource, a size field that gives the number
314 // of bytes of data at that offset, a CodePage that should be used when
315 // decoding code point values within the resource data. Typically for new
316 // applications the code page would be the unicode code page.
317 //
318
319 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
320 DWORD OffsetToData;
321 DWORD Size;
322 DWORD CodePage;
323 DWORD Reserved;
324 } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
325
326
327 // Menu Resources ... added by .....sang cho....
328
329 // Menu resources are composed of a menu header followed by a sequential list
330 // of menu items. There are two types of menu items: pop-ups and normal menu
331 // itmes. The MENUITEM SEPARATOR is a special case of a normal menu item with
332 // an empty name, zero ID, and zero flags.
333
334 typedef struct _IMAGE_MENU_HEADER{
335 WORD wVersion; // Currently zero
336 WORD cbHeaderSize; // Also zero
337 } IMAGE_MENU_HEADER, *PIMAGE_MENU_HEADER;
338
339 typedef struct _IMAGE_POPUP_MENU_ITEM{
340 WORD fItemFlags;
341 WCHAR szItemText[1];
342 } IMAGE_POPUP_MENU_ITEM, *PIMAGE_POPUP_MENU_ITEM;
343
344 typedef struct _IMAGE_NORMAL_MENU_ITEM{
345 WORD fItemFlags;
346 WORD wMenuID;
347 WCHAR szItemText[1];
348 } IMAGE_NORMAL_MENU_ITEM, *PIMAGE_NORMAL_MENU_ITEM;
349
350 #define MI_GRAYED 0x0001 // GRAYED keyword
351 #define MI_INACTIVE 0x0002 // INACTIVE keyword
352 #define MI_BITMAP 0x0004 // BITMAP keyword
353 #define MI_OWNERDRAW 0x0100 // OWNERDRAW keyword
354 #define MI_CHECKED 0x0008 // CHECKED keyword
355 #define MI_POPUP 0x0010 // used internally
356 #define MI_MENUBARBREAK 0x0020 // MENUBARBREAK keyword
357 #define MI_MENUBREAK 0x0040 // MENUBREAK keyword
358 #define MI_ENDMENU 0x0080 // used internally
359
360 // Dialog Box Resources .................. added by sang cho.
361
362 // A dialog box is contained in a single resource and has a header and
363 // a portion repeated for each control in the dialog box.
364 // The item DWORD IStyle is a standard window style composed of flags found
365 // in WINDOWS.H.
366 // The default style for a dialog box is:
367 // WS_POPUP | WS_BORDER | WS_SYSMENU
368 //
369 // The itme marked "Name or Ordinal" are :
370 // If the first word is an 0xffff, the next two bytes contain an ordinal ID.
371 // Otherwise, the first one or more WORDS contain a double-null-terminated string.
372 // An empty string is represented by a single WORD zero in the first location.
373 //
374 // The WORD wPointSize and WCHAR szFontName entries are present if the FONT
375 // statement was included for the dialog box. This can be detected by checking
376 // the entry IStyle. If IStyle & DS_SETFONT ( which is 0x40), then these
377 // entries will be present.
378
379 typedef struct _IMAGE_DIALOG_BOX_HEADER1{
380 DWORD IStyle;
381 DWORD IExtendedStyle; // New for Windows NT
382 WORD nControls; // Number of Controls
383 WORD x;
384 WORD y;
385 WORD cx;
386 WORD cy;
387 // N_OR_O MenuName; // Name or Ordinal ID
388 // N_OR_O ClassName; // Name or Ordinal ID
389 // WCHAR szCaption[];
390 // WORD wPointSize; // Only here if FONT set for dialog
391 // WCHAR szFontName[]; // This too
392 } IMAGE_DIALOG_HEADER, *PIMAGE_DIALOG_HEADER;
393
394 typedef union _NAME_OR_ORDINAL{ // Name or Ordinal ID
395 struct _ORD_ID{
396 WORD flgId;
397 WORD Id;
398 } ORD_ID;
399 WCHAR szName[1];
400 } NAME_OR_ORDINAL, *PNAME_OR_ORDINAL;
401
402 // The data for each control starts on a DWORD boundary (which may require
403 // some padding from the previous control), and its format is as follows:
404
405 typedef struct _IMAGE_CONTROL_DATA{
406 DWORD IStyle;
407 DWORD IExtendedStyle;
408 WORD x;
409 WORD y;
410 WORD cx;
411 WORD cy;
412 WORD wId;
413 // N_OR_O ClassId;
414 // N_OR_O Text;
415 // WORD nExtraStuff;
416 } IMAGE_CONTROL_DATA, *PIMAGE_CONTROL_DATA;
417
418 #define BUTTON 0x80
419 #define EDIT 0x81
420 #define STATIC 0x82
421 #define LISTBOX 0x83
422 #define SCROLLBAR 0x84
423 #define COMBOBOX 0x85
424
425 // The various statements used in a dialog script are all mapped to these
426 // classes along with certain modifying styles. The values for these styles
427 // can be found in WINDOWS.H. All dialog controls have the default styles
428 // of WS_CHILD and WS_VISIBLE. A list of the default styles used follows:
429 //
430 // Statement Default Class Default Styles
431 // CONTROL None WS_CHILD|WS_VISIBLE
432 // LTEXT STATIC ES_LEFT
433 // RTEXT STATIC ES_RIGHT
434 // CTEXT STATIC ES_CENTER
435 // LISTBOX LISTBOX WS_BORDER|LBS_NOTIFY
436 // CHECKBOX BUTTON BS_CHECKBOX|WS_TABSTOP
437 // PUSHBUTTON BUTTON BS_PUSHBUTTON|WS_TABSTOP
438 // GROUPBOX BUTTON BS_GROUPBOX
439 // DEFPUSHBUTTON BUTTON BS_DFPUSHBUTTON|WS_TABSTOP
440 // RADIOBUTTON BUTTON BS_RADIOBUTTON
441 // AUTOCHECKBOX BUTTON BS_AUTOCHECKBOX
442 // AUTO3STATE BUTTON BS_AUTO3STATE
443 // AUTORADIOBUTTON BUTTON BS_AUTORADIOBUTTON
444 // PUSHBOX BUTTON BS_PUSHBOX
445 // STATE3 BUTTON BS_3STATE
446 // EDITTEXT EDIT ES_LEFT|WS_BORDER|WS_TABSTOP
447 // COMBOBOX COMBOBOX None
448 // ICON STATIC SS_ICON
449 // SCROLLBAR SCROLLBAR None
450 ///
451
452 //
453 // Debug Format
454 //
455
456 typedef struct _IMAGE_DEBUG_DIRECTORY {
457 DWORD Characteristics;
458 DWORD TimeDateStamp;
459 WORD MajorVersion;
460 WORD MinorVersion;
461 DWORD Type;
462 DWORD SizeOfData;
463 DWORD AddressOfRawData;
464 DWORD PointerToRawData;
465 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
466
467 #define IMAGE_DEBUG_TYPE_UNKNOWN 0
468 #define IMAGE_DEBUG_TYPE_COFF 1
469 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
470 #define IMAGE_DEBUG_TYPE_FPO 3
471 #define IMAGE_DEBUG_TYPE_MISC 4
472 #define IMAGE_DEBUG_TYPE_EXCEPTION 5
473 #define IMAGE_DEBUG_TYPE_FIXUP 6
474 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
475 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
476
477
478 typedef struct _IMAGE_DEBUG_MISC {
479 DWORD DataType; // type of misc data, see defines
480 DWORD Length; // total length of record, rounded to four
481 // byte multiple.
482 BOOL Unicode; // TRUE if data is unicode string
483 BYTE Reserved[ 3 ];
484 BYTE Data[ 1 ]; // Actual data
485 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
486
487
488 //
489 // Debugging information can be stripped from an image file and placed
490 // in a separate .DBG file, whose file name part is the same as the
491 // image file name part (e.g. symbols for CMD.EXE could be stripped
492 // and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
493 // flag in the Characteristics field of the file header. The beginning of
494 // the .DBG file contains the following structure which captures certain
495 // information from the image file. This allows a debug to proceed even if
496 // the original image file is not accessable. This header is followed by
497 // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
498 // IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
499 // the image file contain file offsets relative to the beginning of the
500 // .DBG file.
501 //
502 // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
503 // is left in the image file, but not mapped. This allows a debugger to
504 // compute the name of the .DBG file, from the name of the image in the
505 // IMAGE_DEBUG_MISC structure.
506 //
507
508 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
509 WORD Signature;
510 WORD Flags;
511 WORD Machine;
512 WORD Characteristics;
513 DWORD TimeDateStamp;
514 DWORD CheckSum;
515 DWORD ImageBase;
516 DWORD SizeOfImage;
517 DWORD NumberOfSections;
518 DWORD ExportedNamesSize;
519 DWORD DebugDirectorySize;
520 DWORD SectionAlignment;
521 DWORD Reserved[2];
522 } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
523
524 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
525
526 #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
527 #define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
528 // old checksum didn't match.
529
530 //
531 // End Image Format
532 //
533
534 #define SIZE_OF_NT_SIGNATURE sizeof (DWORD)
535 #define MAXRESOURCENAME 13
536
537 /* global macros to define header offsets into file */
538 /* offset to PE file signature */
539 #define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
540 ((PIMAGE_DOS_HEADER)a)->e_lfanew))
541
542 /* DOS header identifies the NT PEFile signature dword
543 the PEFILE header exists just after that dword */
544 #define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
545 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
546 SIZE_OF_NT_SIGNATURE))
547
548 /* PE optional header is immediately after PEFile header */
549 #define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
550 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
551 SIZE_OF_NT_SIGNATURE + \
552 sizeof (IMAGE_FILE_HEADER)))
553
554 /* section headers are immediately after PE optional header */
555 #define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
556 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
557 SIZE_OF_NT_SIGNATURE + \
558 sizeof (IMAGE_FILE_HEADER) + \
559 sizeof (IMAGE_OPTIONAL_HEADER)))
560
561 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD)(ptr) + (DWORD)(addValue))
562
563 typedef struct _IMAGE_IMPORT_MODULE_DIRECTORY
564 {
565 DWORD dwRVAFunctionNameList;
566 DWORD dwUseless1;
567 DWORD dwUseless2;
568 DWORD dwRVAModuleName;
569 DWORD dwRVAFunctionAddressList;
570 } IMAGE_IMPORT_MODULE_DIRECTORY, *PIMAGE_IMPORT_MODULE_DIRECTORY;
571
572 typedef struct _RELOCATION_DIRECTORY
573 {
574 DWORD VirtualAddress; /* adresse virtuelle du bloc ou se font les relocations */
575 DWORD SizeOfBlock; // taille de cette structure + des structures
576 // relocation_entry qui suivent (ces dernieres sont
577 // donc au nombre de (SizeOfBlock-8)/2
578 } RELOCATION_DIRECTORY, *PRELOCATION_DIRECTORY;
579
580 typedef struct _RELOCATION_ENTRY
581 {
582 WORD TypeOffset;
583 // (TypeOffset >> 12) est le type
584 // (TypeOffset&0xfff) est l'offset dans le bloc
585 } RELOCATION_ENTRY, *PRELOCATION_ENTRY;
586
587 #define TYPE_RELOC_ABSOLUTE 0
588 #define TYPE_RELOC_HIGH 1
589 #define TYPE_RELOC_LOW 2
590 #define TYPE_RELOC_HIGHLOW 3
591 #define TYPE_RELOC_HIGHADJ 4
592 #define TYPE_RELOC_MIPS_JMPADDR 5
593