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.

387 lines
16 KiB

  1. /*static WCHAR *SCCSID = L"@(#)newexe.h:2.9";*/
  2. /*
  3. * Title
  4. *
  5. * newexe.h
  6. * Pete Stewart
  7. * (C) Copyright Microsoft Corp 1984
  8. * 17 August 1984
  9. *
  10. * Description
  11. *
  12. * Data structure definitions for the DOS 4.0/Windows 2.0
  13. * executable file format.
  14. *
  15. * Modification History
  16. *
  17. * 84/08/17 Pete Stewart Initial version
  18. * 84/10/17 Pete Stewart Changed some constants to match OMF
  19. * 84/10/23 Pete Stewart Updates to match .EXE format revision
  20. * 84/11/20 Pete Stewart Substantial .EXE format revision
  21. * 85/01/09 Pete Stewart Added constants ENEWEXE and ENEWHDR
  22. * 85/01/10 Steve Wood Added resource definitions
  23. * 85/03/04 Vic Heller Reconciled Windows and DOS 4.0 versions
  24. * 85/03/07 Pete Stewart Added movable entry count
  25. * 85/04/01 Pete Stewart Segment alignment field, error bit
  26. * 88/03/28 Craig Critchley Version 3.00 stuff
  27. */
  28. #define EMAGIC 0x5A4D /* Old magic number */
  29. #define ENEWEXE sizeof(struct exe_hdr)
  30. /* Value of E_LFARLC for new .EXEs */
  31. #define ENEWHDR 0x003C /* Offset in old hdr. of ptr. to new */
  32. #define ERESWDS 0x0010 /* No. of reserved words in header */
  33. #define ECP 0x0004 /* Offset in struct of E_CP */
  34. #define ECBLP 0x0002 /* Offset in struct of E_CBLP */
  35. #define EMINALLOC 0x000A /* Offset in struct of E_MINALLOC */
  36. struct exe_hdr /* DOS 1, 2, 3 .EXE header */
  37. {
  38. USHORT e_magic; /* Magic number */
  39. USHORT e_cblp; /* Bytes on last page of file */
  40. USHORT e_cp; /* Pages in file */
  41. USHORT e_crlc; /* Relocations */
  42. USHORT e_cparhdr; /* Size of header in paragraphs */
  43. USHORT e_minalloc; /* Minimum extra paragraphs needed */
  44. USHORT e_maxalloc; /* Maximum extra paragraphs needed */
  45. USHORT e_ss; /* Initial (relative) SS value */
  46. USHORT e_sp; /* Initial SP value */
  47. USHORT e_csum; /* Checksum */
  48. USHORT e_ip; /* Initial IP value */
  49. USHORT e_cs; /* Initial (relative) CS value */
  50. USHORT e_lfarlc; /* File address of relocation table */
  51. USHORT e_ovno; /* Overlay number */
  52. USHORT e_res[ERESWDS]; /* Reserved words */
  53. LONG e_lfanew; /* File address of new exe header */
  54. };
  55. #define E_MAGIC(x) (x).e_magic
  56. #define E_CBLP(x) (x).e_cblp
  57. #define E_CP(x) (x).e_cp
  58. #define E_CRLC(x) (x).e_crlc
  59. #define E_CPARHDR(x) (x).e_cparhdr
  60. #define E_MINALLOC(x) (x).e_minalloc
  61. #define E_MAXALLOC(x) (x).e_maxalloc
  62. #define E_SS(x) (x).e_ss
  63. #define E_SP(x) (x).e_sp
  64. #define E_CSUM(x) (x).e_csum
  65. #define E_IP(x) (x).e_ip
  66. #define E_CS(x) (x).e_cs
  67. #define E_LFARLC(x) (x).e_lfarlc
  68. #define E_OVNO(x) (x).e_ovno
  69. #define E_RES(x) (x).e_res
  70. #define E_LFANEW(x) (x).e_lfanew
  71. #define NEMAGIC 0x454E /* New magic number */
  72. #define NERESBYTES 0
  73. struct new_exe /* New .EXE header */
  74. {
  75. USHORT ne_magic; /* Magic number NE_MAGIC */
  76. BYTE ne_ver; /* Version number */
  77. BYTE ne_rev; /* Revision number */
  78. USHORT ne_enttab; /* Offset of Entry Table */
  79. USHORT ne_cbenttab; /* Number of bytes in Entry Table */
  80. LONG ne_crc; /* Checksum of whole file */
  81. USHORT ne_flags; /* Flag word */
  82. USHORT ne_autodata; /* Automatic data segment number */
  83. USHORT ne_heap; /* Initial heap allocation */
  84. USHORT ne_stack; /* Initial stack allocation */
  85. LONG ne_csip; /* Initial CS:IP setting */
  86. LONG ne_sssp; /* Initial SS:SP setting */
  87. USHORT ne_cseg; /* Count of file segments */
  88. USHORT ne_cmod; /* Entries in Module Reference Table */
  89. USHORT ne_cbnrestab; /* Size of non-resident name table */
  90. USHORT ne_segtab; /* Offset of Segment Table */
  91. USHORT ne_rsrctab; /* Offset of Resource Table */
  92. USHORT ne_restab; /* Offset of resident name table */
  93. USHORT ne_modtab; /* Offset of Module Reference Table */
  94. USHORT ne_imptab; /* Offset of Imported Names Table */
  95. LONG ne_nrestab; /* Offset of Non-resident Names Table */
  96. USHORT ne_cmovent; /* Count of movable entries */
  97. USHORT ne_align; /* Segment alignment shift count */
  98. USHORT ne_cres; /* Count of resource segments */
  99. BYTE ne_exetyp; /* Target operating system */
  100. BYTE ne_flagsother; /* Additional exe flags */
  101. USHORT ne_gangstart; /* offset to gangload area */
  102. USHORT ne_ganglength; /* length of gangload area */
  103. USHORT ne_swaparea; /* Minimum code swap area size */
  104. USHORT ne_expver; /* Expected Windows version number */
  105. };
  106. #define NE_MAGIC(x) (x).ne_magic
  107. #define NE_VER(x) (x).ne_ver
  108. #define NE_REV(x) (x).ne_rev
  109. #define NE_ENTTAB(x) (x).ne_enttab
  110. #define NE_CBENTTAB(x) (x).ne_cbenttab
  111. #define NE_CRC(x) (x).ne_crc
  112. #define NE_FLAGS(x) (x).ne_flags
  113. #define NE_AUTODATA(x) (x).ne_autodata
  114. #define NE_HEAP(x) (x).ne_heap
  115. #define NE_STACK(x) (x).ne_stack
  116. #define NE_CSIP(x) (x).ne_csip
  117. #define NE_SSSP(x) (x).ne_sssp
  118. #define NE_CSEG(x) (x).ne_cseg
  119. #define NE_CMOD(x) (x).ne_cmod
  120. #define NE_CBNRESTAB(x) (x).ne_cbnrestab
  121. #define NE_SEGTAB(x) (x).ne_segtab
  122. #define NE_RSRCTAB(x) (x).ne_rsrctab
  123. #define NE_RESTAB(x) (x).ne_restab
  124. #define NE_MODTAB(x) (x).ne_modtab
  125. #define NE_IMPTAB(x) (x).ne_imptab
  126. #define NE_NRESTAB(x) (x).ne_nrestab
  127. #define NE_CMOVENT(x) (x).ne_cmovent
  128. #define NE_ALIGN(x) (x).ne_align
  129. #define NE_RES(x) (x).ne_res
  130. #define NE_USAGE(x) (WORD)*((WORD FAR *)(x)+1)
  131. #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
  132. #define NE_PAUTODATA(x) (WORD)(x).ne_crc
  133. #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
  134. #ifdef DOS5
  135. #define NE_MTE(x) (x).ne_psegcsum /* DOS 5 MTE handle for this module */
  136. #endif
  137. /*
  138. * Format of NE_FLAGS(x):
  139. *
  140. * p Not-a-process
  141. * l Private Library
  142. * e Errors in image
  143. * xxxx Unused
  144. * ww Uses PM API
  145. * G Library GlobalAlloc above the line
  146. * M Multiple Instance
  147. * L Uses LIM 3.2
  148. * P Runs in protected mode
  149. * r Runs in real mode
  150. * i Instance data
  151. * s Solo data
  152. */
  153. #define NENOTP 0x8000 /* Not a process */
  154. #define NEPRIVLIB 0x4000 /* Private Library */
  155. #define NENONC 0x4000 /* Non-conforming program */
  156. #define NEIERR 0x2000 /* Errors in image */
  157. #define NEWINAPI 0x0300 /* Uses PM API. For binary compat */
  158. #define NEEMSLIB 0x0040 /* Library GA above EMS line */
  159. #define NEMULTINST 0x0020 /* multiple instance flag */
  160. #define NELIM32 0x0010 /* LIM 32 expanded memory */
  161. #define NEPROT 0x0008 /* Runs in protected mode */
  162. #define NEREAL 0x0004 /* Runs in real mode */
  163. #define NEINST 0x0002 /* Instance data */
  164. #define NESOLO 0x0001 /* Solo data */
  165. /*
  166. * Format of additional flags:
  167. *
  168. * xxxx
  169. * p Preload area defined after seg table
  170. * P 2.X supports protected mode
  171. * F 2.X supports proportional font
  172. * L Long file name support
  173. */
  174. #define NEPRELOAD 0x08 /* preload segments */
  175. #define NEINPROT 0x04 /* protect mode */
  176. #define NEINFONT 0x02 /* prop. system font */
  177. #define NELONGNAMES 0x01 /* long file names */
  178. struct new_seg /* New .EXE segment table entry */
  179. {
  180. USHORT ns_sector; /* File sector of start of segment */
  181. USHORT ns_cbseg; /* Number of bytes in file */
  182. USHORT ns_flags; /* Attribute flags */
  183. USHORT ns_minalloc; /* Minimum allocation in bytes */
  184. };
  185. struct new_seg1 /* New .EXE segment table entry */
  186. {
  187. USHORT ns_sector; /* File sector of start of segment */
  188. USHORT ns_cbseg; /* Number of bytes in file */
  189. USHORT ns_flags; /* Attribute flags */
  190. USHORT ns_minalloc; /* Minimum allocation in bytes */
  191. USHORT ns_handle; /* Handle of segment */
  192. };
  193. #define NS_SECTOR(x) (x).ns_sector
  194. #define NS_CBSEG(x) (x).ns_cbseg
  195. #define NS_FLAGS(x) (x).ns_flags
  196. #define NS_MINALLOC(x) (x).ns_minalloc
  197. /*
  198. * Format of NS_FLAGS(x):
  199. *
  200. * xxxx Unused
  201. * DD 286 DPL bits
  202. * d Segment has debug info
  203. * r Segment has relocations
  204. * e Execute/read only
  205. * p Preload segment
  206. * P Pure segment
  207. * m Movable segment
  208. * i Iterated segment
  209. * ttt Segment type
  210. */
  211. #define NSTYPE 0x0007 /* Segment type mask */
  212. #define NSCODE 0x0000 /* Code segment */
  213. #define NSDATA 0x0001 /* Data segment */
  214. #define NSITER 0x0008 /* Iterated segment flag */
  215. #define NSMOVE 0x0010 /* Movable segment flag */
  216. #define NSPURE 0x0020 /* Pure segment flag */
  217. #define NSPRELOAD 0x0040 /* Preload segment flag */
  218. #define NSEXRD 0x0080 /* Execute-only (code segment), or
  219. * read-only (data segment)
  220. */
  221. #define NSRELOC 0x0100 /* Segment has relocations */
  222. #define NSDEBUG 0x0200 /* Segment has debug info */
  223. #define NSDPL 0x0C00 /* 286 DPL bits */
  224. #define NSDISCARD 0x1000 /* Discard bit for segment */
  225. #define NSALIGN 9 /* Segment data aligned on 512 byte boundaries */
  226. struct new_segdata /* Segment data */
  227. {
  228. union
  229. {
  230. struct
  231. {
  232. USHORT ns_niter; /* number of iterations */
  233. USHORT ns_nbytes; /* number of bytes */
  234. BYTE ns_iterdata; /* iterated data bytes */
  235. } ns_iter;
  236. struct
  237. {
  238. BYTE ns_data; /* data bytes */
  239. } ns_noniter;
  240. } ns_union;
  241. };
  242. struct new_rlcinfo /* Relocation info */
  243. {
  244. USHORT nr_nreloc; /* number of relocation items that */
  245. }; /* follow */
  246. struct new_rlc /* Relocation item */
  247. {
  248. BYTE nr_stype; /* Source type */
  249. BYTE nr_flags; /* Flag byte */
  250. USHORT nr_soff; /* Source offset */
  251. union
  252. {
  253. struct
  254. {
  255. BYTE nr_segno; /* Target segment number */
  256. BYTE nr_res; /* Reserved */
  257. USHORT nr_entry; /* Target Entry Table offset */
  258. } nr_intref; /* Internal reference */
  259. struct
  260. {
  261. USHORT nr_mod; /* Index into Module Reference Table */
  262. USHORT nr_proc; /* Procedure ordinal or name offset */
  263. } nr_import; /* Import */
  264. } nr_union; /* Union */
  265. };
  266. #define NR_STYPE(x) (x).nr_stype
  267. #define NR_FLAGS(x) (x).nr_flags
  268. #define NR_SOFF(x) (x).nr_soff
  269. #define NR_SEGNO(x) (x).nr_union.nr_intref.nr_segno
  270. #define NR_RES(x) (x).nr_union.nr_intref.nr_res
  271. #define NR_ENTRY(x) (x).nr_union.nr_intref.nr_entry
  272. #define NR_MOD(x) (x).nr_union.nr_import.nr_mod
  273. #define NR_PROC(x) (x).nr_union.nr_import.nr_proc
  274. /*
  275. * Format of NR_STYPE(x):
  276. *
  277. * xxxxx Unused
  278. * sss Source type
  279. */
  280. #define NRSTYP 0x07 /* Source type mask */
  281. #define NRSSEG 0x02 /* 16-bit segment */
  282. #define NRSPTR 0x03 /* 32-bit pointer */
  283. #define NRSOFF 0x05 /* 16-bit offset */
  284. /*
  285. * Format of NR_FLAGS(x):
  286. *
  287. * xxxxx Unused
  288. * a Additive fixup
  289. * rr Reference type
  290. */
  291. #define NRADD 0x04 /* Additive fixup */
  292. #define NRRTYP 0x03 /* Reference type mask */
  293. #define NRRINT 0x00 /* Internal reference */
  294. #define NRRORD 0x01 /* Import by ordinal */
  295. #define NRRNAM 0x02 /* Import by name */
  296. /* Resource type or name string */
  297. struct rsrc_string
  298. {
  299. USHORT rs_len; /* number of bytes in string */
  300. WCHAR rs_string[ 1 ]; /* text of string */
  301. };
  302. #define RS_LEN( x ) (x).rs_len
  303. #define RS_STRING( x ) (x).rs_string
  304. /* Resource type information block */
  305. struct rsrc_typeinfo
  306. {
  307. USHORT rt_id;
  308. USHORT rt_nres;
  309. LONG rt_proc;
  310. };
  311. #define RT_ID( x ) (x).rt_id
  312. #define RT_NRES( x ) (x).rt_nres
  313. #define RT_PROC( x ) (x).rt_proc
  314. /* Resource name information block */
  315. struct rsrc_nameinfo
  316. {
  317. /* The following two fields must be shifted left by the value of */
  318. /* the rs_align field to compute their actual value. This allows */
  319. /* resources to be larger than 64k, but they do not need to be */
  320. /* aligned on 512 byte boundaries, the way segments are */
  321. USHORT rn_offset; /* file offset to resource data */
  322. USHORT rn_length; /* length of resource data */
  323. USHORT rn_flags; /* resource flags */
  324. USHORT rn_id; /* resource name id */
  325. USHORT rn_handle; /* If loaded, then global handle */
  326. USHORT rn_usage; /* Initially zero. Number of times */
  327. /* the handle for this resource has */
  328. /* been given out */
  329. };
  330. #define RN_OFFSET( x ) (x).rn_offset
  331. #define RN_LENGTH( x ) (x).rn_length
  332. #define RN_FLAGS( x ) (x).rn_flags
  333. #define RN_ID( x ) (x).rn_id
  334. #define RN_HANDLE( x ) (x).rn_handle
  335. #define RN_USAGE( x ) (x).rn_usage
  336. #define RSORDID 0x8000 /* if high bit of ID set then integer id */
  337. /* otherwise ID is offset of string from
  338. the beginning of the resource table */
  339. /* Ideally these are the same as the */
  340. /* corresponding segment flags */
  341. #define RNMOVE 0x0010 /* Moveable resource */
  342. #define RNPURE 0x0020 /* Pure (read-only) resource */
  343. #define RNPRELOAD 0x0040 /* Preloaded resource */
  344. #define RNDISCARD 0x1000 /* Discard bit for resource */
  345. #define RNLOADED 0x0004 /* True if handler proc return handle */
  346. /* Resource table */
  347. struct new_rsrc
  348. {
  349. USHORT rs_align; /* alignment shift count for resources */
  350. struct rsrc_typeinfo rs_typeinfo;
  351. };
  352. #define RS_ALIGN( x ) (x).rs_align
  353.