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.

302 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: exehdr.h
  3. *
  4. * (Brief description)
  5. *
  6. * Created: 08-May-1991 13:42:33
  7. * Author: Bodin Dresevic [BodinD]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. *
  11. * Description
  12. *
  13. * Data structure definitions for the DOS 4.0/Windows 2.0
  14. * executable file format.
  15. *
  16. * Modification History
  17. *
  18. * 84/08/17 Pete Stewart Initial version
  19. * 84/10/17 Pete Stewart Changed some constants to match OMF
  20. * 84/10/23 Pete Stewart Updates to match .EXE format revision
  21. * 84/11/20 Pete Stewart Substantial .EXE format revision
  22. * 85/01/09 Pete Stewart Added constants ENEWEXE and ENEWHDR
  23. * 85/01/10 Steve Wood Added resource definitions
  24. * 85/03/04 Vic Heller Reconciled Windows and DOS 4.0 versions
  25. * 85/03/07 Pete Stewart Added movable entry count
  26. * 85/04/01 Pete Stewart Segment alignment field, error bit
  27. *****
  28. * 90/11/28 Lindsay Harris: copied & trimmed from DOS version
  29. *****
  30. * Wed 08-May-1991 -by- Bodin Dresevic [BodinD]
  31. * update:
  32. * made changes necessary to make the code portable, offsets et.c
  33. *
  34. \**************************************************************************/
  35. #define EMAGIC 0x5A4D // Old magic number
  36. #define ENEWEXE sizeof(struct exe_hdr)
  37. // Value of E_LFARLC for new .EXEs
  38. #define ENEWHDR 0x003C // Offset in old hdr. of ptr. to new
  39. #define ERESWDS 0x0010 // No. of reserved words in header
  40. #define ECP 0x0004 // Offset in struct of E_CP
  41. #define ECBLP 0x0002 // Offset in struct of E_CBLP
  42. #define EMINALLOC 0x000A // Offset in struct of E_MINALLOC
  43. #ifdef DEBUGOFFSETS
  44. // this is the original definition of the structure that I used to compute
  45. // the offsets given below, assuming that the 16 bit compiler puts no padding
  46. // between the fields. It turns out that this assumption is correct
  47. // so that when the file is written to the disk the fields are indeed
  48. // laid out at the offsets computed below
  49. typedef struct exe_hdr // DOS 1, 2, 3 .EXE header
  50. {
  51. unsigned short e_magic; // Magic number
  52. unsigned short e_cblp; // Bytes on last page of file
  53. unsigned short e_cp; // Pages in file
  54. unsigned short e_crlc; // Relocations
  55. unsigned short e_cparhdr; // Size of header in paragraphs
  56. unsigned short e_minalloc; // Minimum extra paragraphs needed
  57. unsigned short e_maxalloc; // Maximum extra paragraphs needed
  58. unsigned short e_ss; // Initial (relative) SS value
  59. unsigned short e_sp; // Initial SP value
  60. unsigned short e_csum; // Checksum
  61. unsigned short e_ip; // Initial IP value
  62. unsigned short e_cs; // Initial (relative) CS value
  63. unsigned short e_lfarlc; // File address of relocation table
  64. unsigned short e_ovno; // Overlay number
  65. unsigned short e_res[ERESWDS]; // Reserved words
  66. long e_lfanew; // File address of new exe header
  67. } EXE_HDR;
  68. #endif // DEBUGOFFSETS
  69. // the only structure fileds used by our code are
  70. // unsigned short e_magic; // Magic number
  71. // long e_lfanew; // File address of new exe header
  72. // these are offsets how the fiels of this structure are laid out in the file
  73. #define OFF_e_magic 0 // unsigned short Magic number
  74. #define OFF_e_cblp 2 // unsigned short Bytes on last page of file
  75. #define OFF_e_cp 4 // unsigned short Pages in file
  76. #define OFF_e_crlc 6 // unsigned short Relocations
  77. #define OFF_e_cparhdr 8 // unsigned short Size of header in paragraphs
  78. #define OFF_e_minalloc 10 // unsigned short Minimum extra paragraphs needed
  79. #define OFF_e_maxalloc 12 // unsigned short Maximum extra paragraphs needed
  80. #define OFF_e_ss 14 // unsigned short Initial (relative) SS value
  81. #define OFF_e_sp 16 // unsigned short Initial SP value
  82. #define OFF_e_csum 18 // unsigned short Checksum
  83. #define OFF_e_ip 20 // unsigned short Initial IP value
  84. #define OFF_e_cs 22 // unsigned short Initial (relative) CS value
  85. #define OFF_e_lfarlc 24 // unsigned short File address of relocation table
  86. #define OFF_e_ovno 26 // unsigned short Overlay number
  87. #define OFF_e_res 28 // unsigned short Reserved words, 16 of then 60 = 28 + 32
  88. #define OFF_e_lfanew 60 // long File address of new exe header
  89. #define CJ_EXE_HDR 64
  90. // ************** stuff associated with new exe hdr ********************
  91. #define NEMAGIC 0x454E // New magic number
  92. #define NERESBYTES 0
  93. #ifdef DEBUGOFFSETS
  94. typedef struct new_exe // New .EXE header
  95. {
  96. unsigned short int ne_magic; // Magic number NE_MAGIC
  97. char ne_ver; // Version number
  98. char ne_rev; // Revision number
  99. unsigned short int ne_enttab; // Offset of Entry Table
  100. unsigned short int ne_cbenttab; // Number of bytes in Entry Table
  101. long ne_crc; // Checksum of whole file
  102. unsigned short int ne_flags; // Flag word
  103. unsigned short int ne_autodata; // Automatic data segment number
  104. unsigned short int ne_heap; // Initial heap allocation
  105. unsigned short int ne_stack; // Initial stack allocation
  106. long ne_csip; // Initial CS:IP setting
  107. long ne_sssp; // Initial SS:SP setting
  108. unsigned short int ne_cseg; // Count of file segments
  109. unsigned short int ne_cmod; // Entries in Module Reference Table
  110. unsigned short int ne_cbnrestab; // Size of non-resident name table
  111. unsigned short int ne_segtab; // Offset of Segment Table
  112. unsigned short int ne_rsrctab; // Offset of Resource Table
  113. unsigned short int ne_restab; // Offset of resident name table
  114. unsigned short int ne_modtab; // Offset of Module Reference Table
  115. unsigned short int ne_imptab; // Offset of Imported Names Table
  116. long ne_nrestab; // Offset of Non-resident Names Table
  117. unsigned short int ne_cmovent; // Count of movable entries
  118. unsigned short int ne_align; // Segment alignment shift count
  119. unsigned short int ne_cres; // Count of resource segments
  120. unsigned char ne_exetyp; // Target Operating system
  121. unsigned char ne_flagsothers; // Other .EXE flags
  122. unsigned short int ne_pretthunks; // offset to return thunks
  123. unsigned short int ne_psegrefbytes;// offset to segment ref. bytes
  124. unsigned short int ne_swaparea; // Minimum code swap area size
  125. unsigned short int ne_expver; // Expected Windows version number
  126. } NEW_EXE;
  127. #endif // DEBUGOFFSETS
  128. // the only structure fileds used by our code are
  129. // unsigned short int ne_magic; // Magic number NE_MAGIC
  130. // unsigned short int ne_rsrctab; // Offset of Resource Table
  131. // long ne_restab; // Offset of resident Names Table
  132. // offsets from beg of the structure as the data is laid out on the disk
  133. #define OFF_ne_magic 0 // unsigned short Magic number NE_MAGIC
  134. #define OFF_ne_ver 2 // char Version number
  135. #define OFF_ne_rev 3 // char Revision number
  136. #define OFF_ne_enttab 4 // unsigned short Offset of Entry Table
  137. #define OFF_ne_cbenttab 6 // unsigned short Number of bytes in Entry Table
  138. #define OFF_ne_crc 8 // long Checksum of whole file
  139. #define OFF_ne_flags 12 // unsigned short Flag word
  140. #define OFF_ne_autodata 14 // unsigned short Automatic data segment number
  141. #define OFF_ne_heap 16 // unsigned short Initial heap allocation
  142. #define OFF_ne_stack 18 // unsigned short Initial stack allocation
  143. #define OFF_ne_csip 20 // long Initial CS:IP setting
  144. #define OFF_ne_sssp 24 // long Initial SS:SP setting
  145. #define OFF_ne_cseg 28 // unsigned short Count of file segments
  146. #define OFF_ne_cmod 30 // unsigned short Entries in Module Reference Table
  147. #define OFF_ne_cbnrestab 32 // unsigned short Size of non-resident name table
  148. #define OFF_ne_segtab 34 // unsigned short Offset of Segment Table
  149. #define OFF_ne_rsrctab 36 // unsigned short Offset of Resource Table
  150. #define OFF_ne_restab 38 // unsigned short Offset of resident name table
  151. #define OFF_ne_modtab 40 // unsigned short Offset of Module Reference Table
  152. #define OFF_ne_imptab 42 // unsigned short Offset of Imported Names Table
  153. #define OFF_ne_nrestab 44 // long Offset of Non-resident Names Table
  154. #define OFF_ne_cmovent 48 // unsigned short Count of movable entries
  155. #define OFF_ne_align 50 // unsigned short Segment alignment shift count
  156. #define OFF_ne_cres 52 // unsigned short Count of resource segments
  157. #define OFF_ne_exetyp 54 // unsigned char Target Operating system
  158. #define OFF_ne_flagsothers 55 // unsigned char Other .EXE flags
  159. #define OFF_ne_pretthunks 56 // unsigned short offset to return thunks
  160. #define OFF_ne_psegrefbytes 58 // unsigned short offset to segment ref. bytes
  161. #define OFF_ne_swaparea 60 // unsigned short Minimum code swap area size
  162. #define OFF_ne_expver 62 // unsigned short Expected Windows version number
  163. #define CJ_NEW_EXE 64
  164. // Resource type or name string
  165. typedef struct rsrc_string
  166. {
  167. char rs_len; // number of bytes in string
  168. char rs_string[ 1 ]; // text of string
  169. } RSRC_STRING;
  170. // Resource type information block
  171. #ifdef DEBUGOFFSETS
  172. typedef struct rsrc_typeinfo
  173. {
  174. unsigned short rt_id;
  175. unsigned short rt_nres;
  176. long rt_proc;
  177. } RSRC_TYPEINFO;
  178. #endif // DEBUGOFFSETS
  179. #define OFF_rt_id 0 // unsigned short
  180. #define OFF_rt_nres 2 // unsigned short
  181. #define OFF_rt_proc 4 // long
  182. #define CJ_TYPEINFO 8
  183. // the only rt_id that we are interested in is the
  184. // one for *.fnt files, RT_FNT, RT_FDIR for font directories
  185. // and RT_PSZ, string resource with a *.ttf file name in an
  186. // fot file. RT_DONTKNOW exhists in fon files but I do not
  187. // know what it corresponds to
  188. #define RT_FDIR 0x8007
  189. #define RT_FNT 0X8008
  190. #define RT_DONTKNOW 0x800h
  191. #define RT_PSZ 0X80CC
  192. // rn_id's that are allowed for certain types of rt_id's
  193. // as I have found them in fot files [bodind]
  194. #define RN_ID_FDIR 0x002c
  195. #define RN_ID_PSZ 0x8001
  196. #ifdef DEBUGOFFSETS
  197. // Resource name information block
  198. typedef struct rsrc_nameinfo
  199. {
  200. // The following two fields must be shifted left by the value of
  201. // the rs_align field to compute their actual value. This allows
  202. // resources to be larger than 64k, but they do not need to be
  203. // aligned on 512 byte boundaries, the way segments are
  204. unsigned short rn_offset; // file offset to resource data
  205. unsigned short rn_length; // length of resource data
  206. unsigned short rn_flags; // resource flags
  207. unsigned short rn_id; // resource name id
  208. unsigned short rn_handle; // If loaded, then global handle
  209. unsigned short rn_usage; // Initially zero. Number of times
  210. // the handle for this resource has
  211. // been given out
  212. } RSRC_NAMEINFO;
  213. #endif // DEBUGOFFSETS
  214. #define OFF_rn_offset 0 // unsigned short
  215. #define OFF_rn_length 2 // unsigned short
  216. #define OFF_rn_flags 4 // unsigned short
  217. #define OFF_rn_id 6 // unsigned short
  218. #define OFF_rn_handle 8 // unsigned short
  219. #define OFF_rn_usage 10 // unsigned short
  220. #define CJ_NAMEINFO 12
  221. #define RSORDID 0x8000 // if high bit of ID set then integer id
  222. // otherwise ID is offset of string from
  223. // the beginning of the resource table
  224. // Ideally these are the same as the
  225. // corresponding segment flags
  226. #define RNMOVE 0x0010 // Moveable resource
  227. #define RNPURE 0x0020 // Pure (read-only) resource
  228. #define RNPRELOAD 0x0040 // Preloaded resource
  229. #define RNDISCARD 0x1000 // Discard bit for resource
  230. #define RNLOADED 0x0004 // True if handler proc return handle
  231. #ifdef DEBUGOFFSETS
  232. // Resource table
  233. typedef struct new_rsrc
  234. {
  235. unsigned short rs_align; // alignment shift count for resources
  236. RSRC_TYPEINFO rs_typeinfo; // Really an array of these
  237. } NEW_RSRC;
  238. #endif // DEBUGOFFSETS
  239. // Target operating systems: Possible values of ne_exetyp field
  240. #define NE_UNKNOWN 0 // Unknown (any "new-format" OS)
  241. #define NE_OS2 1 // Microsoft/IBM OS/2 (default)
  242. #define NE_WINDOWS 2 // Microsoft Windows
  243. #define NE_DOS4 3 // Microsoft MS-DOS 4.x
  244. #define NE_DEV386 4 // Microsoft Windows 386