VirtualBox

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

Last change on this file since 19167 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

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