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.

185 lines
8.9 KiB

  1. /* exe.h - structure of an exe file header */
  2. /* Include some new .exe file info from \link\newexe.h */
  3. #define EMAGIC 0x5A4D /* Old magic number */
  4. #define ENEWEXE sizeof(struct exe_hdr)
  5. /* Value of E_LFARLC for new .EXEs */
  6. #define ENEWHDR 0x003C /* Offset in old hdr. of ptr. to new */
  7. #define ERESWDS 0x0010 /* No. of reserved words (OLD) */
  8. #define ERES1WDS 0x0004 /* No. of reserved words in e_res */
  9. #define ERES2WDS 0x000A /* No. of reserved words in e_res2 */
  10. #define ECP 0x0004 /* Offset in struct of E_CP */
  11. #define ECBLP 0x0002 /* Offset in struct of E_CBLP */
  12. #define EMINALLOC 0x000A /* Offset in struct of E_MINALLOC */
  13. #define E_MAGIC(x) (x).e_magic
  14. #define E_CBLP(x) (x).e_cblp
  15. #define E_CP(x) (x).e_cp
  16. #define E_CRLC(x) (x).e_crlc
  17. #define E_CPARHDR(x) (x).e_cparhdr
  18. #define E_MINALLOC(x) (x).e_minalloc
  19. #define E_MAXALLOC(x) (x).e_maxalloc
  20. #define E_SS(x) (x).e_ss
  21. #define E_SP(x) (x).e_sp
  22. #define E_CSUM(x) (x).e_csum
  23. #define E_IP(x) (x).e_ip
  24. #define E_CS(x) (x).e_cs
  25. #define E_LFARLC(x) (x).e_lfarlc
  26. #define E_OVNO(x) (x).e_ovno
  27. #define E_RES(x) (x).e_res
  28. #define E_OEMID(x) (x).e_oemid
  29. #define E_OEMINFO(x) (x).e_oeminfo
  30. #define E_RES2(x) (x).e_res2
  31. #define E_LFANEW(x) (x).e_lfanew
  32. #define NEMAGIC 0x454E /* New magic number */
  33. #define NTMAGIC 0x4550 /* NT magic number */
  34. #define NERESBYTES 8 /* Eight bytes reserved (now) */
  35. #define NECRC 8 /* Offset into new header of NE_CRC */
  36. #define NEDEFSTUBMSG 0x4E /* Offset into file of default stub msg */
  37. #define NE_MAGIC(x) (x).ne_magic
  38. #define NE_VER(x) (x).ne_ver
  39. #define NE_REV(x) (x).ne_rev
  40. #define NE_ENTTAB(x) (x).ne_enttab
  41. #define NE_CBENTTAB(x) (x).ne_cbenttab
  42. #define NE_CRC(x) (x).ne_crc
  43. #define NE_FLAGS(x) (x).ne_flags
  44. #define NE_AUTODATA(x) (x).ne_autodata
  45. #define NE_HEAP(x) (x).ne_heap
  46. #define NE_STACK(x) (x).ne_stack
  47. #define NE_CSIP(x) (x).ne_csip
  48. #define NE_SSSP(x) (x).ne_sssp
  49. #define NE_CSEG(x) (x).ne_cseg
  50. #define NE_CMOD(x) (x).ne_cmod
  51. #define NE_CBNRESTAB(x) (x).ne_cbnrestab
  52. #define NE_SEGTAB(x) (x).ne_segtab
  53. #define NE_RSRCTAB(x) (x).ne_rsrctab
  54. #define NE_RESTAB(x) (x).ne_restab
  55. #define NE_MODTAB(x) (x).ne_modtab
  56. #define NE_IMPTAB(x) (x).ne_imptab
  57. #define NE_NRESTAB(x) (x).ne_nrestab
  58. #define NE_CMOVENT(x) (x).ne_cmovent
  59. #define NE_ALIGN(x) (x).ne_align
  60. #define NE_IPHI(x) (x).ne_iphi
  61. #define NE_SPHI(x) (x).ne_sphi
  62. #define NE_RES(x) (x).ne_res
  63. #define NE_USAGE(x) (WORD)*((WORD *)(x)+1)
  64. #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
  65. #define NE_ONEWEXE(x) (WORD)(x).ne_crc
  66. #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
  67. /*
  68. * Format of NE_FLAGS(x):
  69. *
  70. * p Not-a-process
  71. * x Unused
  72. * e Errors in image
  73. * xxxxx Unused
  74. * f Floating-point instructions
  75. * 3 386 instructions
  76. * 2 286 instructions
  77. * 0 8086 instructions
  78. * P Protected mode only
  79. * x Unused
  80. * i Instance data
  81. * s Solo data
  82. */
  83. #define NENOTP 0x8000 /* Not a process */
  84. #define NEIERR 0x2000 /* Errors in image */
  85. #define NEFLTP 0x0080 /* Floating-point instructions */
  86. #define NEI386 0x0040 /* 386 instructions */
  87. #define NEI286 0x0020 /* 286 instructions */
  88. #define NEI086 0x0010 /* 8086 instructions */
  89. #define NEPROT 0x0008 /* Runs in protected mode only */
  90. #define NEINST 0x0002 /* Instance data */
  91. #define NESOLO 0x0001 /* Solo data */
  92. struct exeType {
  93. char signature[2]; /* zibo's signature */
  94. unsigned cbPage; /* bytes in image mod 512 */
  95. unsigned cPage; /* size of file in 512 byte pages */
  96. unsigned cReloc; /* number of relocation items */
  97. unsigned cParDir; /* number of paragraphs before image */
  98. unsigned cMinAlloc; /* minimum number of paragrapsh */
  99. unsigned cMaxAlloc; /* maximum number of paragrapsh */
  100. unsigned sStack; /* segment of stack in image */
  101. unsigned oStack; /* offset of stack in image */
  102. unsigned chksum; /* checksum of file */
  103. unsigned oEntry; /* offset of entry point */
  104. unsigned sEntry; /* segment of entry point */
  105. unsigned oReloc; /* offset in file of reloc table */
  106. unsigned iOverlay; /* overlay number */
  107. };
  108. struct exe_hdr /* DOS 1, 2, 3 .EXE header */
  109. {
  110. unsigned short e_magic; /* Magic number */
  111. unsigned short e_cblp; /* Bytes on last page of file */
  112. unsigned short e_cp; /* Pages in file */
  113. unsigned short e_crlc; /* Relocations */
  114. unsigned short e_cparhdr; /* Size of header in paragraphs */
  115. unsigned short e_minalloc; /* Minimum extra paragraphs needed */
  116. unsigned short e_maxalloc; /* Maximum extra paragraphs needed */
  117. unsigned short e_ss; /* Initial (relative) SS value */
  118. unsigned short e_sp; /* Initial SP value */
  119. unsigned short e_csum; /* Checksum */
  120. unsigned short e_ip; /* Initial IP value */
  121. unsigned short e_cs; /* Initial (relative) CS value */
  122. unsigned short e_lfarlc; /* File address of relocation table */
  123. unsigned short e_ovno; /* Overlay number */
  124. unsigned short e_res[ERES1WDS];/* Reserved words */
  125. unsigned short e_oemid; /* OEM identifier (for e_oeminfo) */
  126. unsigned short e_oeminfo; /* OEM information; e_oemid specific */
  127. unsigned short e_res2[ERES2WDS];/* Reserved words */
  128. long e_lfanew; /* File address of new exe header */
  129. };
  130. struct new_exe /* New .EXE header */
  131. {
  132. unsigned short ne_magic; /* Magic number NE_MAGIC */
  133. unsigned char ne_ver; /* Version number */
  134. unsigned char ne_rev; /* Revision number */
  135. unsigned short ne_enttab; /* Offset of Entry Table */
  136. unsigned short ne_cbenttab; /* Number of bytes in Entry Table */
  137. long ne_crc; /* Checksum of whole file */
  138. unsigned short ne_flags; /* Flag word */
  139. unsigned short ne_autodata; /* Automatic data segment number */
  140. unsigned short ne_heap; /* Initial heap allocation */
  141. unsigned short ne_stack; /* Initial stack allocation */
  142. long ne_csip; /* Initial CS:IP setting */
  143. long ne_sssp; /* Initial SS:SP setting */
  144. unsigned short ne_cseg; /* Count of file segments */
  145. unsigned short ne_cmod; /* Entries in Module Reference Table */
  146. unsigned short ne_cbnrestab; /* Size of non-resident name table */
  147. unsigned short ne_segtab; /* Offset of Segment Table */
  148. unsigned short ne_rsrctab; /* Offset of Resource Table */
  149. unsigned short ne_restab; /* Offset of resident name table */
  150. unsigned short ne_modtab; /* Offset of Module Reference Table */
  151. unsigned short ne_imptab; /* Offset of Imported Names Table */
  152. long ne_nrestab; /* Offset of Non-resident Names Table */
  153. unsigned short ne_cmovent; /* Count of movable entries */
  154. unsigned short ne_align; /* Segment alignment shift count */
  155. unsigned short ne_iphi; /* High word of initial IP */
  156. unsigned short ne_sphi; /* High word of initial SP */
  157. char ne_res[NERESBYTES];
  158. /* Pad structure to 64 bytes */
  159. };
  160. enum exeKind {
  161. IOERROR, /* Error, file cannot be accessed */
  162. NOTANEXE, /* Error, file is not an .EXE file */
  163. OLDEXE, /* "oldstyle" DOS 3.XX .exe */
  164. NEWEXE, /* "new" .exe, OS is unknown */
  165. WINDOWS, /* Windows executable */
  166. DOS4, /* DOS 4.XX .EXE */
  167. DOS286, /* 286DOS .EXE */
  168. // changed BOUND to BOUNDEXE since BOUND is defined as a macro in new OS/2
  169. // include files - davewe 8/24/89
  170. BOUNDEXE, /* 286DOS .EXE, bound */
  171. DYNALINK, /* Dynamlink link module */
  172. NTEXE /* NT executable */
  173. };