pe.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. PE32+ header file
  3. */
  4. #ifndef _PE_H
  5. #define _PE_H
  6. #define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
  7. #define IMAGE_OS2_SIGNATURE 0x454E // NE
  8. #define IMAGE_OS2_SIGNATURE_LE 0x454C // LE
  9. #define IMAGE_NT_SIGNATURE 0x00004550 // PE00
  10. #define IMAGE_EDOS_SIGNATURE 0x44454550 // PEED
  11. /*****************************************************************************
  12. * The following stuff comes from winnt.h from the ia64sdk, plus the Plabel for
  13. * loading EM executables.
  14. *****************************************************************************/
  15. //
  16. // Intel IA64 specific
  17. //
  18. #define IMAGE_REL_BASED_IA64_IMM64 9
  19. #define IMAGE_REL_BASED_IA64_DIR64 10
  20. struct Plabel {
  21. UINT64 EntryPoint;
  22. UINT64 NewGP;
  23. };
  24. typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
  25. UINT16 e_magic; // Magic number
  26. UINT16 e_cblp; // Bytes on last page of file
  27. UINT16 e_cp; // Pages in file
  28. UINT16 e_crlc; // Relocations
  29. UINT16 e_cparhdr; // Size of header in paragraphs
  30. UINT16 e_minalloc; // Minimum extra paragraphs needed
  31. UINT16 e_maxalloc; // Maximum extra paragraphs needed
  32. UINT16 e_ss; // Initial (relative) SS value
  33. UINT16 e_sp; // Initial SP value
  34. UINT16 e_csum; // Checksum
  35. UINT16 e_ip; // Initial IP value
  36. UINT16 e_cs; // Initial (relative) CS value
  37. UINT16 e_lfarlc; // File address of relocation table
  38. UINT16 e_ovno; // Overlay number
  39. UINT16 e_res[4]; // Reserved words
  40. UINT16 e_oemid; // OEM identifier (for e_oeminfo)
  41. UINT16 e_oeminfo; // OEM information; e_oemid specific
  42. UINT16 e_res2[10]; // Reserved words
  43. UINT32 e_lfanew; // File address of new exe header
  44. } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
  45. typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header
  46. UINT16 ne_magic; // Magic number
  47. UINT8 ne_ver; // Version number
  48. UINT8 ne_rev; // Revision number
  49. UINT16 ne_enttab; // Offset of Entry Table
  50. UINT16 ne_cbenttab; // Number of bytes in Entry Table
  51. UINT32 ne_crc; // Checksum of whole file
  52. UINT16 ne_flags; // Flag UINT16
  53. UINT16 ne_autodata; // Automatic data segment number
  54. UINT16 ne_heap; // Initial heap allocation
  55. UINT16 ne_stack; // Initial stack allocation
  56. UINT32 ne_csip; // Initial CS:IP setting
  57. UINT32 ne_sssp; // Initial SS:SP setting
  58. UINT16 ne_cseg; // Count of file segments
  59. UINT16 ne_cmod; // Entries in Module Reference Table
  60. UINT16 ne_cbnrestab; // Size of non-resident name table
  61. UINT16 ne_segtab; // Offset of Segment Table
  62. UINT16 ne_rsrctab; // Offset of Resource Table
  63. UINT16 ne_restab; // Offset of resident name table
  64. UINT16 ne_modtab; // Offset of Module Reference Table
  65. UINT16 ne_imptab; // Offset of Imported Names Table
  66. UINT32 ne_nrestab; // Offset of Non-resident Names Table
  67. UINT16 ne_cmovent; // Count of movable entries
  68. UINT16 ne_align; // Segment alignment shift count
  69. UINT16 ne_cres; // Count of resource segments
  70. UINT8 ne_exetyp; // Target Operating system
  71. UINT8 ne_flagsothers; // Other .EXE flags
  72. UINT16 ne_pretthunks; // offset to return thunks
  73. UINT16 ne_psegrefbytes; // offset to segment ref. bytes
  74. UINT16 ne_swaparea; // Minimum code swap area size
  75. UINT16 ne_expver; // Expected Windows version number
  76. } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
  77. //
  78. // File header format.
  79. //
  80. typedef struct _IMAGE_FILE_HEADER {
  81. UINT16 Machine;
  82. UINT16 NumberOfSections;
  83. UINT32 TimeDateStamp;
  84. UINT32 PointerToSymbolTable;
  85. UINT32 NumberOfSymbols;
  86. UINT16 SizeOfOptionalHeader;
  87. UINT16 Characteristics;
  88. } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
  89. #define IMAGE_SIZEOF_FILE_HEADER 20
  90. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
  91. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
  92. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
  93. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
  94. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
  95. #define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
  96. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
  97. #define IMAGE_FILE_SYSTEM 0x1000 // System File.
  98. #define IMAGE_FILE_DLL 0x2000 // File is a DLL.
  99. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
  100. #define IMAGE_FILE_MACHINE_UNKNOWN 0
  101. #define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
  102. #define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0540 big-endian
  103. #define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian
  104. #define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP
  105. #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x1c2 // Arm/Thumb
  106. #define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian
  107. #define IMAGE_FILE_MACHINE_IA64 0x200 // IA-64
  108. #define IMAGE_FILE_MACHINE_TAHOE 0x7cc // Intel EM machine
  109. #define IMAGE_FILE_MACHINE_EBC 0xebc // EFI Byte Code
  110. #define IMAGE_FILE_MACHINE_X64 0x8664 // x86_64
  111. //
  112. // Directory format.
  113. //
  114. typedef struct _IMAGE_DATA_DIRECTORY {
  115. UINT32 VirtualAddress;
  116. UINT32 Size;
  117. } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  118. #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
  119. typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
  120. UINT16 Magic;
  121. UINT8 MajorLinkerVersion;
  122. UINT8 MinorLinkerVersion;
  123. UINT32 SizeOfCode;
  124. UINT32 SizeOfInitializedData;
  125. UINT32 SizeOfUninitializedData;
  126. UINT32 AddressOfEntryPoint;
  127. UINT32 BaseOfCode;
  128. UINT32 BaseOfData;
  129. UINT32 BaseOfBss;
  130. UINT32 GprMask;
  131. UINT32 CprMask[4];
  132. UINT32 GpValue;
  133. } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
  134. typedef struct _IMAGE_OPTIONAL_HEADER {
  135. UINT16 Magic;
  136. UINT8 MajorLinkerVersion;
  137. UINT8 MinorLinkerVersion;
  138. UINT32 SizeOfCode;
  139. UINT32 SizeOfInitializedData;
  140. UINT32 SizeOfUninitializedData;
  141. UINT32 AddressOfEntryPoint;
  142. UINT32 BaseOfCode;
  143. // UINT32 BaseOfData;
  144. UINT64 ImageBase;
  145. UINT32 SectionAlignment;
  146. UINT32 FileAlignment;
  147. UINT16 MajorOperatingSystemVersion;
  148. UINT16 MinorOperatingSystemVersion;
  149. UINT16 MajorImageVersion;
  150. UINT16 MinorImageVersion;
  151. UINT16 MajorSubsystemVersion;
  152. UINT16 MinorSubsystemVersion;
  153. UINT32 Win32VersionValue;
  154. UINT32 SizeOfImage;
  155. UINT32 SizeOfHeaders;
  156. UINT32 CheckSum;
  157. UINT16 Subsystem;
  158. UINT16 DllCharacteristics;
  159. UINT64 SizeOfStackReserve;
  160. UINT64 SizeOfStackCommit;
  161. UINT64 SizeOfHeapReserve;
  162. UINT64 SizeOfHeapCommit;
  163. UINT32 LoaderFlags;
  164. UINT32 NumberOfRvaAndSizes;
  165. IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
  166. } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
  167. #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56
  168. #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28
  169. #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER 224
  170. #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 244
  171. #define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
  172. #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
  173. #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
  174. typedef struct _IMAGE_NT_HEADERS {
  175. UINT32 Signature;
  176. IMAGE_FILE_HEADER FileHeader;
  177. IMAGE_OPTIONAL_HEADER OptionalHeader;
  178. } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
  179. typedef struct _IMAGE_ROM_HEADERS {
  180. IMAGE_FILE_HEADER FileHeader;
  181. IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  182. } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
  183. #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
  184. ((UINT32)ntheader + \
  185. FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \
  186. ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \
  187. ))
  188. // Subsystem Values
  189. #define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem.
  190. #define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem.
  191. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem.
  192. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem.
  193. #define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem.
  194. #define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image run in the Posix character subsystem.
  195. // Directory Entries
  196. #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory
  197. #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory
  198. #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory
  199. #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory
  200. #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory
  201. #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table
  202. #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory
  203. #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String
  204. #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP)
  205. #define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory
  206. #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory
  207. //
  208. // Section header format.
  209. //
  210. #define IMAGE_SIZEOF_SHORT_NAME 8
  211. typedef struct _IMAGE_SECTION_HEADER {
  212. UINT8 Name[IMAGE_SIZEOF_SHORT_NAME];
  213. union {
  214. UINT32 PhysicalAddress;
  215. UINT32 VirtualSize;
  216. } Misc;
  217. UINT32 VirtualAddress;
  218. UINT32 SizeOfRawData;
  219. UINT32 PointerToRawData;
  220. UINT32 PointerToRelocations;
  221. UINT32 PointerToLinenumbers;
  222. UINT16 NumberOfRelocations;
  223. UINT16 NumberOfLinenumbers;
  224. UINT32 Characteristics;
  225. } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
  226. #define IMAGE_SIZEOF_SECTION_HEADER 40
  227. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
  228. #define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code.
  229. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data.
  230. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data.
  231. #define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
  232. #define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
  233. #define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
  234. #define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat.
  235. #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //
  236. #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //
  237. #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //
  238. #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //
  239. #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified.
  240. #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //
  241. #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //
  242. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded.
  243. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable.
  244. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable.
  245. #define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable.
  246. #define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable.
  247. #define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable.
  248. #define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable.
  249. //
  250. // Symbol format.
  251. //
  252. #define IMAGE_SIZEOF_SYMBOL 18
  253. //
  254. // Section values.
  255. //
  256. // Symbols have a section number of the section in which they are
  257. // defined. Otherwise, section numbers have the following meanings:
  258. //
  259. #define IMAGE_SYM_UNDEFINED (UINT16)0 // Symbol is undefined or is common.
  260. #define IMAGE_SYM_ABSOLUTE (UINT16)-1 // Symbol is an absolute value.
  261. #define IMAGE_SYM_DEBUG (UINT16)-2 // Symbol is a special debug item.
  262. //
  263. // Type (fundamental) values.
  264. //
  265. #define IMAGE_SYM_TYPE_NULL 0 // no type.
  266. #define IMAGE_SYM_TYPE_VOID 1 //
  267. #define IMAGE_SYM_TYPE_CHAR 2 // type character.
  268. #define IMAGE_SYM_TYPE_SHORT 3 // type short integer.
  269. #define IMAGE_SYM_TYPE_INT 4 //
  270. #define IMAGE_SYM_TYPE_LONG 5 //
  271. #define IMAGE_SYM_TYPE_FLOAT 6 //
  272. #define IMAGE_SYM_TYPE_DOUBLE 7 //
  273. #define IMAGE_SYM_TYPE_STRUCT 8 //
  274. #define IMAGE_SYM_TYPE_UNION 9 //
  275. #define IMAGE_SYM_TYPE_ENUM 10 // enumeration.
  276. #define IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
  277. #define IMAGE_SYM_TYPE_BYTE 12 //
  278. #define IMAGE_SYM_TYPE_WORD 13 //
  279. #define IMAGE_SYM_TYPE_UINT 14 //
  280. #define IMAGE_SYM_TYPE_DWORD 15 //
  281. //
  282. // Type (derived) values.
  283. //
  284. #define IMAGE_SYM_DTYPE_NULL 0 // no derived type.
  285. #define IMAGE_SYM_DTYPE_POINTER 1 // pointer.
  286. #define IMAGE_SYM_DTYPE_FUNCTION 2 // function.
  287. #define IMAGE_SYM_DTYPE_ARRAY 3 // array.
  288. //
  289. // Storage classes.
  290. //
  291. #define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE )-1
  292. #define IMAGE_SYM_CLASS_NULL 0
  293. #define IMAGE_SYM_CLASS_AUTOMATIC 1
  294. #define IMAGE_SYM_CLASS_EXTERNAL 2
  295. #define IMAGE_SYM_CLASS_STATIC 3
  296. #define IMAGE_SYM_CLASS_REGISTER 4
  297. #define IMAGE_SYM_CLASS_EXTERNAL_DEF 5
  298. #define IMAGE_SYM_CLASS_LABEL 6
  299. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
  300. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
  301. #define IMAGE_SYM_CLASS_ARGUMENT 9
  302. #define IMAGE_SYM_CLASS_STRUCT_TAG 10
  303. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
  304. #define IMAGE_SYM_CLASS_UNION_TAG 12
  305. #define IMAGE_SYM_CLASS_TYPE_DEFINITION 13
  306. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
  307. #define IMAGE_SYM_CLASS_ENUM_TAG 15
  308. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
  309. #define IMAGE_SYM_CLASS_REGISTER_PARAM 17
  310. #define IMAGE_SYM_CLASS_BIT_FIELD 18
  311. #define IMAGE_SYM_CLASS_BLOCK 100
  312. #define IMAGE_SYM_CLASS_FUNCTION 101
  313. #define IMAGE_SYM_CLASS_END_OF_STRUCT 102
  314. #define IMAGE_SYM_CLASS_FILE 103
  315. // new
  316. #define IMAGE_SYM_CLASS_SECTION 104
  317. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
  318. // type packing constants
  319. #define N_BTMASK 017
  320. #define N_TMASK 060
  321. #define N_TMASK1 0300
  322. #define N_TMASK2 0360
  323. #define N_BTSHFT 4
  324. #define N_TSHIFT 2
  325. // MACROS
  326. //
  327. // Communal selection types.
  328. //
  329. #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
  330. #define IMAGE_COMDAT_SELECT_ANY 2
  331. #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
  332. #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  333. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  334. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  335. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  336. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
  337. //
  338. // Relocation format.
  339. //
  340. typedef struct _IMAGE_RELOCATION {
  341. UINT32 VirtualAddress;
  342. UINT32 SymbolTableIndex;
  343. UINT16 Type;
  344. } IMAGE_RELOCATION;
  345. #define IMAGE_SIZEOF_RELOCATION 10
  346. //
  347. // I386 relocation types.
  348. //
  349. #define IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
  350. #define IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
  351. #define IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
  352. #define IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
  353. #define IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
  354. #define IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  355. #define IMAGE_REL_I386_SECTION 012
  356. #define IMAGE_REL_I386_SECREL 013
  357. #define IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
  358. //
  359. // MIPS relocation types.
  360. //
  361. #define IMAGE_REL_MIPS_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
  362. #define IMAGE_REL_MIPS_REFHALF 01
  363. #define IMAGE_REL_MIPS_REFWORD 02
  364. #define IMAGE_REL_MIPS_JMPADDR 03
  365. #define IMAGE_REL_MIPS_REFHI 04
  366. #define IMAGE_REL_MIPS_REFLO 05
  367. #define IMAGE_REL_MIPS_GPREL 06
  368. #define IMAGE_REL_MIPS_LITERAL 07
  369. #define IMAGE_REL_MIPS_SECTION 012
  370. #define IMAGE_REL_MIPS_SECREL 013
  371. #define IMAGE_REL_MIPS_REFWORDNB 042
  372. #define IMAGE_REL_MIPS_PAIR 045
  373. //
  374. // Alpha Relocation types.
  375. //
  376. #define IMAGE_REL_ALPHA_ABSOLUTE 0x0
  377. #define IMAGE_REL_ALPHA_REFLONG 0x1
  378. #define IMAGE_REL_ALPHA_REFQUAD 0x2
  379. #define IMAGE_REL_ALPHA_GPREL32 0x3
  380. #define IMAGE_REL_ALPHA_LITERAL 0x4
  381. #define IMAGE_REL_ALPHA_LITUSE 0x5
  382. #define IMAGE_REL_ALPHA_GPDISP 0x6
  383. #define IMAGE_REL_ALPHA_BRADDR 0x7
  384. #define IMAGE_REL_ALPHA_HINT 0x8
  385. #define IMAGE_REL_ALPHA_INLINE_REFLONG 0x9
  386. #define IMAGE_REL_ALPHA_REFHI 0xA
  387. #define IMAGE_REL_ALPHA_REFLO 0xB
  388. #define IMAGE_REL_ALPHA_PAIR 0xC
  389. #define IMAGE_REL_ALPHA_MATCH 0xD
  390. #define IMAGE_REL_ALPHA_SECTION 0xE
  391. #define IMAGE_REL_ALPHA_SECREL 0xF
  392. #define IMAGE_REL_ALPHA_REFLONGNB 0x10
  393. //
  394. // IBM PowerPC relocation types.
  395. //
  396. #define IMAGE_REL_PPC_ABSOLUTE 0x0000 // NOP
  397. #define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address
  398. #define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address
  399. #define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute)
  400. #define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address
  401. #define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword)
  402. #define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative)
  403. #define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative)
  404. #define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base
  405. #define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword)
  406. #define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base
  407. #define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr)
  408. #define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number
  409. #define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code
  410. #define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction
  411. #define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type
  412. // Flag bits in IMAGE_RELOCATION.TYPE
  413. #define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it
  414. #define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken
  415. #define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken
  416. #define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc)
  417. //
  418. // Based relocation format.
  419. //
  420. typedef struct _IMAGE_BASE_RELOCATION {
  421. UINT32 VirtualAddress;
  422. UINT32 SizeOfBlock;
  423. // UINT16 TypeOffset[1];
  424. } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
  425. #define IMAGE_SIZEOF_BASE_RELOCATION 8
  426. //
  427. // Based relocation types.
  428. //
  429. #define IMAGE_REL_BASED_ABSOLUTE 0
  430. #define IMAGE_REL_BASED_HIGH 1
  431. #define IMAGE_REL_BASED_LOW 2
  432. #define IMAGE_REL_BASED_HIGHLOW 3
  433. #define IMAGE_REL_BASED_HIGHADJ 4
  434. #define IMAGE_REL_BASED_MIPS_JMPADDR 5
  435. #define IMAGE_REL_BASED_IA64_IMM64 9
  436. #define IMAGE_REL_BASED_DIR64 10
  437. //
  438. // Line number format.
  439. //
  440. typedef struct _IMAGE_LINENUMBER {
  441. union {
  442. UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
  443. UINT32 VirtualAddress; // Virtual address of line number.
  444. } Type;
  445. UINT16 Linenumber; // Line number.
  446. } IMAGE_LINENUMBER;
  447. #define IMAGE_SIZEOF_LINENUMBER 6
  448. //
  449. // Archive format.
  450. //
  451. #define IMAGE_ARCHIVE_START_SIZE 8
  452. #define IMAGE_ARCHIVE_START "!<arch>\n"
  453. #define IMAGE_ARCHIVE_END "`\n"
  454. #define IMAGE_ARCHIVE_PAD "\n"
  455. #define IMAGE_ARCHIVE_LINKER_MEMBER "/ "
  456. #define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
  457. typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
  458. UINT8 Name[16]; // File member name - `/' terminated.
  459. UINT8 Date[12]; // File member date - decimal.
  460. UINT8 UserID[6]; // File member user id - decimal.
  461. UINT8 GroupID[6]; // File member group id - decimal.
  462. UINT8 Mode[8]; // File member mode - octal.
  463. UINT8 Size[10]; // File member size - decimal.
  464. UINT8 EndHeader[2]; // String to end header.
  465. } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
  466. #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
  467. //
  468. // DLL support.
  469. //
  470. //
  471. // Export Format
  472. //
  473. typedef struct _IMAGE_EXPORT_DIRECTORY {
  474. UINT32 Characteristics;
  475. UINT32 TimeDateStamp;
  476. UINT16 MajorVersion;
  477. UINT16 MinorVersion;
  478. UINT32 Name;
  479. UINT32 Base;
  480. UINT32 NumberOfFunctions;
  481. UINT32 NumberOfNames;
  482. UINT32 AddressOfFunctions;
  483. UINT32 AddressOfNames;
  484. UINT32 AddressOfNameOrdinals;
  485. } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
  486. //
  487. // Import Format
  488. //
  489. typedef struct _IMAGE_IMPORT_BY_NAME {
  490. UINT16 Hint;
  491. UINT8 Name[1];
  492. } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
  493. typedef struct _IMAGE_THUNK_DATA {
  494. union {
  495. UINT32 Function;
  496. UINT32 Ordinal;
  497. PIMAGE_IMPORT_BY_NAME AddressOfData;
  498. } u1;
  499. } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
  500. #define IMAGE_ORDINAL_FLAG 0x80000000
  501. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
  502. #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
  503. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  504. UINT32 Characteristics;
  505. UINT32 TimeDateStamp;
  506. UINT32 ForwarderChain;
  507. UINT32 Name;
  508. PIMAGE_THUNK_DATA FirstThunk;
  509. } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
  510. #endif