VirtualBox

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

Last change on this file since 24323 was 24106, checked in by vboxsync, 15 years ago

DBGPlugInWinNt.cpp: digging into debug info...

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