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