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