Leaked source code of windows server 2003
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.

379 lines
16 KiB

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