Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1829 lines
75 KiB

  1. /*++ BUILD Version: 0004 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntimage.h
  5. Abstract:
  6. This is the include file that describes all image structures.
  7. Author:
  8. Mike O'Leary (mikeol) 21-Mar-1991
  9. Revision History:
  10. --*/
  11. #ifndef _NTIMAGE_
  12. #define _NTIMAGE_
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. //
  17. // Define the linker version number. This is temporary to aid
  18. // in debugging with people trying to load images built with
  19. // an older linker. This is not required in the final product.
  20. //
  21. #define IMAGE_MAJOR_LINKER_VERSION 2
  22. // begin_winnt
  23. //
  24. // Image Format
  25. //
  26. #ifndef _MAC
  27. #include "pshpack4.h" // 4 byte packing is the default
  28. #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
  29. #define IMAGE_OS2_SIGNATURE 0x454E // NE
  30. #define IMAGE_OS2_SIGNATURE_LE 0x454C // LE
  31. #define IMAGE_VXD_SIGNATURE 0x454C // LE
  32. #define IMAGE_NT_SIGNATURE 0x00004550 // PE00
  33. #include "pshpack2.h" // 16 bit headers are 2 byte packed
  34. #else
  35. #include "pshpack1.h"
  36. #define IMAGE_DOS_SIGNATURE 0x4D5A // MZ
  37. #define IMAGE_OS2_SIGNATURE 0x4E45 // NE
  38. #define IMAGE_OS2_SIGNATURE_LE 0x4C45 // LE
  39. #define IMAGE_NT_SIGNATURE 0x50450000 // PE00
  40. #endif
  41. typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
  42. USHORT e_magic; // Magic number
  43. USHORT e_cblp; // Bytes on last page of file
  44. USHORT e_cp; // Pages in file
  45. USHORT e_crlc; // Relocations
  46. USHORT e_cparhdr; // Size of header in paragraphs
  47. USHORT e_minalloc; // Minimum extra paragraphs needed
  48. USHORT e_maxalloc; // Maximum extra paragraphs needed
  49. USHORT e_ss; // Initial (relative) SS value
  50. USHORT e_sp; // Initial SP value
  51. USHORT e_csum; // Checksum
  52. USHORT e_ip; // Initial IP value
  53. USHORT e_cs; // Initial (relative) CS value
  54. USHORT e_lfarlc; // File address of relocation table
  55. USHORT e_ovno; // Overlay number
  56. USHORT e_res[4]; // Reserved words
  57. USHORT e_oemid; // OEM identifier (for e_oeminfo)
  58. USHORT e_oeminfo; // OEM information; e_oemid specific
  59. USHORT e_res2[10]; // Reserved words
  60. LONG e_lfanew; // File address of new exe header
  61. } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  62. typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
  63. USHORT ne_magic; // Magic number
  64. CHAR ne_ver; // Version number
  65. CHAR ne_rev; // Revision number
  66. USHORT ne_enttab; // Offset of Entry Table
  67. USHORT ne_cbenttab; // Number of bytes in Entry Table
  68. LONG ne_crc; // Checksum of whole file
  69. USHORT ne_flags; // Flag word
  70. USHORT ne_autodata; // Automatic data segment number
  71. USHORT ne_heap; // Initial heap allocation
  72. USHORT ne_stack; // Initial stack allocation
  73. LONG ne_csip; // Initial CS:IP setting
  74. LONG ne_sssp; // Initial SS:SP setting
  75. USHORT ne_cseg; // Count of file segments
  76. USHORT ne_cmod; // Entries in Module Reference Table
  77. USHORT ne_cbnrestab; // Size of non-resident name table
  78. USHORT ne_segtab; // Offset of Segment Table
  79. USHORT ne_rsrctab; // Offset of Resource Table
  80. USHORT ne_restab; // Offset of resident name table
  81. USHORT ne_modtab; // Offset of Module Reference Table
  82. USHORT ne_imptab; // Offset of Imported Names Table
  83. LONG ne_nrestab; // Offset of Non-resident Names Table
  84. USHORT ne_cmovent; // Count of movable entries
  85. USHORT ne_align; // Segment alignment shift count
  86. USHORT ne_cres; // Count of resource segments
  87. UCHAR ne_exetyp; // Target Operating system
  88. UCHAR ne_flagsothers; // Other .EXE flags
  89. USHORT ne_pretthunks; // offset to return thunks
  90. USHORT ne_psegrefbytes; // offset to segment ref. bytes
  91. USHORT ne_swaparea; // Minimum code swap area size
  92. USHORT ne_expver; // Expected Windows version number
  93. } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  94. typedef struct _IMAGE_VXD_HEADER { // Windows VXD header
  95. USHORT e32_magic; // Magic number
  96. UCHAR e32_border; // The byte ordering for the VXD
  97. UCHAR e32_worder; // The word ordering for the VXD
  98. ULONG e32_level; // The EXE format level for now = 0
  99. USHORT e32_cpu; // The CPU type
  100. USHORT e32_os; // The OS type
  101. ULONG e32_ver; // Module version
  102. ULONG e32_mflags; // Module flags
  103. ULONG e32_mpages; // Module # pages
  104. ULONG e32_startobj; // Object # for instruction pointer
  105. ULONG e32_eip; // Extended instruction pointer
  106. ULONG e32_stackobj; // Object # for stack pointer
  107. ULONG e32_esp; // Extended stack pointer
  108. ULONG e32_pagesize; // VXD page size
  109. ULONG e32_lastpagesize; // Last page size in VXD
  110. ULONG e32_fixupsize; // Fixup section size
  111. ULONG e32_fixupsum; // Fixup section checksum
  112. ULONG e32_ldrsize; // Loader section size
  113. ULONG e32_ldrsum; // Loader section checksum
  114. ULONG e32_objtab; // Object table offset
  115. ULONG e32_objcnt; // Number of objects in module
  116. ULONG e32_objmap; // Object page map offset
  117. ULONG e32_itermap; // Object iterated data map offset
  118. ULONG e32_rsrctab; // Offset of Resource Table
  119. ULONG e32_rsrccnt; // Number of resource entries
  120. ULONG e32_restab; // Offset of resident name table
  121. ULONG e32_enttab; // Offset of Entry Table
  122. ULONG e32_dirtab; // Offset of Module Directive Table
  123. ULONG e32_dircnt; // Number of module directives
  124. ULONG e32_fpagetab; // Offset of Fixup Page Table
  125. ULONG e32_frectab; // Offset of Fixup Record Table
  126. ULONG e32_impmod; // Offset of Import Module Name Table
  127. ULONG e32_impmodcnt; // Number of entries in Import Module Name Table
  128. ULONG e32_impproc; // Offset of Import Procedure Name Table
  129. ULONG e32_pagesum; // Offset of Per-Page Checksum Table
  130. ULONG e32_datapage; // Offset of Enumerated Data Pages
  131. ULONG e32_preload; // Number of preload pages
  132. ULONG e32_nrestab; // Offset of Non-resident Names Table
  133. ULONG e32_cbnrestab; // Size of Non-resident Name Table
  134. ULONG e32_nressum; // Non-resident Name Table Checksum
  135. ULONG e32_autodata; // Object # for automatic data object
  136. ULONG e32_debuginfo; // Offset of the debugging information
  137. ULONG e32_debuglen; // The length of the debugging info. in bytes
  138. ULONG e32_instpreload; // Number of instance pages in preload section of VXD file
  139. ULONG e32_instdemand; // Number of instance pages in demand load section of VXD file
  140. ULONG e32_heapsize; // Size of heap - for 16-bit apps
  141. UCHAR e32_res3[12]; // Reserved words
  142. ULONG e32_winresoff;
  143. ULONG e32_winreslen;
  144. USHORT e32_devid; // Device ID for VxD
  145. USHORT e32_ddkver; // DDK version for VxD
  146. } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
  147. #ifndef _MAC
  148. #include "poppack.h" // Back to 4 byte packing
  149. #endif
  150. //
  151. // File header format.
  152. //
  153. typedef struct _IMAGE_FILE_HEADER {
  154. USHORT Machine;
  155. USHORT NumberOfSections;
  156. ULONG TimeDateStamp;
  157. ULONG PointerToSymbolTable;
  158. ULONG NumberOfSymbols;
  159. USHORT SizeOfOptionalHeader;
  160. USHORT Characteristics;
  161. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  162. #define IMAGE_SIZEOF_FILE_HEADER 20
  163. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
  164. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
  165. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
  166. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
  167. #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 // Agressively trim working set
  168. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 // App can handle >2gb addresses
  169. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
  170. #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
  171. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
  172. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file.
  173. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file.
  174. #define IMAGE_FILE_SYSTEM 0x1000 // System File.
  175. #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
  176. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine
  177. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
  178. #define IMAGE_FILE_MACHINE_UNKNOWN 0
  179. #define IMAGE_FILE_MACHINE_I386 0x014c // Intel 386.
  180. #define IMAGE_FILE_MACHINE_R3000 0x0162 // MIPS little-endian, 0x160 big-endian
  181. #define IMAGE_FILE_MACHINE_R4000 0x0166 // MIPS little-endian
  182. #define IMAGE_FILE_MACHINE_R10000 0x0168 // MIPS little-endian
  183. #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 // MIPS little-endian WCE v2
  184. #define IMAGE_FILE_MACHINE_ALPHA 0x0184 // Alpha_AXP
  185. #define IMAGE_FILE_MACHINE_SH3 0x01a2 // SH3 little-endian
  186. #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
  187. #define IMAGE_FILE_MACHINE_SH3E 0x01a4 // SH3E little-endian
  188. #define IMAGE_FILE_MACHINE_SH4 0x01a6 // SH4 little-endian
  189. #define IMAGE_FILE_MACHINE_SH5 0x01a8 // SH5
  190. #define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
  191. #define IMAGE_FILE_MACHINE_THUMB 0x01c2
  192. #define IMAGE_FILE_MACHINE_AM33 0x01d3
  193. #define IMAGE_FILE_MACHINE_POWERPC 0x01F0 // IBM PowerPC Little-Endian
  194. #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
  195. #define IMAGE_FILE_MACHINE_IA64 0x0200 // Intel 64
  196. #define IMAGE_FILE_MACHINE_MIPS16 0x0266 // MIPS
  197. #define IMAGE_FILE_MACHINE_ALPHA64 0x0284 // ALPHA64
  198. #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 // MIPS
  199. #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 // MIPS
  200. #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
  201. #define IMAGE_FILE_MACHINE_TRICORE 0x0520 // Infineon
  202. #define IMAGE_FILE_MACHINE_CEF 0x0CEF
  203. #define IMAGE_FILE_MACHINE_EBC 0x0EBC // EFI Byte Code
  204. #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8)
  205. #define IMAGE_FILE_MACHINE_M32R 0x9041 // M32R little-endian
  206. #define IMAGE_FILE_MACHINE_CEE 0xC0EE
  207. //
  208. // Directory format.
  209. //
  210. typedef struct _IMAGE_DATA_DIRECTORY {
  211. ULONG VirtualAddress;
  212. ULONG Size;
  213. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  214. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
  215. //
  216. // Optional header format.
  217. //
  218. typedef struct _IMAGE_OPTIONAL_HEADER {
  219. //
  220. // Standard fields.
  221. //
  222. USHORT Magic;
  223. UCHAR MajorLinkerVersion;
  224. UCHAR MinorLinkerVersion;
  225. ULONG SizeOfCode;
  226. ULONG SizeOfInitializedData;
  227. ULONG SizeOfUninitializedData;
  228. ULONG AddressOfEntryPoint;
  229. ULONG BaseOfCode;
  230. ULONG BaseOfData;
  231. //
  232. // NT additional fields.
  233. //
  234. ULONG ImageBase;
  235. ULONG SectionAlignment;
  236. ULONG FileAlignment;
  237. USHORT MajorOperatingSystemVersion;
  238. USHORT MinorOperatingSystemVersion;
  239. USHORT MajorImageVersion;
  240. USHORT MinorImageVersion;
  241. USHORT MajorSubsystemVersion;
  242. USHORT MinorSubsystemVersion;
  243. ULONG Win32VersionValue;
  244. ULONG SizeOfImage;
  245. ULONG SizeOfHeaders;
  246. ULONG CheckSum;
  247. USHORT Subsystem;
  248. USHORT DllCharacteristics;
  249. ULONG SizeOfStackReserve;
  250. ULONG SizeOfStackCommit;
  251. ULONG SizeOfHeapReserve;
  252. ULONG SizeOfHeapCommit;
  253. ULONG LoaderFlags;
  254. ULONG NumberOfRvaAndSizes;
  255. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  256. } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
  257. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  258. USHORT Magic;
  259. UCHAR MajorLinkerVersion;
  260. UCHAR MinorLinkerVersion;
  261. ULONG SizeOfCode;
  262. ULONG SizeOfInitializedData;
  263. ULONG SizeOfUninitializedData;
  264. ULONG AddressOfEntryPoint;
  265. ULONG BaseOfCode;
  266. ULONG BaseOfData;
  267. ULONG BaseOfBss;
  268. ULONG GprMask;
  269. ULONG CprMask[4];
  270. ULONG GpValue;
  271. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  272. typedef struct _IMAGE_OPTIONAL_HEADER64 {
  273. USHORT Magic;
  274. UCHAR MajorLinkerVersion;
  275. UCHAR MinorLinkerVersion;
  276. ULONG SizeOfCode;
  277. ULONG SizeOfInitializedData;
  278. ULONG SizeOfUninitializedData;
  279. ULONG AddressOfEntryPoint;
  280. ULONG BaseOfCode;
  281. ULONGLONG ImageBase;
  282. ULONG SectionAlignment;
  283. ULONG FileAlignment;
  284. USHORT MajorOperatingSystemVersion;
  285. USHORT MinorOperatingSystemVersion;
  286. USHORT MajorImageVersion;
  287. USHORT MinorImageVersion;
  288. USHORT MajorSubsystemVersion;
  289. USHORT MinorSubsystemVersion;
  290. ULONG Win32VersionValue;
  291. ULONG SizeOfImage;
  292. ULONG SizeOfHeaders;
  293. ULONG CheckSum;
  294. USHORT Subsystem;
  295. USHORT DllCharacteristics;
  296. ULONGLONG SizeOfStackReserve;
  297. ULONGLONG SizeOfStackCommit;
  298. ULONGLONG SizeOfHeapReserve;
  299. ULONGLONG SizeOfHeapCommit;
  300. ULONG LoaderFlags;
  301. ULONG NumberOfRvaAndSizes;
  302. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  303. } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
  304. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
  305. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
  306. #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
  307. #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
  308. #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
  309. #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
  310. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
  311. #ifdef _WIN64
  312. typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
  313. typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
  314. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
  315. #define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
  316. #else
  317. typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
  318. typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
  319. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
  320. #define IMAGE_NT_OPTIONAL_HDR_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
  321. #endif
  322. typedef struct _IMAGE_NT_HEADERS64 {
  323. ULONG Signature;
  324. IMAGE_FILE_HEADER FileHeader;
  325. IMAGE_OPTIONAL_HEADER64 OptionalHeader;
  326. } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
  327. typedef struct _IMAGE_NT_HEADERS {
  328. ULONG Signature;
  329. IMAGE_FILE_HEADER FileHeader;
  330. IMAGE_OPTIONAL_HEADER32 OptionalHeader;
  331. } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
  332. typedef struct _IMAGE_ROM_HEADERS {
  333. IMAGE_FILE_HEADER FileHeader;
  334. IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  335. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  336. #ifdef _WIN64
  337. typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
  338. typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
  339. #else
  340. typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
  341. typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
  342. #endif
  343. // IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is the same either way.
  344. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
  345. ((ULONG_PTR)ntheader + \
  346. FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
  347. ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
  348. ))
  349. // Subsystem Values
  350. #define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
  351. #define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
  352. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
  353. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
  354. // end_winnt
  355. // reserved 4 // Old Windows CE subsystem.
  356. // begin_winnt
  357. #define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
  358. #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image runs in the Posix character subsystem.
  359. #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 // image is a native Win9x driver.
  360. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 // Image runs in the Windows CE subsystem.
  361. #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 //
  362. #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 //
  363. #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 //
  364. #define IMAGE_SUBSYSTEM_EFI_ROM 13
  365. #define IMAGE_SUBSYSTEM_XBOX 14
  366. // DllCharacteristics Entries
  367. // IMAGE_LIBRARY_PROCESS_INIT 0x0001 // Reserved.
  368. // IMAGE_LIBRARY_PROCESS_TERM 0x0002 // Reserved.
  369. // IMAGE_LIBRARY_THREAD_INIT 0x0004 // Reserved.
  370. // IMAGE_LIBRARY_THREAD_TERM 0x0008 // Reserved.
  371. #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 // Do not bind this image.
  372. // 0x1000 // Reserved.
  373. #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 // Driver uses WDM model
  374. // 0x4000 // Reserved.
  375. #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
  376. // end_winnt
  377. #define IMAGE_DLLCHARACTERISTICS_X86_THUNK 0x1000 // Image is a Wx86 Thunk DLL
  378. // Note: The Borland linker sets IMAGE_LIBRARY_xxx flags in DllCharacteristics
  379. // LoaderFlags Values
  380. #define IMAGE_LOADER_FLAGS_COMPLUS 0x00000001 // COM+ image
  381. #define IMAGE_LOADER_FLAGS_SYSTEM_GLOBAL 0x01000000 // Global subsections apply across TS sessions.
  382. // begin_winnt
  383. // Directory Entries
  384. #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
  385. #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
  386. #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
  387. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
  388. #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
  389. #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
  390. #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
  391. // IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // (X86 usage)
  392. #define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data
  393. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP
  394. #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
  395. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
  396. #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers
  397. #define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table
  398. #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors
  399. #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor
  400. //
  401. // Non-COFF Object file header
  402. //
  403. typedef struct ANON_OBJECT_HEADER {
  404. USHORT Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
  405. USHORT Sig2; // Must be 0xffff
  406. USHORT Version; // >= 1 (implies the CLSID field is present)
  407. USHORT Machine;
  408. ULONG TimeDateStamp;
  409. CLSID ClassID; // Used to invoke CoCreateInstance
  410. ULONG SizeOfData; // Size of data that follows the header
  411. } ANON_OBJECT_HEADER;
  412. //
  413. // Section header format.
  414. //
  415. #define IMAGE_SIZEOF_SHORT_NAME 8
  416. typedef struct _IMAGE_SECTION_HEADER {
  417. UCHAR Name[IMAGE_SIZEOF_SHORT_NAME];
  418. union {
  419. ULONG PhysicalAddress;
  420. ULONG VirtualSize;
  421. } Misc;
  422. ULONG VirtualAddress;
  423. ULONG SizeOfRawData;
  424. ULONG PointerToRawData;
  425. ULONG PointerToRelocations;
  426. ULONG PointerToLinenumbers;
  427. USHORT NumberOfRelocations;
  428. USHORT NumberOfLinenumbers;
  429. ULONG Characteristics;
  430. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  431. #define IMAGE_SIZEOF_SECTION_HEADER 40
  432. //
  433. // Section characteristics.
  434. //
  435. // IMAGE_SCN_TYPE_REG 0x00000000 // Reserved.
  436. // IMAGE_SCN_TYPE_DSECT 0x00000001 // Reserved.
  437. // IMAGE_SCN_TYPE_NOLOAD 0x00000002 // Reserved.
  438. // IMAGE_SCN_TYPE_GROUP 0x00000004 // Reserved.
  439. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
  440. // IMAGE_SCN_TYPE_COPY 0x00000010 // Reserved.
  441. #define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
  442. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
  443. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
  444. #define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
  445. #define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
  446. // IMAGE_SCN_TYPE_OVER 0x00000400 // Reserved.
  447. #define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
  448. #define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
  449. // 0x00002000 // Reserved.
  450. // IMAGE_SCN_MEM_PROTECTED - Obsolete 0x00004000
  451. #define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 // Reset speculative exceptions handling bits in the TLB entries for this section.
  452. #define IMAGE_SCN_GPREL 0x00008000 // Section content can be accessed relative to GP
  453. #define IMAGE_SCN_MEM_FARDATA 0x00008000
  454. // IMAGE_SCN_MEM_SYSHEAP - Obsolete 0x00010000
  455. #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
  456. #define IMAGE_SCN_MEM_16BIT 0x00020000
  457. #define IMAGE_SCN_MEM_LOCKED 0x00040000
  458. #define IMAGE_SCN_MEM_PRELOAD 0x00080000
  459. #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //
  460. #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //
  461. #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //
  462. #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //
  463. #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
  464. #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //
  465. #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //
  466. #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 //
  467. #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 //
  468. #define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 //
  469. #define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 //
  470. #define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 //
  471. #define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 //
  472. #define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 //
  473. // Unused 0x00F00000
  474. #define IMAGE_SCN_ALIGN_MASK 0x00F00000
  475. #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 // Section contains extended relocations.
  476. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
  477. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
  478. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
  479. #define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
  480. #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
  481. #define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
  482. #define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
  483. //
  484. // TLS Chaacteristic Flags
  485. //
  486. #define IMAGE_SCN_SCALE_INDEX 0x00000001 // Tls index is scaled
  487. #ifndef _MAC
  488. #include "pshpack2.h" // Symbols, relocs, and linenumbers are 2 byte packed
  489. #endif
  490. //
  491. // Symbol format.
  492. //
  493. typedef struct _IMAGE_SYMBOL {
  494. union {
  495. UCHAR ShortName[8];
  496. struct {
  497. ULONG Short; // if 0, use LongName
  498. ULONG Long; // offset into string table
  499. } Name;
  500. ULONG LongName[2]; // PUCHAR[2]
  501. } N;
  502. ULONG Value;
  503. SHORT SectionNumber;
  504. USHORT Type;
  505. UCHAR StorageClass;
  506. UCHAR NumberOfAuxSymbols;
  507. } IMAGE_SYMBOL;
  508. typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
  509. #define IMAGE_SIZEOF_SYMBOL 18
  510. //
  511. // Section values.
  512. //
  513. // Symbols have a section number of the section in which they are
  514. // defined. Otherwise, section numbers have the following meanings:
  515. //
  516. #define IMAGE_SYM_UNDEFINED (SHORT)0 // Symbol is undefined or is common.
  517. #define IMAGE_SYM_ABSOLUTE (SHORT)-1 // Symbol is an absolute value.
  518. #define IMAGE_SYM_DEBUG (SHORT)-2 // Symbol is a special debug item.
  519. #define IMAGE_SYM_SECTION_MAX 0xFEFF // Values 0xFF00-0xFFFF are special
  520. //
  521. // Type (fundamental) values.
  522. //
  523. #define IMAGE_SYM_TYPE_NULL 0x0000 // no type.
  524. #define IMAGE_SYM_TYPE_VOID 0x0001 //
  525. #define IMAGE_SYM_TYPE_CHAR 0x0002 // type character.
  526. #define IMAGE_SYM_TYPE_SHORT 0x0003 // type short integer.
  527. #define IMAGE_SYM_TYPE_INT 0x0004 //
  528. #define IMAGE_SYM_TYPE_LONG 0x0005 //
  529. #define IMAGE_SYM_TYPE_FLOAT 0x0006 //
  530. #define IMAGE_SYM_TYPE_DOUBLE 0x0007 //
  531. #define IMAGE_SYM_TYPE_STRUCT 0x0008 //
  532. #define IMAGE_SYM_TYPE_UNION 0x0009 //
  533. #define IMAGE_SYM_TYPE_ENUM 0x000A // enumeration.
  534. #define IMAGE_SYM_TYPE_MOE 0x000B // member of enumeration.
  535. #define IMAGE_SYM_TYPE_UCHAR 0x000C //
  536. #define IMAGE_SYM_TYPE_USHORT 0x000D //
  537. #define IMAGE_SYM_TYPE_UINT 0x000E //
  538. #define IMAGE_SYM_TYPE_ULONG 0x000F //
  539. #define IMAGE_SYM_TYPE_PCODE 0x8000 //
  540. //
  541. // Type (derived) values.
  542. //
  543. #define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
  544. #define IMAGE_SYM_DTYPE_POINTER 1 // pointer.
  545. #define IMAGE_SYM_DTYPE_FUNCTION 2 // function.
  546. #define IMAGE_SYM_DTYPE_ARRAY 3 // array.
  547. //
  548. // Storage classes.
  549. //
  550. #define IMAGE_SYM_CLASS_END_OF_FUNCTION (UCHAR)-1
  551. #define IMAGE_SYM_CLASS_NULL 0x0000
  552. #define IMAGE_SYM_CLASS_AUTOMATIC 0x0001
  553. #define IMAGE_SYM_CLASS_EXTERNAL 0x0002
  554. #define IMAGE_SYM_CLASS_STATIC 0x0003
  555. #define IMAGE_SYM_CLASS_REGISTER 0x0004
  556. #define IMAGE_SYM_CLASS_EXTERNAL_DEF 0x0005
  557. #define IMAGE_SYM_CLASS_LABEL 0x0006
  558. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 0x0007
  559. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 0x0008
  560. #define IMAGE_SYM_CLASS_ARGUMENT 0x0009
  561. #define IMAGE_SYM_CLASS_STRUCT_TAG 0x000A
  562. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 0x000B
  563. #define IMAGE_SYM_CLASS_UNION_TAG 0x000C
  564. #define IMAGE_SYM_CLASS_TYPE_DEFINITION 0x000D
  565. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 0x000E
  566. #define IMAGE_SYM_CLASS_ENUM_TAG 0x000F
  567. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 0x0010
  568. #define IMAGE_SYM_CLASS_REGISTER_PARAM 0x0011
  569. #define IMAGE_SYM_CLASS_BIT_FIELD 0x0012
  570. #define IMAGE_SYM_CLASS_FAR_EXTERNAL 0x0044 //
  571. #define IMAGE_SYM_CLASS_BLOCK 0x0064
  572. #define IMAGE_SYM_CLASS_FUNCTION 0x0065
  573. #define IMAGE_SYM_CLASS_END_OF_STRUCT 0x0066
  574. #define IMAGE_SYM_CLASS_FILE 0x0067
  575. // new
  576. #define IMAGE_SYM_CLASS_SECTION 0x0068
  577. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 0x0069
  578. #define IMAGE_SYM_CLASS_CLR_TOKEN 0x006B
  579. // type packing constants
  580. #define N_BTMASK 0x000F
  581. #define N_TMASK 0x0030
  582. #define N_TMASK1 0x00C0
  583. #define N_TMASK2 0x00F0
  584. #define N_BTSHFT 4
  585. #define N_TSHIFT 2
  586. // MACROS
  587. // Basic Type of x
  588. #define BTYPE(x) ((x) & N_BTMASK)
  589. // Is x a pointer?
  590. #ifndef ISPTR
  591. #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
  592. #endif
  593. // Is x a function?
  594. #ifndef ISFCN
  595. #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
  596. #endif
  597. // Is x an array?
  598. #ifndef ISARY
  599. #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
  600. #endif
  601. // Is x a structure, union, or enumeration TAG?
  602. #ifndef ISTAG
  603. #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
  604. #endif
  605. #ifndef INCREF
  606. #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
  607. #endif
  608. #ifndef DECREF
  609. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  610. #endif
  611. //
  612. // Auxiliary entry format.
  613. //
  614. typedef union _IMAGE_AUX_SYMBOL {
  615. struct {
  616. ULONG TagIndex; // struct, union, or enum tag index
  617. union {
  618. struct {
  619. USHORT Linenumber; // declaration line number
  620. USHORT Size; // size of struct, union, or enum
  621. } LnSz;
  622. ULONG TotalSize;
  623. } Misc;
  624. union {
  625. struct { // if ISFCN, tag, or .bb
  626. ULONG PointerToLinenumber;
  627. ULONG PointerToNextFunction;
  628. } Function;
  629. struct { // if ISARY, up to 4 dimen.
  630. USHORT Dimension[4];
  631. } Array;
  632. } FcnAry;
  633. USHORT TvIndex; // tv index
  634. } Sym;
  635. struct {
  636. UCHAR Name[IMAGE_SIZEOF_SYMBOL];
  637. } File;
  638. struct {
  639. ULONG Length; // section length
  640. USHORT NumberOfRelocations; // number of relocation entries
  641. USHORT NumberOfLinenumbers; // number of line numbers
  642. ULONG CheckSum; // checksum for communal
  643. SHORT Number; // section number to associate with
  644. UCHAR Selection; // communal selection type
  645. } Section;
  646. } IMAGE_AUX_SYMBOL;
  647. typedef IMAGE_AUX_SYMBOL UNALIGNED *PIMAGE_AUX_SYMBOL;
  648. #define IMAGE_SIZEOF_AUX_SYMBOL 18
  649. typedef enum IMAGE_AUX_SYMBOL_TYPE {
  650. IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1,
  651. } IMAGE_AUX_SYMBOL_TYPE;
  652. #include <pshpack2.h>
  653. typedef struct IMAGE_AUX_SYMBOL_TOKEN_DEF {
  654. UCHAR bAuxType; // IMAGE_AUX_SYMBOL_TYPE
  655. UCHAR bReserved; // Must be 0
  656. ULONG SymbolTableIndex;
  657. UCHAR rgbReserved[12]; // Must be 0
  658. } IMAGE_AUX_SYMBOL_TOKEN_DEF;
  659. typedef IMAGE_AUX_SYMBOL_TOKEN_DEF UNALIGNED *PIMAGE_AUX_SYMBOL_TOKEN_DEF;
  660. #include <poppack.h>
  661. //
  662. // Communal selection types.
  663. //
  664. #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
  665. #define IMAGE_COMDAT_SELECT_ANY 2
  666. #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
  667. #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  668. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  669. #define IMAGE_COMDAT_SELECT_LARGEST 6
  670. #define IMAGE_COMDAT_SELECT_NEWEST 7
  671. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  672. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  673. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
  674. //
  675. // Relocation format.
  676. //
  677. typedef struct _IMAGE_RELOCATION {
  678. union {
  679. ULONG VirtualAddress;
  680. ULONG RelocCount; // Set to the real count when IMAGE_SCN_LNK_NRELOC_OVFL is set
  681. };
  682. ULONG SymbolTableIndex;
  683. USHORT Type;
  684. } IMAGE_RELOCATION;
  685. typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
  686. #define IMAGE_SIZEOF_RELOCATION 10
  687. //
  688. // I386 relocation types.
  689. //
  690. #define IMAGE_REL_I386_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  691. #define IMAGE_REL_I386_DIR16 0x0001 // Direct 16-bit reference to the symbols virtual address
  692. #define IMAGE_REL_I386_REL16 0x0002 // PC-relative 16-bit reference to the symbols virtual address
  693. #define IMAGE_REL_I386_DIR32 0x0006 // Direct 32-bit reference to the symbols virtual address
  694. #define IMAGE_REL_I386_DIR32NB 0x0007 // Direct 32-bit reference to the symbols virtual address, base not included
  695. #define IMAGE_REL_I386_SEG12 0x0009 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  696. #define IMAGE_REL_I386_SECTION 0x000A
  697. #define IMAGE_REL_I386_SECREL 0x000B
  698. #define IMAGE_REL_I386_TOKEN 0x000C // clr token
  699. #define IMAGE_REL_I386_SECREL7 0x000D // 7 bit offset from base of section containing target
  700. #define IMAGE_REL_I386_REL32 0x0014 // PC-relative 32-bit reference to the symbols virtual address
  701. //
  702. // MIPS relocation types.
  703. //
  704. #define IMAGE_REL_MIPS_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  705. #define IMAGE_REL_MIPS_REFHALF 0x0001
  706. #define IMAGE_REL_MIPS_REFWORD 0x0002
  707. #define IMAGE_REL_MIPS_JMPADDR 0x0003
  708. #define IMAGE_REL_MIPS_REFHI 0x0004
  709. #define IMAGE_REL_MIPS_REFLO 0x0005
  710. #define IMAGE_REL_MIPS_GPREL 0x0006
  711. #define IMAGE_REL_MIPS_LITERAL 0x0007
  712. #define IMAGE_REL_MIPS_SECTION 0x000A
  713. #define IMAGE_REL_MIPS_SECREL 0x000B
  714. #define IMAGE_REL_MIPS_SECRELLO 0x000C // Low 16-bit section relative referemce (used for >32k TLS)
  715. #define IMAGE_REL_MIPS_SECRELHI 0x000D // High 16-bit section relative reference (used for >32k TLS)
  716. #define IMAGE_REL_MIPS_TOKEN 0x000E // clr token
  717. #define IMAGE_REL_MIPS_JMPADDR16 0x0010
  718. #define IMAGE_REL_MIPS_REFWORDNB 0x0022
  719. #define IMAGE_REL_MIPS_PAIR 0x0025
  720. //
  721. // Alpha Relocation types.
  722. //
  723. #define IMAGE_REL_ALPHA_ABSOLUTE 0x0000
  724. #define IMAGE_REL_ALPHA_REFLONG 0x0001
  725. #define IMAGE_REL_ALPHA_REFQUAD 0x0002
  726. #define IMAGE_REL_ALPHA_GPREL32 0x0003
  727. #define IMAGE_REL_ALPHA_LITERAL 0x0004
  728. #define IMAGE_REL_ALPHA_LITUSE 0x0005
  729. #define IMAGE_REL_ALPHA_GPDISP 0x0006
  730. #define IMAGE_REL_ALPHA_BRADDR 0x0007
  731. #define IMAGE_REL_ALPHA_HINT 0x0008
  732. #define IMAGE_REL_ALPHA_INLINE_REFLONG 0x0009
  733. #define IMAGE_REL_ALPHA_REFHI 0x000A
  734. #define IMAGE_REL_ALPHA_REFLO 0x000B
  735. #define IMAGE_REL_ALPHA_PAIR 0x000C
  736. #define IMAGE_REL_ALPHA_MATCH 0x000D
  737. #define IMAGE_REL_ALPHA_SECTION 0x000E
  738. #define IMAGE_REL_ALPHA_SECREL 0x000F
  739. #define IMAGE_REL_ALPHA_REFLONGNB 0x0010
  740. #define IMAGE_REL_ALPHA_SECRELLO 0x0011 // Low 16-bit section relative reference
  741. #define IMAGE_REL_ALPHA_SECRELHI 0x0012 // High 16-bit section relative reference
  742. #define IMAGE_REL_ALPHA_REFQ3 0x0013 // High 16 bits of 48 bit reference
  743. #define IMAGE_REL_ALPHA_REFQ2 0x0014 // Middle 16 bits of 48 bit reference
  744. #define IMAGE_REL_ALPHA_REFQ1 0x0015 // Low 16 bits of 48 bit reference
  745. #define IMAGE_REL_ALPHA_GPRELLO 0x0016 // Low 16-bit GP relative reference
  746. #define IMAGE_REL_ALPHA_GPRELHI 0x0017 // High 16-bit GP relative reference
  747. //
  748. // IBM PowerPC relocation types.
  749. //
  750. #define IMAGE_REL_PPC_ABSOLUTE 0x0000 // NOP
  751. #define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address
  752. #define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address
  753. #define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute)
  754. #define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address
  755. #define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword)
  756. #define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative)
  757. #define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  758. #define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base
  759. #define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  760. #define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base
  761. #define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr)
  762. #define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number
  763. #define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code
  764. #define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction
  765. #define IMAGE_REL_PPC_SECREL16 0x000F // va of containing section (limited to 16 bits)
  766. #define IMAGE_REL_PPC_REFHI 0x0010
  767. #define IMAGE_REL_PPC_REFLO 0x0011
  768. #define IMAGE_REL_PPC_PAIR 0x0012
  769. #define IMAGE_REL_PPC_SECRELLO 0x0013 // Low 16-bit section relative reference (used for >32k TLS)
  770. #define IMAGE_REL_PPC_SECRELHI 0x0014 // High 16-bit section relative reference (used for >32k TLS)
  771. #define IMAGE_REL_PPC_GPREL 0x0015
  772. #define IMAGE_REL_PPC_TOKEN 0x0016 // clr token
  773. #define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type
  774. // Flag bits in IMAGE_RELOCATION.TYPE
  775. #define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it
  776. #define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken
  777. #define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken
  778. #define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc)
  779. //
  780. // Hitachi SH3 relocation types.
  781. //
  782. #define IMAGE_REL_SH3_ABSOLUTE 0x0000 // No relocation
  783. #define IMAGE_REL_SH3_DIRECT16 0x0001 // 16 bit direct
  784. #define IMAGE_REL_SH3_DIRECT32 0x0002 // 32 bit direct
  785. #define IMAGE_REL_SH3_DIRECT8 0x0003 // 8 bit direct, -128..255
  786. #define IMAGE_REL_SH3_DIRECT8_WORD 0x0004 // 8 bit direct .W (0 ext.)
  787. #define IMAGE_REL_SH3_DIRECT8_LONG 0x0005 // 8 bit direct .L (0 ext.)
  788. #define IMAGE_REL_SH3_DIRECT4 0x0006 // 4 bit direct (0 ext.)
  789. #define IMAGE_REL_SH3_DIRECT4_WORD 0x0007 // 4 bit direct .W (0 ext.)
  790. #define IMAGE_REL_SH3_DIRECT4_LONG 0x0008 // 4 bit direct .L (0 ext.)
  791. #define IMAGE_REL_SH3_PCREL8_WORD 0x0009 // 8 bit PC relative .W
  792. #define IMAGE_REL_SH3_PCREL8_LONG 0x000A // 8 bit PC relative .L
  793. #define IMAGE_REL_SH3_PCREL12_WORD 0x000B // 12 LSB PC relative .W
  794. #define IMAGE_REL_SH3_STARTOF_SECTION 0x000C // Start of EXE section
  795. #define IMAGE_REL_SH3_SIZEOF_SECTION 0x000D // Size of EXE section
  796. #define IMAGE_REL_SH3_SECTION 0x000E // Section table index
  797. #define IMAGE_REL_SH3_SECREL 0x000F // Offset within section
  798. #define IMAGE_REL_SH3_DIRECT32_NB 0x0010 // 32 bit direct not based
  799. #define IMAGE_REL_SH3_GPREL4_LONG 0x0011 // GP-relative addressing
  800. #define IMAGE_REL_SH3_TOKEN 0x0012 // clr token
  801. #define IMAGE_REL_ARM_ABSOLUTE 0x0000 // No relocation required
  802. #define IMAGE_REL_ARM_ADDR32 0x0001 // 32 bit address
  803. #define IMAGE_REL_ARM_ADDR32NB 0x0002 // 32 bit address w/o image base
  804. #define IMAGE_REL_ARM_BRANCH24 0x0003 // 24 bit offset << 2 & sign ext.
  805. #define IMAGE_REL_ARM_BRANCH11 0x0004 // Thumb: 2 11 bit offsets
  806. #define IMAGE_REL_ARM_TOKEN 0x0005 // clr token
  807. #define IMAGE_REL_ARM_GPREL12 0x0006 // GP-relative addressing (ARM)
  808. #define IMAGE_REL_ARM_GPREL7 0x0007 // GP-relative addressing (Thumb)
  809. #define IMAGE_REL_ARM_BLX24 0x0008
  810. #define IMAGE_REL_ARM_BLX11 0x0009
  811. #define IMAGE_REL_ARM_SECTION 0x000E // Section table index
  812. #define IMAGE_REL_ARM_SECREL 0x000F // Offset within section
  813. #define IMAGE_REL_AM_ABSOLUTE 0x0000
  814. #define IMAGE_REL_AM_ADDR32 0x0001
  815. #define IMAGE_REL_AM_ADDR32NB 0x0002
  816. #define IMAGE_REL_AM_CALL32 0x0003
  817. #define IMAGE_REL_AM_FUNCINFO 0x0004
  818. #define IMAGE_REL_AM_REL32_1 0x0005
  819. #define IMAGE_REL_AM_REL32_2 0x0006
  820. #define IMAGE_REL_AM_SECREL 0x0007
  821. #define IMAGE_REL_AM_SECTION 0x0008
  822. #define IMAGE_REL_AM_TOKEN 0x0009
  823. //
  824. // X86-64 relocations
  825. //
  826. #define IMAGE_REL_AMD64_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  827. #define IMAGE_REL_AMD64_ADDR64 0x0001 // 64-bit address (VA).
  828. #define IMAGE_REL_AMD64_ADDR32 0x0002 // 32-bit address (VA).
  829. #define IMAGE_REL_AMD64_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  830. #define IMAGE_REL_AMD64_REL32 0x0004 // 32-bit relative address from byte following reloc
  831. #define IMAGE_REL_AMD64_REL32_1 0x0005 // 32-bit relative address from byte distance 1 from reloc
  832. #define IMAGE_REL_AMD64_REL32_2 0x0006 // 32-bit relative address from byte distance 2 from reloc
  833. #define IMAGE_REL_AMD64_REL32_3 0x0007 // 32-bit relative address from byte distance 3 from reloc
  834. #define IMAGE_REL_AMD64_REL32_4 0x0008 // 32-bit relative address from byte distance 4 from reloc
  835. #define IMAGE_REL_AMD64_REL32_5 0x0009 // 32-bit relative address from byte distance 5 from reloc
  836. #define IMAGE_REL_AMD64_SECTION 0x000A // Section index
  837. #define IMAGE_REL_AMD64_SECREL 0x000B // 32 bit offset from base of section containing target
  838. #define IMAGE_REL_AMD64_SECREL7 0x000C // 7 bit unsigned offset from base of section containing target
  839. #define IMAGE_REL_AMD64_TOKEN 0x000D // 32 bit metadata token
  840. //
  841. // IA64 relocation types.
  842. //
  843. #define IMAGE_REL_IA64_ABSOLUTE 0x0000
  844. #define IMAGE_REL_IA64_IMM14 0x0001
  845. #define IMAGE_REL_IA64_IMM22 0x0002
  846. #define IMAGE_REL_IA64_IMM64 0x0003
  847. #define IMAGE_REL_IA64_DIR32 0x0004
  848. #define IMAGE_REL_IA64_DIR64 0x0005
  849. #define IMAGE_REL_IA64_PCREL21B 0x0006
  850. #define IMAGE_REL_IA64_PCREL21M 0x0007
  851. #define IMAGE_REL_IA64_PCREL21F 0x0008
  852. #define IMAGE_REL_IA64_GPREL22 0x0009
  853. #define IMAGE_REL_IA64_LTOFF22 0x000A
  854. #define IMAGE_REL_IA64_SECTION 0x000B
  855. #define IMAGE_REL_IA64_SECREL22 0x000C
  856. #define IMAGE_REL_IA64_SECREL64I 0x000D
  857. #define IMAGE_REL_IA64_SECREL32 0x000E
  858. //
  859. #define IMAGE_REL_IA64_DIR32NB 0x0010
  860. #define IMAGE_REL_IA64_SREL14 0x0011
  861. #define IMAGE_REL_IA64_SREL22 0x0012
  862. #define IMAGE_REL_IA64_SREL32 0x0013
  863. #define IMAGE_REL_IA64_UREL32 0x0014
  864. #define IMAGE_REL_IA64_PCREL60X 0x0015 // This is always a BRL and never converted
  865. #define IMAGE_REL_IA64_PCREL60B 0x0016 // If possible, convert to MBB bundle with NOP.B in slot 1
  866. #define IMAGE_REL_IA64_PCREL60F 0x0017 // If possible, convert to MFB bundle with NOP.F in slot 1
  867. #define IMAGE_REL_IA64_PCREL60I 0x0018 // If possible, convert to MIB bundle with NOP.I in slot 1
  868. #define IMAGE_REL_IA64_PCREL60M 0x0019 // If possible, convert to MMB bundle with NOP.M in slot 1
  869. #define IMAGE_REL_IA64_IMMGPREL64 0x001A
  870. #define IMAGE_REL_IA64_TOKEN 0x001B // clr token
  871. #define IMAGE_REL_IA64_GPREL32 0x001C
  872. #define IMAGE_REL_IA64_ADDEND 0x001F
  873. //
  874. // CEF relocation types.
  875. //
  876. #define IMAGE_REL_CEF_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  877. #define IMAGE_REL_CEF_ADDR32 0x0001 // 32-bit address (VA).
  878. #define IMAGE_REL_CEF_ADDR64 0x0002 // 64-bit address (VA).
  879. #define IMAGE_REL_CEF_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  880. #define IMAGE_REL_CEF_SECTION 0x0004 // Section index
  881. #define IMAGE_REL_CEF_SECREL 0x0005 // 32 bit offset from base of section containing target
  882. #define IMAGE_REL_CEF_TOKEN 0x0006 // 32 bit metadata token
  883. //
  884. // clr relocation types.
  885. //
  886. #define IMAGE_REL_CEE_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary
  887. #define IMAGE_REL_CEE_ADDR32 0x0001 // 32-bit address (VA).
  888. #define IMAGE_REL_CEE_ADDR64 0x0002 // 64-bit address (VA).
  889. #define IMAGE_REL_CEE_ADDR32NB 0x0003 // 32-bit address w/o image base (RVA).
  890. #define IMAGE_REL_CEE_SECTION 0x0004 // Section index
  891. #define IMAGE_REL_CEE_SECREL 0x0005 // 32 bit offset from base of section containing target
  892. #define IMAGE_REL_CEE_TOKEN 0x0006 // 32 bit metadata token
  893. #define IMAGE_REL_M32R_ABSOLUTE 0x0000 // No relocation required
  894. #define IMAGE_REL_M32R_ADDR32 0x0001 // 32 bit address
  895. #define IMAGE_REL_M32R_ADDR32NB 0x0002 // 32 bit address w/o image base
  896. #define IMAGE_REL_M32R_ADDR24 0x0003 // 24 bit address
  897. #define IMAGE_REL_M32R_GPREL16 0x0004 // GP relative addressing
  898. #define IMAGE_REL_M32R_PCREL24 0x0005 // 24 bit offset << 2 & sign ext.
  899. #define IMAGE_REL_M32R_PCREL16 0x0006 // 16 bit offset << 2 & sign ext.
  900. #define IMAGE_REL_M32R_PCREL8 0x0007 // 8 bit offset << 2 & sign ext.
  901. #define IMAGE_REL_M32R_REFHALF 0x0008 // 16 MSBs
  902. #define IMAGE_REL_M32R_REFHI 0x0009 // 16 MSBs; adj for LSB sign ext.
  903. #define IMAGE_REL_M32R_REFLO 0x000A // 16 LSBs
  904. #define IMAGE_REL_M32R_PAIR 0x000B // Link HI and LO
  905. #define IMAGE_REL_M32R_SECTION 0x000C // Section table index
  906. #define IMAGE_REL_M32R_SECREL32 0x000D // 32 bit section relative reference
  907. #define IMAGE_REL_M32R_TOKEN 0x000E // clr token
  908. #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */ \
  909. Value |= (((ULONGLONG)((*(Address) >> InstPos) & (((ULONGLONG)1 << Size) - 1))) << ValPos) // Intel-IA64-Filler
  910. #define INS_IMM64(Value, Address, Size, InstPos, ValPos) /* Intel-IA64-Filler */\
  911. *(PULONG)Address = (*(PULONG)Address & ~(((1 << Size) - 1) << InstPos)) | /* Intel-IA64-Filler */\
  912. ((ULONG)((((ULONGLONG)Value >> ValPos) & (((ULONGLONG)1 << Size) - 1))) << InstPos) // Intel-IA64-Filler
  913. #define EMARCH_ENC_I17_IMM7B_INST_WORD_X 3 // Intel-IA64-Filler
  914. #define EMARCH_ENC_I17_IMM7B_SIZE_X 7 // Intel-IA64-Filler
  915. #define EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X 4 // Intel-IA64-Filler
  916. #define EMARCH_ENC_I17_IMM7B_VAL_POS_X 0 // Intel-IA64-Filler
  917. #define EMARCH_ENC_I17_IMM9D_INST_WORD_X 3 // Intel-IA64-Filler
  918. #define EMARCH_ENC_I17_IMM9D_SIZE_X 9 // Intel-IA64-Filler
  919. #define EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X 18 // Intel-IA64-Filler
  920. #define EMARCH_ENC_I17_IMM9D_VAL_POS_X 7 // Intel-IA64-Filler
  921. #define EMARCH_ENC_I17_IMM5C_INST_WORD_X 3 // Intel-IA64-Filler
  922. #define EMARCH_ENC_I17_IMM5C_SIZE_X 5 // Intel-IA64-Filler
  923. #define EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X 13 // Intel-IA64-Filler
  924. #define EMARCH_ENC_I17_IMM5C_VAL_POS_X 16 // Intel-IA64-Filler
  925. #define EMARCH_ENC_I17_IC_INST_WORD_X 3 // Intel-IA64-Filler
  926. #define EMARCH_ENC_I17_IC_SIZE_X 1 // Intel-IA64-Filler
  927. #define EMARCH_ENC_I17_IC_INST_WORD_POS_X 12 // Intel-IA64-Filler
  928. #define EMARCH_ENC_I17_IC_VAL_POS_X 21 // Intel-IA64-Filler
  929. #define EMARCH_ENC_I17_IMM41a_INST_WORD_X 1 // Intel-IA64-Filler
  930. #define EMARCH_ENC_I17_IMM41a_SIZE_X 10 // Intel-IA64-Filler
  931. #define EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X 14 // Intel-IA64-Filler
  932. #define EMARCH_ENC_I17_IMM41a_VAL_POS_X 22 // Intel-IA64-Filler
  933. #define EMARCH_ENC_I17_IMM41b_INST_WORD_X 1 // Intel-IA64-Filler
  934. #define EMARCH_ENC_I17_IMM41b_SIZE_X 8 // Intel-IA64-Filler
  935. #define EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X 24 // Intel-IA64-Filler
  936. #define EMARCH_ENC_I17_IMM41b_VAL_POS_X 32 // Intel-IA64-Filler
  937. #define EMARCH_ENC_I17_IMM41c_INST_WORD_X 2 // Intel-IA64-Filler
  938. #define EMARCH_ENC_I17_IMM41c_SIZE_X 23 // Intel-IA64-Filler
  939. #define EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X 0 // Intel-IA64-Filler
  940. #define EMARCH_ENC_I17_IMM41c_VAL_POS_X 40 // Intel-IA64-Filler
  941. #define EMARCH_ENC_I17_SIGN_INST_WORD_X 3 // Intel-IA64-Filler
  942. #define EMARCH_ENC_I17_SIGN_SIZE_X 1 // Intel-IA64-Filler
  943. #define EMARCH_ENC_I17_SIGN_INST_WORD_POS_X 27 // Intel-IA64-Filler
  944. #define EMARCH_ENC_I17_SIGN_VAL_POS_X 63 // Intel-IA64-Filler
  945. //
  946. // Line number format.
  947. //
  948. typedef struct _IMAGE_LINENUMBER {
  949. union {
  950. ULONG SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
  951. ULONG VirtualAddress; // Virtual address of line number.
  952. } Type;
  953. USHORT Linenumber; // Line number.
  954. } IMAGE_LINENUMBER;
  955. typedef IMAGE_LINENUMBER UNALIGNED *PIMAGE_LINENUMBER;
  956. #define IMAGE_SIZEOF_LINENUMBER 6
  957. #ifndef _MAC
  958. #include "poppack.h" // Back to 4 byte packing
  959. #endif
  960. //
  961. // Based relocation format.
  962. //
  963. typedef struct _IMAGE_BASE_RELOCATION {
  964. ULONG VirtualAddress;
  965. ULONG SizeOfBlock;
  966. // USHORT TypeOffset[1];
  967. } IMAGE_BASE_RELOCATION;
  968. typedef IMAGE_BASE_RELOCATION UNALIGNED * PIMAGE_BASE_RELOCATION;
  969. #define IMAGE_SIZEOF_BASE_RELOCATION 8
  970. //
  971. // Based relocation types.
  972. //
  973. #define IMAGE_REL_BASED_ABSOLUTE 0
  974. #define IMAGE_REL_BASED_HIGH 1
  975. #define IMAGE_REL_BASED_LOW 2
  976. #define IMAGE_REL_BASED_HIGHLOW 3
  977. #define IMAGE_REL_BASED_HIGHADJ 4
  978. #define IMAGE_REL_BASED_MIPS_JMPADDR 5
  979. // end_winnt
  980. #define IMAGE_REL_BASED_SECTION 6
  981. #define IMAGE_REL_BASED_REL32 7
  982. // IMAGE_REL_BASED_VXD_RELATIVE 8
  983. // begin_winnt
  984. #define IMAGE_REL_BASED_MIPS_JMPADDR16 9
  985. #define IMAGE_REL_BASED_IA64_IMM64 9
  986. #define IMAGE_REL_BASED_DIR64 10
  987. //
  988. // Archive format.
  989. //
  990. #define IMAGE_ARCHIVE_START_SIZE 8
  991. #define IMAGE_ARCHIVE_START "!<arch>\n"
  992. #define IMAGE_ARCHIVE_END "`\n"
  993. #define IMAGE_ARCHIVE_PAD "\n"
  994. #define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
  995. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
  996. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  997. UCHAR Name[16]; // File member name - `/' terminated.
  998. UCHAR Date[12]; // File member date - decimal.
  999. UCHAR UserID[6]; // File member user id - decimal.
  1000. UCHAR GroupID[6]; // File member group id - decimal.
  1001. UCHAR Mode[8]; // File member mode - octal.
  1002. UCHAR Size[10]; // File member size - decimal.
  1003. UCHAR EndHeader[2]; // String to end header.
  1004. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  1005. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
  1006. //
  1007. // DLL support.
  1008. //
  1009. //
  1010. // Export Format
  1011. //
  1012. typedef struct _IMAGE_EXPORT_DIRECTORY {
  1013. ULONG Characteristics;
  1014. ULONG TimeDateStamp;
  1015. USHORT MajorVersion;
  1016. USHORT MinorVersion;
  1017. ULONG Name;
  1018. ULONG Base;
  1019. ULONG NumberOfFunctions;
  1020. ULONG NumberOfNames;
  1021. ULONG AddressOfFunctions; // RVA from base of image
  1022. ULONG AddressOfNames; // RVA from base of image
  1023. ULONG AddressOfNameOrdinals; // RVA from base of image
  1024. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  1025. //
  1026. // Import Format
  1027. //
  1028. typedef struct _IMAGE_IMPORT_BY_NAME {
  1029. USHORT Hint;
  1030. UCHAR Name[1];
  1031. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  1032. #include "pshpack8.h" // Use align 8 for the 64-bit IAT.
  1033. typedef struct _IMAGE_THUNK_DATA64 {
  1034. union {
  1035. ULONGLONG ForwarderString; // PUCHAR
  1036. ULONGLONG Function; // PULONG
  1037. ULONGLONG Ordinal;
  1038. ULONGLONG AddressOfData; // PIMAGE_IMPORT_BY_NAME
  1039. } u1;
  1040. } IMAGE_THUNK_DATA64;
  1041. typedef IMAGE_THUNK_DATA64 * PIMAGE_THUNK_DATA64;
  1042. #include "poppack.h" // Back to 4 byte packing
  1043. typedef struct _IMAGE_THUNK_DATA32 {
  1044. union {
  1045. ULONG ForwarderString; // PUCHAR
  1046. ULONG Function; // PULONG
  1047. ULONG Ordinal;
  1048. ULONG AddressOfData; // PIMAGE_IMPORT_BY_NAME
  1049. } u1;
  1050. } IMAGE_THUNK_DATA32;
  1051. typedef IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32;
  1052. #define IMAGE_ORDINAL_FLAG64 0x8000000000000000
  1053. #define IMAGE_ORDINAL_FLAG32 0x80000000
  1054. #define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffff)
  1055. #define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff)
  1056. #define IMAGE_SNAP_BY_ORDINAL64(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG64) != 0)
  1057. #define IMAGE_SNAP_BY_ORDINAL32(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG32) != 0)
  1058. //
  1059. // Thread Local Storage
  1060. //
  1061. typedef VOID
  1062. (NTAPI *PIMAGE_TLS_CALLBACK) (
  1063. PVOID DllHandle,
  1064. ULONG Reason,
  1065. PVOID Reserved
  1066. );
  1067. typedef struct _IMAGE_TLS_DIRECTORY64 {
  1068. ULONGLONG StartAddressOfRawData;
  1069. ULONGLONG EndAddressOfRawData;
  1070. ULONGLONG AddressOfIndex; // PULONG
  1071. ULONGLONG AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *;
  1072. ULONG SizeOfZeroFill;
  1073. ULONG Characteristics;
  1074. } IMAGE_TLS_DIRECTORY64;
  1075. typedef IMAGE_TLS_DIRECTORY64 * PIMAGE_TLS_DIRECTORY64;
  1076. typedef struct _IMAGE_TLS_DIRECTORY32 {
  1077. ULONG StartAddressOfRawData;
  1078. ULONG EndAddressOfRawData;
  1079. ULONG AddressOfIndex; // PULONG
  1080. ULONG AddressOfCallBacks; // PIMAGE_TLS_CALLBACK *
  1081. ULONG SizeOfZeroFill;
  1082. ULONG Characteristics;
  1083. } IMAGE_TLS_DIRECTORY32;
  1084. typedef IMAGE_TLS_DIRECTORY32 * PIMAGE_TLS_DIRECTORY32;
  1085. #ifdef _WIN64
  1086. #define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG64
  1087. #define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL64(Ordinal)
  1088. typedef IMAGE_THUNK_DATA64 IMAGE_THUNK_DATA;
  1089. typedef PIMAGE_THUNK_DATA64 PIMAGE_THUNK_DATA;
  1090. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL64(Ordinal)
  1091. typedef IMAGE_TLS_DIRECTORY64 IMAGE_TLS_DIRECTORY;
  1092. typedef PIMAGE_TLS_DIRECTORY64 PIMAGE_TLS_DIRECTORY;
  1093. #else
  1094. #define IMAGE_ORDINAL_FLAG IMAGE_ORDINAL_FLAG32
  1095. #define IMAGE_ORDINAL(Ordinal) IMAGE_ORDINAL32(Ordinal)
  1096. typedef IMAGE_THUNK_DATA32 IMAGE_THUNK_DATA;
  1097. typedef PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA;
  1098. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) IMAGE_SNAP_BY_ORDINAL32(Ordinal)
  1099. typedef IMAGE_TLS_DIRECTORY32 IMAGE_TLS_DIRECTORY;
  1100. typedef PIMAGE_TLS_DIRECTORY32 PIMAGE_TLS_DIRECTORY;
  1101. #endif
  1102. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  1103. union {
  1104. ULONG Characteristics; // 0 for terminating null import descriptor
  1105. ULONG OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
  1106. };
  1107. ULONG TimeDateStamp; // 0 if not bound,
  1108. // -1 if bound, and real date\time stamp
  1109. // in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
  1110. // O.W. date/time stamp of DLL bound to (Old BIND)
  1111. ULONG ForwarderChain; // -1 if no forwarders
  1112. ULONG Name;
  1113. ULONG FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
  1114. } IMAGE_IMPORT_DESCRIPTOR;
  1115. typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;
  1116. //
  1117. // New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  1118. //
  1119. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  1120. ULONG TimeDateStamp;
  1121. USHORT OffsetModuleName;
  1122. USHORT NumberOfModuleForwarderRefs;
  1123. // Array of zero or more IMAGE_BOUND_FORWARDER_REF follows
  1124. } IMAGE_BOUND_IMPORT_DESCRIPTOR, *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  1125. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  1126. ULONG TimeDateStamp;
  1127. USHORT OffsetModuleName;
  1128. USHORT Reserved;
  1129. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  1130. //
  1131. // Resource Format.
  1132. //
  1133. //
  1134. // Resource directory consists of two counts, following by a variable length
  1135. // array of directory entries. The first count is the number of entries at
  1136. // beginning of the array that have actual names associated with each entry.
  1137. // The entries are in ascending order, case insensitive strings. The second
  1138. // count is the number of entries that immediately follow the named entries.
  1139. // This second count identifies the number of entries that have 16-bit integer
  1140. // Ids as their name. These entries are also sorted in ascending order.
  1141. //
  1142. // This structure allows fast lookup by either name or number, but for any
  1143. // given resource entry only one form of lookup is supported, not both.
  1144. // This is consistant with the syntax of the .RC file and the .RES file.
  1145. //
  1146. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  1147. ULONG Characteristics;
  1148. ULONG TimeDateStamp;
  1149. USHORT MajorVersion;
  1150. USHORT MinorVersion;
  1151. USHORT NumberOfNamedEntries;
  1152. USHORT NumberOfIdEntries;
  1153. // IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[];
  1154. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  1155. #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000
  1156. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000
  1157. //
  1158. // Each directory contains the 32-bit Name of the entry and an offset,
  1159. // relative to the beginning of the resource directory of the data associated
  1160. // with this directory entry. If the name of the entry is an actual text
  1161. // string instead of an integer Id, then the high order bit of the name field
  1162. // is set to one and the low order 31-bits are an offset, relative to the
  1163. // beginning of the resource directory of the string, which is of type
  1164. // IMAGE_RESOURCE_DIRECTORY_STRING. Otherwise the high bit is clear and the
  1165. // low-order 16-bits are the integer Id that identify this resource directory
  1166. // entry. If the directory entry is yet another resource directory (i.e. a
  1167. // subdirectory), then the high order bit of the offset field will be
  1168. // set to indicate this. Otherwise the high bit is clear and the offset
  1169. // field points to a resource data entry.
  1170. //
  1171. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  1172. union {
  1173. struct {
  1174. ULONG NameOffset:31;
  1175. ULONG NameIsString:1;
  1176. };
  1177. ULONG Name;
  1178. USHORT Id;
  1179. };
  1180. union {
  1181. ULONG OffsetToData;
  1182. struct {
  1183. ULONG OffsetToDirectory:31;
  1184. ULONG DataIsDirectory:1;
  1185. };
  1186. };
  1187. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  1188. //
  1189. // For resource directory entries that have actual string names, the Name
  1190. // field of the directory entry points to an object of the following type.
  1191. // All of these string objects are stored together after the last resource
  1192. // directory entry and before the first resource data object. This minimizes
  1193. // the impact of these variable length objects on the alignment of the fixed
  1194. // size directory entry objects.
  1195. //
  1196. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  1197. USHORT Length;
  1198. CHAR NameString[ 1 ];
  1199. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  1200. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  1201. USHORT Length;
  1202. WCHAR NameString[ 1 ];
  1203. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  1204. //
  1205. // Each resource data entry describes a leaf node in the resource directory
  1206. // tree. It contains an offset, relative to the beginning of the resource
  1207. // directory of the data for the resource, a size field that gives the number
  1208. // of bytes of data at that offset, a CodePage that should be used when
  1209. // decoding code point values within the resource data. Typically for new
  1210. // applications the code page would be the unicode code page.
  1211. //
  1212. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  1213. ULONG OffsetToData;
  1214. ULONG Size;
  1215. ULONG CodePage;
  1216. ULONG Reserved;
  1217. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  1218. //
  1219. // Load Configuration Directory Entry
  1220. //
  1221. typedef struct {
  1222. ULONG Characteristics;
  1223. ULONG TimeDateStamp;
  1224. USHORT MajorVersion;
  1225. USHORT MinorVersion;
  1226. ULONG GlobalFlagsClear;
  1227. ULONG GlobalFlagsSet;
  1228. ULONG CriticalSectionDefaultTimeout;
  1229. ULONG DeCommitFreeBlockThreshold;
  1230. ULONG DeCommitTotalFreeThreshold;
  1231. ULONG LockPrefixTable; // VA
  1232. ULONG MaximumAllocationSize;
  1233. ULONG VirtualMemoryThreshold;
  1234. ULONG ProcessHeapFlags;
  1235. ULONG ProcessAffinityMask;
  1236. USHORT CSDVersion;
  1237. USHORT Reserved1;
  1238. ULONG EditList; // VA
  1239. ULONG Reserved[ 1 ];
  1240. } IMAGE_LOAD_CONFIG_DIRECTORY32, *PIMAGE_LOAD_CONFIG_DIRECTORY32;
  1241. typedef struct {
  1242. ULONG Characteristics;
  1243. ULONG TimeDateStamp;
  1244. USHORT MajorVersion;
  1245. USHORT MinorVersion;
  1246. ULONG GlobalFlagsClear;
  1247. ULONG GlobalFlagsSet;
  1248. ULONG CriticalSectionDefaultTimeout;
  1249. ULONGLONG DeCommitFreeBlockThreshold;
  1250. ULONGLONG DeCommitTotalFreeThreshold;
  1251. ULONGLONG LockPrefixTable; // VA
  1252. ULONGLONG MaximumAllocationSize;
  1253. ULONGLONG VirtualMemoryThreshold;
  1254. ULONGLONG ProcessAffinityMask;
  1255. ULONG ProcessHeapFlags;
  1256. USHORT CSDVersion;
  1257. USHORT Reserved1;
  1258. ULONGLONG EditList; // VA
  1259. ULONG Reserved[ 2 ];
  1260. } IMAGE_LOAD_CONFIG_DIRECTORY64, *PIMAGE_LOAD_CONFIG_DIRECTORY64;
  1261. #ifdef _WIN64
  1262. typedef IMAGE_LOAD_CONFIG_DIRECTORY64 IMAGE_LOAD_CONFIG_DIRECTORY;
  1263. typedef PIMAGE_LOAD_CONFIG_DIRECTORY64 PIMAGE_LOAD_CONFIG_DIRECTORY;
  1264. #else
  1265. typedef IMAGE_LOAD_CONFIG_DIRECTORY32 IMAGE_LOAD_CONFIG_DIRECTORY;
  1266. typedef PIMAGE_LOAD_CONFIG_DIRECTORY32 PIMAGE_LOAD_CONFIG_DIRECTORY;
  1267. #endif
  1268. //
  1269. // WIN CE Exception table format
  1270. //
  1271. //
  1272. // Function table entry format. Function table is pointed to by the
  1273. // IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  1274. //
  1275. typedef struct _IMAGE_CE_RUNTIME_FUNCTION_ENTRY {
  1276. ULONG FuncStart;
  1277. ULONG PrologLen : 8;
  1278. ULONG FuncLen : 22;
  1279. ULONG ThirtyTwoBit : 1;
  1280. ULONG ExceptionFlag : 1;
  1281. } IMAGE_CE_RUNTIME_FUNCTION_ENTRY, * PIMAGE_CE_RUNTIME_FUNCTION_ENTRY;
  1282. typedef struct _IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY {
  1283. ULONGLONG BeginAddress;
  1284. ULONGLONG EndAddress;
  1285. ULONGLONG ExceptionHandler;
  1286. ULONGLONG HandlerData;
  1287. ULONGLONG PrologEndAddress;
  1288. } IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY;
  1289. typedef struct _IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY {
  1290. ULONG BeginAddress;
  1291. ULONG EndAddress;
  1292. ULONG ExceptionHandler;
  1293. ULONG HandlerData;
  1294. ULONG PrologEndAddress;
  1295. } IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY, *PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY;
  1296. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  1297. ULONG BeginAddress;
  1298. ULONG EndAddress;
  1299. ULONG UnwindInfoAddress;
  1300. } _IMAGE_RUNTIME_FUNCTION_ENTRY, *_PIMAGE_RUNTIME_FUNCTION_ENTRY;
  1301. typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
  1302. typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_IA64_RUNTIME_FUNCTION_ENTRY;
  1303. #if defined(_AXP64_)
  1304. typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  1305. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_AXP64_RUNTIME_FUNCTION_ENTRY;
  1306. typedef IMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  1307. typedef PIMAGE_ALPHA64_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  1308. #elif defined(_ALPHA_)
  1309. typedef IMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  1310. typedef PIMAGE_ALPHA_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  1311. #else
  1312. typedef _IMAGE_RUNTIME_FUNCTION_ENTRY IMAGE_RUNTIME_FUNCTION_ENTRY;
  1313. typedef _PIMAGE_RUNTIME_FUNCTION_ENTRY PIMAGE_RUNTIME_FUNCTION_ENTRY;
  1314. #endif
  1315. //
  1316. // Debug Format
  1317. //
  1318. typedef struct _IMAGE_DEBUG_DIRECTORY {
  1319. ULONG Characteristics;
  1320. ULONG TimeDateStamp;
  1321. USHORT MajorVersion;
  1322. USHORT MinorVersion;
  1323. ULONG Type;
  1324. ULONG SizeOfData;
  1325. ULONG AddressOfRawData;
  1326. ULONG PointerToRawData;
  1327. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  1328. #define IMAGE_DEBUG_TYPE_UNKNOWN 0
  1329. #define IMAGE_DEBUG_TYPE_COFF 1
  1330. #define IMAGE_DEBUG_TYPE_CODEVIEW 2
  1331. #define IMAGE_DEBUG_TYPE_FPO 3
  1332. #define IMAGE_DEBUG_TYPE_MISC 4
  1333. #define IMAGE_DEBUG_TYPE_EXCEPTION 5
  1334. #define IMAGE_DEBUG_TYPE_FIXUP 6
  1335. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
  1336. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
  1337. #define IMAGE_DEBUG_TYPE_BORLAND 9
  1338. #define IMAGE_DEBUG_TYPE_RESERVED10 10
  1339. #define IMAGE_DEBUG_TYPE_CLSID 11
  1340. // end_winnt
  1341. // IMAGE_DEBUG_TYPE values > 0x7FFFFFFF are reserved for BBT
  1342. // begin_winnt
  1343. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  1344. ULONG NumberOfSymbols;
  1345. ULONG LvaToFirstSymbol;
  1346. ULONG NumberOfLinenumbers;
  1347. ULONG LvaToFirstLinenumber;
  1348. ULONG RvaToFirstByteOfCode;
  1349. ULONG RvaToLastByteOfCode;
  1350. ULONG RvaToFirstByteOfData;
  1351. ULONG RvaToLastByteOfData;
  1352. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  1353. #define FRAME_FPO 0
  1354. #define FRAME_TRAP 1
  1355. #define FRAME_TSS 2
  1356. #define FRAME_NONFPO 3
  1357. typedef struct _FPO_DATA {
  1358. ULONG ulOffStart; // offset 1st byte of function code
  1359. ULONG cbProcSize; // # bytes in function
  1360. ULONG cdwLocals; // # bytes in locals/4
  1361. USHORT cdwParams; // # bytes in params/4
  1362. USHORT cbProlog : 8; // # bytes in prolog
  1363. USHORT cbRegs : 3; // # regs saved
  1364. USHORT fHasSEH : 1; // TRUE if SEH in func
  1365. USHORT fUseBP : 1; // TRUE if EBP has been allocated
  1366. USHORT reserved : 1; // reserved for future use
  1367. USHORT cbFrame : 2; // frame type
  1368. } FPO_DATA, *PFPO_DATA;
  1369. #define SIZEOF_RFPO_DATA 16
  1370. #define IMAGE_DEBUG_MISC_EXENAME 1
  1371. typedef struct _IMAGE_DEBUG_MISC {
  1372. ULONG DataType; // type of misc data, see defines
  1373. ULONG Length; // total length of record, rounded to four
  1374. // byte multiple.
  1375. BOOLEAN Unicode; // TRUE if data is unicode string
  1376. UCHAR Reserved[ 3 ];
  1377. UCHAR Data[ 1 ]; // Actual data
  1378. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  1379. //
  1380. // Function table extracted from MIPS/ALPHA/IA64 images. Does not contain
  1381. // information needed only for runtime support. Just those fields for
  1382. // each entry needed by a debugger.
  1383. //
  1384. typedef struct _IMAGE_FUNCTION_ENTRY {
  1385. ULONG StartingAddress;
  1386. ULONG EndingAddress;
  1387. ULONG EndOfPrologue;
  1388. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  1389. typedef struct _IMAGE_FUNCTION_ENTRY64 {
  1390. ULONGLONG StartingAddress;
  1391. ULONGLONG EndingAddress;
  1392. union {
  1393. ULONGLONG EndOfPrologue;
  1394. ULONGLONG UnwindInfoAddress;
  1395. };
  1396. } IMAGE_FUNCTION_ENTRY64, *PIMAGE_FUNCTION_ENTRY64;
  1397. //
  1398. // Debugging information can be stripped from an image file and placed
  1399. // in a separate .DBG file, whose file name part is the same as the
  1400. // image file name part (e.g. symbols for CMD.EXE could be stripped
  1401. // and placed in CMD.DBG). This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  1402. // flag in the Characteristics field of the file header. The beginning of
  1403. // the .DBG file contains the following structure which captures certain
  1404. // information from the image file. This allows a debug to proceed even if
  1405. // the original image file is not accessable. This header is followed by
  1406. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  1407. // IMAGE_DEBUG_DIRECTORY structures. The latter structures and those in
  1408. // the image file contain file offsets relative to the beginning of the
  1409. // .DBG file.
  1410. //
  1411. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  1412. // is left in the image file, but not mapped. This allows a debugger to
  1413. // compute the name of the .DBG file, from the name of the image in the
  1414. // IMAGE_DEBUG_MISC structure.
  1415. //
  1416. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  1417. USHORT Signature;
  1418. USHORT Flags;
  1419. USHORT Machine;
  1420. USHORT Characteristics;
  1421. ULONG TimeDateStamp;
  1422. ULONG CheckSum;
  1423. ULONG ImageBase;
  1424. ULONG SizeOfImage;
  1425. ULONG NumberOfSections;
  1426. ULONG ExportedNamesSize;
  1427. ULONG DebugDirectorySize;
  1428. ULONG SectionAlignment;
  1429. ULONG Reserved[2];
  1430. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  1431. typedef struct _NON_PAGED_DEBUG_INFO {
  1432. USHORT Signature;
  1433. USHORT Flags;
  1434. ULONG Size;
  1435. USHORT Machine;
  1436. USHORT Characteristics;
  1437. ULONG TimeDateStamp;
  1438. ULONG CheckSum;
  1439. ULONG SizeOfImage;
  1440. ULONGLONG ImageBase;
  1441. //DebugDirectorySize
  1442. //IMAGE_DEBUG_DIRECTORY
  1443. } NON_PAGED_DEBUG_INFO, *PNON_PAGED_DEBUG_INFO;
  1444. #ifndef _MAC
  1445. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  1446. #define NON_PAGED_DEBUG_SIGNATURE 0x494E
  1447. #else
  1448. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4449 // DI
  1449. #define NON_PAGED_DEBUG_SIGNATURE 0x4E49 // NI
  1450. #endif
  1451. #define IMAGE_SEPARATE_DEBUG_FLAGS_MASK 0x8000
  1452. #define IMAGE_SEPARATE_DEBUG_MISMATCH 0x8000 // when DBG was updated, the
  1453. // old checksum didn't match.
  1454. //
  1455. // The .arch section is made up of headers, each describing an amask position/value
  1456. // pointing to an array of IMAGE_ARCHITECTURE_ENTRY's. Each "array" (both the header
  1457. // and entry arrays) are terminiated by a quadword of 0xffffffffL.
  1458. //
  1459. // NOTE: There may be quadwords of 0 sprinkled around and must be skipped.
  1460. //
  1461. typedef struct _ImageArchitectureHeader {
  1462. unsigned int AmaskValue: 1; // 1 -> code section depends on mask bit
  1463. // 0 -> new instruction depends on mask bit
  1464. int :7; // MBZ
  1465. unsigned int AmaskShift: 8; // Amask bit in question for this fixup
  1466. int :16; // MBZ
  1467. ULONG FirstEntryRVA; // RVA into .arch section to array of ARCHITECTURE_ENTRY's
  1468. } IMAGE_ARCHITECTURE_HEADER, *PIMAGE_ARCHITECTURE_HEADER;
  1469. typedef struct _ImageArchitectureEntry {
  1470. ULONG FixupInstRVA; // RVA of instruction to fixup
  1471. ULONG NewInst; // fixup instruction (see alphaops.h)
  1472. } IMAGE_ARCHITECTURE_ENTRY, *PIMAGE_ARCHITECTURE_ENTRY;
  1473. #include "poppack.h" // Back to the initial value
  1474. // The following structure defines the new import object. Note the values of the first two fields,
  1475. // which must be set as stated in order to differentiate old and new import members.
  1476. // Following this structure, the linker emits two null-terminated strings used to recreate the
  1477. // import at the time of use. The first string is the import's name, the second is the dll's name.
  1478. #define IMPORT_OBJECT_HDR_SIG2 0xffff
  1479. typedef struct IMPORT_OBJECT_HEADER {
  1480. USHORT Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
  1481. USHORT Sig2; // Must be IMPORT_OBJECT_HDR_SIG2.
  1482. USHORT Version;
  1483. USHORT Machine;
  1484. ULONG TimeDateStamp; // Time/date stamp
  1485. ULONG SizeOfData; // particularly useful for incremental links
  1486. union {
  1487. USHORT Ordinal; // if grf & IMPORT_OBJECT_ORDINAL
  1488. USHORT Hint;
  1489. };
  1490. USHORT Type : 2; // IMPORT_TYPE
  1491. USHORT NameType : 3; // IMPORT_NAME_TYPE
  1492. USHORT Reserved : 11; // Reserved. Must be zero.
  1493. } IMPORT_OBJECT_HEADER;
  1494. typedef enum IMPORT_OBJECT_TYPE
  1495. {
  1496. IMPORT_OBJECT_CODE = 0,
  1497. IMPORT_OBJECT_DATA = 1,
  1498. IMPORT_OBJECT_CONST = 2,
  1499. } IMPORT_OBJECT_TYPE;
  1500. typedef enum IMPORT_OBJECT_NAME_TYPE
  1501. {
  1502. IMPORT_OBJECT_ORDINAL = 0, // Import by ordinal
  1503. IMPORT_OBJECT_NAME = 1, // Import name == public symbol name.
  1504. IMPORT_OBJECT_NAME_NO_PREFIX = 2, // Import name == public symbol name skipping leading ?, @, or optionally _.
  1505. IMPORT_OBJECT_NAME_UNDECORATE = 3, // Import name == public symbol name skipping leading ?, @, or optionally _
  1506. // and truncating at first @
  1507. } IMPORT_OBJECT_NAME_TYPE;
  1508. // end_winnt
  1509. // The structure is used by the NT loader for clr URT support. It
  1510. // is a duplicate of the definition in corhdr.h.
  1511. // begin_winnt
  1512. #ifndef __IMAGE_COR20_HEADER_DEFINED__
  1513. #define __IMAGE_COR20_HEADER_DEFINED__
  1514. typedef enum ReplacesCorHdrNumericDefines
  1515. {
  1516. // COM+ Header entry point flags.
  1517. COMIMAGE_FLAGS_ILONLY =0x00000001,
  1518. COMIMAGE_FLAGS_32BITREQUIRED =0x00000002,
  1519. COMIMAGE_FLAGS_IL_LIBRARY =0x00000004,
  1520. COMIMAGE_FLAGS_TRACKDEBUGDATA =0x00010000,
  1521. // Version flags for image.
  1522. COR_VERSION_MAJOR_V2 =2,
  1523. COR_VERSION_MAJOR =COR_VERSION_MAJOR_V2,
  1524. COR_VERSION_MINOR =0,
  1525. COR_DELETED_NAME_LENGTH =8,
  1526. COR_VTABLEGAP_NAME_LENGTH =8,
  1527. // Maximum size of a NativeType descriptor.
  1528. NATIVE_TYPE_MAX_CB =1,
  1529. COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE=0xFF,
  1530. // #defines for the MIH FLAGS
  1531. IMAGE_COR_MIH_METHODRVA =0x01,
  1532. IMAGE_COR_MIH_EHRVA =0x02,
  1533. IMAGE_COR_MIH_BASICBLOCK =0x08,
  1534. // V-table constants
  1535. COR_VTABLE_32BIT =0x01, // V-table slots are 32-bits in size.
  1536. COR_VTABLE_64BIT =0x02, // V-table slots are 64-bits in size.
  1537. COR_VTABLE_FROM_UNMANAGED =0x04, // If set, transition from unmanaged.
  1538. COR_VTABLE_CALL_MOST_DERIVED =0x10, // Call most derived method described by
  1539. // EATJ constants
  1540. IMAGE_COR_EATJ_THUNK_SIZE =32, // Size of a jump thunk reserved range.
  1541. // Max name lengths
  1542. //@todo: Change to unlimited name lengths.
  1543. MAX_CLASS_NAME =1024,
  1544. MAX_PACKAGE_NAME =1024,
  1545. } ReplacesCorHdrNumericDefines;
  1546. // COM+ 2.0 header structure.
  1547. typedef struct IMAGE_COR20_HEADER
  1548. {
  1549. // Header versioning
  1550. ULONG cb;
  1551. USHORT MajorRuntimeVersion;
  1552. USHORT MinorRuntimeVersion;
  1553. // Symbol table and startup information
  1554. IMAGE_DATA_DIRECTORY MetaData;
  1555. ULONG Flags;
  1556. ULONG EntryPointToken;
  1557. // Binding information
  1558. IMAGE_DATA_DIRECTORY Resources;
  1559. IMAGE_DATA_DIRECTORY StrongNameSignature;
  1560. // Regular fixup and binding information
  1561. IMAGE_DATA_DIRECTORY CodeManagerTable;
  1562. IMAGE_DATA_DIRECTORY VTableFixups;
  1563. IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
  1564. // Precompiled image info (internal use only - set to zero)
  1565. IMAGE_DATA_DIRECTORY ManagedNativeHeader;
  1566. } IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
  1567. #endif // __IMAGE_COR20_HEADER_DEFINED__
  1568. //
  1569. // End Image Format
  1570. //
  1571. // end_winnt
  1572. #endif // _NTIMAGE_