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.

591 lines
24 KiB

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