09a2f84f961d14a4dcaf12591ded440df2d91a34
[reactos.git] / reactos / include / pe.h
1 #ifndef __INCLUDE_PE_H
2 #define __INCLUDE_PE_H
3
4 //#define _ANONYMOUS_UNION __extension__
5 //#define _ANONYMOUS_STRUCT __extension__
6
7 #ifdef __GNUC__
8 #ifndef NONAMELESSUNION
9 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
10 #define _ANONYMOUS_UNION __extension__
11 #define _ANONYMOUS_STRUCT __extension__
12 #else
13 #if defined(__cplusplus)
14 #define _ANONYMOUS_UNION __extension__
15 #endif
16 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */
17 #endif /* NONAMELESSUNION */
18 #else
19 #define _ANONYMOUS_UNION
20 #define _ANONYMOUS_STRUCT
21 #endif /* __GNUC__ */
22
23
24 #ifndef NTAPI
25 #define NTAPI STDCALL
26 #endif
27
28 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
29 #define IMAGE_SIZEOF_SHORT_NAME 8
30 #define IMAGE_SIZEOF_SYMBOL 18
31
32 #ifndef __USE_W32API
33
34 #define IMAGE_DOS_SIGNATURE 0x5a4d
35 #define IMAGE_OS2_SIGNATURE 0x454e
36 #define IMAGE_OS2_SIGNATURE_LE 0x454c
37 #define IMAGE_VXD_SIGNATURE 0x454c
38
39 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
40 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
41 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
42 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
43 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
44 #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
45 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
46 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
47 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
48 #define IMAGE_FILE_SYSTEM 0x1000 // System File.
49 #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
50 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
51 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
52
53 #define IMAGE_FILE_MACHINE_UNKNOWN 0
54 #define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
55 #define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0x160 big-endian
56 #define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
57 #define IMAGE_FILE_MACHINE_R10000 0x168 // MIPS little-endian
58 #define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
59 #define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian
60
61 #pragma pack(push,4)
62 typedef struct _IMAGE_FILE_HEADER {
63 WORD Machine;
64 WORD NumberOfSections;
65 DWORD TimeDateStamp;
66 DWORD PointerToSymbolTable;
67 DWORD NumberOfSymbols;
68 WORD SizeOfOptionalHeader;
69 WORD Characteristics;
70 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
71 typedef struct _IMAGE_DATA_DIRECTORY {
72 DWORD VirtualAddress;
73 DWORD Size;
74 } IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY;
75 typedef struct _IMAGE_OPTIONAL_HEADER {
76 WORD Magic;
77 BYTE MajorLinkerVersion;
78 BYTE MinorLinkerVersion;
79 DWORD SizeOfCode;
80 DWORD SizeOfInitializedData;
81 DWORD SizeOfUninitializedData;
82 DWORD AddressOfEntryPoint;
83 DWORD BaseOfCode;
84 DWORD BaseOfData;
85 DWORD ImageBase;
86 DWORD SectionAlignment;
87 DWORD FileAlignment;
88 WORD MajorOperatingSystemVersion;
89 WORD MinorOperatingSystemVersion;
90 WORD MajorImageVersion;
91 WORD MinorImageVersion;
92 WORD MajorSubsystemVersion;
93 WORD MinorSubsystemVersion;
94 DWORD Reserved1;
95 DWORD SizeOfImage;
96 DWORD SizeOfHeaders;
97 DWORD CheckSum;
98 WORD Subsystem;
99 WORD DllCharacteristics;
100 DWORD SizeOfStackReserve;
101 DWORD SizeOfStackCommit;
102 DWORD SizeOfHeapReserve;
103 DWORD SizeOfHeapCommit;
104 DWORD LoaderFlags;
105 DWORD NumberOfRvaAndSizes;
106 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
107 } IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER;
108 typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
109 WORD Magic;
110 BYTE MajorLinkerVersion;
111 BYTE MinorLinkerVersion;
112 DWORD SizeOfCode;
113 DWORD SizeOfInitializedData;
114 DWORD SizeOfUninitializedData;
115 DWORD AddressOfEntryPoint;
116 DWORD BaseOfCode;
117 DWORD BaseOfData;
118 DWORD BaseOfBss;
119 DWORD GprMask;
120 DWORD CprMask[4];
121 DWORD GpValue;
122 } IMAGE_ROM_OPTIONAL_HEADER,*PIMAGE_ROM_OPTIONAL_HEADER;
123 #pragma pack(pop)
124 #pragma pack(push,2)
125 typedef struct _IMAGE_DOS_HEADER {
126 WORD e_magic;
127 WORD e_cblp;
128 WORD e_cp;
129 WORD e_crlc;
130 WORD e_cparhdr;
131 WORD e_minalloc;
132 WORD e_maxalloc;
133 WORD e_ss;
134 WORD e_sp;
135 WORD e_csum;
136 WORD e_ip;
137 WORD e_cs;
138 WORD e_lfarlc;
139 WORD e_ovno;
140 WORD e_res[4];
141 WORD e_oemid;
142 WORD e_oeminfo;
143 WORD e_res2[10];
144 LONG e_lfanew;
145 } IMAGE_DOS_HEADER,*PIMAGE_DOS_HEADER;
146 typedef struct _IMAGE_OS2_HEADER {
147 WORD ne_magic;
148 CHAR ne_ver;
149 CHAR ne_rev;
150 WORD ne_enttab;
151 WORD ne_cbenttab;
152 LONG ne_crc;
153 WORD ne_flags;
154 WORD ne_autodata;
155 WORD ne_heap;
156 WORD ne_stack;
157 LONG ne_csip;
158 LONG ne_sssp;
159 WORD ne_cseg;
160 WORD ne_cmod;
161 WORD ne_cbnrestab;
162 WORD ne_segtab;
163 WORD ne_rsrctab;
164 WORD ne_restab;
165 WORD ne_modtab;
166 WORD ne_imptab;
167 LONG ne_nrestab;
168 WORD ne_cmovent;
169 WORD ne_align;
170 WORD ne_cres;
171 BYTE ne_exetyp;
172 BYTE ne_flagsothers;
173 WORD ne_pretthunks;
174 WORD ne_psegrefbytes;
175 WORD ne_swaparea;
176 WORD ne_expver;
177 } IMAGE_OS2_HEADER,*PIMAGE_OS2_HEADER;
178 #pragma pack(pop)
179 #pragma pack(push,4)
180 typedef struct _IMAGE_NT_HEADERS {
181 DWORD Signature;
182 IMAGE_FILE_HEADER FileHeader;
183 IMAGE_OPTIONAL_HEADER OptionalHeader;
184 } IMAGE_NT_HEADERS,*PIMAGE_NT_HEADERS;
185 typedef struct _IMAGE_ROM_HEADERS {
186 IMAGE_FILE_HEADER FileHeader;
187 IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
188 } IMAGE_ROM_HEADERS,*PIMAGE_ROM_HEADERS;
189 typedef struct _IMAGE_SECTION_HEADER {
190 BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
191 union {
192 DWORD PhysicalAddress;
193 DWORD VirtualSize;
194 } Misc;
195 DWORD VirtualAddress;
196 DWORD SizeOfRawData;
197 DWORD PointerToRawData;
198 DWORD PointerToRelocations;
199 DWORD PointerToLinenumbers;
200 WORD NumberOfRelocations;
201 WORD NumberOfLinenumbers;
202 DWORD Characteristics;
203 } IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER;
204 #pragma pack(pop)
205 #pragma pack(push,2)
206 typedef struct _IMAGE_SYMBOL {
207 union {
208 BYTE ShortName[8];
209 struct {
210 DWORD Short;
211 DWORD Long;
212 } Name;
213 PBYTE LongName[2];
214 } N;
215 DWORD Value;
216 SHORT SectionNumber;
217 WORD Type;
218 BYTE StorageClass;
219 BYTE NumberOfAuxSymbols;
220 } IMAGE_SYMBOL,*PIMAGE_SYMBOL;
221 typedef union _IMAGE_AUX_SYMBOL {
222 struct {
223 DWORD TagIndex;
224 union {
225 struct {
226 WORD Linenumber;
227 WORD Size;
228 } LnSz;
229 DWORD TotalSize;
230 } Misc;
231 union {
232 struct {
233 DWORD PointerToLinenumber;
234 DWORD PointerToNextFunction;
235 } Function;
236 struct {
237 WORD Dimension[4];
238 } Array;
239 } FcnAry;
240 WORD TvIndex;
241 } Sym;
242 struct {
243 BYTE Name[IMAGE_SIZEOF_SYMBOL];
244 } File;
245 struct {
246 DWORD Length;
247 WORD NumberOfRelocations;
248 WORD NumberOfLinenumbers;
249 DWORD CheckSum;
250 SHORT Number;
251 BYTE Selection;
252 } Section;
253 } IMAGE_AUX_SYMBOL,*PIMAGE_AUX_SYMBOL;
254 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
255 DWORD NumberOfSymbols;
256 DWORD LvaToFirstSymbol;
257 DWORD NumberOfLinenumbers;
258 DWORD LvaToFirstLinenumber;
259 DWORD RvaToFirstByteOfCode;
260 DWORD RvaToLastByteOfCode;
261 DWORD RvaToFirstByteOfData;
262 DWORD RvaToLastByteOfData;
263 } IMAGE_COFF_SYMBOLS_HEADER,*PIMAGE_COFF_SYMBOLS_HEADER;
264 typedef struct _IMAGE_RELOCATION {
265 _ANONYMOUS_UNION union {
266 DWORD VirtualAddress;
267 DWORD RelocCount;
268 } DUMMYUNIONNAME;
269 DWORD SymbolTableIndex;
270 WORD Type;
271 } IMAGE_RELOCATION,*PIMAGE_RELOCATION;
272 #pragma pack(pop)
273 #pragma pack(push,4)
274 typedef struct _IMAGE_BASE_RELOCATION {
275 DWORD VirtualAddress;
276 DWORD SizeOfBlock;
277 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
278 #pragma pack(pop)
279 #pragma pack(push,2)
280 typedef struct _IMAGE_LINENUMBER {
281 union {
282 DWORD SymbolTableIndex;
283 DWORD VirtualAddress;
284 } Type;
285 WORD Linenumber;
286 } IMAGE_LINENUMBER,*PIMAGE_LINENUMBER;
287 #pragma pack(pop)
288 #pragma pack(push,4)
289 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
290 BYTE Name[16];
291 BYTE Date[12];
292 BYTE UserID[6];
293 BYTE GroupID[6];
294 BYTE Mode[8];
295 BYTE Size[10];
296 BYTE EndHeader[2];
297 } IMAGE_ARCHIVE_MEMBER_HEADER,*PIMAGE_ARCHIVE_MEMBER_HEADER;
298 typedef struct _IMAGE_EXPORT_DIRECTORY {
299 DWORD Characteristics;
300 DWORD TimeDateStamp;
301 WORD MajorVersion;
302 WORD MinorVersion;
303 DWORD Name;
304 DWORD Base;
305 DWORD NumberOfFunctions;
306 DWORD NumberOfNames;
307 PDWORD *AddressOfFunctions;
308 PDWORD *AddressOfNames;
309 PWORD *AddressOfNameOrdinals;
310 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
311 typedef struct _IMAGE_IMPORT_BY_NAME {
312 WORD Hint;
313 BYTE Name[1];
314 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
315 typedef struct _IMAGE_THUNK_DATA {
316 union {
317 PBYTE ForwarderString;
318 PDWORD Function;
319 DWORD Ordinal;
320 PIMAGE_IMPORT_BY_NAME AddressOfData;
321 } u1;
322 } IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
323 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
324 _ANONYMOUS_UNION union {
325 DWORD Characteristics;
326 PIMAGE_THUNK_DATA OriginalFirstThunk;
327 } DUMMYUNIONNAME;
328 DWORD TimeDateStamp;
329 DWORD ForwarderChain;
330 DWORD Name;
331 PIMAGE_THUNK_DATA FirstThunk;
332 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
333 typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
334 DWORD TimeDateStamp;
335 WORD OffsetModuleName;
336 WORD NumberOfModuleForwarderRefs;
337 } IMAGE_BOUND_IMPORT_DESCRIPTOR,*PIMAGE_BOUND_IMPORT_DESCRIPTOR;
338 typedef struct _IMAGE_BOUND_FORWARDER_REF {
339 DWORD TimeDateStamp;
340 WORD OffsetModuleName;
341 WORD Reserved;
342 } IMAGE_BOUND_FORWARDER_REF,*PIMAGE_BOUND_FORWARDER_REF;
343 typedef void(NTAPI *PIMAGE_TLS_CALLBACK)(PVOID,DWORD,PVOID);
344 typedef struct _IMAGE_TLS_DIRECTORY {
345 DWORD StartAddressOfRawData;
346 DWORD EndAddressOfRawData;
347 PDWORD AddressOfIndex;
348 PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
349 DWORD SizeOfZeroFill;
350 DWORD Characteristics;
351 } IMAGE_TLS_DIRECTORY,*PIMAGE_TLS_DIRECTORY;
352 typedef struct _IMAGE_RESOURCE_DIRECTORY {
353 DWORD Characteristics;
354 DWORD TimeDateStamp;
355 WORD MajorVersion;
356 WORD MinorVersion;
357 WORD NumberOfNamedEntries;
358 WORD NumberOfIdEntries;
359 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
360 /*_ANONYMOUS_STRUCT typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
361 _ANONYMOUS_UNION union {
362 _ANONYMOUS_STRUCT struct {
363 DWORD NameOffset:31;
364 DWORD NameIsString:1;
365 }DUMMYSTRUCTNAME;
366 DWORD Name;
367 WORD Id;
368 } DUMMYUNIONNAME;
369 _ANONYMOUS_UNION union {
370 DWORD OffsetToData;
371 _ANONYMOUS_STRUCT struct {
372 DWORD OffsetToDirectory:31;
373 DWORD DataIsDirectory:1;
374 } DUMMYSTRUCTNAME2;
375 } DUMMYUNIONNAME2;
376 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
377 */
378 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
379 WORD Length;
380 CHAR NameString[1];
381 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
382 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
383 WORD Length;
384 WCHAR NameString[1];
385 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
386 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
387 DWORD OffsetToData;
388 DWORD Size;
389 DWORD CodePage;
390 DWORD Reserved;
391 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
392 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
393 DWORD Characteristics;
394 DWORD TimeDateStamp;
395 WORD MajorVersion;
396 WORD MinorVersion;
397 DWORD GlobalFlagsClear;
398 DWORD GlobalFlagsSet;
399 DWORD CriticalSectionDefaultTimeout;
400 DWORD DeCommitFreeBlockThreshold;
401 DWORD DeCommitTotalFreeThreshold;
402 PVOID LockPrefixTable;
403 DWORD MaximumAllocationSize;
404 DWORD VirtualMemoryThreshold;
405 DWORD ProcessHeapFlags;
406 DWORD Reserved[4];
407 } IMAGE_LOAD_CONFIG_DIRECTORY,*PIMAGE_LOAD_CONFIG_DIRECTORY;
408 typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
409 DWORD BeginAddress;
410 DWORD EndAddress;
411 PVOID ExceptionHandler;
412 PVOID HandlerData;
413 DWORD PrologEndAddress;
414 } IMAGE_RUNTIME_FUNCTION_ENTRY,*PIMAGE_RUNTIME_FUNCTION_ENTRY;
415 typedef struct _IMAGE_DEBUG_DIRECTORY {
416 DWORD Characteristics;
417 DWORD TimeDateStamp;
418 WORD MajorVersion;
419 WORD MinorVersion;
420 DWORD Type;
421 DWORD SizeOfData;
422 DWORD AddressOfRawData;
423 DWORD PointerToRawData;
424 } IMAGE_DEBUG_DIRECTORY,*PIMAGE_DEBUG_DIRECTORY;
425 typedef struct _FPO_DATA {
426 DWORD ulOffStart;
427 DWORD cbProcSize;
428 DWORD cdwLocals;
429 WORD cdwParams;
430 WORD cbProlog:8;
431 WORD cbRegs:3;
432 WORD fHasSEH:1;
433 WORD fUseBP:1;
434 WORD reserved:1;
435 WORD cbFrame:2;
436 } FPO_DATA,*PFPO_DATA;
437 typedef struct _IMAGE_DEBUG_MISC {
438 DWORD DataType;
439 DWORD Length;
440 BOOLEAN Unicode;
441 BYTE Reserved[3];
442 BYTE Data[1];
443 } IMAGE_DEBUG_MISC,*PIMAGE_DEBUG_MISC;
444 typedef struct _IMAGE_FUNCTION_ENTRY {
445 DWORD StartingAddress;
446 DWORD EndingAddress;
447 DWORD EndOfPrologue;
448 } IMAGE_FUNCTION_ENTRY,*PIMAGE_FUNCTION_ENTRY;
449 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
450 WORD Signature;
451 WORD Flags;
452 WORD Machine;
453 WORD Characteristics;
454 DWORD TimeDateStamp;
455 DWORD CheckSum;
456 DWORD ImageBase;
457 DWORD SizeOfImage;
458 DWORD NumberOfSections;
459 DWORD ExportedNamesSize;
460 DWORD DebugDirectorySize;
461 DWORD Reserved[3];
462 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
463 #pragma pack(pop)
464
465 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
466
467 //
468 // Each directory contains the 32-bit Name of the entry and an offset,
469 // relative to the beginning of the resource directory of the data associated
470 // with this directory entry. If the name of the entry is an actual text
471 // string instead of an integer Id, then the high order bit of the name field
472 // is set to one and the low order 31-bits are an offset, relative to the
473 // beginning of the resource directory of the string, which is of type
474 // IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
475 // low-order 16-bits are the integer Id that identify this resource directory
476 // entry. If the directory entry is yet another resource directory (i.e. a
477 // subdirectory), then the high order bit of the offset field will be
478 // set to indicate this. Otherwise the high bit is clear and the offset
479 // field points to a resource data entry.
480 //
481 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
482 DWORD Name;
483 DWORD OffsetToData;
484 } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
485 /*
486 typedef struct _IMAGE_RESOURCE_DIRECTORY {
487 DWORD Characteristics;
488 DWORD TimeDateStamp;
489 WORD MajorVersion;
490 WORD MinorVersion;
491 WORD NumberOfNamedEntries;
492 WORD NumberOfIdEntries;
493 IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[0];
494 } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
495 */
496
497 #endif /* !__USE_W32API */
498
499 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
500
501 #define IMAGE_SECTION_CHAR_CODE 0x00000020
502 #define IMAGE_SECTION_CHAR_DATA 0x00000040
503 #define IMAGE_SECTION_CHAR_BSS 0x00000080
504 #define IMAGE_SECTION_CHAR_NON_CACHABLE 0x04000000
505 #define IMAGE_SECTION_CHAR_NON_PAGEABLE 0x08000000
506 #define IMAGE_SECTION_CHAR_SHARED 0x10000000
507 #define IMAGE_SECTION_CHAR_EXECUTABLE 0x20000000
508 #define IMAGE_SECTION_CHAR_READABLE 0x40000000
509 #define IMAGE_SECTION_CHAR_WRITABLE 0x80000000
510 #define IMAGE_SECTION_NOLOAD 0x00000002
511
512 #define IMAGE_DOS_MAGIC 0x5a4d
513 #define IMAGE_PE_MAGIC 0x00004550
514
515 #define IMAGE_NT_SIGNATURE 0x00004550
516
517
518 #define IMAGE_SIZEOF_FILE_HEADER 20
519
520
521 #define IMAGE_SUBSYSTEM_UNKNOWN 0
522 #define IMAGE_SUBSYSTEM_NATIVE 1
523 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
524 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
525 #define IMAGE_SUBSYSTEM_OS2_GUI 4
526 #define IMAGE_SUBSYSTEM_OS2_CUI 5
527 #define IMAGE_SUBSYSTEM_POSIX_GUI 6
528 #define IMAGE_SUBSYSTEM_POSIX_CUI 7
529 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
530 #define IMAGE_SUBSYSTEM_XBOX 14
531
532
533 // Directory Entries
534
535 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
536 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
537 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
538 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
539 #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
540 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
541 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
542 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
543 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
544 #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
545 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
546 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
547 #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address
548 //
549 // Section header format.
550 //
551 #define IMAGE_SIZEOF_FILE_HEADER 20
552 #define IMAGE_FILE_MACHINE_UNKNOWN 0
553 #define IMAGE_NT_SIGNATURE 0x00004550
554 #define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
555 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
556 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
557 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
558 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
559 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
560 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER 224
561 #define IMAGE_SIZEOF_SECTION_HEADER 40
562 #define IMAGE_SIZEOF_AUX_SYMBOL 18
563 #define IMAGE_SIZEOF_RELOCATION 10
564 #define IMAGE_SIZEOF_BASE_RELOCATION 8
565 #define IMAGE_SIZEOF_LINENUMBER 6
566 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
567 #define SIZEOF_RFPO_DATA 16
568 #define IMAGE_FIRST_SECTION(h) ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader))
569 #define IMAGE_SCN_TYPE_NO_PAD 8
570 #define IMAGE_SCN_CNT_CODE 32
571 #define IMAGE_SCN_CNT_INITIALIZED_DATA 64
572 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 128
573 #define IMAGE_SCN_LNK_OTHER 256
574 #define IMAGE_SCN_LNK_INFO 512
575 #define IMAGE_SCN_LNK_REMOVE 2048
576 #define IMAGE_SCN_LNK_COMDAT 4096
577 #define IMAGE_SCN_MEM_FARDATA 0x8000
578 #define IMAGE_SCN_MEM_PURGEABLE 0x20000
579 #define IMAGE_SCN_MEM_16BIT 0x20000
580 #define IMAGE_SCN_MEM_LOCKED 0x40000
581 #define IMAGE_SCN_MEM_PRELOAD 0x80000
582 #define IMAGE_SCN_ALIGN_1BYTES 0x100000
583 #define IMAGE_SCN_ALIGN_2BYTES 0x200000
584 #define IMAGE_SCN_ALIGN_4BYTES 0x300000
585 #define IMAGE_SCN_ALIGN_8BYTES 0x400000
586 #define IMAGE_SCN_ALIGN_16BYTES 0x500000
587 #define IMAGE_SCN_ALIGN_32BYTES 0x600000
588 #define IMAGE_SCN_ALIGN_64BYTES 0x700000
589 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x1000000
590 #define IMAGE_SCN_MEM_DISCARDABLE 0x2000000
591 #define IMAGE_SCN_MEM_NOT_CACHED 0x4000000
592 #define IMAGE_SCN_MEM_NOT_PAGED 0x8000000
593 #define IMAGE_SCN_MEM_SHARED 0x10000000
594 #define IMAGE_SCN_MEM_EXECUTE 0x20000000
595 #define IMAGE_SCN_MEM_READ 0x40000000
596 #define IMAGE_SCN_MEM_WRITE 0x80000000
597 #define IMAGE_SYM_UNDEFINED 0
598 #define IMAGE_SYM_ABSOLUTE (-1)
599 #define IMAGE_SYM_DEBUG (-2)
600 #define IMAGE_SYM_TYPE_NULL 0
601 #define IMAGE_SYM_TYPE_VOID 1
602 #define IMAGE_SYM_TYPE_CHAR 2
603 #define IMAGE_SYM_TYPE_SHORT 3
604 #define IMAGE_SYM_TYPE_INT 4
605 #define IMAGE_SYM_TYPE_LONG 5
606 #define IMAGE_SYM_TYPE_FLOAT 6
607 #define IMAGE_SYM_TYPE_DOUBLE 7
608 #define IMAGE_SYM_TYPE_STRUCT 8
609 #define IMAGE_SYM_TYPE_UNION 9
610 #define IMAGE_SYM_TYPE_ENUM 10
611 #define IMAGE_SYM_TYPE_MOE 11
612 #define IMAGE_SYM_TYPE_BYTE 12
613 #define IMAGE_SYM_TYPE_WORD 13
614 #define IMAGE_SYM_TYPE_UINT 14
615 #define IMAGE_SYM_TYPE_DWORD 15
616 #define IMAGE_SYM_TYPE_PCODE 32768
617 #define IMAGE_SYM_DTYPE_NULL 0
618 #define IMAGE_SYM_DTYPE_POINTER 1
619 #define IMAGE_SYM_DTYPE_FUNCTION 2
620 #define IMAGE_SYM_DTYPE_ARRAY 3
621 #define IMAGE_SYM_CLASS_END_OF_FUNCTION (-1)
622 #define IMAGE_SYM_CLASS_NULL 0
623 #define IMAGE_SYM_CLASS_AUTOMATIC 1
624 #define IMAGE_SYM_CLASS_EXTERNAL 2
625 #define IMAGE_SYM_CLASS_STATIC 3
626 #define IMAGE_SYM_CLASS_REGISTER 4
627 #define IMAGE_SYM_CLASS_EXTERNAL_DEF 5
628 #define IMAGE_SYM_CLASS_LABEL 6
629 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
630 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
631 #define IMAGE_SYM_CLASS_ARGUMENT 9
632 #define IMAGE_SYM_CLASS_STRUCT_TAG 10
633 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
634 #define IMAGE_SYM_CLASS_UNION_TAG 12
635 #define IMAGE_SYM_CLASS_TYPE_DEFINITION 13
636 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
637 #define IMAGE_SYM_CLASS_ENUM_TAG 15
638 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
639 #define IMAGE_SYM_CLASS_REGISTER_PARAM 17
640 #define IMAGE_SYM_CLASS_BIT_FIELD 18
641 #define IMAGE_SYM_CLASS_FAR_EXTERNAL 68
642 #define IMAGE_SYM_CLASS_BLOCK 100
643 #define IMAGE_SYM_CLASS_FUNCTION 101
644 #define IMAGE_SYM_CLASS_END_OF_STRUCT 102
645 #define IMAGE_SYM_CLASS_FILE 103
646 #define IMAGE_SYM_CLASS_SECTION 104
647 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
648 #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
649 #define IMAGE_COMDAT_SELECT_ANY 2
650 #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
651 #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
652 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
653 #define IMAGE_COMDAT_SELECT_LARGEST 6
654 #define IMAGE_COMDAT_SELECT_NEWEST 7
655 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
656 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
657 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
658 #define IMAGE_REL_I386_ABSOLUTE 0
659 #define IMAGE_REL_I386_DIR16 1
660 #define IMAGE_REL_I386_REL16 2
661 #define IMAGE_REL_I386_DIR32 6
662 #define IMAGE_REL_I386_DIR32NB 7
663 #define IMAGE_REL_I386_SEG12 9
664 #define IMAGE_REL_I386_SECTION 10
665 #define IMAGE_REL_I386_SECREL 11
666 #define IMAGE_REL_I386_REL32 20
667 #define IMAGE_REL_MIPS_ABSOLUTE 0
668 #define IMAGE_REL_MIPS_REFHALF 1
669 #define IMAGE_REL_MIPS_REFWORD 2
670 #define IMAGE_REL_MIPS_JMPADDR 3
671 #define IMAGE_REL_MIPS_REFHI 4
672 #define IMAGE_REL_MIPS_REFLO 5
673 #define IMAGE_REL_MIPS_GPREL 6
674 #define IMAGE_REL_MIPS_LITERAL 7
675 #define IMAGE_REL_MIPS_SECTION 10
676 #define IMAGE_REL_MIPS_SECREL 11
677 #define IMAGE_REL_MIPS_SECRELLO 12
678 #define IMAGE_REL_MIPS_SECRELHI 13
679 #define IMAGE_REL_MIPS_REFWORDNB 34
680 #define IMAGE_REL_MIPS_PAIR 35
681 #define IMAGE_REL_ALPHA_ABSOLUTE 0
682 #define IMAGE_REL_ALPHA_REFLONG 1
683 #define IMAGE_REL_ALPHA_REFQUAD 2
684 #define IMAGE_REL_ALPHA_GPREL32 3
685 #define IMAGE_REL_ALPHA_LITERAL 4
686 #define IMAGE_REL_ALPHA_LITUSE 5
687 #define IMAGE_REL_ALPHA_GPDISP 6
688 #define IMAGE_REL_ALPHA_BRADDR 7
689 #define IMAGE_REL_ALPHA_HINT 8
690 #define IMAGE_REL_ALPHA_INLINE_REFLONG 9
691 #define IMAGE_REL_ALPHA_REFHI 10
692 #define IMAGE_REL_ALPHA_REFLO 11
693 #define IMAGE_REL_ALPHA_PAIR 12
694 #define IMAGE_REL_ALPHA_MATCH 13
695 #define IMAGE_REL_ALPHA_SECTION 14
696 #define IMAGE_REL_ALPHA_SECREL 15
697 #define IMAGE_REL_ALPHA_REFLONGNB 16
698 #define IMAGE_REL_ALPHA_SECRELLO 17
699 #define IMAGE_REL_ALPHA_SECRELHI 18
700 #define IMAGE_REL_PPC_ABSOLUTE 0
701 #define IMAGE_REL_PPC_ADDR64 1
702 #define IMAGE_REL_PPC_ADDR32 2
703 #define IMAGE_REL_PPC_ADDR24 3
704 #define IMAGE_REL_PPC_ADDR16 4
705 #define IMAGE_REL_PPC_ADDR14 5
706 #define IMAGE_REL_PPC_REL24 6
707 #define IMAGE_REL_PPC_REL14 7
708 #define IMAGE_REL_PPC_TOCREL16 8
709 #define IMAGE_REL_PPC_TOCREL14 9
710 #define IMAGE_REL_PPC_ADDR32NB 10
711 #define IMAGE_REL_PPC_SECREL 11
712 #define IMAGE_REL_PPC_SECTION 12
713 #define IMAGE_REL_PPC_IFGLUE 13
714 #define IMAGE_REL_PPC_IMGLUE 14
715 #define IMAGE_REL_PPC_SECREL16 15
716 #define IMAGE_REL_PPC_REFHI 16
717 #define IMAGE_REL_PPC_REFLO 17
718 #define IMAGE_REL_PPC_PAIR 18
719 #define IMAGE_REL_PPC_TYPEMASK 255
720 #define IMAGE_REL_PPC_NEG 256
721 #define IMAGE_REL_PPC_BRTAKEN 512
722 #define IMAGE_REL_PPC_BRNTAKEN 1024
723 #define IMAGE_REL_PPC_TOCDEFN 2048
724 #define IMAGE_REL_BASED_ABSOLUTE 0
725 #define IMAGE_REL_BASED_HIGH 1
726 #define IMAGE_REL_BASED_LOW 2
727 #define IMAGE_REL_BASED_HIGHLOW 3
728 #define IMAGE_REL_BASED_HIGHADJ 4
729 #define IMAGE_REL_BASED_MIPS_JMPADDR 5
730 #define IMAGE_ARCHIVE_START_SIZE 8
731 #define IMAGE_ARCHIVE_START "!<arch>\n"
732 #define IMAGE_ARCHIVE_END "`\n"
733 #define IMAGE_ARCHIVE_PAD "\n"
734 #define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
735 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
736 #define IMAGE_ORDINAL_FLAG 0x80000000
737 #define IMAGE_SNAP_BY_ORDINAL(o) ((o&IMAGE_ORDINAL_FLAG)!=0)
738 #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
739 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
740 #define IMAGE_DEBUG_TYPE_UNKNOWN 0
741 #define IMAGE_DEBUG_TYPE_COFF 1
742 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
743 #define IMAGE_DEBUG_TYPE_FPO 3
744 #define IMAGE_DEBUG_TYPE_MISC 4
745 #define IMAGE_DEBUG_TYPE_EXCEPTION 5
746 #define IMAGE_DEBUG_TYPE_FIXUP 6
747 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
748 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
749
750
751 #define IMAGE_SIZEOF_SHORT_NAME 8
752
753 #define IMAGE_SIZEOF_SECTION_HEADER 40
754
755 #define IMAGE_SECTION_CODE (0x20)
756 #define IMAGE_SECTION_INITIALIZED_DATA (0x40)
757 #define IMAGE_SECTION_UNINITIALIZED_DATA (0x80)
758
759 //
760 // Import Format
761 //
762
763 #define IMAGE_ORDINAL_FLAG 0x80000000
764
765
766 // Predefined resource types ... there may be some more, but I don't have
767 // the information yet. .....sang cho.....
768
769 #define RT_NEWRESOURCE 0x2000
770 #define RT_ERROR 0x7fff
771 #define NEWBITMAP (RT_BITMAP|RT_NEWRESOURCE)
772 #define NEWMENU (RT_MENU|RT_NEWRESOURCE)
773 #define NEWDIALOG (RT_DIALOG|RT_NEWRESOURCE)
774
775
776 //
777 // Resource Format.
778 //
779
780 //
781 // Resource directory consists of two counts, following by a variable length
782 // array of directory entries. The first count is the number of entries at
783 // beginning of the array that have actual names associated with each entry.
784 // The entries are in ascending order, case insensitive strings. The second
785 // count is the number of entries that immediately follow the named entries.
786 // This second count identifies the number of entries that have 16-bit integer
787 // Ids as their name. These entries are also sorted in ascending order.
788 //
789 // This structure allows fast lookup by either name or number, but for any
790 // given resource entry only one form of lookup is supported, not both.
791 // This is consistant with the syntax of the .RC file and the .RES file.
792 //
793
794
795 #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
796 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
797
798
799
800 //
801 // For resource directory entries that have actual string names, the Name
802 // field of the directory entry points to an object of the following type.
803 // All of these string objects are stored together after the last resource
804 // directory entry and before the first resource data object. This minimizes
805 // the impact of these variable length objects on the alignment of the fixed
806 // size directory entry objects.
807 //
808 /* defined above from mingw. ei
809 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
810 WORD Length;
811 CHAR NameString[ 1 ];
812 } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
813
814
815 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
816 WORD Length;
817 WCHAR NameString[ 1 ];
818 } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
819 */
820
821 //
822 // Each resource data entry describes a leaf node in the resource directory
823 // tree. It contains an offset, relative to the beginning of the resource
824 // directory of the data for the resource, a size field that gives the number
825 // of bytes of data at that offset, a CodePage that should be used when
826 // decoding code point values within the resource data. Typically for new
827 // applications the code page would be the unicode code page.
828 //
829 /* ei
830 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
831 DWORD OffsetToData;
832 DWORD Size;
833 DWORD CodePage;
834 DWORD Reserved;
835 } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
836 */
837
838 // Menu Resources ... added by .....sang cho....
839
840 // Menu resources are composed of a menu header followed by a sequential list
841 // of menu items. There are two types of menu items: pop-ups and normal menu
842 // itmes. The MENUITEM SEPARATOR is a special case of a normal menu item with
843 // an empty name, zero ID, and zero flags.
844
845 typedef struct _IMAGE_MENU_HEADER{
846 WORD wVersion; // Currently zero
847 WORD cbHeaderSize; // Also zero
848 } IMAGE_MENU_HEADER, *PIMAGE_MENU_HEADER;
849
850 typedef struct _IMAGE_POPUP_MENU_ITEM{
851 WORD fItemFlags;
852 WCHAR szItemText[1];
853 } IMAGE_POPUP_MENU_ITEM, *PIMAGE_POPUP_MENU_ITEM;
854
855 typedef struct _IMAGE_NORMAL_MENU_ITEM{
856 WORD fItemFlags;
857 WORD wMenuID;
858 WCHAR szItemText[1];
859 } IMAGE_NORMAL_MENU_ITEM, *PIMAGE_NORMAL_MENU_ITEM;
860
861 #define MI_GRAYED 0x0001 // GRAYED keyword
862 #define MI_INACTIVE 0x0002 // INACTIVE keyword
863 #define MI_BITMAP 0x0004 // BITMAP keyword
864 #define MI_OWNERDRAW 0x0100 // OWNERDRAW keyword
865 #define MI_CHECKED 0x0008 // CHECKED keyword
866 #define MI_POPUP 0x0010 // used internally
867 #define MI_MENUBARBREAK 0x0020 // MENUBARBREAK keyword
868 #define MI_MENUBREAK 0x0040 // MENUBREAK keyword
869 #define MI_ENDMENU 0x0080 // used internally
870
871 // Dialog Box Resources .................. added by sang cho.
872
873 // A dialog box is contained in a single resource and has a header and
874 // a portion repeated for each control in the dialog box.
875 // The item DWORD IStyle is a standard window style composed of flags found
876 // in WINDOWS.H.
877 // The default style for a dialog box is:
878 // WS_POPUP | WS_BORDER | WS_SYSMENU
879 //
880 // The itme marked "Name or Ordinal" are :
881 // If the first word is an 0xffff, the next two bytes contain an ordinal ID.
882 // Otherwise, the first one or more WORDS contain a double-null-terminated string.
883 // An empty string is represented by a single WORD zero in the first location.
884 //
885 // The WORD wPointSize and WCHAR szFontName entries are present if the FONT
886 // statement was included for the dialog box. This can be detected by checking
887 // the entry IStyle. If IStyle & DS_SETFONT ( which is 0x40), then these
888 // entries will be present.
889
890 typedef struct _IMAGE_DIALOG_BOX_HEADER1{
891 DWORD IStyle;
892 DWORD IExtendedStyle; // New for Windows NT
893 WORD nControls; // Number of Controls
894 WORD x;
895 WORD y;
896 WORD cx;
897 WORD cy;
898 // N_OR_O MenuName; // Name or Ordinal ID
899 // N_OR_O ClassName; // Name or Ordinal ID
900 // WCHAR szCaption[];
901 // WORD wPointSize; // Only here if FONT set for dialog
902 // WCHAR szFontName[]; // This too
903 } IMAGE_DIALOG_HEADER, *PIMAGE_DIALOG_HEADER;
904
905 typedef union _NAME_OR_ORDINAL{ // Name or Ordinal ID
906 struct _ORD_ID{
907 WORD flgId;
908 WORD Id;
909 } ORD_ID;
910 WCHAR szName[1];
911 } NAME_OR_ORDINAL, *PNAME_OR_ORDINAL;
912
913 // The data for each control starts on a DWORD boundary (which may require
914 // some padding from the previous control), and its format is as follows:
915
916 typedef struct _IMAGE_CONTROL_DATA{
917 DWORD IStyle;
918 DWORD IExtendedStyle;
919 WORD x;
920 WORD y;
921 WORD cx;
922 WORD cy;
923 WORD wId;
924 // N_OR_O ClassId;
925 // N_OR_O Text;
926 // WORD nExtraStuff;
927 } IMAGE_CONTROL_DATA, *PIMAGE_CONTROL_DATA;
928
929 #define BUTTON 0x80
930 #define EDIT 0x81
931 //#define STATIC 0x82
932 #define LISTBOX 0x83
933 #define SCROLLBAR 0x84
934 #define COMBOBOX 0x85
935
936 // The various statements used in a dialog script are all mapped to these
937 // classes along with certain modifying styles. The values for these styles
938 // can be found in WINDOWS.H. All dialog controls have the default styles
939 // of WS_CHILD and WS_VISIBLE. A list of the default styles used follows:
940 //
941 // Statement Default Class Default Styles
942 // CONTROL None WS_CHILD|WS_VISIBLE
943 // LTEXT STATIC ES_LEFT
944 // RTEXT STATIC ES_RIGHT
945 // CTEXT STATIC ES_CENTER
946 // LISTBOX LISTBOX WS_BORDER|LBS_NOTIFY
947 // CHECKBOX BUTTON BS_CHECKBOX|WS_TABSTOP
948 // PUSHBUTTON BUTTON BS_PUSHBUTTON|WS_TABSTOP
949 // GROUPBOX BUTTON BS_GROUPBOX
950 // DEFPUSHBUTTON BUTTON BS_DFPUSHBUTTON|WS_TABSTOP
951 // RADIOBUTTON BUTTON BS_RADIOBUTTON
952 // AUTOCHECKBOX BUTTON BS_AUTOCHECKBOX
953 // AUTO3STATE BUTTON BS_AUTO3STATE
954 // AUTORADIOBUTTON BUTTON BS_AUTORADIOBUTTON
955 // PUSHBOX BUTTON BS_PUSHBOX
956 // STATE3 BUTTON BS_3STATE
957 // EDITTEXT EDIT ES_LEFT|WS_BORDER|WS_TABSTOP
958 // COMBOBOX COMBOBOX None
959 // ICON STATIC SS_ICON
960 // SCROLLBAR SCROLLBAR None
961 ///
962
963 #define IMAGE_DEBUG_TYPE_UNKNOWN 0
964 #define IMAGE_DEBUG_TYPE_COFF 1
965 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
966 #define IMAGE_DEBUG_TYPE_FPO 3
967 #define IMAGE_DEBUG_TYPE_MISC 4
968 #define IMAGE_DEBUG_TYPE_EXCEPTION 5
969 #define IMAGE_DEBUG_TYPE_FIXUP 6
970 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
971 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
972
973
974
975 //
976 // Debugging information can be stripped from an image file and placed
977 // in a separate .DBG file, whose file name part is the same as the
978 // image file name part (e.g. symbols for CMD.EXE could be stripped
979 // and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
980 // flag in the Characteristics field of the file header. The beginning of
981 // the .DBG file contains the following structure which captures certain
982 // information from the image file. This allows a debug to proceed even if
983 // the original image file is not accessable. This header is followed by
984 // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
985 // IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
986 // the image file contain file offsets relative to the beginning of the
987 // .DBG file.
988 //
989 // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
990 // is left in the image file, but not mapped. This allows a debugger to
991 // compute the name of the .DBG file, from the name of the image in the
992 // IMAGE_DEBUG_MISC structure.
993 //
994 /* ei
995 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
996 WORD Signature;
997 WORD Flags;
998 WORD Machine;
999 WORD Characteristics;
1000 DWORD TimeDateStamp;
1001 DWORD CheckSum;
1002 DWORD ImageBase;
1003 DWORD SizeOfImage;
1004 DWORD NumberOfSections;
1005 DWORD ExportedNamesSize;
1006 DWORD DebugDirectorySize;
1007 DWORD SectionAlignment;
1008 DWORD Reserved[2];
1009 } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
1010 */
1011 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
1012
1013 #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
1014 #define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
1015 // old checksum didn't match.
1016
1017 //
1018 // End Image Format
1019 //
1020
1021 #define SIZE_OF_NT_SIGNATURE sizeof (DWORD)
1022 #define MAXRESOURCENAME 13
1023
1024 /* global macros to define header offsets into file */
1025 /* offset to PE file signature */
1026 #define NTSIGNATURE(a) ((LPVOID)((BYTE *)a + \
1027 ((PIMAGE_DOS_HEADER)a)->e_lfanew))
1028
1029 /* DOS header identifies the NT PEFile signature dword
1030 the PEFILE header exists just after that dword */
1031 #define PEFHDROFFSET(a) ((LPVOID)((BYTE *)a + \
1032 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
1033 SIZE_OF_NT_SIGNATURE))
1034
1035 /* PE optional header is immediately after PEFile header */
1036 #define OPTHDROFFSET(a) ((LPVOID)((BYTE *)a + \
1037 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
1038 SIZE_OF_NT_SIGNATURE + \
1039 sizeof (IMAGE_FILE_HEADER)))
1040
1041 /* section headers are immediately after PE optional header */
1042 #define SECHDROFFSET(a) ((LPVOID)((BYTE *)a + \
1043 ((PIMAGE_DOS_HEADER)a)->e_lfanew + \
1044 SIZE_OF_NT_SIGNATURE + \
1045 sizeof (IMAGE_FILE_HEADER) + \
1046 sizeof (IMAGE_OPTIONAL_HEADER)))
1047
1048 //#define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
1049 /* defined above ei
1050 #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
1051 ((ULONG_PTR)ntheader + \
1052 FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
1053 ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
1054 ))
1055 */
1056
1057 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD)(ptr) + (DWORD)(addValue))
1058
1059 typedef struct _IMAGE_IMPORT_MODULE_DIRECTORY
1060 {
1061 DWORD dwRVAFunctionNameList;
1062 DWORD dwUseless1;
1063 DWORD dwUseless2;
1064 DWORD dwRVAModuleName;
1065 DWORD dwRVAFunctionAddressList;
1066 } IMAGE_IMPORT_MODULE_DIRECTORY, *PIMAGE_IMPORT_MODULE_DIRECTORY;
1067
1068 typedef struct _RELOCATION_DIRECTORY
1069 {
1070 DWORD VirtualAddress; /* adresse virtuelle du bloc ou se font les relocations */
1071 DWORD SizeOfBlock; // taille de cette structure + des structures
1072 // relocation_entry qui suivent (ces dernieres sont
1073 // donc au nombre de (SizeOfBlock-8)/2
1074 } RELOCATION_DIRECTORY, *PRELOCATION_DIRECTORY;
1075
1076 typedef struct _RELOCATION_ENTRY
1077 {
1078 WORD TypeOffset;
1079 // (TypeOffset >> 12) est le type
1080 // (TypeOffset&0xfff) est l'offset dans le bloc
1081 } RELOCATION_ENTRY, *PRELOCATION_ENTRY;
1082
1083 #define TYPE_RELOC_ABSOLUTE 0
1084 #define TYPE_RELOC_HIGH 1
1085 #define TYPE_RELOC_LOW 2
1086 #define TYPE_RELOC_HIGHLOW 3
1087 #define TYPE_RELOC_HIGHADJ 4
1088 #define TYPE_RELOC_MIPS_JMPADDR 5
1089
1090 #endif /* __INCLUDE_PE_H */