VirtualBox

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

Last change on this file since 38581 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.1 KB
Line 
1/* $Id: ldrPE.h 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - Windows NT PE Structures and Constants.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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/* debug dir */
183#define IMAGE_DEBUG_TYPE_UNKNOWN 0x0
184#define IMAGE_DEBUG_TYPE_COFF 0x1
185#define IMAGE_DEBUG_TYPE_CODEVIEW 0x2
186#define IMAGE_DEBUG_TYPE_FPO 0x3
187#define IMAGE_DEBUG_TYPE_MISC 0x4
188#define IMAGE_DEBUG_TYPE_EXCEPTION 0x5
189#define IMAGE_DEBUG_TYPE_FIXUP 0x6
190#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 0x7
191#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 0x8
192#define IMAGE_DEBUG_TYPE_BORLAND 0x9
193#define IMAGE_DEBUG_TYPE_RESERVED10 0x10
194
195/* security directory */
196#define WIN_CERT_REVISION_1_0 UINT16_C(0x0100)
197#define WIN_CERT_REVISION_2_0 UINT16_C(0x0200)
198
199#define WIN_CERT_TYPE_X509 UINT16_C(1)
200#define WIN_CERT_TYPE_PKCS_SIGNED_DATA UINT16_C(2)
201#define WIN_CERT_TYPE_RESERVED_1 UINT16_C(3)
202#define WIN_CERT_TYPE_TS_STACK_SIGNED UINT16_C(4)
203#define WIN_CERT_TYPE_EFI_PKCS115 UINT16_C(0x0ef0)
204#define WIN_CERT_TYPE_EFI_GUID UINT16_C(0x0ef1)
205
206
207/*******************************************************************************
208* Structures and Typedefs *
209*******************************************************************************/
210typedef struct _IMAGE_FILE_HEADER
211{
212 uint16_t Machine;
213 uint16_t NumberOfSections;
214 uint32_t TimeDateStamp;
215 uint32_t PointerToSymbolTable;
216 uint32_t NumberOfSymbols;
217 uint16_t SizeOfOptionalHeader;
218 uint16_t Characteristics;
219} IMAGE_FILE_HEADER;
220typedef IMAGE_FILE_HEADER *PIMAGE_FILE_HEADER;
221
222
223typedef struct _IMAGE_DATA_DIRECTORY
224{
225 uint32_t VirtualAddress;
226 uint32_t Size;
227} IMAGE_DATA_DIRECTORY;
228typedef IMAGE_DATA_DIRECTORY *PIMAGE_DATA_DIRECTORY;
229
230
231typedef struct _IMAGE_OPTIONAL_HEADER32
232{
233 uint16_t Magic;
234 uint8_t MajorLinkerVersion;
235 uint8_t MinorLinkerVersion;
236 uint32_t SizeOfCode;
237 uint32_t SizeOfInitializedData;
238 uint32_t SizeOfUninitializedData;
239 uint32_t AddressOfEntryPoint;
240 uint32_t BaseOfCode;
241 uint32_t BaseOfData;
242 uint32_t ImageBase;
243 uint32_t SectionAlignment;
244 uint32_t FileAlignment;
245 uint16_t MajorOperatingSystemVersion;
246 uint16_t MinorOperatingSystemVersion;
247 uint16_t MajorImageVersion;
248 uint16_t MinorImageVersion;
249 uint16_t MajorSubsystemVersion;
250 uint16_t MinorSubsystemVersion;
251 uint32_t Win32VersionValue;
252 uint32_t SizeOfImage;
253 uint32_t SizeOfHeaders;
254 uint32_t CheckSum;
255 uint16_t Subsystem;
256 uint16_t DllCharacteristics;
257 uint32_t SizeOfStackReserve;
258 uint32_t SizeOfStackCommit;
259 uint32_t SizeOfHeapReserve;
260 uint32_t SizeOfHeapCommit;
261 uint32_t LoaderFlags;
262 uint32_t NumberOfRvaAndSizes;
263 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
264} IMAGE_OPTIONAL_HEADER32;
265typedef IMAGE_OPTIONAL_HEADER32 *PIMAGE_OPTIONAL_HEADER32;
266
267typedef struct _IMAGE_OPTIONAL_HEADER64
268{
269 uint16_t Magic;
270 uint8_t MajorLinkerVersion;
271 uint8_t MinorLinkerVersion;
272 uint32_t SizeOfCode;
273 uint32_t SizeOfInitializedData;
274 uint32_t SizeOfUninitializedData;
275 uint32_t AddressOfEntryPoint;
276 uint32_t BaseOfCode;
277 uint64_t ImageBase;
278 uint32_t SectionAlignment;
279 uint32_t FileAlignment;
280 uint16_t MajorOperatingSystemVersion;
281 uint16_t MinorOperatingSystemVersion;
282 uint16_t MajorImageVersion;
283 uint16_t MinorImageVersion;
284 uint16_t MajorSubsystemVersion;
285 uint16_t MinorSubsystemVersion;
286 uint32_t Win32VersionValue;
287 uint32_t SizeOfImage;
288 uint32_t SizeOfHeaders;
289 uint32_t CheckSum;
290 uint16_t Subsystem;
291 uint16_t DllCharacteristics;
292 uint64_t SizeOfStackReserve;
293 uint64_t SizeOfStackCommit;
294 uint64_t SizeOfHeapReserve;
295 uint64_t SizeOfHeapCommit;
296 uint32_t LoaderFlags;
297 uint32_t NumberOfRvaAndSizes;
298 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
299} IMAGE_OPTIONAL_HEADER64;
300typedef IMAGE_OPTIONAL_HEADER64 *PIMAGE_OPTIONAL_HEADER64;
301
302
303typedef struct _IMAGE_NT_HEADERS
304{
305 uint32_t Signature;
306 IMAGE_FILE_HEADER FileHeader;
307 IMAGE_OPTIONAL_HEADER32 OptionalHeader;
308} IMAGE_NT_HEADERS32;
309typedef IMAGE_NT_HEADERS32 *PIMAGE_NT_HEADERS32;
310
311typedef struct _IMAGE_NT_HEADERS64
312{
313 uint32_t Signature;
314 IMAGE_FILE_HEADER FileHeader;
315 IMAGE_OPTIONAL_HEADER64 OptionalHeader;
316} IMAGE_NT_HEADERS64;
317typedef IMAGE_NT_HEADERS64 *PIMAGE_NT_HEADERS64;
318
319
320typedef struct _IMAGE_SECTION_HEADER
321{
322 uint8_t Name[IMAGE_SIZEOF_SHORT_NAME];
323 union
324 {
325 uint32_t PhysicalAddress;
326 uint32_t VirtualSize;
327 } Misc;
328 uint32_t VirtualAddress;
329 uint32_t SizeOfRawData;
330 uint32_t PointerToRawData;
331 uint32_t PointerToRelocations;
332 uint32_t PointerToLinenumbers;
333 uint16_t NumberOfRelocations;
334 uint16_t NumberOfLinenumbers;
335 uint32_t Characteristics;
336} IMAGE_SECTION_HEADER;
337typedef IMAGE_SECTION_HEADER *PIMAGE_SECTION_HEADER;
338
339
340typedef struct _IMAGE_BASE_RELOCATION
341{
342 uint32_t VirtualAddress;
343 uint32_t SizeOfBlock;
344} IMAGE_BASE_RELOCATION;
345typedef IMAGE_BASE_RELOCATION *PIMAGE_BASE_RELOCATION;
346
347
348typedef struct _IMAGE_EXPORT_DIRECTORY
349{
350 uint32_t Characteristics;
351 uint32_t TimeDateStamp;
352 uint16_t MajorVersion;
353 uint16_t MinorVersion;
354 uint32_t Name;
355 uint32_t Base;
356 uint32_t NumberOfFunctions;
357 uint32_t NumberOfNames;
358 uint32_t AddressOfFunctions;
359 uint32_t AddressOfNames;
360 uint32_t AddressOfNameOrdinals;
361} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
362
363
364typedef struct _IMAGE_IMPORT_DESCRIPTOR
365{
366 union
367 {
368 uint32_t Characteristics;
369 uint32_t OriginalFirstThunk;
370 } u;
371 uint32_t TimeDateStamp;
372 uint32_t ForwarderChain;
373 uint32_t Name;
374 uint32_t FirstThunk;
375} IMAGE_IMPORT_DESCRIPTOR;
376typedef IMAGE_IMPORT_DESCRIPTOR *PIMAGE_IMPORT_DESCRIPTOR;
377
378
379typedef struct _IMAGE_IMPORT_BY_NAME
380{
381 uint16_t Hint;
382 uint8_t Name[1];
383} IMAGE_IMPORT_BY_NAME;
384typedef IMAGE_IMPORT_BY_NAME *PIMAGE_IMPORT_BY_NAME;
385
386
387/* The image_thunk_data32/64 structures are not very helpful except for getting RSI. keep them around till all the code has been converted. */
388typedef struct _IMAGE_THUNK_DATA64
389{
390 union
391 {
392 uint64_t ForwarderString;
393 uint64_t Function;
394 uint64_t Ordinal;
395 uint64_t AddressOfData;
396 } u1;
397} IMAGE_THUNK_DATA64;
398typedef IMAGE_THUNK_DATA64 *PIMAGE_THUNK_DATA64;
399
400typedef struct _IMAGE_THUNK_DATA32
401{
402 union
403 {
404 uint32_t ForwarderString;
405 uint32_t Function;
406 uint32_t Ordinal;
407 uint32_t AddressOfData;
408 } u1;
409} IMAGE_THUNK_DATA32;
410typedef IMAGE_THUNK_DATA32 *PIMAGE_THUNK_DATA32;
411
412
413typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY32
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 uint32_t DeCommitFreeBlockThreshold;
423 uint32_t DeCommitTotalFreeThreshold;
424 uint32_t LockPrefixTable;
425 uint32_t MaximumAllocationSize;
426 uint32_t VirtualMemoryThreshold;
427 uint32_t ProcessHeapFlags;
428 uint32_t ProcessAffinityMask;
429 uint16_t CSDVersion;
430 uint16_t Reserved1;
431 uint32_t EditList;
432 uint32_t SecurityCookie;
433 uint32_t SEHandlerTable;
434 uint32_t SEHandlerCount;
435} IMAGE_LOAD_CONFIG_DIRECTORY32;
436typedef IMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY32;
437
438typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY64
439{
440 uint32_t Size;
441 uint32_t TimeDateStamp;
442 uint16_t MajorVersion;
443 uint16_t MinorVersion;
444 uint32_t GlobalFlagsClear;
445 uint32_t GlobalFlagsSet;
446 uint32_t CriticalSectionDefaultTimeout;
447 uint64_t DeCommitFreeBlockThreshold;
448 uint64_t DeCommitTotalFreeThreshold;
449 uint64_t LockPrefixTable;
450 uint64_t MaximumAllocationSize;
451 uint64_t VirtualMemoryThreshold;
452 uint64_t ProcessAffinityMask;
453 uint32_t ProcessHeapFlags;
454 uint16_t CSDVersion;
455 uint16_t Reserved1;
456 uint64_t EditList;
457 uint64_t SecurityCookie;
458 uint64_t SEHandlerTable;
459 uint64_t SEHandlerCount;
460} IMAGE_LOAD_CONFIG_DIRECTORY64;
461typedef IMAGE_LOAD_CONFIG_DIRECTORY64 *PIMAGE_LOAD_CONFIG_DIRECTORY64;
462
463
464typedef struct _IMAGE_DEBUG_DIRECTORY
465{
466 uint32_t Characteristics;
467 uint32_t TimeDateStamp;
468 uint16_t MajorVersion;
469 uint16_t MinorVersion;
470 uint32_t Type;
471 uint32_t SizeOfData;
472 uint32_t AddressOfRawData;
473 uint32_t PointerToRawData;
474} IMAGE_DEBUG_DIRECTORY;
475typedef IMAGE_DEBUG_DIRECTORY *PIMAGE_DEBUG_DIRECTORY;
476
477
478typedef struct WIN_CERTIFICATE
479{
480 uint32_t dwLength;
481 uint16_t wRevision;
482 uint16_t wCertificateType;
483 uint8_t bCertificate[8];
484} WIN_CERTIFICATE;
485typedef WIN_CERTIFICATE *PWIN_CERTIFICATE;
486
487#pragma pack()
488
489#endif
490
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