VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/ldrPE.h@ 6696

Last change on this file since 6696 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.8 KB
Line 
1/* $Id: ldrPE.h 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Windows NT PE Structures and Constants.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___internal_ldrPE_h
28#define ___internal_ldrPE_h
29
30#include <iprt/types.h>
31
32#pragma pack(4)
33
34
35/*******************************************************************************
36* Defined Constants And Macros *
37*******************************************************************************/
38#define IMAGE_NT_SIGNATURE 0x00004550
39
40/* file header */
41#define IMAGE_FILE_MACHINE_I386 0x014c
42#define IMAGE_FILE_MACHINE_AMD64 0x8664
43
44#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
45#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
46#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
47#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
48#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
49#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
50#define IMAGE_FILE_16BIT_MACHINE 0x0040
51#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
52#define IMAGE_FILE_32BIT_MACHINE 0x0100
53#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
54#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
55#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
56#define IMAGE_FILE_SYSTEM 0x1000
57#define IMAGE_FILE_DLL 0x2000
58#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
59#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
60
61
62/* optional header */
63#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10B
64#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20B
65
66#define IMAGE_SUBSYSTEM_UNKNOWN 0x0
67#define IMAGE_SUBSYSTEM_NATIVE 0x1
68#define IMAGE_SUBSYSTEM_WINDOWS_GUI 0x2
69#define IMAGE_SUBSYSTEM_WINDOWS_CUI 0x3
70#define IMAGE_SUBSYSTEM_OS2_GUI 0x4
71#define IMAGE_SUBSYSTEM_OS2_CUI 0x5
72#define IMAGE_SUBSYSTEM_POSIX_CUI 0x7
73
74#define IMAGE_LIBRARY_PROCESS_INIT 0x0001
75#define IMAGE_LIBRARY_PROCESS_TERM 0x0002
76#define IMAGE_LIBRARY_THREAD_INIT 0x0004
77#define IMAGE_LIBRARY_THREAD_TERM 0x0008
78#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
79#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
80#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
81#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
82#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
83
84#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 0x10
85
86#define IMAGE_DIRECTORY_ENTRY_EXPORT 0x0
87#define IMAGE_DIRECTORY_ENTRY_IMPORT 0x1
88#define IMAGE_DIRECTORY_ENTRY_RESOURCE 0x2
89#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 0x3
90#define IMAGE_DIRECTORY_ENTRY_SECURITY 0x4
91#define IMAGE_DIRECTORY_ENTRY_BASERELOC 0x5
92#define IMAGE_DIRECTORY_ENTRY_DEBUG 0x6
93#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 0x7
94#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT IMAGE_DIRECTORY_ENTRY_ARCHITECTURE
95#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 0x8
96#define IMAGE_DIRECTORY_ENTRY_TLS 0x9
97#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 0xa
98#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 0xb
99#define IMAGE_DIRECTORY_ENTRY_IAT 0xc
100#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 0xd
101#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 0xe
102
103
104/* section header */
105#define IMAGE_SIZEOF_SHORT_NAME 0x8
106
107#define IMAGE_SCN_TYPE_REG 0x00000000
108#define IMAGE_SCN_TYPE_DSECT 0x00000001
109#define IMAGE_SCN_TYPE_NOLOAD 0x00000002
110#define IMAGE_SCN_TYPE_GROUP 0x00000004
111#define IMAGE_SCN_TYPE_NO_PAD 0x00000008
112#define IMAGE_SCN_TYPE_COPY 0x00000010
113
114#define IMAGE_SCN_CNT_CODE 0x00000020
115#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
116#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
117
118#define IMAGE_SCN_LNK_OTHER 0x00000100
119#define IMAGE_SCN_LNK_INFO 0x00000200
120#define IMAGE_SCN_TYPE_OVER 0x00000400
121#define IMAGE_SCN_LNK_REMOVE 0x00000800
122#define IMAGE_SCN_LNK_COMDAT 0x00001000
123#define IMAGE_SCN_MEM_PROTECTED 0x00004000
124#define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000
125#define IMAGE_SCN_GPREL 0x00008000
126#define IMAGE_SCN_MEM_FARDATA 0x00008000
127#define IMAGE_SCN_MEM_SYSHEAP 0x00010000
128#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
129#define IMAGE_SCN_MEM_16BIT 0x00020000
130#define IMAGE_SCN_MEM_LOCKED 0x00040000
131#define IMAGE_SCN_MEM_PRELOAD 0x00080000
132
133#define IMAGE_SCN_ALIGN_1BYTES 0x00100000
134#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
135#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
136#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
137#define IMAGE_SCN_ALIGN_16BYTES 0x00500000
138#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
139#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
140#define IMAGE_SCN_ALIGN_128BYTES 0x00800000
141#define IMAGE_SCN_ALIGN_256BYTES 0x00900000
142#define IMAGE_SCN_ALIGN_512BYTES 0x00A00000
143#define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000
144#define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000
145#define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000
146#define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000
147#define IMAGE_SCN_ALIGN_MASK 0x00F00000
148
149#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
150#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
151#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000
152#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000
153#define IMAGE_SCN_MEM_SHARED 0x10000000
154#define IMAGE_SCN_MEM_EXECUTE 0x20000000
155#define IMAGE_SCN_MEM_READ 0x40000000
156#define IMAGE_SCN_MEM_WRITE 0x80000000
157
158
159/* relocations */
160#define IMAGE_REL_BASED_ABSOLUTE 0x0
161#define IMAGE_REL_BASED_HIGH 0x1
162#define IMAGE_REL_BASED_LOW 0x2
163#define IMAGE_REL_BASED_HIGHLOW 0x3
164#define IMAGE_REL_BASED_HIGHADJ 0x4
165#define IMAGE_REL_BASED_MIPS_JMPADDR 0x5
166#define IMAGE_REL_BASED_MIPS_JMPADDR16 0x9
167#define IMAGE_REL_BASED_IA64_IMM64 0x9
168#define IMAGE_REL_BASED_DIR64 0xa
169#define IMAGE_REL_BASED_HIGH3ADJ 0xb
170
171
172/* imports */
173#define IMAGE_ORDINAL_FLAG32 0x80000000
174#define IMAGE_ORDINAL32(ord) ((ord) & 0xffff)
175#define IMAGE_SNAP_BY_ORDINAL32(ord) (!!((ord) & IMAGE_ORDINAL_FLAG32))
176
177#define IMAGE_ORDINAL_FLAG64 0x8000000000000000ULL
178#define IMAGE_ORDINAL64(ord) ((ord) & 0xffff)
179#define IMAGE_SNAP_BY_ORDINAL64(ord) (!!((ord) & IMAGE_ORDINAL_FLAG64))
180
181
182/*******************************************************************************
183* Structures and Typedefs *
184*******************************************************************************/
185typedef struct _IMAGE_FILE_HEADER
186{
187 uint16_t Machine;
188 uint16_t NumberOfSections;
189 uint32_t TimeDateStamp;
190 uint32_t PointerToSymbolTable;
191 uint32_t NumberOfSymbols;
192 uint16_t SizeOfOptionalHeader;
193 uint16_t Characteristics;
194} IMAGE_FILE_HEADER;
195typedef IMAGE_FILE_HEADER *PIMAGE_FILE_HEADER;
196
197
198typedef struct _IMAGE_DATA_DIRECTORY
199{
200 uint32_t VirtualAddress;
201 uint32_t Size;
202} IMAGE_DATA_DIRECTORY;
203typedef IMAGE_DATA_DIRECTORY *PIMAGE_DATA_DIRECTORY;
204
205
206typedef struct _IMAGE_OPTIONAL_HEADER32
207{
208 uint16_t Magic;
209 uint8_t MajorLinkerVersion;
210 uint8_t MinorLinkerVersion;
211 uint32_t SizeOfCode;
212 uint32_t SizeOfInitializedData;
213 uint32_t SizeOfUninitializedData;
214 uint32_t AddressOfEntryPoint;
215 uint32_t BaseOfCode;
216 uint32_t BaseOfData;
217 uint32_t ImageBase;
218 uint32_t SectionAlignment;
219 uint32_t FileAlignment;
220 uint16_t MajorOperatingSystemVersion;
221 uint16_t MinorOperatingSystemVersion;
222 uint16_t MajorImageVersion;
223 uint16_t MinorImageVersion;
224 uint16_t MajorSubsystemVersion;
225 uint16_t MinorSubsystemVersion;
226 uint32_t Win32VersionValue;
227 uint32_t SizeOfImage;
228 uint32_t SizeOfHeaders;
229 uint32_t CheckSum;
230 uint16_t Subsystem;
231 uint16_t DllCharacteristics;
232 uint32_t SizeOfStackReserve;
233 uint32_t SizeOfStackCommit;
234 uint32_t SizeOfHeapReserve;
235 uint32_t SizeOfHeapCommit;
236 uint32_t LoaderFlags;
237 uint32_t NumberOfRvaAndSizes;
238 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
239} IMAGE_OPTIONAL_HEADER32;
240typedef IMAGE_OPTIONAL_HEADER32 *PIMAGE_OPTIONAL_HEADER32;
241
242typedef struct _IMAGE_OPTIONAL_HEADER64
243{
244 uint16_t Magic;
245 uint8_t MajorLinkerVersion;
246 uint8_t MinorLinkerVersion;
247 uint32_t SizeOfCode;
248 uint32_t SizeOfInitializedData;
249 uint32_t SizeOfUninitializedData;
250 uint32_t AddressOfEntryPoint;
251 uint32_t BaseOfCode;
252 uint64_t ImageBase;
253 uint32_t SectionAlignment;
254 uint32_t FileAlignment;
255 uint16_t MajorOperatingSystemVersion;
256 uint16_t MinorOperatingSystemVersion;
257 uint16_t MajorImageVersion;
258 uint16_t MinorImageVersion;
259 uint16_t MajorSubsystemVersion;
260 uint16_t MinorSubsystemVersion;
261 uint32_t Win32VersionValue;
262 uint32_t SizeOfImage;
263 uint32_t SizeOfHeaders;
264 uint32_t CheckSum;
265 uint16_t Subsystem;
266 uint16_t DllCharacteristics;
267 uint64_t SizeOfStackReserve;
268 uint64_t SizeOfStackCommit;
269 uint64_t SizeOfHeapReserve;
270 uint64_t SizeOfHeapCommit;
271 uint32_t LoaderFlags;
272 uint32_t NumberOfRvaAndSizes;
273 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
274} IMAGE_OPTIONAL_HEADER64;
275typedef IMAGE_OPTIONAL_HEADER64 *PIMAGE_OPTIONAL_HEADER64;
276
277
278typedef struct _IMAGE_NT_HEADERS
279{
280 uint32_t Signature;
281 IMAGE_FILE_HEADER FileHeader;
282 IMAGE_OPTIONAL_HEADER32 OptionalHeader;
283} IMAGE_NT_HEADERS32;
284typedef IMAGE_NT_HEADERS32 *PIMAGE_NT_HEADERS32;
285
286typedef struct _IMAGE_NT_HEADERS64
287{
288 uint32_t Signature;
289 IMAGE_FILE_HEADER FileHeader;
290 IMAGE_OPTIONAL_HEADER64 OptionalHeader;
291} IMAGE_NT_HEADERS64;
292typedef IMAGE_NT_HEADERS64 *PIMAGE_NT_HEADERS64;
293
294
295typedef struct _IMAGE_SECTION_HEADER
296{
297 uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
298 union
299 {
300 uint32_t PhysicalAddress;
301 uint32_t VirtualSize;
302 } Misc;
303 uint32_t VirtualAddress;
304 uint32_t SizeOfRawData;
305 uint32_t PointerToRawData;
306 uint32_t PointerToRelocations;
307 uint32_t PointerToLinenumbers;
308 uint16_t NumberOfRelocations;
309 uint16_t NumberOfLinenumbers;
310 uint32_t Characteristics;
311} IMAGE_SECTION_HEADER;
312typedef IMAGE_SECTION_HEADER *PIMAGE_SECTION_HEADER;
313
314
315typedef struct _IMAGE_BASE_RELOCATION
316{
317 uint32_t VirtualAddress;
318 uint32_t SizeOfBlock;
319} IMAGE_BASE_RELOCATION;
320typedef IMAGE_BASE_RELOCATION *PIMAGE_BASE_RELOCATION;
321
322
323typedef struct _IMAGE_EXPORT_DIRECTORY
324{
325 uint32_t Characteristics;
326 uint32_t TimeDateStamp;
327 uint16_t MajorVersion;
328 uint16_t MinorVersion;
329 uint32_t Name;
330 uint32_t Base;
331 uint32_t NumberOfFunctions;
332 uint32_t NumberOfNames;
333 uint32_t AddressOfFunctions;
334 uint32_t AddressOfNames;
335 uint32_t AddressOfNameOrdinals;
336} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
337
338
339typedef struct _IMAGE_IMPORT_DESCRIPTOR
340{
341 union
342 {
343 uint32_t Characteristics;
344 uint32_t OriginalFirstThunk;
345 } u;
346 uint32_t TimeDateStamp;
347 uint32_t ForwarderChain;
348 uint32_t Name;
349 uint32_t FirstThunk;
350} IMAGE_IMPORT_DESCRIPTOR;
351typedef IMAGE_IMPORT_DESCRIPTOR *PIMAGE_IMPORT_DESCRIPTOR;
352
353
354typedef struct _IMAGE_IMPORT_BY_NAME
355{
356 uint16_t Hint;
357 uint8_t Name[1];
358} IMAGE_IMPORT_BY_NAME;
359typedef IMAGE_IMPORT_BY_NAME *PIMAGE_IMPORT_BY_NAME;
360
361
362/* The image_thunk_data32/64 structures are not very helpful except for getting RSI. keep them around till all the code has been converted. */
363typedef struct _IMAGE_THUNK_DATA64
364{
365 union
366 {
367 uint64_t ForwarderString;
368 uint64_t Function;
369 uint64_t Ordinal;
370 uint64_t AddressOfData;
371 } u1;
372} IMAGE_THUNK_DATA64;
373typedef IMAGE_THUNK_DATA64 *PIMAGE_THUNK_DATA64;
374
375typedef struct _IMAGE_THUNK_DATA32
376{
377 union
378 {
379 uint32_t ForwarderString;
380 uint32_t Function;
381 uint32_t Ordinal;
382 uint32_t AddressOfData;
383 } u1;
384} IMAGE_THUNK_DATA32;
385typedef IMAGE_THUNK_DATA32 *PIMAGE_THUNK_DATA32;
386
387
388typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY32
389{
390 uint32_t Size;
391 uint32_t TimeDateStamp;
392 uint16_t MajorVersion;
393 uint16_t MinorVersion;
394 uint32_t GlobalFlagsClear;
395 uint32_t GlobalFlagsSet;
396 uint32_t CriticalSectionDefaultTimeout;
397 uint32_t DeCommitFreeBlockThreshold;
398 uint32_t DeCommitTotalFreeThreshold;
399 uint32_t LockPrefixTable;
400 uint32_t MaximumAllocationSize;
401 uint32_t VirtualMemoryThreshold;
402 uint32_t ProcessHeapFlags;
403 uint32_t ProcessAffinityMask;
404 uint16_t CSDVersion;
405 uint16_t Reserved1;
406 uint32_t EditList;
407 uint32_t SecurityCookie;
408 uint32_t SEHandlerTable;
409 uint32_t SEHandlerCount;
410} IMAGE_LOAD_CONFIG_DIRECTORY32;
411typedef IMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY32;
412
413typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY64
414{
415 uint32_t Size;
416 uint32_t TimeDateStamp;
417 uint16_t MajorVersion;
418 uint16_t MinorVersion;
419 uint32_t GlobalFlagsClear;
420 uint32_t GlobalFlagsSet;
421 uint32_t CriticalSectionDefaultTimeout;
422 uint64_t DeCommitFreeBlockThreshold;
423 uint64_t DeCommitTotalFreeThreshold;
424 uint64_t LockPrefixTable;
425 uint64_t MaximumAllocationSize;
426 uint64_t VirtualMemoryThreshold;
427 uint64_t ProcessAffinityMask;
428 uint32_t ProcessHeapFlags;
429 uint16_t CSDVersion;
430 uint16_t Reserved1;
431 uint64_t EditList;
432 uint64_t SecurityCookie;
433 uint64_t SEHandlerTable;
434 uint64_t SEHandlerCount;
435} IMAGE_LOAD_CONFIG_DIRECTORY64;
436typedef IMAGE_LOAD_CONFIG_DIRECTORY64 *PIMAGE_LOAD_CONFIG_DIRECTORY64;
437
438
439#pragma pack()
440
441#endif
442
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette