home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / ARTLSRC.RAR / EXEHDR.PAS < prev    next >
Pascal/Delphi Source File  |  2000-08-15  |  61KB  |  1,444 lines

  1. //█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
  2. //█                                                       █
  3. //█      Virtual Pascal Runtime Library.  Version 2.1.    █
  4. //█      OS/2 & Win32 Executable Header Definitions       █
  5. //█      ─────────────────────────────────────────────────█
  6. //█      Copyright (C) 1995-2000 vpascal.com              █
  7. //█                                                       █
  8. //▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  9.  
  10. {&AlignRec+,Use32-}
  11.  
  12. unit ExeHdr;
  13.  
  14. interface
  15.  
  16. {----[ EXE ]----}
  17.  
  18. type
  19.   bbmask    = Word;
  20.  
  21.   exe = packed record
  22.     eid        : Word;  // contains EXEID, below
  23.     elast      : Word;  // # of Bytes in last page
  24.     epagsiz    : Word;  // # of pages in whole file
  25.     erelcnt    : Word;  // # of relocation entrys
  26.     ehdrsiz    : Word;  // size of header, in paragraphs
  27.     eminfre    : Word;  // min # of free paragraphs needed
  28.     emaxfre    : Word;  // max # of free paragraphs needed
  29.     eiSS       : Word;  // initial SS value
  30.     eiSP       : Word;  // initial SP value
  31.     enegsum    : Word;  // negative sum of entire file
  32.     eiIP       : Word;  // initial IP value
  33.     eiCS       : Word;  // initial CS value
  34.     ereloff    : Word;  // offset in file of relocation table
  35.     eovlnum    : Word;  // number of the overlay
  36.  
  37. //     the following fields may not be present.
  38. //              ereloff = 28            not present
  39. //                      = 30            exe.ever present and valid
  40. //                      = 32            exe.ever field contains garbage
  41. //              ereloff > 32            exe.ever present and valid
  42. //                                              = 0 if "don't know"
  43. //
  44.  
  45.     ever       : Word;  // version # of producing linker
  46.     dumy       : Word;  // unused
  47.  
  48. //     the following fields may not be present - if the exe.ereloff
  49. //      value encompasses the fields then they are present and valid.
  50.  
  51.     ebb        : bbmask;                // behavior bits
  52.     dumy2      : array[0..6] of Word;   // must be 0 until defined
  53.   end;
  54.  
  55. const
  56.   ExeId = $5A4D;        // Magic ID value
  57.  
  58.  
  59. {----[ EXE386 ]----}
  60.  
  61. // Data structure definitions for the OS/2 executable file format (flat model)
  62.  
  63. const
  64.   BitPerWord    = 16;
  65.   BitPerByte    = 8;
  66.   ObjPageLen    = 4096;
  67.   E32Magic1     = 'L';      // New Magic number  "LX"
  68.   E32Magic2     = 'X';      // New Magic number  "LX"
  69.   E32Magic      = $584c;    // New Magic number  "LX"
  70.   E32ResByteS1  = 0;        // First Bytes reserved
  71.   E32ResByteS2  = 0;        // Second Bytes reserved
  72.   E32ResByteS3  = 20;       // Third Bytes reserved
  73.   E32LEBO       = $00;      // Little Endian Byte Order
  74.   E32BEBO       = $01;      // Big Endian Byte Order
  75.   E32LEWO       = $00;      // Little Endian Word Order
  76.   E32BEWO       = $01;      // Big Endian Word Order
  77.   E32Level      = 0;        // 32-bit EXE format Level
  78.   E32CPU286     = $001;     // Intel 80286 or upwardly compatibile
  79.   E32CPU386     = $002;     // Intel 80386 or upwardly compatibile
  80.   E32CPU486     = $003;     // Intel 80486 or upwardly compatibile
  81.  
  82. type
  83.   e32_exe = packed record           // New 32-bit .EXE header
  84.     e32_Magic         : array[0..1] of Byte; // Magic number E32_Magic
  85.     e32_border        : Byte;       // The Byte ordering for the .EXE
  86.     e32_Worder        : Byte;       // The Word ordering for the .EXE
  87.     e32_Level         : Longint;    // The EXE format Level for now = 0
  88.     e32_cpu           : Word;       // The CPU type
  89.     e32_os            : Word;       // The OS type
  90.     e32_ver           : Longint;    // Module version
  91.     e32_mflags        : Longint;    // Module flags
  92.     e32_mpages        : Longint;    // Module # pages
  93.     e32_startobj      : Longint;    // Object # for instruction pointer
  94.     e32_eip           : Longint;    // Extended instruction pointer
  95.     e32_stackobj      : Longint;    // Object # for stack pointer
  96.     e32_esp           : Longint;    // Extended stack pointer
  97.     e32_pagesize      : Longint;    // .EXE page size
  98.     e32_pageshift     : Longint;    // Page alignment shift in .EXE
  99.     e32_fixupsize     : Longint;    // Fixup section size
  100.     e32_fixupsum      : Longint;    // Fixup section checksum
  101.     e32_ldrsize       : Longint;    // Loader section size
  102.     e32_ldrsum        : Longint;    // Loader section checksum
  103.     e32_objtab        : Longint;    // Object table offset
  104.     e32_objcnt        : Longint;    // Number of objects in module
  105.     e32_objmap        : Longint;    // Object page map offset
  106.     e32_itermap       : Longint;    // Object iterated data map offset
  107.     e32_rsrctab       : Longint;    // Offset of Resource Table
  108.     e32_rsrccnt       : Longint;    // Number of resource entries
  109.     e32_restab        : Longint;    // Offset of resident name table
  110.     e32_enttab        : Longint;    // Offset of Entry Table
  111.     e32_dirtab        : Longint;    // Offset of Module Directive Table
  112.     e32_dircnt        : Longint;    // Number of module directives
  113.     e32_fpagetab      : Longint;    // Offset of Fixup Page Table
  114.     e32_frectab       : Longint;    // Offset of Fixup Record Table
  115.     e32_impmod        : Longint;    // Offset of Import Module Name Table
  116.     e32_impmodcnt     : Longint;    // Number of entries in Import Module Name Table
  117.     e32_impproc       : Longint;    // Offset of Import Procedure Name Table
  118.     e32_pagesum       : Longint;    // Offset of Per-Page Checksum Table
  119.     e32_datapage      : Longint;    // Offset of Enumerated Data Pages
  120.     e32_preload       : Longint;    // Number of preload pages
  121.     e32_nrestab       : Longint;    // Offset of Non-resident Names Table
  122.     e32_cbnrestab     : Longint;    // Size of Non-resident Name Table
  123.     e32_nressum       : Longint;    // Non-resident Name Table Checksum
  124.     e32_autodata      : Longint;    // Object # for automatic data object
  125.     e32_debuginfo     : Longint;    // Offset of the debugging information
  126.     e32_debuglen      : Longint;    // The length of the debugging info. in Bytes
  127.     e32_instpreload   : Longint;    // Number of instance pages in preload section of .EXE file
  128.     e32_instdemand    : Longint;    // Number of instance pages in demand load section of .EXE file
  129.     e32_heapsize      : Longint;    // Size of heap - for 16-bit apps
  130.     e32_stacksize     : Longint;    // Size of stack
  131.     e32_res3: array[0..E32RESByteS3-1] of Byte; // Pad structure to 196 Bytes
  132.   end;
  133.  
  134. //  Format of E32_MFLAGS(x):
  135. //
  136. //  Low Word has the following format:
  137. //
  138. //  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
  139. //   |     |          | |     | | | |
  140. //   |     |          | |     | | | +------- Per-Process Library Initialization
  141. //   |     |          | |     | | +--------- SystemDLL (internal fixups discarded)
  142. //   |     |          | |     | +----------- No Internal Fixups for Module in .EXE
  143. //   |     |          | |     +------------- No External Fixups for Module in .EXE
  144. //   |     |          | +------------------- Incompatible with PM Windowing
  145. //   |     |          +--------------------- Compatible with PM Windowing
  146. //   |     |                                 Uses PM Windowing API
  147. //   |     +-------------------------------- Module not Loadable
  148. //   +-------------------------------------- Library Module
  149.  
  150. const
  151.   E32NotP           = $8000;     // Library Module - used as NENOTP
  152.   E32NoLoad         = $2000;     // Module not Loadable
  153.   E32PMAPI          = $0300;     // Uses PM Windowing API
  154.   E32PMW            = $0200;     // Compatible with PM Windowing
  155.   E32NoPMW          = $0100;     // Incompatible with PM Windowing
  156.   E32NoExtFix       = $0020;     // NO External Fixups in .EXE
  157.   E32NoIntFix       = $0010;     // NO Internal Fixups in .EXE
  158.   E32SysDll         = $0008;     // System DLL, Internal Fixups discarded
  159.   E32LibInit        = $0004;     // Per-Process Library Initialization
  160.   E32LibTerm        = $40000000; // Per-Process Library Termination
  161.   E32AppMask        = $0300;     // Application Type Mask
  162.  
  163. //  Format of E32_MFLAGS(x):
  164. //
  165. //  High Word has the following format:
  166. //
  167. //  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
  168. //                                    | |
  169. //                                    | +--- Protected memory library module
  170. //                                    +----- Device driver
  171.  
  172.   E32ProtDll        = $10000;   // Protected memory library module
  173.   E32Device         = $20000;   // Device driver
  174.   E32ModExe         = $00000;   // .EXE module
  175.   E32ModDll         = $08000;   // .DLL module
  176.   E32ModProtDll     = $18000;   // Protected memory library module
  177.   E32ModPdev        = $20000;   // Physical device driver
  178.   E32ModVdev        = $28000;   // Virtual device driver
  179.   E32ModMask        = $38000;   // Module type mask
  180.  
  181. // RELOCATION DEFINITIONS - RUN-TIME FIXUPS
  182.  
  183. type
  184.   Offset = packed record
  185.     Offset16 : Word;
  186.     Offset32 : Longint;
  187.   end;                          // 16-bit or 32-bit offset
  188.  
  189.   //**ET+ r32_rlc - Relocation item
  190.  
  191.   r32_rlc = packed record      // Relocation item
  192.     nr_stype    : Byte;        // Source type - field shared with new_rlc
  193.     nr_flags    : Byte;        // Flag Byte - field shared with new_rlc
  194.     r32_soff    : Integer;     // Source offset
  195.     r32_objmod  : Word;        // Target object number or Module ordinal
  196.  
  197.     r23_target : packed record
  198.       Case Byte of
  199.         0 : ( IntRef : Longint );                // Internal fixup
  200.  
  201.         1 : ( ExtRef : packed record
  202.                 Case Boolean of
  203.                   True  : ( Proc : Longint );    // Procedure name offset
  204.                   False : ( Ord  : Longint );    // Procedure ordinal
  205.               end );
  206.  
  207.         2 : ( Addfix : packed record
  208.                 Entry   : Word;                  // Entry ordinal
  209.                 Addval  : Longint;               // Value added to the address
  210.               end );
  211.     end;
  212.  
  213.     r32_srccount : Word;       // Number of chained fixup records
  214.     r32_chain    : Word;       // Chain head
  215.   end;
  216.  
  217. //  In 32-bit .EXE file run-time relocations are written as varying size
  218. //  records, so we need many size definitions.
  219.  
  220. const
  221.   RIntSize16      = 8;
  222.   RIntSize32      = 10;
  223.   ROrdSize        = 8;
  224.   RNamSize16      = 8;
  225.   RNamSize32      = 10;
  226.   RAddSize16      = 10;
  227.   RAddSize32      = 12;
  228.  
  229. //  Format of NR_SType(x)
  230. //
  231. //       7 6 5 4 3 2 1 0  - bit no
  232. //           | | | | | |
  233. //           | | +-+-+-+--- Source type
  234. //           | +----------- Fixup to 16:16 alias
  235. //           +------------- List of source offset follows fixup recOrd
  236.  
  237.  NRSrcMask       = $0f;            // Source type mask
  238.  NRAlias         = $10;            // Fixup to alias
  239.  NRChain         = $20;            // List of source offset follows
  240.                                    // fixup recOrd, source offset field
  241.                                    // in fixup recOrd contains number
  242.                                    // of elements in list
  243.  
  244. //  Format of NR_Flags(x) and R32_Flags(x):
  245. //
  246. //       7 6 5 4 3 2 1 0  - bit no
  247. //       | | | |   | | |
  248. //       | | | |   | +-+--- Reference type
  249. //       | | | |   +------- Additive fixup
  250. //       | | | +----------- 32-bit Target Offset Flag (1 - 32-bit; 0 - 16-bit)
  251. //       | | +------------- 32-bit Additive Flag (1 - 32-bit; 0 - 16-bit)
  252. //       | +--------------- 16-bit Object/Module Ordinal (1 - 16-bit; 0 - 8-bit)
  253. //       +----------------- 8-bit import Ordinal (1 - 8-bit;
  254. //                                                0 - NR32BitOff toggles
  255. //                                                    between 16 and 32 bit
  256. //                                                    Ordinal)
  257.  
  258.   NRREnt          = $03;           // Internal entry table fixup
  259.   NR32BitOff      = $10;           // 32-bit Target Offset
  260.   NR32BitAdd      = $20;           // 32-bit Additive fixup
  261.   NR16ObjMod      = $40;           // 16-bit Object/Module Ordinal
  262.   NR8BitOrd       = $80;           // 8-bit import Ordinal
  263.  
  264. //  Data structures for storing run-time fixups in linker virtual memory.
  265. //
  266. //  Each object has a list of Object Page Directories which specify
  267. //  fixups for given page. Each page has its own hash table which is
  268. //  used to detect fixups to the same target.
  269.  
  270.   PagePerDir      = 62;
  271.   LG2Dir          = 7;
  272.  
  273.  
  274. type
  275.   ObjPageDir = packed record
  276.     Next : Longint;                // Virtual poInter to next dir on list
  277.     Ht   : array[ 0..PagePerDir-1 ] of Word; // Pointers to individual hash tables
  278.   end;
  279.  
  280. // OBJECT TABLE
  281.  
  282. //**ET+ o32_obj Object Table Entry
  283.  
  284.   o32_obj = packed record         // Flat .Exe object table entry
  285.     o32_Size       : LongInt;     // Object virtual Size
  286.     o32_base       : LongInt;     // Object base virtual Address
  287.     o32_flags      : LongInt;     // Attribute flags
  288.     o32_pagemap    : LongInt;     // Object page map index
  289.     o32_mapSize    : LongInt;     // Number of entries in object page map
  290.     o32_reserved   : LongInt;     // Reserved
  291.   end;
  292.  
  293. //  Format of O32_Flags(x)
  294. //
  295. //  High Word of dWord flag field is not used for now.
  296. //  Low Word has the following format:
  297. //
  298. //  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
  299. //   |  |  |  |     | | | | | | | | | | |
  300. //   |  |  |  |     | | | | | | | | | | +--- Readable Object
  301. //   |  |  |  |     | | | | | | | | | +----- Writeable Object
  302. //   |  |  |  |     | | | | | | | | +------- Executable Object
  303. //   |  |  |  |     | | | | | | | +--------- Resource Object
  304. //   |  |  |  |     | | | | | | +----------- Object is Discardable
  305. //   |  |  |  |     | | | | | +------------- Object is Shared
  306. //   |  |  |  |     | | | | +--------------- Object has preload pages
  307. //   |  |  |  |     | | | +----------------- Object has invalid pages
  308. //   |  |  |  |     | | +------------------- Object is permanent and swappable
  309. //   |  |  |  |     | +--------------------- Object is permanent and resident
  310. //   |  |  |  |     +----------------------- Object is permanent and long lockable
  311. //   |  |  |  +----------------------------- 16:16 alias required (80x86 specific)
  312. //   |  |  +-------------------------------- Big/Default bit setting (80x86 specific)
  313. //   |  +----------------------------------- Object is conforming for code (80x86 specific)
  314. //   +-------------------------------------- Object I/O privilege Level (80x86 specific)
  315.  
  316. const
  317.   ObjRead         = $0001;  // Readable Object
  318.   ObjWrite        = $0002;  // Writeable Object
  319.   ObjRsrc         = $0008;  // Resource Object
  320.   ObjInvalid      = $0080;  // Object has invalid pages
  321.   LNKNonperm      = $0600;  // Object is nonpermanent - should be
  322.   ObjNonperm      = $0000;  // zero in the .Exe but LINK386 uses 6
  323.   ObjPerm         = $0100;  // Object is permanent and swappable
  324.   ObjResident     = $0200;  // Object is permanent and resident
  325.   ObjContig       = $0300;  // Object is resident and contiguous
  326.   ObjDynamic      = $0400;  // Object is permanent and long locable
  327.   ObjTypeMask     = $0700;  // Object type mask
  328.   ObjAlias16      = $1000;  // 16:16 alias required (80x86 specific)
  329.   ObjBigDef       = $2000;  // Big/Default bit setting (80x86 specific)
  330.   ObjIOPL         = $8000;  // Object I/O privilege Level (80x86 specific)
  331.  
  332.   ObjDiscard       = $0010; // Object is Discardable
  333.   ObjShared        = $0020; // Object is Shared
  334.   ObjPreLoad       = $0040; // Object has preload pages
  335.   ObjExec          = $0004; // Executable Object
  336.   ObjConform       = $4000; // Object is conforming for code (80x86 specific)
  337.  
  338.   NSDiscard        = $0010;  // Object is Discardable
  339.   NSMove           = NSDiscard; //{ Moveable object is for sure Discardable
  340.   NSShared         = $0020;  // Object is Shared
  341.   NSPreLoad        = $0040;  // Object has preload pages
  342.   NSExRd           = $0004;  // Executable Object
  343.   NSConform        = $4000;  // Object is conforming for code (80x86 specific)
  344.  
  345. //**ET+ o32_map - Object Page Map entry
  346.  
  347. type
  348.   o32_map = packed record          { Object Page Table entry }
  349.     o32_pagedataoffset  : Longint; { file offset of page }
  350.     o32_pageSize        : Word;    { # Bytes of page data }
  351.     o32_pageflags       : Word;    { Per-Page attributes }
  352.   end;
  353.  
  354. const
  355.   Valid            = $0000;  { Valid Physical Page in .Exe }
  356.   IterData         = $0001;  { Iterated Data Page }
  357.   Invalid          = $0002;  { Invalid Page }
  358.   Zeroed           = $0003;  { Zero Filled Page }
  359.   Range            = $0004;  { Range of pages }
  360.   IterData2        = $0005;  { Iterated Data Page Type II }
  361.  
  362. { RESOURCE TABLE }
  363.  
  364. {**ET+ rsrc32 - Resource Table Entry }
  365.  
  366. type
  367.   rsrc32 = packed record           { Resource Table Entry }
  368.     rType  : Word;                 { Resource type }
  369.     Name   : Word;                 { Resource name }
  370.     cb     : LongInt;              { Resource Size }
  371.     Obj    : Word;                 { Object number }
  372.     Offset : LongInt;              { Offset within object }
  373.   end;
  374.  
  375.   { Iteration Record format for 'ExePACK'ed pages. }
  376.   LX_Iter = packed record
  377.     LX_nIter    : Word;            { number of iterations }
  378.     LX_nBytes   : Word;            { number of Bytes }
  379.     LX_Iterdata : Byte;            { iterated data Byte(s) }
  380.   end;
  381.  
  382.  
  383. { ENTRY TABLE DEFINITIONS }
  384.  
  385. {**ET+ b32_bundle - Entry Table }
  386.  
  387.   b32_bundle = packed record
  388.     b32_cnt  :  Byte;              { Number of entries in this bundle }
  389.     b32_type :  Byte;              { Bundle type }
  390.     b32_obj  :  Word;              { Object number }
  391.   end;                             { Follows entry types }
  392.  
  393.   e32_entry = packed record
  394.     e32_flags : Byte;              { Entry point flags }
  395.  
  396.     e32_variant  : packed record
  397.       Case Byte of
  398.         0 : ( e32_offset : Longint );     { 16-bit/32-bit offset entry }
  399.         1 : ( e32_callgate: packed record { 286 (16-bit) call gate }
  400.                 Offset : Longint;         { Offset in segment }
  401.                 callgate : Longint
  402.               end );     { Callgate selector }
  403.         2 : ( e32_fwd: packed record      { Forwarder }
  404.                 ModOrd : Word;            { Module Ordinal number }
  405.                 Value  : LongInt;         { Proc name offset or Ordinal }
  406.              end );
  407.     end;
  408.   end;
  409.  
  410. const
  411.   FixEnt16        = 3;
  412.   FixEnt32        = 5;
  413.   GateEnt16       = 5;
  414.   FwdEnt          = 7;
  415.  
  416. { BUNDLE TYPES }
  417.  
  418.   Empty        = $00;             { Empty bundle }
  419.   Entry16      = $01;             { 16-bit offset entry poInt }
  420.   Gate16       = $02;             { 286 call gate (16-bit IOPL) }
  421.   Entry32      = $03;             { 32-bit offset entry poInt }
  422.   EntryFWD     = $04;             { Forwarder entry poInt }
  423.   TypeInfo     = $80;             { Typing information present flag }
  424.  
  425. {
  426.  *  Format for E32_EFlags(x)
  427.  *
  428.  *       7 6 5 4 3 2 1 0  - bit no
  429.  *       | | | | | | | |
  430.  *       | | | | | | | +--- exported entry
  431.  *       | | | | | | +----- uses shared data
  432.  *       +-+-+-+-+-+------- parameter Word count
  433.  }
  434.  
  435.   E32Export       = $01;          { Exported entry }
  436.   E32Shared       = $02;          { Uses shared data }
  437.   E32Params       = $f8;          { Parameter Word count mask }
  438.  
  439. { Flags for forwarders only: }
  440.  
  441.   Fwd_Ordinal     = $01;          { Imported by Ordinal }
  442.  
  443.  
  444. {----[ NEWEXE ]----}
  445.  
  446. { Data structure definitions for the DOS 4.0/Windows 2.0/OS-2 }
  447. { executable file format.  Includes WLO definitions. }
  448.  
  449. { DOS 3 EXE HEADER }
  450.  
  451. const
  452.   EMagic          = $5A4D;          { Old magic number }
  453.                                     { Value of E_LFARLC for new .Exes }
  454.   ENewHdr         = $003C;          { Offset in old hdr. of ptr. to new }
  455.   EResWds         = $0010;          { No. of reserved wOrds (OLD) }
  456.   ERes1Wds        = $0004;          { No. of reserved wOrds in e_res }
  457.   ERes2Wds        = $000A;          { No. of reserved wOrds in e_res2 }
  458.   ECp             = $0004;          { Offset in struct of E_CP }
  459.   ECBLP           = $0002;          { Offset in struct of E_CBLP }
  460.   EMinAlloc       = $000A;          { Offset in struct of E_MINAlloc }
  461.  
  462. type
  463.   exe_hdr = packed record        { DOS 1, 2, 3 .Exe header }
  464.     e_magic         : Word;      { Magic number }
  465.     e_cblp          : Word;      { Bytes on last page of file }
  466.     e_cp            : Word;      { Pages in file }
  467.     e_crlc          : Word;      { Relocations }
  468.     e_cparhdr       : Word;      { Size of header in paragraphs }
  469.     e_minalloc      : Word;      { Minimum extra paragraphs needed }
  470.     e_maxalloc      : Word;      { Maximum extra paragraphs needed }
  471.     e_ss            : Word;      { Initial (relative) SS value }
  472.     e_sp            : Word;      { Initial SP value }
  473.     e_csum          : Word;      { Checksum }
  474.     e_ip            : Word;      { Initial IP value }
  475.     e_cs            : Word;      { Initial (relative) CS value }
  476.     e_lfarlc        : Word;      { File Address of relocation table }
  477.     e_ovno          : Word;      { Overlay number }
  478.     e_res : Array[ 1..ERes1Wds ] of Word;  { Reserved wOrds }
  479.     e_oemid         : Word;      { OEM identifier (for e_oeminfo) }
  480.     e_oeminfo       : Word;      { OEM information; e_oemid specific }
  481.     e_res2 : Array[ 1..ERes2Wds ] of Word; { Reserved wOrds }
  482.     e_lfanew        : Longint;       { File Address of new exe header }
  483.   end;
  484.  
  485. const
  486.   ENewExe         = Sizeof(exe_hdr);
  487.  
  488.   {  OS/2 & WINDOWS .Exe FILE HEADER DEFINITION - 286 version      }
  489.  
  490.   NEMagic         = $454E;          { New magic number }
  491.   NEResBytes      = 8;              { Eight bytes reserved (now) }
  492.   NECrc           = 8;              { Offset Into new header of NE_CRC }
  493.  
  494. type
  495.   new_exe  = packed record          { New .Exe header }
  496.     ne_magic            : Word;     { Magic number NE_Magic }
  497.     ne_ver              : Byte;     { Version number }
  498.     ne_rev              : Byte;     { Revision number }
  499.     ne_enttab           : Word;     { Offset of Entry Table }
  500.     ne_cbenttab         : Word;     { Number of bytes in Entry Table }
  501.     ne_crc              : LongInt;  { Checksum of whole file }
  502.     ne_flags            : Word;     { Flag wOrd }
  503.     ne_autodata         : Word;     { Automatic data segment number }
  504.     ne_heap             : Word;     { Initial heap allocation }
  505.     ne_stack            : Word;     { Initial stack allocation }
  506.     ne_csip             : LongInt;  { Initial CS:IP setting }
  507.     ne_sssp             : LongInt;  { Initial SS:SP setting }
  508.     ne_cseg             : Word;     { Count of file segments }
  509.     ne_cmod             : Word;     { Entries in Module Reference Table }
  510.     ne_cbnrestab        : Word;     { Size of non-resident name table }
  511.     ne_segtab           : Word;     { Offset of Segment Table }
  512.     ne_rsrctab          : Word;     { Offset of Resource Table }
  513.     ne_restab           : Word;     { Offset of resident name table }
  514.     ne_modtab           : Word;     { Offset of Module Reference Table }
  515.     ne_imptab           : Word;     { Offset of Imported Names Table }
  516.     ne_nrestab          : LongInt;  { Offset of Non-resident Names Table }
  517.     ne_cmovent          : Word;     { Count of movable entries }
  518.     ne_align            : Word;     { Segment alignment shift count }
  519.     ne_cres             : Word;     { Count of resource entries }
  520.     ne_exetyp           : Byte;     { Target operating system }
  521.     ne_flagsothers      : Byte;     { Other .Exe flags }
  522.     ne_res              : Array[1..NERESBytes] of Byte; { Pad structure to 64 bytes }
  523.   end;
  524.  
  525. { Target operating systems }
  526. const
  527.   NE_Unknown    = $0;            { Unknown (any "new-format" OS) }
  528.   NE_Os2        = $1;            { OS/2 (default)  }
  529.   NE_Windows    = $2;            { Windows }
  530.   NE_Dos4       = $3;            { DOS 4.x }
  531.   NE_Dev386     = $4;            { Windows 386 }
  532.  
  533.  
  534. {
  535.  *  Format of NE_Flags(x):
  536.  *
  537.  *  p                                   Not-a-process
  538.  *   x                                  Unused
  539.  *    e                                 Errors in image
  540.  *     x                                Unused
  541.  *      b                               Bound Family/API
  542.  *       ttt                            Application type
  543.  *          f                           Floating-poInt instructions
  544.  *           3                          386 instructions
  545.  *            2                         286 instructions
  546.  *             0                        8086 instructions
  547.  *              P                       Protected mode only
  548.  *               p                      Per-process library initialization
  549.  *                i                     Instance data
  550.  *                 s                    Solo data
  551.  }
  552.   NENotP         = $8000;         { Not a process }
  553.   NEIErr         = $2000;         { Errors in image }
  554.   NEBound        = $0800;         { Bound Family/API }
  555.   NEAppTyp       = $0700;         { Application type mask }
  556.   NENotWinCompat = $0100;         { Not compatible with P.M. Windowing }
  557.   NEWincompat    = $0200;         { Compatible with P.M. Windowing }
  558.   NEWinApi       = $0300;         { Uses P.M. Windowing API }
  559.   NEFltP         = $0080;         { Floating-poInt instructions }
  560.   NEi386         = $0040;         { 386 instructions }
  561.   NEi286         = $0020;         { 286 instructions }
  562.   NEi086         = $0010;         { 8086 instructions }
  563.   NEProt         = $0008;         { Runs in Protected mode only }
  564.   NEPpli         = $0004;         { Per-Process Library Initialization }
  565.   NEInst         = $0002;         { Instance data }
  566.   NESolo         = $0001;         { Solo data }
  567.  
  568. {
  569.  *  Format of NE_FlagsOTHERS(x):
  570.  *
  571.  *      7 6 5 4 3 2 1 0  - bit no
  572.  *      |         | | |
  573.  *      |         | | +---------------- Support for long file names
  574.  *      |         | +------------------ Windows 2.x app runs in Prot mode
  575.  *      |         +-------------------- Windows 2.x app gets prop. font
  576.  *      +------------------------------ WLO appl on OS/2 (markwlo.exe)
  577.  *
  578.  }
  579.  
  580.   NELongNames     = $01;
  581.   NewInisProt     = $02;
  582.   NewInGetPropFon = $04;
  583.   NewLoAppl       = $80;
  584.  
  585.  
  586. type
  587.   new_seg = packed record      { New .Exe segment table entry }
  588.     ns_sector   : Word;        { File sector of start of segment }
  589.     ns_cbseg    : Word;        { Number of bytes in file }
  590.     ns_flags    : Word;        { Attribute flags }
  591.     ns_minalloc : Word;        { Minimum allocation in bytes }
  592.   end;
  593.  
  594. {
  595.  *  Format of NS_Flags(x)
  596.  *
  597.  *  Flag wOrd has the following format:
  598.  *
  599.  *      15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  - bit no
  600.  *          |  |  |  |  | | | | | | | | | | |
  601.  *          |  |  |  |  | | | | | | | | +-+-+--- Segment type Data/Code
  602.  *          |  |  |  |  | | | | | | | +--------- Iterated segment
  603.  *          |  |  |  |  | | | | | | +----------- Movable segment
  604.  *          |  |  |  |  | | | | | +------------- Segment can be shared
  605.  *          |  |  |  |  | | | | +--------------- Preload segment
  606.  *          |  |  |  |  | | | +----------------- Execute/read-only for code/data segment
  607.  *          |  |  |  |  | | +------------------- Segment has relocations
  608.  *          |  |  |  |  | +--------------------- Code conforming/Data is expand down
  609.  *          |  |  |  +--+----------------------- I/O privilege level
  610.  *          |  |  +----------------------------- Discardable segment
  611.  *          |  +-------------------------------- 32-bit code segment
  612.  *          +----------------------------------- Huge segment/GDT allocation requested
  613.  *
  614.  }
  615.  
  616. const
  617.   neNSType       = $0007;         { Segment type mask }
  618.  
  619.   neNSCode       = $0000;         { Code segment }
  620.   neNSData       = $0001;         { Data segment }
  621.   neNSIter       = $0008;         { Iterated segment flag }
  622.   neNSMove       = $0010;         { Movable segment flag }
  623.   neNSShared     = $0020;         { Shared segment flag }
  624.   neNSPreLoad    = $0040;         { Preload segment flag }
  625.   neNSExRd       = $0080;         { Execute-only (code segment), or
  626.                                         *  read-only (data segment)
  627.                                         }
  628.   neNSReloc      = $0100;         { Segment has relocations }
  629.   neNSConform    = $0200;         { Conforming segment }
  630.   neNSExpDown    = $0200;         { Data segment is expand down }
  631.   neNSDPL        = $0C00;         { I/O privilege level (286 DPL bits) }
  632.   neShiftDpl     = 10;            { Left shift count for SegDPL field }
  633.   neNSDiscard    = $1000;         { Segment is discardable }
  634.   neNS32Bit      = $2000;         { 32-bit code segment }
  635.   neNSHuge       = $4000;         { Huge memory segment, length of
  636.                                          * segment and minimum allocation
  637.                                          * Size are in segment sector units
  638.                                          }
  639.   neNSGDT        = $8000;         { GDT allocation requested }
  640.  
  641.   neNSPure       = NSShared;      { For compatibility }
  642.  
  643.   neNSAlign      = 9;             { Segment data aligned on 512 byte boundaries }
  644.  
  645.   neNSLOADED     = $0004;         { ns_sector field contains memory Addr }
  646.  
  647. type
  648.   new_segdata = packed record        { Segment data }
  649.     Case Boolean of
  650.       True : ( ns_iter : packed record
  651.                  ns_niter    : Word; { number of iterations }
  652.                  ns_nbytes   : Word; { number of bytes }
  653.                  ns_iterdata : char; { iterated data bytes }
  654.                end );
  655.       False: ( ns_noniter : packed record
  656.                 ns_data      : char; { data bytes }
  657.                end );
  658.   end;
  659.  
  660.   new_rlcinfo = packed record        { Relocation info }
  661.     nr_nreloc : Word;                { number of relocation items that }
  662.   end;                               { follow }
  663.  
  664.   new_rlc = packed record            { Relocation item }
  665.     nr_stype   : char;               { Source type }
  666.     nr_flags   : char;               { Flag byte }
  667.     nr_soff    : Word;               { Source offset }
  668.     nr_union   : packed record
  669.       Case Byte of
  670.         0 : ( nr_Intref : packed record { Internal reference }
  671.                 nr_segno  : char;    { Target segment number }
  672.                 nr_res    : char;    { Reserved }
  673.                 nr_entry  : Word;    { Target Entry Table offset }
  674.               end );
  675.         1 : ( nr_import : packed record { Import }
  676.                 nr_mod    : Word;    { Index Into Module Reference Table }
  677.                 nr_proc   : Word;    { Procedure Ordinal or name offset }
  678.               end );
  679.         2 : ( nr_osfix : packed record { Operating system fixup }
  680.                 nr_ostype : Word;    { OSFixUP type }
  681.                 nr_osres  : Word;    { reserved }
  682.               end );
  683.       end;
  684.    end;
  685.  
  686. const
  687. {
  688.  *  Format of NR_SType(x) and R32_SType(x):
  689.  *
  690.  *       7 6 5 4 3 2 1 0  - bit no
  691.  *               | | | |
  692.  *               +-+-+-+--- source type
  693.  *
  694.  }
  695.  
  696.   NRSTyp         = $0f;           { Source type mask }
  697.   NRSByt         = $00;           { lo byte (8-bits)}
  698.   NRSSeg         = $02;           { 16-bit segment (16-bits) }
  699.   NRSPtr         = $03;           { 16:16 poInter (32-bits) }
  700.   NRSOff         = $05;           { 16-bit offset (16-bits) }
  701.   NRPtr48        = $06;           { 16:32 poInter (48-bits) }
  702.   NROff32        = $07;           { 32-bit offset (32-bits) }
  703.   NRSOff32       = $08;           { 32-bit self-relative offset (32-bits) }
  704.  
  705.  
  706. {
  707.  *  Format of NR_Flags(x) and R32_Flags(x):
  708.  *
  709.  *       7 6 5 4 3 2 1 0  - bit no
  710.  *                 | | |
  711.  *                 | +-+--- Reference type
  712.  *                 +------- Additive fixup
  713.  }
  714.  
  715.   NRAdd          = $04;           { Additive fixup }
  716.   NRRTyp         = $03;           { Reference type mask }
  717.   NRRInt         = $00;           { Internal reference }
  718.   NRROrd         = $01;           { Import by Ordinal }
  719.   NRRNam         = $02;           { Import by name }
  720.   NRROSF         = $03;           { Operating system fixup }
  721.  
  722. type
  723.   { Resource type or name string }
  724.   rsrc_string = packed record
  725.     rs_len      : Char;            { number of bytes in string }
  726.     rs_string   : Array[ 1..1 ] of Char;    { text of string }
  727.   end;
  728.  
  729.   { Resource type information block }
  730.   rsrc_typeinfo = packed record
  731.     rt_id   : Word;
  732.     rt_nres : Word;
  733.     rt_proc : LongInt;
  734.   end;
  735.  
  736.   { Resource name information block }
  737.   rsrc_nameinfo = packed record
  738.     { The following two fields must be shifted left by the value of  }
  739.     { the rs_align field to compute their actual value.  This allows }
  740.     { resources to be larger than 64k, but they do not need to be    }
  741.     { aligned on 512 byte boundaries, the way segments are           }
  742.     rn_offset : Word; { file offset to resource data }
  743.     rn_length : Word; { length of resource data }
  744.     rn_flags  : Word; { resource flags }
  745.     rn_id     : Word; { resource name id }
  746.     rn_handle : Word; { If loaded, then global handle }
  747.     rn_usage  : Word; { Initially zero.  Number of times }
  748.                       { the handle for this resource has }
  749.                       { been given out }
  750.   end;
  751.  
  752. const
  753.   RSOrdID    = $8000;     { if high bit of ID set then Integer id }
  754.                           { otherwise ID is offset of string from
  755.                           the beginning of the resource table }
  756.  
  757.                           { Ideally these are the same as the }
  758.                           { corresponding segment flags }
  759.   RNMove     = $0010;     { Moveable resource }
  760.   RNPURE     = $0020;     { Pure (read-only) resource }
  761.   RNPreLoad  = $0040;     { Preloaded resource }
  762.   RNDiscard  = $F000;     { Discard priority level for resource }
  763.  
  764. type
  765.   { Resource table }
  766.   new_rsrc = packed record
  767.     rs_align    : Word;   { alignment shift count for resources }
  768.     rs_TypeInfo : rsrc_typeinfo;
  769.   end;
  770.  
  771. // Declarations describing the format of PE executables
  772. // Converted from WINNT.H
  773.  
  774. type
  775.   DWord = Longint;
  776.   PDWord = ^DWord;
  777.   PByte = ^Byte;
  778.  
  779. // Image Format
  780.  
  781. const
  782.   image_DOS_Signature                   = $5A4D;     // 'MZ'
  783.   image_OS2_Signature                   = $454E;     // 'NE'
  784.   image_OS2_Signature_LE                = $454C;     // 'LE'
  785.   image_VXD_Signature                   = $454C;     // 'LE'
  786.   image_NT_Signature                    = $00004550; // 'PE'#0#0
  787.  
  788. // DOS .EXE header
  789.  
  790. type
  791.   PImageDosHeader = ^TImageDosHeader;
  792.   TImageDosHeader = packed record
  793.     e_magic:    Word;                   // Magic number
  794.     e_cblp:     Word;                   // Bytes on last page of file
  795.     e_cp:       Word;                   // Pages in file
  796.     e_crlc:     Word;                   // Relocations
  797.     e_cparhdr:  Word;                   // Size of header in paragraphs
  798.     e_minalloc: Word;                   // Minimum extra paragraphs needed
  799.     e_maxalloc: Word;                   // Maximum extra paragraphs needed
  800.     e_ss:       Word;                   // Initial (relative) SS value
  801.     e_sp:       Word;                   // Initial SP value
  802.     e_csum:     Word;                   // Checksum
  803.     e_ip:       Word;                   // Initial IP value
  804.     e_cs:       Word;                   // Initial (relative) CS value
  805.     e_lfarlc:   Word;                   // File address of relocation table
  806.     e_ovno:     Word;                   // Overlay number
  807.     e_res: packed array[0..3] of Word;  // Reserved words
  808.     e_oemid:    Word;                   // OEM identifier (for e_oeminfo)
  809.     e_oeminfo:  Word;                   // OEM information: e_oemid specific
  810.     e_res2: packed array[0..9] of Word; // Reserved words
  811.     e_lfanew:   Longint;                // File address of new exe header
  812.   end;
  813.  
  814. // File header format
  815.  
  816.   PImageFileHeader = ^TImageFileHeader;
  817.   TImageFileHeader = packed record
  818.     Machine:              Word;
  819.     NumberOfSections:     Word;
  820.     TimeDateStamp:        DWord;
  821.     PointerToSymbolTable: DWord;
  822.     NumberOfSymbols:      DWord;
  823.     SizeOfOptionalHeader: Word;
  824.     Characteristics:      Word;
  825.   end;
  826.  
  827. const
  828.   image_SizeOf_File_Header              = 20;
  829.  
  830.   image_File_Relocs_Stripped            = $0001; // Relocation info stripped from file.
  831.   image_File_Executable_Image           = $0002; // File is executable  (i.e. no unresolved externel references).
  832.   image_File_Line_Nums_Stripped         = $0004; // Line nunbers stripped from file.
  833.   image_File_Local_Syms_Stripped        = $0008; // Local symbols stripped from file.
  834.   image_File_Aggresive_WS_Trim          = $0010; // Agressively trim working set
  835.   image_File_Bytes_Reversed_Lo          = $0080; // Bytes of machine word are reversed.
  836.   image_File_32Bit_Machine              = $0100; // 32 bit word machine.
  837.   image_File_Debug_Stripped             = $0200; // Debugging info stripped from file in .DBG file
  838.   image_File_Removable_Run_From_Swap    = $0400; // If Image is on removable media, copy and run from the swap file.
  839.   image_File_Net_Run_From_Swap          = $0800; // If Image is on Net, copy and run from the swap file.
  840.   image_File_System                     = $1000; // System File.
  841.   image_File_Dll                        = $2000; // File is a DLL.
  842.   image_File_Up_System_Only             = $4000; // File should only be run on a UP machine
  843.   image_File_Bytes_Reversed_Hi          = $8000; // Bytes of machine word are reversed.
  844.  
  845.   image_File_Machine_Unknown            = $000;
  846.   image_File_Machine_i386               = $14C;  // Intel 386.
  847.   image_File_Machine_R3000              = $162;  // MIPS little-endian, 0x160 big-endian
  848.   image_File_Machine_R4000              = $166;  // MIPS little-endian
  849.   image_File_Machine_R10000             = $168;  // MIPS little-endian
  850.   image_File_Machine_Alpha              = $184;  // Alpha_AXP
  851.   image_File_Machine_PowerPC            = $1F0;  // IBM PowerPC Little-Endian
  852.  
  853. // Directory format
  854.  
  855. type
  856.   PImageDataDirectory = ^TImageDataDirectory;
  857.   TImageDataDirectory = packed record
  858.     VirtualAddress: DWord;
  859.     Size:           DWord;
  860.   end;
  861.  
  862. const
  863.   image_NumberOf_Directory_Entries      = 16;
  864.  
  865. // Optional header format
  866.  
  867. type
  868.   PImageOptionalHeader = ^TImageOptionalHeader;
  869.   TImageOptionalHeader = packed record
  870.     // Standard fields
  871.     Magic:                       Word;
  872.     MajorLinkerVersion:          Byte;
  873.     MinorLinkerVersion:          Byte;
  874.     SizeOfCode:                  DWord;
  875.     SizeOfInitializedData:       DWord;
  876.     SizeOfUninitializedData:     DWord;
  877.     AddressOfEntryPoint:         DWord;
  878.     BaseOfCode:                  DWord;
  879.     BaseOfData:                  DWord;
  880.     // NT additional fields
  881.     ImageBase:                   DWord;
  882.     SectionAlignment:            DWord;
  883.     FileAlignment:               DWord;
  884.     MajorOperatingSystemVersion: Word;
  885.     MinorOperatingSystemVersion: Word;
  886.     MajorImageVersion:           Word;
  887.     MinorImageVersion:           Word;
  888.     MajorSubsystemVersion:       Word;
  889.     MinorSubsystemVersion:       Word;
  890.     Win32VersionValue:           DWord;
  891.     SizeOfImage:                 DWord;
  892.     SizeOfHeaders:               DWord;
  893.     CheckSum:                    DWord;
  894.     Subsystem:                   Word;
  895.     DllCharacteristics:          Word;
  896.     SizeOfStackReserve:          DWord;
  897.     SizeOfStackCommit:           DWord;
  898.     SizeOfHeapReserve:           DWord;
  899.     SizeOfHeapCommit:            DWord;
  900.     LoaderFlags:                 DWord;
  901.     NumberOfRvaAndSizes:         DWord;
  902.     DataDirectory: packed array[0..image_NumberOf_Directory_Entries-1] of TImageDataDirectory;
  903.   end;
  904.  
  905.   PImageRomOptionalHeader = ^TImageRomOptionalHeader;
  906.   TImageRomOptionalHeader = packed record
  907.     Magic:                   Word;
  908.     MajorLinkerVersion:      Byte;
  909.     MinorLinkerVersion:      Byte;
  910.     SizeOfCode:              DWord;
  911.     SizeOfInitializedData:   DWord;
  912.     SizeOfUninitializedData: DWord;
  913.     AddressOfEntryPoint:     DWord;
  914.     BaseOfCode:              DWord;
  915.     BaseOfData:              DWord;
  916.     BaseOfBss:               DWord;
  917.     GprMask:                 DWord;
  918.     CprMask:                 packed array[0..3] of DWord;
  919.     GpValue:                 DWord;
  920.   end;
  921.  
  922. const
  923.   image_SizeOf_ROM_Optional_Header      = 56;
  924.   image_SizeOf_Std_Optional_Header      = 28;
  925.   image_SizeOf_NT_Optional_Header       = 224;
  926.  
  927.   image_NT_Optional_Hdr_Magic           = $010B;
  928.   image_ROM_Optional_Hdr_Magic          = $0107;
  929.  
  930. type
  931.   PImageNtHeaders = ^TImageNtHeaders;
  932.   TImageNtHeaders = packed record
  933.     Signature:      DWord;
  934.     FileHeader:     TImageFileHeader;
  935.     OptionalHeader: TImageOptionalHeader;
  936.   end;
  937.  
  938.   PImageRomHeaders = ^TImageRomHeaders;
  939.   TImageRomHeaders = packed record
  940.     FileHeader:     TImageFileHeader;
  941.     OptionalHeader: TImageRomOptionalHeader;
  942.   end;
  943.  
  944. // Subsystem Values
  945.  
  946. const
  947.   image_Subsystem_Unknown               = 0; // Unknown subsystem.
  948.   image_Subsystem_Native                = 1; // Image doesn't require a subsystem.
  949.   image_Subsystem_Windows_GUI           = 2; // Image runs in the Windows GUI subsystem.
  950.   image_Subsystem_Windows_CUI           = 3; // Image runs in the Windows character subsystem.
  951.   image_Subsystem_OS2_CUI               = 5; // image runs in the OS/2 character subsystem.
  952.   image_Subsystem_Posix_CUI             = 7; // image run  in the Posix character subsystem.
  953.   image_Subsystem_Reserved8             = 8; // image run  in the 8 subsystem.
  954.  
  955. // Directory Entries
  956.  
  957.   image_Directory_Entry_Export          = 0;  // Export Directory
  958.   image_Directory_Entry_Import          = 1;  // Import Directory
  959.   image_Directory_Entry_Resource        = 2;  // Resource Directory
  960.   image_Directory_Entry_Exception       = 3;  // Exception Directory
  961.   image_Directory_Entry_Security        = 4;  // Security Directory
  962.   image_Directory_Entry_BaseReloc       = 5;  // Base Relocation Table
  963.   image_Directory_Entry_Debug           = 6;  // Debug Directory
  964.   image_Directory_Entry_Copyright       = 7;  // Description String
  965.   image_Directory_Entry_GlobalPtr       = 8;  // Machine Value (MIPS GP)
  966.   image_Directory_Entry_Tls             = 9;  // TLS Directory
  967.   image_Directory_Entry_Load_Config     = 10; // Load Configuration Directory
  968.   image_Directory_Entry_Bound_Import    = 11; // Bound Import Directory in headers
  969.   image_Directory_Entry_IAT             = 12; // Import Address Table
  970.  
  971. // Section header format.
  972.  
  973.   image_SizeOf_Short_Name               = 8;
  974.  
  975. type
  976.   TISHMisc = packed record
  977.     case Integer of
  978.       0: (PhysicalAddress: DWord);
  979.       1: (VirtualSize:     DWord);
  980.   end;
  981.  
  982.   PImageSectionHeader = ^TImageSectionHeader;
  983.   TImageSectionHeader = packed record
  984.     Name:                 packed array[0..image_SizeOf_Short_Name-1] of Byte;
  985.     Misc:                 TISHMisc;
  986.     VirtualAddress:       DWord;
  987.     SizeOfRawData:        DWord;
  988.     PointerToRawData:     DWord;
  989.     PointerToRelocations: DWord;
  990.     PointerToLinenumbers: DWord;
  991.     NumberOfRelocations:  Word;
  992.     NumberOfLinenumbers:  Word;
  993.     Characteristics:      DWord;
  994.   end;
  995.  
  996. const
  997.   image_SizeOf_Section_Header           = 40;
  998.  
  999. // Section characteristics.
  1000.  
  1001. //image_Scn_Type_Reg                      $00000000  // Reserved.
  1002. //image_Scn_Type_DSect                    $00000001  // Reserved.
  1003. //image_Scn_Type_NoLoad                   $00000002  // Reserved.
  1004. //image_Scn_Type_Group                    $00000004  // Reserved.
  1005.   image_Scn_Type_No_Pad                 = $00000008; // Reserved.
  1006. //image_Scn_Type_Copy                     $00000010  // Reserved.
  1007.  
  1008.   image_Scn_Cnt_Code                    = $00000020; // Section contains code.
  1009.   image_Scn_Cnt_Initialized_Data        = $00000040; // Section contains initialized data.
  1010.   image_Scn_Cnt_Uninitialized_Data      = $00000080; // Section contains uninitialized data.
  1011.  
  1012.   image_Scn_Lnk_Other                   = $00000100; // Reserved.
  1013.   image_Scn_Lnk_Info                    = $00000200; // Section contains comments or some other type of information.
  1014. //image_Scn_Type_Over                     $00000400  // Reserved.
  1015.   image_Scn_Lnk_Remove                  = $00000800; // Section contents will not become part of image.
  1016.   image_Scn_Lnk_ComDat                  = $00001000; // Section contents comdat.
  1017. //                                        $00002000  // Reserved.
  1018.  
  1019. //image_Scn_Mem_Protected - Obsolete      $00004000
  1020.   image_Scn_Mem_FarData                 = $00008000;
  1021. //image_Scn_Mem_SYSHEAP  - Obsolete       $00010000
  1022.   image_Scn_Mem_Purgeable               = $00020000;
  1023.   image_Scn_Mem_16Bit                   = $00020000;
  1024.   image_Scn_Mem_Locked                  = $00040000;
  1025.   image_Scn_Mem_Preload                 = $00080000;
  1026.  
  1027.   image_Scn_Align_1Bytes                = $00100000;
  1028.   image_Scn_Align_2Bytes                = $00200000;
  1029.   image_Scn_Align_4Bytes                = $00300000;
  1030.   image_Scn_Align_8Bytes                = $00400000;
  1031.   image_Scn_Align_16Bytes               = $00500000; // Default alignment if no others are specified.
  1032.   image_Scn_Align_32Bytes               = $00600000;
  1033.   image_Scn_Align_64Bytes               = $00700000;
  1034. //Unused                                  $00800000
  1035.  
  1036.   image_Scn_Lnk_NReloc_Ovfl             = $01000000; // Section contains extended relocations.
  1037.   image_Scn_Mem_Discardable             = $02000000; // Section can be discarded.
  1038.   image_Scn_Mem_Not_Cached              = $04000000; // Section is not cachable.
  1039.   image_Scn_Mem_Not_Paged               = $08000000; // Section is not pageable.
  1040.   image_Scn_Mem_Shared                  = $10000000; // Section is shareable.
  1041.   image_Scn_Mem_Execute                 = $20000000; // Section is executable.
  1042.   image_Scn_Mem_Read                    = $40000000; // Section is readable.
  1043.   image_Scn_Mem_Write                   = $80000000; // Section is writeable.
  1044.  
  1045. // Relocation format.
  1046.  
  1047. type
  1048.   PImageRelocation = ^TImageRelocation;
  1049.   TImageRelocation = packed record
  1050.     case Integer of
  1051.       0: (VirtualAddress: DWord;
  1052.           SymbolTableIndex: DWord;
  1053.           _Type:            Word);  // renamed form Type
  1054.       1: (RelocCount:       DWord); // Set to the real count when image_Scn_Lnk_NReloc_Ovfl is set
  1055.   end;
  1056.  
  1057. const
  1058.   image_SizeOf_Relocation               = 10;
  1059.  
  1060. // I386 relocation types.
  1061.  
  1062.   image_Rel_i386_Absolute               = $0000; // Reference is absolute, no relocation is necessary
  1063.   image_Rel_i386_Dir16                  = $0001; // Direct 16-bit reference to the symbols virtual address
  1064.   image_Rel_i386_Rel16                  = $0002; // PC-relative 16-bit reference to the symbols virtual address
  1065.   image_Rel_i386_Dir32                  = $0006; // Direct 32-bit reference to the symbols virtual address
  1066.   image_Rel_i386_Dir32NB                = $0007; // Direct 32-bit reference to the symbols virtual address, base not included
  1067.   image_Rel_i386_Seg12                  = $0009; // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
  1068.   image_Rel_i386_Section                = $000A;
  1069.   image_Rel_i386_SecRel                 = $000B;
  1070.   image_Rel_i386_Rel32                  = $0014; // PC-relative 32-bit reference to the symbols virtual address
  1071.  
  1072. // Based relocation format.
  1073.  
  1074. type
  1075.   PImageBaseRelocation = ^TImageBaseRelocation;
  1076.   TImageBaseRelocation = packed record
  1077.     VirtualAddress: DWord;
  1078.     SizeOfBlock:    DWord;
  1079.   //TypeOffset: array[0..X] of Word;
  1080.   end;
  1081.  
  1082. const
  1083.   image_SizeOf_Base_Relocation          = 8;
  1084.  
  1085. // Based relocation types.
  1086.  
  1087.   image_Rel_Based_Absolute              = 0;
  1088.   image_Rel_Based_High                  = 1;
  1089.   image_Rel_Based_Low                   = 2;
  1090.   image_Rel_Based_HighLow               = 3;
  1091.   image_Rel_Based_HighAdj               = 4;
  1092.   image_Rel_Based_MIPS_JmpAddr          = 5;
  1093.  
  1094. // Line number format.
  1095.  
  1096. type
  1097.   PImageLineNumber = ^TImageLineNumber;
  1098.   TImageLineNumber = packed record
  1099.     case Integer of
  1100.       0: (SymbolTableIndex: DWord;      // Symbol table index of function name if Linenumber is 0.
  1101.           Linenumber:       Word);      // Line number.
  1102.       1: (VirtualAddress:   DWord);     // Virtual address of line number.
  1103.   end;
  1104.  
  1105. const
  1106.   image_SizeOf_LineNumber               = 6;
  1107.  
  1108. // DLL support.
  1109. // Export Format
  1110.  
  1111. type
  1112.   PImageExportDirectory = ^TImageExportDirectory;
  1113.   TImageExportDirectory = packed record
  1114.     Characteristics:       DWord;
  1115.     TimeDateStamp:         DWord;
  1116.     MajorVersion:          Word;
  1117.     MinorVersion:          Word;
  1118.     Name:                  DWord;
  1119.     Base:                  DWord;
  1120.     NumberOfFunctions:     DWord;
  1121.     NumberOfNames:         DWord;
  1122.     case Integer of
  1123.      0: (AddressOfFunctions:    ^PDWord;
  1124.          AddressOfNames:        ^PDWord;
  1125.          AddressOfNameOrdinals: ^PDWord);
  1126.  
  1127.      1: (AddrOfFuncs: DWord; // Used in the linker to avoid ugly typecasts
  1128.          AddrOfNames: DWord;
  1129.          AddrOfNOrds: DWord)
  1130.   end;
  1131.  
  1132. // Import Format
  1133.  
  1134.   PImageImportByName = ^TImageImportByName;
  1135.   TImageImportByName = packed record
  1136.     Hint: Word;
  1137.     Name: packed array[0..0] of Char;
  1138.   end;
  1139.  
  1140.   PImageThunkData = ^TImageThunkData;
  1141.   TImageThunkData = packed record
  1142.     case Integer of
  1143.       0: (ForwarderString: PByte);
  1144.       1: (_Function:       PDWord); // renamed from Function
  1145.       2: (Ordinal:         DWord);
  1146.       3: (AddressOfData:   PImageImportByName);
  1147.   end;
  1148.  
  1149. const
  1150.   image_Ordinal_Flag                    = $80000000;
  1151.  
  1152. type
  1153.   PImageImportDescriptor = ^TImageImportDescriptor;
  1154.   TImageImportDescriptor = packed record
  1155.     OriginalFirstThunk: PImageThunkData; // RVA to original unbound IAT
  1156.     TimeDateStamp:      DWord;           // 0 if not bound,
  1157.                                          // -1 if bound, and real date\time stamp
  1158.                                          //     in image_Directory_Entry_Bound_Import (new BIND)
  1159.                                          // O.W. date/time stamp of DLL bound to (Old BIND)
  1160.     ForwarderChain:     DWord;           // -1 if no forwarders
  1161.     Name:               DWord;
  1162.     FirstThunk:         PImageThunkData; // RVA to IAT (if bound this IAT has actual addresses)
  1163.   end;
  1164.  
  1165. // New format import descriptors pointed to by DataDirectory[image_Directory_Entry_Bound_Import]
  1166.  
  1167.   PImageBoundImportDescriptor = ^TImageBoundImportDescriptor;
  1168.   TImageBoundImportDescriptor = packed record
  1169.     TimeDateStamp:               DWord;
  1170.     OffsetModuleName:            Word;
  1171.     NumberOfModuleForwarderRefs: Word;
  1172.   // Array of zero or more TImageBoundForwarderRef follows
  1173.   end;
  1174.  
  1175.   PImageBoundForwarderRef = ^TImageBoundForwarderRef;
  1176.   TImageBoundForwarderRef = packed record
  1177.     TimeDateStamp:    DWord;
  1178.     OffsetModuleName: Word;
  1179.     Reserved:         Word;
  1180.   end;
  1181.  
  1182. // Thread Local Storage
  1183.  
  1184.   TImageTLSCallBack = procedure(DllHandle: Pointer; Reason: DWord; Reserved: Pointer);
  1185.  
  1186.   PImageTLSDirectory = ^TImageTLSDirectory;
  1187.   TImageTLSDirectory = packed record
  1188.     StartAddressOfRawData: DWord;
  1189.     EndAddressOfRawData:   DWord;
  1190.     AddressOfIndex:        PDWord;
  1191.     AddressOfCallBacks:    ^TImageTLSCallBack;
  1192.     SizeOfZeroFill:        DWord;
  1193.     Characteristics:       DWord;
  1194.   end;
  1195.  
  1196. // Resource Format
  1197. //
  1198. // Resource directory consists of two counts, following by a variable length
  1199. // array of directory entries.  The first count is the number of entries at
  1200. // beginning of the array that have actual names associated with each entry.
  1201. // The entries are in ascending order, case insensitive strings.  The second
  1202. // count is the number of entries that immediately follow the named entries.
  1203. // This second count identifies the number of entries that have 16-bit integer
  1204. // Ids as their name.  These entries are also sorted in ascending order.
  1205. //
  1206. // This structure allows fast lookup by either name or number, but for any
  1207. // given resource entry only one form of lookup is supported, not both.
  1208. // This is consistant with the syntax of the .RC file and the .RES file.
  1209. //
  1210.  
  1211.   PImageResourceDirectory = ^TImageResourceDirectory;
  1212.   TImageResourceDirectory = packed record
  1213.     Characteristics:      DWord;
  1214.     TimeDateStamp:        DWord;
  1215.     MajorVersion:         Word;
  1216.     MinorVersion:         Word;
  1217.     NumberOfNamedEntries: Word;
  1218.     NumberOfIdEntries:    Word;
  1219. //  DirectoryEntries: array [0..X] of TImageResourceDirectoryEntry;
  1220.   end;
  1221.  
  1222. const
  1223.   image_Resource_Name_Is_String         = $80000000;
  1224.   image_Resource_Data_Is_Directory      = $80000000;
  1225.  
  1226. // Each directory contains the 32-bit Name of the entry and an offset,
  1227. // relative to the beginning of the resource directory of the data associated
  1228. // with this directory entry.  If the name of the entry is an actual text
  1229. // string instead of an integer Id, then the high order bit of the name field
  1230. // is set to one and the low order 31-bits are an offset, relative to the
  1231. // beginning of the resource directory of the string, which is of type
  1232. // IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
  1233. // low-order 16-bits are the integer Id that identify this resource directory
  1234. // entry. If the directory entry is yet another resource directory (i.e. a
  1235. // subdirectory), then the high order bit of the offset field will be
  1236. // set to indicate this.  Otherwise the high bit is clear and the offset
  1237. // field points to a resource data entry.
  1238. //
  1239.  
  1240. type
  1241.   PImageResourceDirectoryEntry = ^TImageResourceDirectoryEntry;
  1242.   TImageResourceDirectoryEntry = packed record
  1243.     case Integer of
  1244.       0: (Name:         DWord;
  1245.           OffsetToData: DWord);
  1246.       1: (Id:     Word);
  1247.   end;
  1248.  
  1249. // For resource directory entries that have actual string names, the Name
  1250. // field of the directory entry points to an object of the following type.
  1251. // All of these string objects are stored together after the last resource
  1252. // directory entry and before the first resource data object.  This minimizes
  1253. // the impact of these variable length objects on the alignment of the fixed
  1254. // size directory entry objects.
  1255. //
  1256.  
  1257.   PImageResourceDirectoryString = ^TImageResourceDirectoryString;
  1258.   TImageResourceDirectoryString = packed record
  1259.     Length: Word;
  1260.     NameString: packed array [0..0] of Char;
  1261.   end;
  1262.  
  1263.   PImageResourceDirStringU = ^TImageResourceDirStringU;
  1264.   TImageResourceDirStringU = packed record
  1265.     Length: Word;
  1266.     NameString: packed array[0..0] of Word;
  1267.   end;
  1268.  
  1269. // Each resource data entry describes a leaf node in the resource directory
  1270. // tree.  It contains an offset, relative to the beginning of the resource
  1271. // directory of the data for the resource, a size field that gives the number
  1272. // of bytes of data at that offset, a CodePage that should be used when
  1273. // decoding code point values within the resource data.  Typically for new
  1274. // applications the code page would be the unicode code page.
  1275.  
  1276.   PImageResourceDataEntry = ^TImageResourceDataEntry;
  1277.   TImageResourceDataEntry = packed record
  1278.     OffsetToData: DWord;
  1279.     Size:         DWord;
  1280.     CodePage:     DWord;
  1281.     Reserved:     DWord;
  1282.   end;
  1283.  
  1284. // Load Configuration Directory Entry
  1285.  
  1286.   PImageLoadConfigDirectory = ^TImageLoadConfigDirectory;
  1287.   TImageLoadConfigDirectory = packed record
  1288.     Characteristics:               DWord;
  1289.     TimeDateStamp:                 DWord;
  1290.     MajorVersion:                  Word;
  1291.     MinorVersion:                  Word;
  1292.     GlobalFlagsClear:              DWord;
  1293.     GlobalFlagsSet:                DWord;
  1294.     CriticalSectionDefaultTimeout: DWord;
  1295.     DeCommitFreeBlockThreshold:    DWord;
  1296.     DeCommitTotalFreeThreshold:    DWord;
  1297.     LockPrefixTable:               Pointer;
  1298.     MaximumAllocationSize:         DWord;
  1299.     VirtualMemoryThreshold:        DWord;
  1300.     ProcessHeapFlags:              DWord;
  1301.     ProcessAffinityMask:           DWord;
  1302.     Reserved:packed array[0..2] of DWord;
  1303.   end;
  1304.  
  1305. // Function table entry format for MIPS/ALPHA images.  Function table is
  1306. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  1307.  
  1308.   PImageRuntimeFunctionEntry = ^TImageRuntimeFunctionEntry;
  1309.   TImageRuntimeFunctionEntry = packed record
  1310.     BeginAddress:       DWord;
  1311.     EndAddress:         DWord;
  1312.     ExceptionHandler:   Pointer;
  1313.     HandlerData:        Pointer;
  1314.     PrologEndAddress:   DWord;
  1315.   end;
  1316.  
  1317. // Debug Format
  1318.  
  1319.   PImageDebugDirectory = ^TImageDebugDirectory;
  1320.   TImageDebugDirectory = packed record
  1321.     Characteristics:    DWord;
  1322.     TimeDateStamp:      DWord;
  1323.     MajorVersion:       Word;
  1324.     MinorVersion:       Word;
  1325.     _Type:              DWord; // Renamed from Type
  1326.     SizeOfData:         DWord;
  1327.     AddressOfRawData:   DWord;
  1328.     PointerToRawData:   DWord;
  1329.   end;
  1330.  
  1331. const
  1332.   image_Debug_Type_Unknown              = 0;
  1333.   image_Debug_Type_Coff                 = 1;
  1334.   image_Debug_Type_CodeView             = 2;
  1335.   image_Debug_Type_FPO                  = 3;
  1336.   image_Debug_Type_Misc                 = 4;
  1337.   image_Debug_Type_Exception            = 5;
  1338.   image_Debug_Type_Fixup                = 6;
  1339.   image_Debug_Type_OMap_To_Src          = 7;
  1340.   image_Debug_Type_OMap_From_Src        = 8;
  1341.  
  1342. type
  1343.   PImageCOFFSymbolsHeader = ^TImageCOFFSymbolsHeader;
  1344.   TImageCOFFSymbolsHeader = packed record
  1345.     NumberOfSymbols:      DWord;
  1346.     LvaToFirstSymbol:     DWord;
  1347.     NumberOfLinenumbers:  DWord;
  1348.     LvaToFirstLinenumber: DWord;
  1349.     RvaToFirstByteOfCode: DWord;
  1350.     RvaToLastByteOfCode:  DWord;
  1351.     RvaToFirstByteOfData: DWord;
  1352.     RvaToLastByteOfData:  DWord;
  1353.   end;
  1354.  
  1355. const
  1356.   frame_FPO                             = 0;
  1357.   frame_Trap                            = 1;
  1358.   frame_TSS                             = 2;
  1359.   frame_NonFPO                          = 3;
  1360.  
  1361. type
  1362.   PFpoData = ^TFpoData;
  1363.   TFpoData = packed record
  1364.     ulOffStart:  DWord;                 // offset 1st byte of function code
  1365.     cbProcSize:  DWord;                 // # bytes in function
  1366.     cdwLocals:   DWord;                 // # bytes in locals/4
  1367.     cdwParams:   Word;                  // # bytes in params/4
  1368. {    WORD        cbProlog : 8;          // # bytes in prolog
  1369.      WORD        cbRegs   : 3;          // # regs saved
  1370.      WORD        fHasSEH  : 1;          // TRUE if SEH in func
  1371.      WORD        fUseBP   : 1;          // TRUE if EBP has been allocated
  1372.      WORD        reserved : 1;          // reserved for future use
  1373.      WORD        cbFrame  : 2;}         // frame type
  1374.      cbProlog:   Byte;
  1375.      OtherStuff: Byte;
  1376.   end;
  1377.  
  1378. const
  1379.   sizeof_RFPO_Data         = 16;
  1380.   image_Debug_Misc_ExeName = 1;
  1381.  
  1382. type
  1383.   PImageDebugMisc = ^TImageDebugMisc;
  1384.   TImageDebugMisc = packed record
  1385.     DataType:   DWord;                  // type of misc data, see defines
  1386.     Length:     DWord;                  // total length of record, rounded to four
  1387.                                         // byte multiple.
  1388.     Unicode:    ByteBool;               // TRUE if data is unicode string
  1389.     Reserved:   packed array[0..2] of Byte;
  1390.     Data:       packed array[0..0] of Byte;  // Actual data
  1391.   end;
  1392.  
  1393. // Function table extracted from MIPS/ALPHA images.  Does not contain
  1394. // information needed only for runtime support.  Just those fields for
  1395. // each entry needed by a debugger.
  1396.  
  1397.   PImageFunctionEntry = ^TImageFunctionEntry;
  1398.   TImageFunctionEntry = packed record
  1399.     StartingAddress: DWord;
  1400.     EndingAddress:   DWord;
  1401.     EndOfPrologue:   DWord;
  1402.   end;
  1403.  
  1404. // Debugging information can be stripped from an image file and placed
  1405. // in a separate .DBG file, whose file name part is the same as the
  1406. // image file name part (e.g. symbols for CMD.EXE could be stripped
  1407. // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  1408. // flag in the Characteristics field of the file header.  The beginning of
  1409. // the .DBG file contains the following structure which captures certain
  1410. // information from the image file.  This allows a debug to proceed even if
  1411. // the original image file is not accessable.  This header is followed by
  1412. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  1413. // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
  1414. // the image file contain file offsets relative to the beginning of the
  1415. // .DBG file.
  1416. //
  1417. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  1418. // is left in the image file, but not mapped.  This allows a debugger to
  1419. // compute the name of the .DBG file, from the name of the image in the
  1420. // IMAGE_DEBUG_MISC structure.
  1421.  
  1422.   PImageSeparateDebugHeader = ^TImageSeparateDebugHeader;
  1423.   TImageSeparateDebugHeader = packed record
  1424.     Signature:          Word;
  1425.     Flags:              Word;
  1426.     Machine:            Word;
  1427.     Characteristics:    Word;
  1428.     TimeDateStamp:      DWord;
  1429.     CheckSum:           DWord;
  1430.     ImageBase:          DWord;
  1431.     SizeOfImage:        DWord;
  1432.     NumberOfSections:   DWord;
  1433.     ExportedNamesSize:  DWord;
  1434.     DebugDirectorySize: DWord;
  1435.     Reserved: packed array[0..2] of DWord;  // Note: reserved[0] is actually the section alignment
  1436.   end;
  1437.  
  1438. const
  1439.   image_Separate_Debug_Signature        = $4944; // 'DI'
  1440.  
  1441. implementation
  1442.  
  1443. end.
  1444.