pecoff.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2020 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. #ifndef PECOFF_H
  34. #define PECOFF_H
  35. /*
  36. * Microsoft Portable Executable and Common Object
  37. * File Format Specification
  38. *
  39. * Revision 8.1 – February 15, 2008
  40. */
  41. /*
  42. * Machine types
  43. */
  44. #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
  45. #define IMAGE_FILE_MACHINE_AM33 0x01d3
  46. #define IMAGE_FILE_MACHINE_AMD64 0x8664
  47. #define IMAGE_FILE_MACHINE_EBC 0x0ebc
  48. #define IMAGE_FILE_MACHINE_M32R 0x9041
  49. #define IMAGE_FILE_MACHINE_ALPHA 0x0184
  50. #define IMAGE_FILE_MACHINE_ARM 0x01c0
  51. #define IMAGE_FILE_MACHINE_ALPHA64 0x0284
  52. #define IMAGE_FILE_MACHINE_I386 0x014c
  53. #define IMAGE_FILE_MACHINE_IA64 0x0200
  54. #define IMAGE_FILE_MACHINE_M68K 0x0268
  55. #define IMAGE_FILE_MACHINE_MIPS16 0x0266
  56. #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
  57. #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
  58. #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
  59. #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
  60. #define IMAGE_FILE_MACHINE_R3000 0x0162
  61. #define IMAGE_FILE_MACHINE_R4000 0x0166
  62. #define IMAGE_FILE_MACHINE_R10000 0x0168
  63. #define IMAGE_FILE_MACHINE_SH3 0x01a2
  64. #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
  65. #define IMAGE_FILE_MACHINE_SH4 0x01a6
  66. #define IMAGE_FILE_MACHINE_SH5 0x01a8
  67. #define IMAGE_FILE_MACHINE_THUMB 0x01c2
  68. #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
  69. #define IMAGE_FILE_MACHINE_MASK 0xffff
  70. /*
  71. * Characteristics
  72. */
  73. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001
  74. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
  75. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
  76. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
  77. #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
  78. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
  79. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
  80. #define IMAGE_FILE_32BIT_MACHINE 0x0100
  81. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
  82. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
  83. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
  84. #define IMAGE_FILE_SYSTEM 0x1000
  85. #define IMAGE_FILE_DLL 0x2000
  86. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
  87. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
  88. /*
  89. * Windows subsystem
  90. */
  91. #define IMAGE_SUBSYSTEM_UNKNOWN 0
  92. #define IMAGE_SUBSYSTEM_NATIVE 1
  93. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
  94. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
  95. #define IMAGE_SUBSYSTEM_POSIX_CUI 7
  96. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
  97. #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
  98. #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
  99. #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
  100. #define IMAGE_SUBSYSTEM_EFI_ROM 13
  101. #define IMAGE_SUBSYSTEM_XBOX 14
  102. /*
  103. * DLL characteristics
  104. */
  105. #define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
  106. #define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
  107. #define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
  108. #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
  109. #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
  110. #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
  111. #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
  112. #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
  113. /*
  114. * Section flags
  115. */
  116. #define IMAGE_SCN_TYPE_REG 0x00000000
  117. #define IMAGE_SCN_TYPE_DSECT 0x00000001
  118. #define IMAGE_SCN_TYPE_NOLOAD 0x00000002
  119. #define IMAGE_SCN_TYPE_GROUP 0x00000004
  120. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008
  121. #define IMAGE_SCN_TYPE_COPY 0x00000010
  122. #define IMAGE_SCN_CNT_CODE 0x00000020
  123. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
  124. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
  125. #define IMAGE_SCN_LNK_OTHER 0x00000100
  126. #define IMAGE_SCN_LNK_INFO 0x00000200
  127. #define IMAGE_SCN_TYPE_OVER 0x00000400
  128. #define IMAGE_SCN_LNK_REMOVE 0x00000800
  129. #define IMAGE_SCN_LNK_COMDAT 0x00001000
  130. #define IMAGE_SCN_MAX_RELOC 0xffff
  131. #define IMAGE_SCN_MEM_FARDATA 0x00008000
  132. #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
  133. #define IMAGE_SCN_MEM_16BIT 0x00020000
  134. #define IMAGE_SCN_MEM_LOCKED 0x00040000
  135. #define IMAGE_SCN_MEM_PRELOAD 0x00080000
  136. #define IMAGE_SCN_ALIGN_1BYTES 0x00100000
  137. #define IMAGE_SCN_ALIGN_2BYTES 0x00200000
  138. #define IMAGE_SCN_ALIGN_4BYTES 0x00300000
  139. #define IMAGE_SCN_ALIGN_8BYTES 0x00400000
  140. #define IMAGE_SCN_ALIGN_16BYTES 0x00500000
  141. #define IMAGE_SCN_ALIGN_32BYTES 0x00600000
  142. #define IMAGE_SCN_ALIGN_64BYTES 0x00700000
  143. #define IMAGE_SCN_ALIGN_128BYTES 0x00800000
  144. #define IMAGE_SCN_ALIGN_256BYTES 0x00900000
  145. #define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
  146. #define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
  147. #define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
  148. #define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
  149. #define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
  150. #define IMAGE_SCN_ALIGN_MASK 0x00f00000
  151. #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
  152. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
  153. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000
  154. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000
  155. #define IMAGE_SCN_MEM_SHARED 0x10000000
  156. #define IMAGE_SCN_MEM_EXECUTE 0x20000000
  157. #define IMAGE_SCN_MEM_READ 0x40000000
  158. #define IMAGE_SCN_MEM_WRITE 0x80000000
  159. /*
  160. * Relocation type x86-64
  161. */
  162. #define IMAGE_REL_AMD64_ABSOLUTE 0x0000
  163. #define IMAGE_REL_AMD64_ADDR64 0x0001
  164. #define IMAGE_REL_AMD64_ADDR32 0x0002
  165. #define IMAGE_REL_AMD64_ADDR32NB 0x0003
  166. #define IMAGE_REL_AMD64_REL32 0x0004
  167. #define IMAGE_REL_AMD64_REL32_1 0x0005
  168. #define IMAGE_REL_AMD64_REL32_2 0x0006
  169. #define IMAGE_REL_AMD64_REL32_3 0x0007
  170. #define IMAGE_REL_AMD64_REL32_4 0x0008
  171. #define IMAGE_REL_AMD64_REL32_5 0x0009
  172. #define IMAGE_REL_AMD64_SECTION 0x000a
  173. #define IMAGE_REL_AMD64_SECREL 0x000b
  174. #define IMAGE_REL_AMD64_SECREL7 0x000c
  175. #define IMAGE_REL_AMD64_TOKEN 0x000d
  176. #define IMAGE_REL_AMD64_SREL32 0x000e
  177. #define IMAGE_REL_AMD64_PAIR 0x000f
  178. #define IMAGE_REL_AMD64_SSPAN32 0x0010
  179. /*
  180. * Relocation types i386
  181. */
  182. #define IMAGE_REL_I386_ABSOLUTE 0x0000
  183. #define IMAGE_REL_I386_DIR16 0x0001
  184. #define IMAGE_REL_I386_REL16 0x0002
  185. #define IMAGE_REL_I386_DIR32 0x0006
  186. #define IMAGE_REL_I386_DIR32NB 0x0007
  187. #define IMAGE_REL_I386_SEG12 0x0009
  188. #define IMAGE_REL_I386_SECTION 0x000a
  189. #define IMAGE_REL_I386_SECREL 0x000b
  190. #define IMAGE_REL_I386_TOKEN 0x000c
  191. #define IMAGE_REL_I386_SECREL7 0x000d
  192. #define IMAGE_REL_I386_REL32 0x0014
  193. /*
  194. * Relocation types ARM
  195. */
  196. #define IMAGE_REL_ARM_ABSOLUTE 0x0000
  197. #define IMAGE_REL_ARM_ADDR32 0x0001
  198. #define IMAGE_REL_ARM_ADDR32NB 0x0002
  199. #define IMAGE_REL_ARM_BRANCH24 0x0003
  200. #define IMAGE_REL_ARM_BRANCH11 0x0004
  201. #define IMAGE_REL_ARM_SECTION 0x000e
  202. #define IMAGE_REL_ARM_SECREL 0x000f
  203. /*
  204. * Relocation types Hitachi SuperH
  205. */
  206. #define IMAGE_REL_SH3_ABSOLUTE 0x0000
  207. #define IMAGE_REL_SH3_DIRECT16 0x0001
  208. #define IMAGE_REL_SH3_DIRECT32 0x0002
  209. #define IMAGE_REL_SH3_DIRECT8 0x0003
  210. #define IMAGE_REL_SH3_DIRECT8_WORD 0x0004
  211. #define IMAGE_REL_SH3_DIRECT8_LONG 0x0005
  212. #define IMAGE_REL_SH3_DIRECT4 0x0006
  213. #define IMAGE_REL_SH3_DIRECT4_WORD 0x0007
  214. #define IMAGE_REL_SH3_DIRECT4_LONG 0x0008
  215. #define IMAGE_REL_SH3_PCREL8_WORD 0x0009
  216. #define IMAGE_REL_SH3_PCREL8_LONG 0x000a
  217. #define IMAGE_REL_SH3_PCREL12_WORD 0x000b
  218. #define IMAGE_REL_SH3_STARTOF_SECTION 0x000c
  219. #define IMAGE_REL_SH3_SIZEOF_SECTION 0x000d
  220. #define IMAGE_REL_SH3_SECTION 0x000e
  221. #define IMAGE_REL_SH3_SECREL 0x000f
  222. #define IMAGE_REL_SH3_DIRECT32_NB 0x0010
  223. #define IMAGE_REL_SH3_GPREL4_LONG 0x0011
  224. #define IMAGE_REL_SH3_TOKEN 0x0012
  225. #define IMAGE_REL_SHM_PCRELPT 0x0013
  226. #define IMAGE_REL_SHM_REFLO 0x0014
  227. #define IMAGE_REL_SHM_REFHALF 0x0015
  228. #define IMAGE_REL_SHM_RELLO 0x0016
  229. #define IMAGE_REL_SHM_RELHALF 0x0017
  230. #define IMAGE_REL_SHM_PAIR 0x0018
  231. #define IMAGE_REL_SHM_NOMODE 0x8000
  232. /*
  233. * Relocation types IBM PowerPC processors
  234. */
  235. #define IMAGE_REL_PPC_ABSOLUTE 0x0000
  236. #define IMAGE_REL_PPC_ADDR64 0x0001
  237. #define IMAGE_REL_PPC_ADDR32 0x0002
  238. #define IMAGE_REL_PPC_ADDR24 0x0003
  239. #define IMAGE_REL_PPC_ADDR16 0x0004
  240. #define IMAGE_REL_PPC_ADDR14 0x0005
  241. #define IMAGE_REL_PPC_REL24 0x0006
  242. #define IMAGE_REL_PPC_REL14 0x0007
  243. #define IMAGE_REL_PPC_ADDR32NB 0x000a
  244. #define IMAGE_REL_PPC_SECREL 0x000b
  245. #define IMAGE_REL_PPC_SECTION 0x000c
  246. #define IMAGE_REL_PPC_SECREL16 0x000f
  247. #define IMAGE_REL_PPC_REFHI 0x0010
  248. #define IMAGE_REL_PPC_REFLO 0x0011
  249. #define IMAGE_REL_PPC_PAIR 0x0012
  250. #define IMAGE_REL_PPC_SECRELLO 0x0013
  251. #define IMAGE_REL_PPC_GPREL 0x0015
  252. #define IMAGE_REL_PPC_TOKEN 0x0016
  253. /*
  254. * Relocation types Intel Itanium processor family (IPF)
  255. */
  256. #define IMAGE_REL_IA64_ABSOLUTE 0x0000
  257. #define IMAGE_REL_IA64_IMM14 0x0001
  258. #define IMAGE_REL_IA64_IMM22 0x0002
  259. #define IMAGE_REL_IA64_IMM64 0x0003
  260. #define IMAGE_REL_IA64_DIR32 0x0004
  261. #define IMAGE_REL_IA64_DIR64 0x0005
  262. #define IMAGE_REL_IA64_PCREL21B 0x0006
  263. #define IMAGE_REL_IA64_PCREL21M 0x0007
  264. #define IMAGE_REL_IA64_PCREL21F 0x0008
  265. #define IMAGE_REL_IA64_GPREL22 0x0009
  266. #define IMAGE_REL_IA64_LTOFF22 0x000a
  267. #define IMAGE_REL_IA64_SECTION 0x000b
  268. #define IMAGE_REL_IA64_SECREL22 0x000c
  269. #define IMAGE_REL_IA64_SECREL64I 0x000d
  270. #define IMAGE_REL_IA64_SECREL32 0x000e
  271. #define IMAGE_REL_IA64_DIR32NB 0x0010
  272. #define IMAGE_REL_IA64_SREL14 0x0011
  273. #define IMAGE_REL_IA64_SREL22 0x0012
  274. #define IMAGE_REL_IA64_SREL32 0x0013
  275. #define IMAGE_REL_IA64_UREL32 0x0014
  276. #define IMAGE_REL_IA64_PCREL60X 0x0015
  277. #define IMAGE_REL_IA64_PCREL 60B 0x0016
  278. #define IMAGE_REL_IA64_PCREL60F 0x0017
  279. #define IMAGE_REL_IA64_PCREL60I 0x0018
  280. #define IMAGE_REL_IA64_PCREL60M 0x0019
  281. #define IMAGE_REL_IA64_IMMGPREL64 0x001a
  282. #define IMAGE_REL_IA64_TOKEN 0x001b
  283. #define IMAGE_REL_IA64_GPREL32 0x001c
  284. #define IMAGE_REL_IA64_ADDEND 0x001f
  285. /*
  286. * Relocation types MIPS Processors
  287. */
  288. #define IMAGE_REL_MIPS_ABSOLUTE 0x0000
  289. #define IMAGE_REL_MIPS_REFHALF 0x0001
  290. #define IMAGE_REL_MIPS_REFWORD 0x0002
  291. #define IMAGE_REL_MIPS_JMPADDR 0x0003
  292. #define IMAGE_REL_MIPS_REFHI 0x0004
  293. #define IMAGE_REL_MIPS_REFLO 0x0005
  294. #define IMAGE_REL_MIPS_GPREL 0x0006
  295. #define IMAGE_REL_MIPS_LITERAL 0x0007
  296. #define IMAGE_REL_MIPS_SECTION 0x000a
  297. #define IMAGE_REL_MIPS_SECREL 0x000b
  298. #define IMAGE_REL_MIPS_SECRELLO 0x000c
  299. #define IMAGE_REL_MIPS_SECRELHI 0x000d
  300. #define IMAGE_REL_MIPS_JMPADDR16 0x0010
  301. #define IMAGE_REL_MIPS_REFWORDNB 0x0022
  302. #define IMAGE_REL_MIPS_PAIR 0x0025
  303. /*
  304. * Relocation types Mitsubishi M32R
  305. */
  306. #define IMAGE_REL_M32R_ABSOLUTE 0x0000
  307. #define IMAGE_REL_M32R_ADDR32 0x0001
  308. #define IMAGE_REL_M32R_ADDR32NB 0x0002
  309. #define IMAGE_REL_M32R_ADDR24 0x0003
  310. #define IMAGE_REL_M32R_GPREL16 0x0004
  311. #define IMAGE_REL_M32R_PCREL24 0x0005
  312. #define IMAGE_REL_M32R_PCREL16 0x0006
  313. #define IMAGE_REL_M32R_PCREL8 0x0007
  314. #define IMAGE_REL_M32R_REFHALF 0x0008
  315. #define IMAGE_REL_M32R_REFHI 0x0009
  316. #define IMAGE_REL_M32R_REFLO 0x000a
  317. #define IMAGE_REL_M32R_PAIR 0x000b
  318. #define IMAGE_REL_M32R_SECTION 0x000c
  319. #define IMAGE_REL_M32R_SECREL 0x000d
  320. #define IMAGE_REL_M32R_TOKEN 0x000e
  321. /*
  322. * Section number values
  323. */
  324. #define IMAGE_SYM_UNDEFINED 0
  325. #define IMAGE_SYM_ABSOLUTE -1
  326. #define IMAGE_SYM_DEBUG -2
  327. /*
  328. * Type representation
  329. */
  330. #define IMAGE_SYM_TYPE_NULL 0
  331. #define IMAGE_SYM_TYPE_VOID 1
  332. #define IMAGE_SYM_TYPE_CHAR 2
  333. #define IMAGE_SYM_TYPE_SHORT 3
  334. #define IMAGE_SYM_TYPE_INT 4
  335. #define IMAGE_SYM_TYPE_LONG 5
  336. #define IMAGE_SYM_TYPE_FLOAT 6
  337. #define IMAGE_SYM_TYPE_DOUBLE 7
  338. #define IMAGE_SYM_TYPE_STRUCT 8
  339. #define IMAGE_SYM_TYPE_UNION 9
  340. #define IMAGE_SYM_TYPE_ENUM 10
  341. #define IMAGE_SYM_TYPE_MOE 11
  342. #define IMAGE_SYM_TYPE_BYTE 12
  343. #define IMAGE_SYM_TYPE_WORD 13
  344. #define IMAGE_SYM_TYPE_UINT 14
  345. #define IMAGE_SYM_TYPE_DWORD 15
  346. #define IMAGE_SYM_DTYPE_NULL 0
  347. #define IMAGE_SYM_DTYPE_POINTER 1
  348. #define IMAGE_SYM_DTYPE_FUNCTION 2
  349. #define IMAGE_SYM_DTYPE_ARRAY 3
  350. /*
  351. * Storage class
  352. */
  353. #define IMAGE_SYM_CLASS_END_OF_FUNCTION -1
  354. #define IMAGE_SYM_CLASS_NULL 0
  355. #define IMAGE_SYM_CLASS_AUTOMATIC 1
  356. #define IMAGE_SYM_CLASS_EXTERNAL 2
  357. #define IMAGE_SYM_CLASS_STATIC 3
  358. #define IMAGE_SYM_CLAS S_REGISTER 4
  359. #define IMAGE_SYM_CLASS_EXTERNAL_DEF 5
  360. #define IMAGE_SYM_CLASS_LABEL 6
  361. #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
  362. #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
  363. #define IMAGE_SYM_CLASS_ARGUMENT 9
  364. #define IMAGE_SYM_CLASS_STRUCT_TAG 10
  365. #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
  366. #define IMAGE_SYM_CLASS_UNION_TAG 12
  367. #define IMAGE_SYM_CLASS_TYPE_DEFINITION 13
  368. #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
  369. #define IMAGE_SYM_CLASS_ENUM_TAG 15
  370. #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
  371. #define IMAGE_SYM_CLASS_REGISTER_PARAM 17
  372. #define IMAGE_SYM_CLASS_BIT_FIELD 18
  373. #define IMAGE_SYM_CLASS_BLOCK 100
  374. #define IMAGE_SYM_CLASS_FUNCTION 101
  375. #define IMAGE_SYM_CLASS_END_OF_STRUCT 102
  376. #define IMAGE_SYM_CLASS_FILE 103
  377. #define IMAGE_SYM_CLASS_SECTION 104
  378. #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
  379. #define IMAGE_SYM_CLASS_CLR_TOKEN 107
  380. /*
  381. * COMDAT sections
  382. */
  383. #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
  384. #define IMAGE_COMDAT_SELECT_ANY 2
  385. #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
  386. #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  387. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  388. #define IMAGE_COMDAT_SELECT_LARGEST 6
  389. /*
  390. * Attribute certificate table
  391. */
  392. #define WIN_CERT_REVISION_1_0 0x0100
  393. #define WIN_CERT_REVISION_2_0 0x0200
  394. #define WIN_CERT_TYPE_X509 0x0001
  395. #define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
  396. #define WIN_CERT_TYPE_RESERVED_1 0x0003
  397. #define WIN_CERT_TYPE_TS_STACK_SIGNED 0x0004
  398. /*
  399. * Debug type
  400. */
  401. #define IMAGE_DEBUG_TYPE_UNKNOWN 0
  402. #define IMAGE_DEBUG_TYPE_COFF 1
  403. #define IMAGE_DEBUG_TYPE_CODEVIEW 2
  404. #define IMAGE_DEBUG_TYPE_FPO 3
  405. #define IMAGE_DEBUG_TYPE_MISC 4
  406. #define IMAGE_DEBUG_TYPE_EXCEPTION 5
  407. #define IMAGE_DEBUG_TYPE_FIXUP 6
  408. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7
  409. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8
  410. #define IMAGE_DEBUG_TYP E_BORLAND 9
  411. #define IMAGE_DEBUG_TYPE_RESERVED10 10
  412. #define IMAGE_DEBUG_TYPE_CLSID 11
  413. /*
  414. * Base relocation types
  415. */
  416. #define IMAGE_REL_BASED_ABSOLUTE 0
  417. #define IMAGE_REL_BASED_HIGH 1
  418. #define IMAGE_REL_BASED_LOW 2
  419. #define IMAGE_REL_BASED_HIGHLOW 3
  420. #define IMAGE_REL_BASED_HIGHADJ 4
  421. #define IMAGE_REL_BASED_MIPS_JMPADDR 5
  422. #define IMAGE_REL_BASED_MIPS_JMPADDR16 9
  423. #define IMAGE_REL_BASED_DIR64 10
  424. /*
  425. * TLS callback functions
  426. */
  427. #define DLL_PROCESS_ATTACH 1
  428. #define DLL_THREAD_ATTACH 2
  429. #define DLL_THREAD_DETACH 3
  430. #define DLL_PROCESS_DETACH 0
  431. /*
  432. * Import Type
  433. */
  434. #define IMPORT_CODE 0
  435. #define IMPORT_DATA 1
  436. #define IMPORT_CONST 2
  437. /*
  438. * Import name type
  439. */
  440. #define IMPORT_ORDINAL 0
  441. #define IMPORT_NAME 1
  442. #define IMPORT_NAME_NOPREFIX 2
  443. #define IMPORT_NAME_UNDECORATE 3
  444. struct coff_Section {
  445. struct SAA *data;
  446. uint32_t len;
  447. int nrelocs;
  448. int32_t index;
  449. struct coff_Reloc *head, **tail;
  450. uint32_t flags; /* section flags */
  451. uint32_t align_flags; /* user-specified alignment flags */
  452. uint32_t sectalign_flags; /* minimum alignment from sectalign */
  453. char *name;
  454. int32_t namepos; /* Offset of name into the strings table */
  455. int32_t pos, relpos;
  456. int64_t pass_last_seen;
  457. };
  458. struct coff_Reloc {
  459. struct coff_Reloc *next;
  460. int32_t address; /* relative to _start_ of section */
  461. int32_t symbol; /* symbol number */
  462. enum {
  463. SECT_SYMBOLS,
  464. ABS_SYMBOL,
  465. REAL_SYMBOLS
  466. } symbase; /* relocation for symbol number :) */
  467. int16_t type;
  468. };
  469. struct coff_Symbol {
  470. char name[9];
  471. int32_t strpos; /* string table position of name */
  472. int32_t value; /* address, or COMMON variable size */
  473. int section; /* section number where it's defined
  474. * - in COFF codes, not NASM codes */
  475. bool is_global; /* is it a global symbol or not? */
  476. int16_t type; /* 0 - notype, 0x20 - function */
  477. int32_t namlen; /* full name length */
  478. };
  479. struct coff_DebugInfo {
  480. int32_t segto;
  481. int32_t seg;
  482. uint64_t size;
  483. struct coff_Section *section;
  484. };
  485. extern struct coff_Section **coff_sects;
  486. extern int coff_nsects;
  487. extern struct SAA *coff_syms;
  488. extern uint32_t coff_nsyms;
  489. extern struct SAA *coff_strs;
  490. extern bool win32, win64;
  491. extern char coff_infile[FILENAME_MAX];
  492. extern char coff_outfile[FILENAME_MAX];
  493. extern int coff_make_section(char *name, uint32_t flags);
  494. #endif /* PECOFF_H */