Added Win16 implementation for GetRegionData().
[wine.git] / include / peexe.h
blob8e07683c0e05719b174cb1eb72e69c8f2b199d22
1 /*
2 * Copyright Eric Youngdale (1994)
3 */
4 #ifndef __WINE_PEEXE_H
5 #define __WINE_PEEXE_H
7 #include "wintypes.h"
8 #include "neexe.h"
10 typedef struct _IMAGE_FILE_HEADER {
11 WORD Machine; /* 00 */
12 WORD NumberOfSections; /* 02 */
13 DWORD TimeDateStamp; /* 04 */
14 DWORD PointerToSymbolTable; /* 08 */
15 DWORD NumberOfSymbols; /* 0c */
16 WORD SizeOfOptionalHeader; /* 10 */
17 WORD Characteristics; /* 12 */
18 } IMAGE_FILE_HEADER,*PIMAGE_FILE_HEADER;
20 #define IMAGE_SIZEOF_FILE_HEADER 20
22 /* These defines describe the meanings of the bits in the Characteristics
23 field */
25 #define IMAGE_FILE_RELOCS_STRIPPED 1 /* No relocation info */
26 #define IMAGE_FILE_EXECUTABLE_IMAGE 2
27 #define IMAGE_FILE_LINE_NUMS_STRIPPED 4
28 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 8
29 #define IMAGE_FILE_16BIT_MACHINE 0x40
30 #define IMAGE_FILE_BYTES_REVERSED_LO 0x80
31 #define IMAGE_FILE_32BIT_MACHINE 0x100
32 #define IMAGE_FILE_DEBUG_STRIPPED 0x200
33 #define IMAGE_FILE_SYSTEM 0x1000
34 #define IMAGE_FILE_DLL 0x2000
35 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
37 /* These are the settings of the Machine field. */
38 #define IMAGE_FILE_MACHINE_UNKNOWN 0
39 #define IMAGE_FILE_MACHINE_I860 0x14d
40 #define IMAGE_FILE_MACHINE_I386 0x14c
41 #define IMAGE_FILE_MACHINE_R3000 0x162
42 #define IMAGE_FILE_MACHINE_R4000 0x166
43 #define IMAGE_FILE_MACHINE_R10000 0x168
44 #define IMAGE_FILE_MACHINE_ALPHA 0x184
45 #define IMAGE_FILE_MACHINE_POWERPC 0x1F0
47 typedef struct _IMAGE_DATA_DIRECTORY
49 DWORD VirtualAddress;
50 DWORD Size;
51 } IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY;
53 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
55 /* Optional coff header - used by NT to provide additional information. */
56 typedef struct _IMAGE_OPTIONAL_HEADER
59 * Standard fields.
62 WORD Magic; /* 00 */
63 BYTE MajorLinkerVersion; /* 02 */
64 BYTE MinorLinkerVersion; /* 03 */
65 DWORD SizeOfCode; /* 04 */
66 DWORD SizeOfInitializedData; /* 08 */
67 DWORD SizeOfUninitializedData; /* 0C */
68 DWORD AddressOfEntryPoint; /* 10 */
69 DWORD BaseOfCode; /* 14 */
70 DWORD BaseOfData; /* 18 */
73 * NT additional fields.
76 DWORD ImageBase; /* 1C */
77 DWORD SectionAlignment; /* 20 */
78 DWORD FileAlignment; /* 24 */
79 WORD MajorOperatingSystemVersion; /* 28 */
80 WORD MinorOperatingSystemVersion; /* 2A */
81 WORD MajorImageVersion; /* 2C */
82 WORD MinorImageVersion; /* 2E */
83 WORD MajorSubsystemVersion; /* 30 */
84 WORD MinorSubsystemVersion; /* 32 */
85 DWORD Reserved1; /* 34 */
86 DWORD SizeOfImage; /* 38 */
87 DWORD SizeOfHeaders; /* 3C */
88 DWORD CheckSum; /* 40 */
89 WORD Subsystem; /* 44 */
90 WORD DllCharacteristics; /* 46 */
91 DWORD SizeOfStackReserve; /* 48 */
92 DWORD SizeOfStackCommit; /* 4C */
93 DWORD SizeOfHeapReserve; /* 50 */
94 DWORD SizeOfHeapCommit; /* 54 */
95 DWORD LoaderFlags; /* 58 */
96 DWORD NumberOfRvaAndSizes; /* 5C */
97 /* 60: */
98 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
99 } IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER;
101 /* Possible Magic values */
102 #define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
103 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
105 /* These are indexes into the DataDirectory array */
106 #define IMAGE_FILE_EXPORT_DIRECTORY 0
107 #define IMAGE_FILE_IMPORT_DIRECTORY 1
108 #define IMAGE_FILE_RESOURCE_DIRECTORY 2
109 #define IMAGE_FILE_EXCEPTION_DIRECTORY 3
110 #define IMAGE_FILE_SECURITY_DIRECTORY 4
111 #define IMAGE_FILE_BASE_RELOCATION_TABLE 5
112 #define IMAGE_FILE_DEBUG_DIRECTORY 6
113 #define IMAGE_FILE_DESCRIPTION_STRING 7
114 #define IMAGE_FILE_MACHINE_VALUE 8 /* Mips */
115 #define IMAGE_FILE_THREAD_LOCAL_STORAGE 9
116 #define IMAGE_FILE_CALLBACK_DIRECTORY 10
118 /* Directory Entries, indices into the DataDirectory array */
120 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0
121 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1
122 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2
123 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
124 #define IMAGE_DIRECTORY_ENTRY_SECURITY 4
125 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
126 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6
127 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
128 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 /* (MIPS GP) */
129 #define IMAGE_DIRECTORY_ENTRY_TLS 9
130 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
131 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11
132 #define IMAGE_DIRECTORY_ENTRY_IAT 12 /* Import Address Table */
133 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13
135 /* Subsystem Values */
137 #define IMAGE_SUBSYSTEM_UNKNOWN 0
138 #define IMAGE_SUBSYSTEM_NATIVE 1
139 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 /* Windows GUI subsystem */
140 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 /* Windows character subsystem*/
141 #define IMAGE_SUBSYSTEM_OS2_CUI 5
142 #define IMAGE_SUBSYSTEM_POSIX_CUI 7
144 typedef struct _IMAGE_NT_HEADERS {
145 DWORD Signature; /* 00: PE\0\0 */
146 IMAGE_FILE_HEADER FileHeader; /* 04: Fileheader */
147 IMAGE_OPTIONAL_HEADER OptionalHeader; /* 18: Optional Header */
148 } IMAGE_NT_HEADERS,*PIMAGE_NT_HEADERS;
151 #define PE_HEADER(module) \
152 ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
153 (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
155 #define PE_SECTIONS(module) \
156 ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
157 PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
159 #define RVA_PTR(module,field) ((LPBYTE)(module) + PE_HEADER(module)->field)
161 /* Section header format */
163 #define IMAGE_SIZEOF_SHORT_NAME 8
165 typedef struct _IMAGE_SECTION_HEADER {
166 BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; /* 00: */
167 union {
168 DWORD PhysicalAddress; /* 04: */
169 DWORD VirtualSize; /* 04: */
170 } Misc;
171 DWORD VirtualAddress; /* 08: */
172 DWORD SizeOfRawData; /* 0C: */
173 DWORD PointerToRawData; /* 10: */
174 DWORD PointerToRelocations; /* 14: */
175 DWORD PointerToLinenumbers; /* 18: */
176 WORD NumberOfRelocations; /* 1C: */
177 WORD NumberOfLinenumbers; /* 1E: */
178 DWORD Characteristics; /* 20: */
179 /* 24: */
180 } IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER;
182 #define IMAGE_SIZEOF_SECTION_HEADER 40
184 /* These defines are for the Characteristics bitfield. */
185 /* #define IMAGE_SCN_TYPE_REG 0x00000000 - Reserved */
186 /* #define IMAGE_SCN_TYPE_DSECT 0x00000001 - Reserved */
187 /* #define IMAGE_SCN_TYPE_NOLOAD 0x00000002 - Reserved */
188 /* #define IMAGE_SCN_TYPE_GROUP 0x00000004 - Reserved */
189 /* #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 - Reserved */
190 /* #define IMAGE_SCN_TYPE_COPY 0x00000010 - Reserved */
192 #define IMAGE_SCN_CNT_CODE 0x00000020
193 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
194 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
196 #define IMAGE_SCN_LNK_OTHER 0x00000100
197 #define IMAGE_SCN_LNK_INFO 0x00000200
198 /* #define IMAGE_SCN_TYPE_OVER 0x00000400 - Reserved */
199 #define IMAGE_SCN_LNK_REMOVE 0x00000800
200 #define IMAGE_SCN_LNK_COMDAT 0x00001000
202 /* 0x00002000 - Reserved */
203 /* #define IMAGE_SCN_MEM_PROTECTED 0x00004000 - Obsolete */
204 #define IMAGE_SCN_MEM_FARDATA 0x00008000
206 /* #define IMAGE_SCN_MEM_SYSHEAP 0x00010000 - Obsolete */
207 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
208 #define IMAGE_SCN_MEM_16BIT 0x00020000
209 #define IMAGE_SCN_MEM_LOCKED 0x00040000
210 #define IMAGE_SCN_MEM_PRELOAD 0x00080000
212 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
213 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
214 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
215 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
216 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 /* Default */
217 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
218 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
219 /* 0x00800000 - Unused */
221 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
224 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
225 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000
226 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000
227 #define IMAGE_SCN_MEM_SHARED 0x10000000
228 #define IMAGE_SCN_MEM_EXECUTE 0x20000000
229 #define IMAGE_SCN_MEM_READ 0x40000000
230 #define IMAGE_SCN_MEM_WRITE 0x80000000
233 /* Import name entry */
234 typedef struct _IMAGE_IMPORT_BY_NAME {
235 WORD Hint;
236 BYTE Name[1];
237 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
239 /* Import thunk */
240 typedef struct _IMAGE_THUNK_DATA {
241 union {
242 LPBYTE ForwarderString;
243 FARPROC32 Function;
244 DWORD Ordinal;
245 PIMAGE_IMPORT_BY_NAME AddressOfData;
246 } u1;
247 } IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
249 /* Import module directory */
251 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
252 union {
253 DWORD Characteristics; /* 0 for terminating null import descriptor */
254 PIMAGE_THUNK_DATA OriginalFirstThunk; /* RVA to original unbound IAT */
255 } u;
256 DWORD TimeDateStamp; /* 0 if not bound,
257 * -1 if bound, and real date\time stamp
258 * in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
259 * (new BIND)
260 * otherwise date/time stamp of DLL bound to
261 * (Old BIND)
263 DWORD ForwarderChain; /* -1 if no forwarders */
264 DWORD Name;
265 /* RVA to IAT (if bound this IAT has actual addresses) */
266 PIMAGE_THUNK_DATA FirstThunk;
267 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
269 #define IMAGE_ORDINAL_FLAG 0x80000000
270 #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
271 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
273 /* Export module directory */
275 typedef struct _IMAGE_EXPORT_DIRECTORY {
276 DWORD Characteristics;
277 DWORD TimeDateStamp;
278 WORD MajorVersion;
279 WORD MinorVersion;
280 DWORD Name;
281 DWORD Base;
282 DWORD NumberOfFunctions;
283 DWORD NumberOfNames;
284 LPDWORD *AddressOfFunctions;
285 LPDWORD *AddressOfNames;
286 LPWORD *AddressOfNameOrdinals;
287 /* u_char ModuleName[1]; */
288 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
292 * Resource directory stuff
294 typedef struct _IMAGE_RESOURCE_DIRECTORY {
295 DWORD Characteristics;
296 DWORD TimeDateStamp;
297 WORD MajorVersion;
298 WORD MinorVersion;
299 WORD NumberOfNamedEntries;
300 WORD NumberOfIdEntries;
301 /* IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
302 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
304 #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
305 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
307 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
308 union {
309 struct {
310 DWORD NameOffset:31;
311 DWORD NameIsString:1;
312 } s;
313 DWORD Name;
314 WORD Id;
315 } u1;
316 union {
317 DWORD OffsetToData;
318 struct {
319 DWORD OffsetToDirectory:31;
320 DWORD DataIsDirectory:1;
321 } s;
322 } u2;
323 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
326 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
327 WORD Length;
328 CHAR NameString[ 1 ];
329 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
331 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
332 WORD Length;
333 WCHAR NameString[ 1 ];
334 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
336 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
337 DWORD OffsetToData;
338 DWORD Size;
339 DWORD CodePage;
340 DWORD ResourceHandle;
341 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
343 typedef struct _IMAGE_BASE_RELOCATION
345 DWORD VirtualAddress;
346 DWORD SizeOfBlock;
347 WORD TypeOffset[1];
348 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
350 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
351 DWORD Characteristics;
352 DWORD TimeDateStamp;
353 WORD MajorVersion;
354 WORD MinorVersion;
355 DWORD GlobalFlagsClear;
356 DWORD GlobalFlagsSet;
357 DWORD CriticalSectionDefaultTimeout;
358 DWORD DeCommitFreeBlockThreshold;
359 DWORD DeCommitTotalFreeThreshold;
360 LPVOID LockPrefixTable;
361 DWORD MaximumAllocationSize;
362 DWORD VirtualMemoryThreshold;
363 DWORD ProcessHeapFlags;
364 DWORD Reserved[ 4 ];
365 } IMAGE_LOAD_CONFIG_DIRECTORY,*PIMAGE_LOAD_CONFIG_DIRECTORY;
367 typedef VOID (CALLBACK *PIMAGE_TLS_CALLBACK)(
368 LPVOID DllHandle,DWORD Reason,LPVOID Reserved
371 typedef struct _IMAGE_TLS_DIRECTORY {
372 DWORD StartAddressOfRawData;
373 DWORD EndAddressOfRawData;
374 LPDWORD AddressOfIndex;
375 PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
376 DWORD SizeOfZeroFill;
377 DWORD Characteristics;
378 } IMAGE_TLS_DIRECTORY,*PIMAGE_TLS_DIRECTORY;
381 * The IMAGE_DEBUG_DIRECTORY data directory points to an array of
382 * these structures.
384 typedef struct _IMAGE_DEBUG_DIRECTORY {
385 DWORD Characteristics;
386 DWORD TimeDateStamp;
387 WORD MajorVersion;
388 WORD MinorVersion;
389 DWORD Type;
390 DWORD SizeOfData;
391 DWORD AddressOfRawData;
392 DWORD PointerToRawData;
393 } IMAGE_DEBUG_DIRECTORY,*PIMAGE_DEBUG_DIRECTORY;
396 * The type field above can take these (plus a few other
397 * irrelevant) values.
399 #define IMAGE_DEBUG_TYPE_UNKNOWN 0
400 #define IMAGE_DEBUG_TYPE_COFF 1
401 #define IMAGE_DEBUG_TYPE_CODEVIEW 2
402 #define IMAGE_DEBUG_TYPE_FPO 3
403 #define IMAGE_DEBUG_TYPE_MISC 4
404 #define IMAGE_DEBUG_TYPE_EXCEPTION 5
405 #define IMAGE_DEBUG_TYPE_FIXUP 6
406 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
407 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
410 #define IMAGE_REL_BASED_ABSOLUTE 0
411 #define IMAGE_REL_BASED_HIGH 1
412 #define IMAGE_REL_BASED_LOW 2
413 #define IMAGE_REL_BASED_HIGHLOW 3
414 #define IMAGE_REL_BASED_HIGHADJ 4
415 #define IMAGE_REL_BASED_MIPS_JMPADDR 5
418 * This is the structure that appears at the very start of a .DBG file.
420 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
421 WORD Signature;
422 WORD Flags;
423 WORD Machine;
424 WORD Characteristics;
425 DWORD TimeDateStamp;
426 DWORD CheckSum;
427 DWORD ImageBase;
428 DWORD SizeOfImage;
429 DWORD NumberOfSections;
430 DWORD ExportedNamesSize;
431 DWORD DebugDirectorySize;
432 DWORD Reserved[ 3 ];
433 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
435 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
437 #endif /* __WINE_PEEXE_H */