home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oxcc1433.zip / SRC / BINIMG.H next >
C/C++ Source or Header  |  1995-11-01  |  61KB  |  1,557 lines

  1. /* binimg.h -- defs for a.out+coff+elf+pe+exe+ne+le+omf formats */
  2.  
  3. #ifndef __GNUC__
  4. #pragma pack(1)
  5. #define __attribute__()
  6. #endif
  7.  
  8. /* ****************** MAGIC NUMBERS ************************ */
  9. #define OBJMAGIC 0x80   /* omf THEADR record type, first byte */
  10. #define LIBMAGIC 0xF0   /* omf LIBR first byte */
  11. #define ARMAGIC  0x3c21 /* !< beginning of unix style archive */
  12. #define OMAGIC   0x0107    /* a.out object file 0407 */
  13. #define NMAGIC   0x0108    /* a.out pure executable 0410 */
  14. #define ZMAGIC   0x010b    /* a.out demand paged executable 0413 */
  15. #define IMAGIC   0x014c    /* coff header f_magic for i386 */
  16. #define AIXMAGIC 0x0175    /* coff header f_magic for aix i386 */
  17. #define MIBMAGIC 0x0162 /* coff header f_magic for mips big endian R3000 */
  18. #define MI3MAGIC 0x0162 /* coff header f_magic for mips little endian R3000 */
  19. #define MI4MAGIC 0x0166 /* coff header f_magic for mips little endian R4000 */
  20. #define MI1MAGIC 0x0166 /* coff header f_magic for mips little endian R10000 */
  21. #define AL1MAGIC 0x0184 /* coff header f_magic for Alpha AXP */
  22. #define AL2MAGIC 0x0186 /* coff header f_magic for Alpha APX */
  23. #define M68MAGIC 0x0268 /* coff header f_magic for M68000 series */
  24. #define PPCMAGIC 0x01f0 /* coff header f_magic for PowerPC little endian */
  25. #define PAMAGIC  0x0290 /* coff header f_magic for HP PA RISC */
  26. #define DOSMAGIC 0x5A4D    /* MZ start of .exe files */
  27. #define NEMAGIC  0x454E    /* NE os2,win31 16bit */
  28. #define LEMAGIC  0x454C /* LE os2,vxd 32 bit */
  29. #define PEMAGIC  0x4550 /* PE nt,win95,win32s */
  30. #define NTMAGIC  0x010b /* NT OPTIONAL HEADER */
  31. #define ROMMAGIC 0x0107 /* NT ROM OPTIONAL HEADER */
  32. #define OPOMAGIC 0x0104 /* coff optional header object file, as output */
  33. #define OPZMAGIC 0x010b /* coff optional header demand load format, ld output */
  34. #define OPTMAGIC 0x0101 /* coff optional header target shared library */
  35. #define OPHMAGIC 0x0123 /* coff optional header host shared library */
  36. #define ELFMAGIC 0x457f /* beginning of elf ident "\177ELF" */
  37.  
  38. /* ********************* FILE HEADERS *************************** */
  39.  
  40. #define NEW_EXECUTABLE(ptr) (ptr->e_lfarlc >= 0x0040)
  41.  
  42. typedef struct {      /* DOS .EXE header */
  43.     unsigned short   e_magic;       /* 00 Magic number */
  44.     unsigned short   e_cblp;        /* 02 Bytes on last page of file */
  45.     unsigned short   e_cp;          /* 04 Pages in file */
  46.     unsigned short   e_crlc;        /* 06 Relocations */
  47.     unsigned short   e_cparhdr;     /* 08 Size of header in paragraphs */
  48.     unsigned short   e_minalloc;    /* 0A Minimum extra paragraphs needed */
  49.     unsigned short   e_maxalloc;    /* 0C Maximum extra paragraphs needed */
  50.     unsigned short   e_ss;          /* 0E Initial (relative) SS value */
  51.     unsigned short   e_sp;          /* 10 Initial SP value */
  52.     unsigned short   e_csum;        /* 12 Checksum */
  53.     unsigned short   e_ip;          /* 14 Initial IP value */
  54.     unsigned short   e_cs;          /* 16 Initial (relative) CS value */
  55.     unsigned short   e_lfarlc;      /* 18 File address of relocation table */
  56.     unsigned short   e_ovno;        /* 1A Overlay number */
  57.     unsigned short   e_res[4];      /* 1C Reserved words */
  58.     unsigned short   e_oemid;       /* 24 OEM identifier (for e_oeminfo) */
  59.     unsigned short   e_oeminfo;     /* 26 OEM information; e_oemid specific */
  60.     unsigned short   e_res2[10];    /* 28 Reserved words */
  61.     long   e_lfanew __attribute__((packed));  /* 3C File address of new exe header */
  62.   } DOS_HDR, *PDOS_HDR;
  63.  
  64. typedef struct {      /* OS/2 .EXE header */
  65.     unsigned short   ne_magic;     /* Magic number */
  66.     char   ne_ver;                 /* Version number */
  67.     char   ne_rev;                 /* Revision number */
  68.     unsigned short   ne_enttab __attribute__((packed));/* Offset of Entry Table */
  69.     unsigned short   ne_cbenttab;  /* Number of bytes in Entry Table */
  70.     long   ne_crc __attribute__((packed)); /* Checksum of whole file */
  71.     unsigned short   ne_flags;     /* Flag word */
  72.     unsigned short   ne_autodata;  /* Automatic data segment number */
  73.     unsigned short   ne_heap;      /* Initial heap allocation */
  74.     unsigned short   ne_stack;     /* Initial stack allocation */
  75.     long   ne_csip __attribute__((packed)); /* Initial CS:IP setting */
  76.     long   ne_sssp;                /* Initial SS:SP setting */
  77.     unsigned short   ne_cseg;      /* Count of file segments */
  78.     unsigned short   ne_cmod;      /* Entries in Module Reference Table */
  79.     unsigned short   ne_cbnrestab; /* Size of non-resident name table */
  80.     unsigned short   ne_segtab;    /* Offset of Segment Table */
  81.     unsigned short   ne_rsrctab;   /* Offset of Resource Table */
  82.     unsigned short   ne_restab;    /* Offset of resident name table */
  83.     unsigned short   ne_modtab;    /* Offset of Module Reference Table */
  84.     unsigned short   ne_imptab;    /* Offset of Imported Names Table */
  85.     long   ne_nrestab __attribute__((packed)); /* Offset of Non-resident Names Table */
  86.     unsigned short   ne_cmovent;   /* Count of movable entries */
  87.     unsigned short   ne_align;     /* Segment alignment shift count */
  88.     unsigned short   ne_cres;      /* Count of resource segments */
  89.     unsigned char   ne_exetyp;     /* Target Operating system */
  90.     unsigned char   ne_flagsothers; /* Other .EXE flags */
  91.     unsigned short   ne_pretthunks __attribute__((packed)); /* offset to return thunks */
  92.     unsigned short   ne_psegrefbytes; /* offset to segment ref. bytes */
  93.     unsigned short   ne_swaparea;     /* Minimum code swap area size */
  94.     unsigned short   ne_expver;       /* Expected Windows version number */
  95.   } OS2_HDR, *POS2_HDR;
  96.  
  97. typedef struct {      /* WIN31 .EXE header */
  98.     unsigned short   ne_magic;     /* Magic number */
  99.     char   ne_ver;                 /* Version number */
  100.     char   ne_rev;                 /* Revision number */
  101.     unsigned short   ne_enttab __attribute__((packed));/* Offset of Entry Table */
  102.     unsigned short   ne_cbenttab;  /* Number of bytes in Entry Table */
  103.     long   ne_crc __attribute__((packed)); /* Checksum of whole file */
  104.     unsigned short   ne_flags;     /* Flag word */
  105.     unsigned short   ne_autodata;  /* Automatic data segment number */
  106.     unsigned short   ne_heap;      /* Initial heap allocation */
  107.     unsigned short   ne_stack;     /* Initial stack allocation */
  108.     long   ne_csip __attribute__((packed)); /* Initial CS:IP setting */
  109.     long   ne_sssp;                /* Initial SS:SP setting */
  110.     unsigned short   ne_cseg;      /* Count of file segments */
  111.     unsigned short   ne_cmod;      /* Entries in Module Reference Table */
  112.     unsigned short   ne_cbnrestab; /* Size of non-resident name table */
  113.     unsigned short   ne_segtab;    /* Offset of Segment Table */
  114.     unsigned short   ne_rsrctab;   /* Offset of Resource Table */
  115.     unsigned short   ne_restab;    /* Offset of resident name table */
  116.     unsigned short   ne_modtab;    /* Offset of Module Reference Table */
  117.     unsigned short   ne_imptab;    /* Offset of Imported Names Table */
  118.     long   ne_nrestab __attribute__((packed)); /* Offset of Non-resident Names Table */
  119.     unsigned short   ne_cmovent;   /* Count of movable entries */
  120.     unsigned short   ne_align;     /* Segment alignment shift count */
  121.     unsigned short   ne_cres;      /* Count of resource segments */
  122.     unsigned char   ne_exetyp;     /* Target Operating system */
  123.     unsigned char   ne_flagsothers; /* Other .EXE flags */
  124.     unsigned short   ne_fastload __attribute__((packed)); /* ofs in sectors to fast load area */
  125.     unsigned short   ne_fastsize; /* size in sectors of fast load area */
  126.     unsigned short   ne_swaparea;     /* reserved */
  127.     unsigned short   ne_expver;       /* Expected Windows version number */
  128.   } WIN31_HDR, *PWIN31_HDR;
  129.  
  130. typedef struct {      /* Windows VXD header */
  131.     unsigned short   e32_magic;       /* Magic number */
  132.     unsigned char   e32_border;       /* The byte ordering for the VXD */
  133.     unsigned char   e32_worder;       /* The word ordering for the VXD */
  134.     unsigned long  e32_level __attribute__((packed));/* The EXE format level for now = 0 */
  135.     unsigned short   e32_cpu;         /* The CPU type */
  136.     unsigned short   e32_os;          /* The OS type */
  137.     unsigned long  e32_ver __attribute__((packed)); /* Module version */
  138.     unsigned long  e32_mflags;        /* Module flags */
  139.     unsigned long  e32_mpages;        /* Module # pages */
  140.     unsigned long  e32_startobj;      /* Object # for instruction pointer */
  141.     unsigned long  e32_eip;           /* Extended instruction pointer */
  142.     unsigned long  e32_stackobj;      /* Object # for stack pointer */
  143.     unsigned long  e32_esp;           /* Extended stack pointer */
  144.     unsigned long  e32_pagesize;      /* VXD page size */
  145.     unsigned long  e32_lastpagesize;  /* Last page size in VXD */
  146.     unsigned long  e32_fixupsize;     /* Fixup section size */
  147.     unsigned long  e32_fixupsum;      /* Fixup section checksum */
  148.     unsigned long  e32_ldrsize;       /* Loader section size */
  149.     unsigned long  e32_ldrsum;        /* Loader section checksum */
  150.     unsigned long  e32_objtab;        /* Object table offset */
  151.     unsigned long  e32_objcnt;        /* Number of objects in module */
  152.     unsigned long  e32_objmap;        /* Object page map offset */
  153.     unsigned long  e32_itermap;       /* Object iterated data map offset */
  154.     unsigned long  e32_rsrctab;       /* Offset of Resource Table */
  155.     unsigned long  e32_rsrccnt;       /* Number of resource entries */
  156.     unsigned long  e32_restab;        /* Offset of resident name table */
  157.     unsigned long  e32_enttab;        /* Offset of Entry Table */
  158.     unsigned long  e32_dirtab;        /* Offset of Module Directive Table */
  159.     unsigned long  e32_dircnt;        /* Number of module directives */
  160.     unsigned long  e32_fpagetab;      /* Offset of Fixup Page Table */
  161.     unsigned long  e32_frectab;       /* Offset of Fixup Record Table */
  162.     unsigned long  e32_impmod;        /* Offset of Import Module Name Table */
  163.     unsigned long  e32_impmodcnt;     /* Number of entries in Import Module Name Table */
  164.     unsigned long  e32_impproc;       /* Offset of Import Procedure Name Table */
  165.     unsigned long  e32_pagesum;       /* Offset of Per-Page Checksum Table */
  166.     unsigned long  e32_datapage;      /* Offset of Enumerated Data Pages */
  167.     unsigned long  e32_preload;       /* Number of preload pages */
  168.     unsigned long  e32_nrestab;       /* Offset of Non-resident Names Table */
  169.     unsigned long  e32_cbnrestab;     /* Size of Non-resident Name Table */
  170.     unsigned long  e32_nressum;       /* Non-resident Name Table Checksum */
  171.     unsigned long  e32_autodata;      /* Object # for automatic data object */
  172.     unsigned long  e32_debuginfo;     /* Offset of the debugging information */
  173.     unsigned long  e32_debuglen;      /* The length of the debugging info. in bytes */
  174.     unsigned long  e32_instpreload;   /* Number of instance pages in preload section of VXD file */
  175.     unsigned long  e32_instdemand;    /* Number of instance pages in demand load section of VXD file */
  176.     unsigned long  e32_heapsize;      /* Size of heap - for 16-bit apps */
  177.     unsigned char   e32_res3[12];     /* Reserved words */
  178.     unsigned long  e32_winresoff __attribute__((packed));
  179.     unsigned long  e32_winreslen;
  180.     unsigned short   e32_devid;       /* Device ID for VxD */
  181.     unsigned short   e32_ddkver;      /* DDK version for VxD */
  182.   } VXD_HDR, *PVXD_HDR;
  183.  
  184. typedef struct exec
  185. {
  186.   short a_magic;     /* a magic number */
  187.   short a_whocares;     /* machtype and flags, set to zero */
  188.   unsigned a_text __attribute__((packed));   /* length of text, in bytes */
  189.   unsigned a_data;   /* length of data, in bytes */
  190.   unsigned a_bss;    /* length of uninitialized data area for file, in bytes */
  191.   unsigned a_syms;   /* length of symbol table data in file, in bytes */
  192.   unsigned a_entry;  /* start address */
  193.   unsigned a_trsize; /* length of relocation info for text, in bytes */
  194.   unsigned a_drsize; /* length of relocation info for data, in bytes */
  195. } EXEC_HDR, *PEXEC_HDR;
  196.  
  197. typedef struct {
  198.     unsigned short f_magic;        /* magic number, machine type        */
  199.     unsigned short f_nscns;        /* number of sections        */
  200.     unsigned long f_timdat __attribute__((packed));    /* time & date stamp */
  201.     unsigned long f_symptr;        /* file pointer to symtab    */
  202.     unsigned long f_nsyms;        /* number of symtab entries    */
  203.     unsigned short f_opthdr;    /* sizeof(optional hdr)        */
  204.     unsigned short f_flags;        /* flags            */
  205. } COFF_HDR, *PCOFF_HDR;
  206.  
  207.  
  208. /* Bits for f_flags:
  209.  *    F_RELFLG    relocation info stripped from file
  210.  *    F_EXEC        file is executable (no unresolved external references)
  211.  *    F_LINNO        line numbers stripped from file
  212.  *    F_LSYMS        local symbols stripped from file
  213.  *  F_MINIMAL    minimal object, reserved NT
  214.  *  F_UPDATE    update object, reserved NT
  215.  *    F_16BIT        16 bit machine, reserved NT
  216.  *    F_LILEND    file has little endian byte ordering
  217.  *    F_32BIT        32 bit machine
  218.  *    F_DEBUG        debug info stripped
  219.  *  F_PATCH        reserved NT
  220.  *    F_SYSTEM    system file, not a user pgm NT
  221.  *    F_DLL        dynamic link library, NT
  222.  *    F_BIGEND    file has big endian byte ordering
  223.  */
  224.  
  225. #define F_RELFLG        (0x0001)
  226. #define COFF_F_RELFLG    (0x0001)
  227. #define F_EXEC            (0x0002)
  228. #define COFF_F_EXEC        (0x0002)
  229. #define F_LINNO            (0x0004)
  230. #define COFF_F_LINNO    (0x0004)
  231. #define F_LSYMS            (0x0008)
  232. #define COFF_F_LSYMS    (0x0008)
  233. #define F_MINIMAL        (0x0010)
  234. #define COFF_F_MINMAL    (0x0020)
  235. #define F_UPDATE        (0x0020)
  236. #define COFF_F_UPDATE    (0x0040)
  237. #define F_16BIT            (0x0040)
  238. #define F_LILEND        (0x0080)
  239. #define F_32BIT            (0x0100)
  240. #define COFF_F_SWABD    (0x0100)
  241. #define F_DEBUG            (0x0200)
  242. #define COFF_F_AR16WR    (0x0200)
  243. #define F_PATCH            (0x0400)
  244. #define COFF_F_AR32WR    (0x0400)
  245. #define F_SYSTEM        (0x1000)
  246. #define COFF_F_AR32W    (0x1000)
  247. #define F_DLL            (0x2000)
  248. #define COFF_F_PATCH    (0x2000)
  249. #define COFF_F_NODF        (0x2000)
  250. #define F_BIGEND        (0x8000)
  251.  
  252. /*
  253.  * These defines are byte order independent. There is no alignment of fields
  254.  * permitted in the structures. Therefore they are declared as characters
  255.  * and the values loaded from the character positions. It also makes it
  256.  * nice to have it "endian" independent.
  257.  */
  258.  
  259. /* Load a short int from the following tables with little-endian formats */
  260. #define COFF_SHORT_L(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
  261.                   ((unsigned short)((unsigned char)ps[0]))))
  262.  
  263. /* Load a long int from the following tables with little-endian formats */
  264. #define COFF_LONG_L(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
  265.                  ((unsigned long)((unsigned char)ps[2])<<16) |\
  266.                  ((unsigned long)((unsigned char)ps[1])<<8)  |\
  267.                  ((unsigned long)((unsigned char)ps[0])))))
  268.  
  269. /* Load a short int from the following tables with big-endian formats */
  270. #define COFF_SHORT_H(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
  271.                   ((unsigned short)((unsigned char)ps[1]))))
  272.  
  273. /* Load a long int from the following tables with big-endian formats */
  274. #define COFF_LONG_H(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
  275.                  ((unsigned long)((unsigned char)ps[1])<<16) |\
  276.                  ((unsigned long)((unsigned char)ps[2])<<8)  |\
  277.                  ((unsigned long)((unsigned char)ps[3])))))
  278.  
  279. /* These may be overridden later by brain dead implementations which generate
  280.    a big-endian header with little-endian data. In that case, generate a
  281.    replacement macro which tests a flag and uses either of the two above
  282.    as appropriate. */
  283.  
  284. #define COFF_LONG(v)   COFF_LONG_L(v)
  285. #define COFF_SHORT(v)  COFF_SHORT_L(v)
  286.  
  287. /* linux style info */
  288.  
  289. struct COFF_filehdr {
  290.     char f_magic[2];    /* magic number            */
  291.     char f_nscns[2];    /* number of sections        */
  292.     char f_timdat[4];    /* time & date stamp        */
  293.     char f_symptr[4];    /* file pointer to symtab    */
  294.     char f_nsyms[4];    /* number of symtab entries    */
  295.     char f_opthdr[2];    /* sizeof(optional hdr)        */
  296.     char f_flags[2];    /* flags            */
  297. };
  298.  
  299. #define COFF_STMAGIC    0401
  300. #define COFF_OMAGIC     0404
  301. #define COFF_JMAGIC     0407    /* dirty text and data image, can't share  */
  302. #define COFF_DMAGIC     0410    /* dirty text segment, data aligned        */
  303. #define COFF_ZMAGIC     0413    /* The proper magic number for executables  */
  304. #define COFF_SHMAGIC    0443    /* shared library header                   */
  305.  
  306. /* ************************** A.OUT DEFS ************************** */
  307. #define N_MAGIC(x) ((x).a_magic)
  308. #define P_MAGIC(x) ((x)->a_magic)
  309.  
  310. /* file offsets */
  311. #define N_TXTOFF(x) (sizeof(struct exec))
  312. #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
  313. #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
  314. #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
  315. #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
  316. #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
  317.  
  318. #define P_TXTOFF(x) sizeof(struct exec)
  319. #define P_DATOFF(x) (P_TXTOFF(x) + (x)->a_text)
  320. #define P_TRELOFF(x) (P_DATOFF(x) + (x)->a_data)
  321. #define P_DRELOFF(x) (P_TRELOFF(x) + (x)->a_trsize)
  322. #define P_SYMOFF(x) (P_DRELOFF(x) + (x)->a_drsize)
  323. #define P_STROFF(x) (P_SYMOFF(x) + (x)->a_syms)
  324.  
  325. /* loaded offsets */
  326. #define N_TXTADDR(x) (0) /* depends on operating system and linker used */
  327. #define N_DATADDR(x) (N_TXTADDR(x)+(x).a_text) 
  328. #define N_BSSADDR(x) (N_DATADDR(x)+(x).a_data)
  329.  
  330. #define P_TXTADDR(x) (0) /* depends on operating system and linker used */
  331. #define P_DATADDR(x) (N_TXTADDR(x)+(x)->a_text) 
  332. #define P_BSSADDR(x) (N_DATADDR(x)+(x)->a_data)
  333.  
  334. typedef struct nlist {
  335.   union {
  336.     char *n_name;
  337.     struct nlist *n_next;
  338.     long n_strx;
  339.   } n_un;
  340.   unsigned char n_type;
  341.   char n_other;
  342.   short n_desc;
  343.   unsigned long n_value;
  344. } NLIST, *PNLIST;
  345.  
  346. /* entries in the n_type field */
  347. #define N_UNDF 0x00
  348. #define N_ABS 0x02
  349. #define N_TEXT 0x04
  350. #define N_DATA 0x06
  351. #define N_BSS 0x08
  352. #define N_NDC 0x10
  353. #define N_COMM 0x12
  354. #define N_FN 0x0f
  355. #define N_EXT 0x01
  356. #define N_TYPE 0x1e
  357. #define N_STAB 0xe0
  358. #define N_SWTAB 0x20            /* oxcc switch table entry */
  359. #define N_STDCAL 0x24            /* rsxnt stuff */
  360. #define N_THUNK 0x30
  361. #define N_SETA  0x14            /* Absolute set element symbol */
  362. #define N_SETT  0x16            /* Text set element symbol */
  363. #define N_SETD  0x18            /* Data set element symbol */
  364. #define N_SETB  0x1A            /* Bss set element symbol */
  365. #define N_SETV  0x1C            /* Pointer to set vector in data area.  */
  366.  
  367. #define sym_in_text_section(sym) \
  368. (((sym)->n_type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)
  369. #define sym_in_data_section(sym) \
  370. (((sym)->n_type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)
  371. #define sym_in_bss_section(sym) \
  372. (((sym)->n_type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)
  373. #define sym_is_undefined(sym) \
  374. ((sym)->n_type == (N_EXT) && (sym)->n_value == 0)
  375. #define sym_is_global_defn(sym) \
  376. (((sym)->n_type & N_EXT) && (sym)->n_type & N_TYPE)
  377. #define sym_is_debugger_info(sym) \
  378. ((sym)->n_type & ~(N_EXT | N_TYPE))
  379. #define sym_is_fortrancommon(sym)       \
  380. (((sym)->n_type == (N_EXT)) && (sym)->n_value != 0)
  381. #define sym_is_absolute(sym) \
  382. (((sym)->n_type  & N_TYPE)== N_ABS)
  383. #define sym_is_indirect(sym) \
  384. (((sym)->n_type & N_TYPE)== N_INDR)
  385.  
  386.  
  387. typedef struct relocation_info
  388. {
  389.   /* Address (within segment) to be relocated.  */
  390.   int r_address;
  391.   unsigned int r_symbolnum:24;
  392.   unsigned int r_pcrel:1;
  393.   unsigned int r_length:2;
  394.   unsigned int r_extern:1;
  395.   unsigned int r_pad:4;
  396. } RELOCATION_INFO, *PRELOCATION_INFO;
  397.  
  398. #define RELOC_ADDRESS(r)        ((r)->r_address)
  399. #define RELOC_EXTERN_P(r)        ((r)->r_extern)
  400. #define RELOC_SYMBOL(r)            ((r)->r_symbolnum)
  401. #define RELOC_PCREL_P(r)        ((r)->r_pcrel)
  402. #define RELOC_TARGET_SIZE(r)    ((r)->r_length)
  403.  
  404. /* ****************** ARCHIVE FORMAT *********************** */
  405.  
  406. #define ARMAG "!<arch>\n"           /* archive start */
  407. #define SARMAG 8
  408. #define ARFMAG "`\n"                /* archive end */
  409. #define ARPAD  "\n"                 /* null entry */
  410. #define ARLNKR "/               "   /* NT linker member */
  411. #define ARLONG "//              "   /* NT longnames member */
  412.  
  413. typedef struct ar_hdr {
  414.   char ar_name[16];    /* member name, `/' terminated */
  415.   char ar_date[12]; /* member date, decimal */
  416.   char ar_uid[6];    /* member user id, decimal */
  417.   char ar_gid[6];    /* member group id, decimal */
  418.   char ar_mode[8];  /* member mode, octal */
  419.   char ar_size[10]; /* member size, decimal */
  420.   char ar_fmag[2];
  421. } AR_HDR, *PAR_HDR;
  422. /* 
  423.    Format of __.SYMDEF:
  424.    First, a longword containing the size of the 'symdef' data that follows.
  425.    Second, zero or more 'symdef' structures.
  426.    Third, a word containing the length of symbol name strings.
  427.    Fourth, zero or more symbol name strings (each followed by a zero).
  428. */
  429.  
  430. struct symdef {
  431.   long symbol_name_string_index;
  432.   long library_member_offset;
  433. };
  434.  
  435. /********************** COFF BASIC "OPTIONAL HEADER" **********************/
  436. /* USED WITH PE format of WINNT also */
  437.  
  438. typedef struct 
  439. {
  440.   unsigned short     magic;        /* type of file                */
  441.   unsigned short    vstamp;        /* version stamp            */
  442.   unsigned long        tsize;        /* text size in bytes, padded to FW bdry*/
  443.   unsigned long        dsize;        /* initialized data "  "        */
  444.   unsigned long        bsize;        /* uninitialized data "   "        */
  445.   unsigned long        entry;        /* entry pt.                */
  446.   unsigned long     text_start;    /* base of text used for this file */
  447.   unsigned long     data_start;    /* base of data used for this file */
  448. } OPT_HDR, *POPT_HDR;
  449.  
  450. typedef struct {
  451.     COFF_HDR c __attribute__((packed));
  452.     OPT_HDR o __attribute__((packed));
  453. } XCOFF_HDR, *PXCOFF_HDR;
  454. /*************** NT SPECIFIC ADDITIONS TO OPTIONAL HDR **********/
  455.  
  456. #define PE_DIRS 16
  457.  
  458. typedef struct {
  459.     unsigned long  RVA;
  460.     unsigned long  size;
  461. } PE_DATA_DIR, *PPE_DATA_DIR;
  462.  
  463. /*
  464. // Directory Entries
  465. */
  466.  
  467. #define DIR_ENTRY_EXPORT         0   /* Export Directory */
  468. #define DIR_ENTRY_IMPORT         1   /* Import Directory */
  469. #define DIR_ENTRY_RESOURCE       2   /* Resource Directory */
  470. #define DIR_ENTRY_EXCEPTION      3   /* Exception Directory */
  471. #define DIR_ENTRY_SECURITY       4   /* Security Directory */
  472. #define DIR_ENTRY_BASERELOC      5   /* Base Relocation Table */
  473. #define DIR_ENTRY_DEBUG          6   /* Debug Directory */
  474. #define DIR_ENTRY_COPYRIGHT      7   /* Description String */
  475. #define DIR_ENTRY_GLOBALPTR      8   /* Machine Value (MIPS GP) size == 0 */
  476. #define DIR_ENTRY_TLS            9   /* TLS Directory */
  477. #define DIR_ENTRY_LOAD_CONFIG   10   /* Load Configuration Directory */
  478. #define DIR_ENTRY_BOUND_IMPORT  11   /* Bound Import Directory in headers */
  479. #define DIR_ENTRY_IAT           12   /* Import Address Table */
  480.  
  481. typedef struct {
  482.     unsigned long   ImageBase;
  483.     unsigned long   SectionAlignment;
  484.     unsigned long   FileAlignment;
  485.     unsigned short  MajorOperatingSystemVersion;
  486.     unsigned short  MinorOperatingSystemVersion;
  487.     unsigned short  MajorImageVersion;
  488.     unsigned short  MinorImageVersion;
  489.     unsigned short  MajorSubsystemVersion;
  490.     unsigned short  MinorSubsystemVersion;
  491.     unsigned long   Reserved1 __attribute__((packed));
  492.     unsigned long   SizeOfImage;
  493.     unsigned long   SizeOfHeaders;
  494.     unsigned long   CheckSum;
  495.     unsigned short  Subsystem;
  496.     unsigned short  DllCharacteristics;
  497.     unsigned long   SizeOfStackReserve __attribute__((packed));
  498.     unsigned long   SizeOfStackCommit;
  499.     unsigned long   SizeOfHeapReserve;
  500.     unsigned long   SizeOfHeapCommit;
  501.     unsigned long   LoaderFlags;
  502.     unsigned long   NumberOfDataDirs;
  503.     PE_DATA_DIR DataDirectory[PE_DIRS];
  504. } PE_OPT_HDR, *PPE_OPT_HDR;
  505.  
  506. typedef struct {
  507.     unsigned long  BaseOfBss;
  508.     unsigned long  GprMask;
  509.     unsigned long  CprMask[4];
  510.     unsigned long  GpValue;
  511. } PE_ROM_OPT_HDR, *PPE_ROM_OPT_HDR;
  512.  
  513. typedef struct {
  514.     unsigned short magic;    /* PE */
  515.     unsigned short pad;
  516.     COFF_HDR c __attribute__((packed));
  517.     OPT_HDR o __attribute__((packed));
  518.     PE_OPT_HDR p __attribute__((packed));
  519. } PE_HDR, *PPE_HDR;
  520.  
  521. /*
  522. // Subsystem Values NT
  523. */
  524. #define SUBSYS_UNKNOWN       0   /* Unknown subsystem. */
  525. #define SUBSYS_NATIVE        1   /* doesn't require a subsystem. */
  526. #define SUBSYS_WINDOWS_GUI   2   /* runs in the Windows GUI subsystem. */
  527. #define SUBSYS_WINDOWS_CUI   3   /* runs in the Windows character subsystem. */
  528. #define SUBSYS_OS2_CUI       5   /* runs in the OS/2 character subsystem. */
  529. #define SUBSYS_POSIX_CUI     7   /* runs in the Posix character subsystem. */
  530.  
  531.  
  532.     
  533. /********************** SECTION HEADER **********************/
  534.  
  535. typedef struct scnhdr {
  536.     char                s_name[8];    /* section name            */
  537.     unsigned long        s_vsize;    /* virtual size when loaded (image) */
  538.     unsigned long        s_vaddr;    /* virtual address        */
  539.     unsigned long        s_size;        /* raw data size            */
  540.     unsigned long        s_scnptr;    /* file ptr to raw data for section */
  541.     unsigned long        s_relptr;    /* file ptr to relocation    */
  542.     unsigned long        s_lnnoptr;    /* file ptr to line numbers    */
  543.     unsigned short        s_nreloc;    /* number of relocation entries    */
  544.     unsigned short        s_nlnno;    /* number of line number entries*/
  545.     unsigned long        s_flags;    /* characteristics            */
  546. } SCNHDR, *PSCNHDR;
  547. /*
  548.  * names of "special" sections
  549.  */
  550. #define _TEXT    ".text"
  551. #define _DATA    ".data"
  552. #define _BSS    ".bss"
  553. #define _COMMENT ".comment"
  554. #define _LIB     ".lib"
  555. #define _EDATA    ".edata"    /* export info */
  556. #define _IDATA    ".idata"    /* import info */
  557. #define _RDATA  ".rdata"    /* read only data + debug directory info */
  558. #define _RELOC  ".reloc"    /* PE image fixups */
  559. #define _RSRC   ".rsrc"        /* windows resources */
  560. #define _PDATA  ".pdata"
  561. #define _DEBUG  ".debug"
  562. /*
  563.  * s_flags "type"
  564.  */
  565. #define STYP_TEXT          (0x00000020) /* section contains text only */
  566. #define STYP_DATA          (0x00000040) /* section contains data only */
  567. #define STYP_BSS          (0x00000080) /* section contains bss only */
  568. #define STYP_INFO          (0x00000100) /* section contains comments or something */
  569. #define STYP_REMOVE          (0x00000800) /* don't include section in loaded image */
  570. #define STYP_COMDAT          (0x00001000) /* section contents comdat */
  571. #define STYP_FARDATA      (0x00008000)
  572. #define STYP_PURGABLE     (0x00020000)
  573. #define STYP_16BIT          (0x00020000)
  574. #define STYP_MEMLOCK      (0x00040000)
  575. #define STYP_PRELOAD      (0x00080000)
  576. #define STYP_ALIGNMENT      (0x00700000)
  577. #define STYP_ALGN1          (0x00100000)
  578. #define STYP_ALGN2          (0x00200000)
  579. #define STYP_ALGN4          (0x00300000) /* default for emx,djgpp */
  580. #define STYP_ALGN8          (0x00400000)
  581. #define STYP_ALGN16          (0x00500000) /* default for NT */
  582. #define STYP_ALGN32          (0x00600000)
  583. #define STYP_ALGN64          (0x00700000)
  584. #define STYP_NRELOC_OVFL  (0x01000000) /* section contains extended relocations */
  585. #define STYP_DISCARDABLE  (0x02000000) /* section can be discarded */
  586. #define STYP_NOT_CACHED   (0x04000000) /* section is not cachable */
  587. #define STYP_NOT_PAGED    (0x08000000) /* section is not pageable */
  588. #define STYP_SHARED       (0x10000000) /* section is shareable */
  589. #define STYP_EXECUTE      (0x20000000) /* section is executable */
  590. #define STYP_READ         (0x40000000) /* section is readable */
  591. #define STYP_WRITE        (0x80000000) /* section is writeable */
  592.  
  593. /* linux style */
  594. #define COFF_STYP_REG     0x00 /* regular segment                          */
  595. #define COFF_STYP_DSECT   0x01 /* dummy segment                            */
  596. #define COFF_STYP_NOLOAD  0x02 /* no-load segment                          */
  597. #define COFF_STYP_GROUP   0x04 /* group segment                            */
  598. #define COFF_STYP_PAD     0x08 /* .pad segment                             */
  599. #define COFF_STYP_COPY    0x10 /* copy section                             */
  600. #define COFF_STYP_TEXT    0x20 /* .text segment                            */
  601. #define COFF_STYP_DATA    0x40 /* .data segment                            */
  602. #define COFF_STYP_BSS     0x80 /* .bss segment                             */
  603. #define COFF_STYP_INFO   0x200 /* .comment section                         */
  604. #define COFF_STYP_OVER   0x400 /* overlay section                          */
  605. #define COFF_STYP_LIB    0x800 /* library section                          */
  606.  
  607. /*
  608.  * Shared libraries have the following section header in the data field for
  609.  * each library.
  610.  */
  611.  
  612. struct COFF_slib {
  613.   char        sl_entsz[4];    /* Size of this entry               */
  614.   char        sl_pathndx[4];    /* size of the header field         */
  615. };
  616.  
  617. #define    COFF_SLIBHD    struct COFF_slib
  618. #define    COFF_SLIBSZ    sizeof(COFF_SLIBHD)
  619.  
  620. /********************** LINE NUMBERS **********************/
  621.  
  622. /* 1 line number entry for every "breakpointable" source line in a section.
  623.  * Line numbers are grouped on a per function basis; first entry in a function
  624.  * grouping will have l_lnno = 0 and in place of physical address will be the
  625.  * symbol table index of the function name.
  626.  */
  627. typedef struct coff_lineno{
  628.     union {
  629.         unsigned long l_symndx __attribute__((packed));    /* function name symbol index, iff l_lnno == 0 */
  630.         unsigned long l_vaddr __attribute__((packed));    /* RVA of line number */
  631.     } l_addr;
  632.     unsigned short l_lnno;                        /* line number */
  633. } LINENO, *PLINENO;
  634. #define COFF_LINENO_SIZE (6)
  635.  
  636. /********************** SYMBOLS **********************/
  637.  
  638. #define E_SYMNMLEN    8    /* # characters in a symbol name    */
  639. #define E_FILNMLEN    14    /* # characters in a file name        */
  640. #define E_DIMNUM    4    /* # array dimensions in auxiliary entry */
  641. #define COFF_E_SYMNMLEN     8
  642. #define COFF_E_FILNMLEN    14
  643. #define COFF_E_DIMNUM     4
  644.  
  645. struct COFF_symbol
  646. {
  647.   union {
  648.     char e_name[E_SYMNMLEN];
  649.     struct {
  650.       unsigned long e_zeroes __attribute__((packed)); /* if 0 use string tbl */
  651.       unsigned long e_offset __attribute__((packed)); /* offset into string tbl */
  652.     } e;
  653.   } e;
  654.   unsigned long e_value __attribute__((packed));
  655.   short e_scnum;                /* section number */
  656.   unsigned short e_type;        /* type */
  657.   unsigned char e_sclass;        /* storage class */
  658.   unsigned char e_numaux;        /* number of aux symbols */
  659. };
  660. typedef struct COFF_symbol COFF_SYMBOL, *PCOFF_SYMBOL;
  661. #define COFF_SYMBOL_SIZE (18)
  662.  
  663. union COFF_auxent {
  664.     struct {
  665.         unsigned long x_tagndx __attribute__((packed));/* str, un, or enum tag indx */
  666.         union {
  667.             struct {
  668.                 unsigned short  x_lnno;    /* declaration line number */
  669.                 unsigned short  x_size; /* str/union/array size */
  670.             } x_lnsz;
  671.             unsigned long x_fsize __attribute__((packed));/* size of function */
  672.         } x_misc;
  673.         union {
  674.             struct { /* if ISFCN, tag, or .bb */
  675.                 unsigned long x_lnnoptr __attribute__((packed));/* ptr to fcn line # */
  676.                 unsigned long x_next __attribute__((packed));    /* ptr to next fcn */
  677.             } x_fcn;
  678.             struct { /* if ISARY, up to 4 dimen. */
  679.                 unsigned short x_dimen[E_DIMNUM];
  680.             } x_ary;
  681.         } x_fcnary;
  682.         unsigned short x_tvndx;    /* tv index */
  683.     } x_sym;
  684.  
  685.     union {
  686.         char x_fname[E_FILNMLEN];
  687.         struct {
  688.             unsigned long x_zeroes __attribute__((packed));
  689.             unsigned long x_offset __attribute__((packed));
  690.         } x_n;
  691.     } x_file;
  692.  
  693.     struct {
  694.         unsigned long x_scnlen __attribute__((packed));        /* section length */
  695.         unsigned short x_nreloc;                    /* # relocation entries */
  696.         unsigned short x_nlinno;                    /* # line numbers */
  697.         unsigned long cksum __attribute__((packed)); /* cksum for communal NT */
  698.         short x_scnum;   /* section number to associate with */
  699.         char x_sel;        /* communal selection type NT */
  700.     } x_scn;
  701.  
  702.         struct {
  703.         unsigned long x_tvfill __attribute__((packed));        /* tv fill value */
  704.         unsigned short x_tvlen;                        /* length of .tv */
  705.         unsigned short x_tvran[2];                    /* tv range */
  706.     } x_tv;        /* info about .tv section (in auxent of symbol .tv)) */
  707. };
  708. typedef union COFF_auxent AUXENT, *PAUXENT;
  709.  
  710. #define COFF_AUXENT_SIZE COFF_SYMBOL_SIZE
  711.  
  712. #define _ETEXT    "etext"
  713.  
  714.  
  715. /* Relocatable symbols have number of the section in which they are defined,
  716.    or one of the following: */
  717.  
  718. #define SYM_UNDEF ((short)0)    /* undefined symbol */
  719. #define SYM_ABS      ((short)-1)    /* value of symbol is absolute */
  720. #define SYM_DEBUG ((short)-2)    /* debugging symbol -- value is meaningless */
  721. #define SYM_NTV      ((short)-3)    /* indicates symbol needs preload transfer vector */
  722. #define SYM_PTV      ((short)-4)    /* indicates symbol needs postload transfer vector*/
  723.  
  724. /*
  725.  * Type of a symbol, in e_type
  726.  */
  727. #define T_NULL        0x0000
  728. #define T_VOID        0x0001    /* function argument (only used by compiler) */
  729. #define T_CHAR        0x0002    /* character        */
  730. #define T_SHORT        0x0003    /* short integer    */
  731. #define T_INT        0x0004    /* integer        */
  732. #define T_LONG        0x0005    /* long integer        */
  733. #define T_FLOAT        0x0006    /* floating point    */
  734. #define T_DOUBLE    0x0007    /* double word        */
  735. #define T_STRUCT    0x0008    /* structure         */
  736. #define T_UNION        0x0009    /* union         */
  737. #define T_ENUM        0x000A    /* enumeration         */
  738. #define T_MOE        0x000B    /* member of enumeration*/
  739. #define T_UCHAR        0x000C    /* unsigned character    */
  740. #define T_USHORT    0x000D    /* unsigned short    */
  741. #define T_UINT        0x000E    /* unsigned integer    */
  742. #define T_ULONG        0x000F    /* unsigned long    */
  743. #define T_LNGDBL    0x0010    /* long double        */
  744. #define T_PCODE        0x8000    /* pcode */
  745.  
  746. /*
  747.  * derived types, in e_type
  748. */
  749. #define DT_NON        (0)    /* no derived type */
  750. #define DT_PTR        (1)    /* pointer */
  751. #define DT_FCN        (2)    /* function */
  752. #define DT_ARY        (3)    /* array */
  753.  
  754. /* type packing constants */
  755. #define N_BTMASK    (0x000F)
  756. #define N_TMASK        (0x0030)
  757. #define N_TMASK1    (0x00C0)
  758. #define N_TMASK2    (0x00F0)
  759. #define N_BTSHFT    (4)
  760. #define N_TSHIFT    (2)
  761.   
  762. #define BTYPE(x)    ((x) & N_BTMASK)    /* basic type */
  763.  
  764. /* this stuff is bugged [NDC] */
  765. #define ISPTR(x)    (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  766. #define ISFCN(x)    (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  767. #define ISARY(x)    (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  768. #define ISTAG(x)    ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
  769. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  770.  
  771. /********************** STORAGE CLASSES **********************/
  772.  
  773. #define C_EFCN        0xff    /* physical end of function    */
  774. #define C_NULL        0x0000
  775. #define C_AUTO        0x0001    /* automatic variable        */
  776. #define C_EXT        0x0002    /* external symbol        */
  777. #define C_STAT        0x0003    /* static            */
  778. #define C_REG        0x0004    /* register variable        */
  779. #define C_EXTDEF    0x0005    /* external definition        */
  780. #define C_LABEL        0x0006    /* label            */
  781. #define C_ULABEL    0x0007    /* undefined label        */
  782. #define C_MOS        0x0008    /* member of structure        */
  783. #define C_ARG        0x0009    /* function argument        */
  784. #define C_STRTAG    0x000A    /* structure tag        */
  785. #define C_MOU        0x000B    /* member of union        */
  786. #define C_UNTAG        0x000C    /* union tag            */
  787. #define C_TPDEF        0x000D    /* type definition        */
  788. #define C_USTATIC    0x000E    /* undefined static        */
  789. #define C_ENTAG        0x000F    /* enumeration tag        */
  790. #define C_MOE        0x0010    /* member of enumeration    */
  791. #define C_REGPARM    0x0011    /* register parameter        */
  792. #define C_FIELD        0x0012    /* bit field            */
  793. #define C_AUTOARG    0x0013    /* auto argument        */
  794. #define C_LASTENT    0x0014    /* dummy entry (end of block)    */
  795. #define C_FAREXT    0x0044    /* far external NT */
  796. #define C_BLOCK        0x0064    /* ".bb" or ".eb"        */
  797. #define C_FCN        0x0065    /* ".bf" or ".ef"        */
  798. #define C_EOS        0x0066    /* end of structure        */
  799. #define C_FILE        0x0067    /* file name            */
  800. #define C_LINE        0x0068    /* line # reformatted as symbol table entry */
  801. #define C_SECTION    0x0068    /* new NT section */
  802. #define C_ALIAS         0x0069    /* duplicate tag        */
  803. #define C_WEAKEXT    0x0069    /* new NT weak external */
  804. #define C_HIDDEN    0x0070    /* ext symbol in dmert public lib */
  805.  
  806.  
  807. /********************** RELOCATION DIRECTIVES **********************/
  808.  
  809. struct coff_reloc {
  810.   union {
  811.     unsigned long r_vaddr __attribute__((packed));
  812.  /* set to real count when STYP_RELOC_OVFL is set NT */
  813.     unsigned long r_count __attribute__((packed));
  814.   }u;
  815.   unsigned long r_symndx __attribute__((packed));
  816.   unsigned short r_type;
  817. }; 
  818.  
  819. typedef struct coff_reloc COFF_RELOC, *PCOFF_RELOC;
  820. #define COFF_RELOC_SIZE (10)
  821.  
  822. /*
  823. // NT I386 relocation types in r_type.
  824. */
  825.  
  826. #define REL_I386_ABSOLUTE  0x0000  /* Reference is absolute, no relocation is necessary */
  827. #define REL_I386_DIR16     0x0001  /* Direct 16-bit reference to the symbols virtual address */
  828. #define REL_I386_REL16     0x0002  /* PC-relative 16-bit reference to the symbols virtual address */
  829. #define REL_I386_DIR32     0x0006  /* Direct 32-bit reference to the symbols virtual address */
  830. #define REL_I386_DIR32NB   0x0007  /* Direct 32-bit reference to the symbols virtual address, base not included */
  831. #define REL_I386_SEG12     0x0009  /* Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address */
  832. #define REL_I386_SECTION   0x000A
  833. #define REL_I386_SECREL    0x000B
  834. #define REL_I386_REL32     0x0014  /* PC-relative 32-bit reference to the symbols virtual address */
  835.  
  836. /*
  837. // NT MIPS relocation types.
  838. */
  839.  
  840. #define REL_MIPS_ABSOLUTE         0x0000  /* Reference is absolute, no relocation is necessary */
  841. #define REL_MIPS_REFHALF          0x0001
  842. #define REL_MIPS_REFWORD          0x0002
  843. #define REL_MIPS_JMPADDR          0x0003
  844. #define REL_MIPS_REFHI            0x0004
  845. #define REL_MIPS_REFLO            0x0005
  846. #define REL_MIPS_GPREL            0x0006
  847. #define REL_MIPS_LITERAL          0x0007
  848. #define REL_MIPS_SECTION          0x000A
  849. #define REL_MIPS_SECREL           0x000B
  850. #define REL_MIPS_SECRELLO         0x000C  /* Low 16-bit section relative referemce (used for >32k TLS) */
  851. #define REL_MIPS_SECRELHI         0x000D  /* High 16-bit section relative reference (used for >32k TLS) */
  852. #define REL_MIPS_REFWORDNB        0x0022
  853. #define REL_MIPS_PAIR             0x0025
  854.  
  855. /*
  856. // NT Alpha Relocation types.
  857. */
  858.  
  859. #define REL_ALPHA_ABSOLUTE        0x0000
  860. #define REL_ALPHA_REFLONG         0x0001
  861. #define REL_ALPHA_REFQUAD         0x0002
  862. #define REL_ALPHA_GPREL32         0x0003
  863. #define REL_ALPHA_LITERAL         0x0004
  864. #define REL_ALPHA_LITUSE          0x0005
  865. #define REL_ALPHA_GPDISP          0x0006
  866. #define REL_ALPHA_BRADDR          0x0007
  867. #define REL_ALPHA_HINT            0x0008
  868. #define REL_ALPHA_INLINE_REFLONG  0x0009
  869. #define REL_ALPHA_REFHI           0x000A
  870. #define REL_ALPHA_REFLO           0x000B
  871. #define REL_ALPHA_PAIR            0x000C
  872. #define REL_ALPHA_MATCH           0x000D
  873. #define REL_ALPHA_SECTION         0x000E
  874. #define REL_ALPHA_SECREL          0x000F
  875. #define REL_ALPHA_REFLONGNB       0x0010
  876. #define REL_ALPHA_SECRELLO        0x0011  /* Low 16-bit section relative reference */
  877. #define REL_ALPHA_SECRELHI        0x0012  /* High 16-bit section relative reference */
  878.  
  879. /*
  880. // NT IBM PowerPC relocation types.
  881. */
  882.  
  883. #define REL_PPC_ABSOLUTE          0x0000  /* NOP */
  884. #define REL_PPC_ADDR64            0x0001  /* 64-bit address */
  885. #define REL_PPC_ADDR32            0x0002  /* 32-bit address */
  886. #define REL_PPC_ADDR24            0x0003  /* 26-bit address, shifted left 2 (branch absolute) */
  887. #define REL_PPC_ADDR16            0x0004  /* 16-bit address */
  888. #define REL_PPC_ADDR14            0x0005  /* 16-bit address, shifted left 2 (load doubleword) */
  889. #define REL_PPC_REL24             0x0006  /* 26-bit PC-relative offset, shifted left 2 (branch relative) */
  890. #define REL_PPC_REL14             0x0007  /* 16-bit PC-relative offset, shifted left 2 (br cond relative) */
  891. #define REL_PPC_TOCREL16          0x0008  /* 16-bit offset from TOC base */
  892. #define REL_PPC_TOCREL14          0x0009  /* 16-bit offset from TOC base, shifted left 2 (load doubleword) */
  893.  
  894. #define REL_PPC_ADDR32NB          0x000A  /* 32-bit addr w/o image base */
  895. #define REL_PPC_SECREL            0x000B  /* va of containing section (as in an image sectionhdr) */
  896. #define REL_PPC_SECTION           0x000C  /* sectionheader number */
  897. #define REL_PPC_IFGLUE            0x000D  /* substitute TOC restore instruction iff symbol is glue code */
  898. #define REL_PPC_IMGLUE            0x000E  /* symbol is glue code; virtual address is TOC restore instruction */
  899. #define REL_PPC_SECREL16          0x000F  /* va of containing section (limited to 16 bits) */
  900. #define REL_PPC_REFHI             0x0010
  901. #define REL_PPC_REFLO             0x0011
  902. #define REL_PPC_PAIR              0x0012
  903.  
  904. #define REL_PPC_TYPEMASK          0x00FF  /* mask to isolate above values in IMAGE_RELOCATION.Type */
  905.  
  906. /* Flag bits in IMAGE_RELOCATION.TYPE */
  907.  
  908. #define REL_PPC_NEG               0x0100  /* subtract reloc value rather than adding it */
  909. #define REL_PPC_BRTAKEN           0x0200  /* fix branch prediction bit to predict branch taken */
  910. #define REL_PPC_BRNTAKEN          0x0400  /* fix branch prediction bit to predict branch not taken */
  911. #define REL_PPC_TOCDEFN           0x0800  /* toc slot defined in file (or, data in toc) */
  912.  
  913. /*
  914. // NT Based relocation format.
  915. */
  916.  
  917. typedef struct {
  918.     unsigned long   RVA;
  919.     unsigned long   size;
  920. } PE_FIXUP, *PPE_FIXUP;
  921.  
  922.  
  923. /*
  924. // NT Based relocation types.
  925. */
  926.  
  927. #define REL_BASED_ABSOLUTE              0
  928. #define REL_BASED_HIGH                  1
  929. #define REL_BASED_LOW                   2
  930. #define REL_BASED_HIGHLOW               3
  931. #define REL_BASED_HIGHADJ               4
  932. #define REL_BASED_MIPS_JMPADDR          5
  933.  
  934.  
  935. #define DEFAULT_UNIX_ALIGNMENT 4
  936. #define DEFAULT_NT_ALIGNMENT 16
  937.  
  938. /*
  939. // NT Communal selection types.
  940. */
  941.  
  942. #define COMDAT_SELECT_NODUPLICATES    1
  943. #define COMDAT_SELECT_ANY             2
  944. #define COMDAT_SELECT_SAME_SIZE       3
  945. #define COMDAT_SELECT_EXACT_MATCH     4
  946. #define COMDAT_SELECT_ASSOCIATIVE     5
  947. #define COMDAT_SELECT_LARGEST         6
  948. #define COMDAT_SELECT_NEWEST          7
  949.  
  950. #define WEAK_EXTERN_SEARCH_NOLIBRARY  1
  951. #define WEAK_EXTERN_SEARCH_LIBRARY    2
  952. #define WEAK_EXTERN_SEARCH_ALIAS      3
  953.  
  954.  
  955. /*
  956. // NT DLL support.
  957. */
  958.  
  959. /*
  960. // Export Format
  961. */
  962.  
  963. typedef struct {
  964.     unsigned long   Flags;
  965.     unsigned long   TimeDate;
  966.     unsigned short  MajorVersion;
  967.     unsigned short  MinorVersion;
  968.     unsigned long   DllNameRVA;
  969.     unsigned long   OrdinalBase;
  970.     unsigned long   NumFuncs;
  971.     unsigned long   NumNames;
  972.     unsigned long   AddressTableRVA;
  973.     unsigned long   NameTableRVA;
  974.     unsigned long   OrdinalTableRVA;
  975. } PE_EXPORT_DIR, *PPE_EXPORT_DIR;
  976.  
  977. /*
  978. // Import Format
  979. */
  980.  
  981. typedef struct {
  982.     unsigned long ILT_RVA;         /* RVA of the Import Lookup Table */
  983.     unsigned long timedate;
  984.     unsigned long ForwarderChain;  /* ??? */
  985.     unsigned long DllNameRVA;      /* Address of asciiz dll name */
  986.     unsigned long IAT_RVA;         /* RVA of the Import Address Table */
  987. } PE_IMPORT_DIR, *PPE_IMPORT_DIR;
  988.  
  989. typedef struct {
  990.     unsigned short hint;
  991.     char name[1];
  992. } PE_HINT_NAME, *PPE_HINT_NAME;
  993.  
  994.  
  995. typedef struct {
  996.     union {
  997.         unsigned char*  ForwarderString;
  998.         unsigned long* Function;
  999.         unsigned long Ordinal;
  1000.         PPE_HINT_NAME AddressOfData;
  1001.     } u1;
  1002. } PE_THUNK_DATA, *PPE_THUNK_DATA;
  1003.  
  1004. #define IMAGE_ORDINAL_FLAG 0x80000000
  1005. #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
  1006. #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
  1007.  
  1008. typedef struct _IMAGE_IMPORT_DESCRIPTOR {
  1009.     union {
  1010.      unsigned long   Characteristics; /* 0 for terminating null import descriptor */
  1011.      PPE_THUNK_DATA OriginalFirstThunk; /* RVA to original unbound IAT */
  1012.     } u;
  1013.     unsigned long   TimeDateStamp;  /* 0 if not bound, */
  1014.                                     /* -1 if bound, and real date\time stamp */
  1015.                          /* in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND) */
  1016.                           /* O.W. date/time stamp of DLL bound to (Old BIND) */
  1017.  
  1018.     long   ForwarderChain;         /* -1 if no forwarders */
  1019.     unsigned long   Name;
  1020.     PPE_THUNK_DATA FirstThunk;  /* RVA to IAT (if bound this IAT has actual addresses) */
  1021. } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
  1022.  
  1023. /*
  1024.     New format import descriptors pointed to by
  1025.     DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
  1026. */
  1027.  
  1028. typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR {
  1029.     unsigned long   TimeDateStamp;
  1030.     unsigned short    OffsetModuleName;
  1031.     unsigned short    NumberOfModuleForwarderRefs;
  1032. /* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
  1033. } IMAGE_BOUND_IMPORT_DESCRIPTOR, *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
  1034.  
  1035. typedef struct _IMAGE_BOUND_FORWARDER_REF {
  1036.     unsigned long   TimeDateStamp;
  1037.     unsigned short    OffsetModuleName;
  1038.     unsigned short    Reserved;
  1039. } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
  1040.  
  1041.  
  1042. /*
  1043. // Thread Local Storage
  1044. */
  1045.  
  1046. typedef void (*PIMAGE_TLS_CALLBACK) ();
  1047.  
  1048. typedef struct _IMAGE_TLS_DIRECTORY {
  1049.     unsigned long   StartAddressOfRawData;
  1050.     unsigned long   EndAddressOfRawData;
  1051.     unsigned long*  AddressOfIndex;
  1052.     PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
  1053.     unsigned long   SizeOfZeroFill;
  1054.     unsigned long   Characteristics;
  1055. } IMAGE_TLS_DIRECTORY, *PIMAGE_TLS_DIRECTORY;
  1056.  
  1057.  
  1058. /*
  1059. // Resource Format.
  1060. */
  1061.  
  1062. /*
  1063. // Resource directory consists of two counts, following by a variable length
  1064. // array of directory entries.  The first count is the number of entries at
  1065. // beginning of the array that have actual names associated with each entry.
  1066. // The entries are in ascending order, case insensitive strings.  The second
  1067. // count is the number of entries that immediately follow the named entries.
  1068. // This second count identifies the number of entries that have 16-bit integer
  1069. // Ids as their name.  These entries are also sorted in ascending order.
  1070. //
  1071. // This structure allows fast lookup by either name or number, but for any
  1072. // given resource entry only one form of lookup is supported, not both.
  1073. // This is consistant with the syntax of the .RC file and the .RES file.
  1074. */
  1075.  
  1076. typedef struct _IMAGE_RESOURCE_DIRECTORY {
  1077.     unsigned long   Characteristics;
  1078.     unsigned long   TimeDateStamp;
  1079.     unsigned short    MajorVersion;
  1080.     unsigned short    MinorVersion;
  1081.     unsigned short    NumberOfNamedEntries;
  1082.     unsigned short    NumberOfIdEntries;
  1083. /*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
  1084. } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
  1085.  
  1086. #define IMAGE_RESOURCE_NAME_IS_STRING        0x80000000
  1087. #define IMAGE_RESOURCE_DATA_IS_DIRECTORY     0x80000000
  1088.  
  1089. /*
  1090. // Each directory contains the 32-bit Name of the entry and an offset,
  1091. // relative to the beginning of the resource directory of the data associated
  1092. // with this directory entry.  If the name of the entry is an actual text
  1093. // string instead of an integer Id, then the high order bit of the name field
  1094. // is set to one and the low order 31-bits are an offset, relative to the
  1095. // beginning of the resource directory of the string, which is of type
  1096. // IMAGE_RESOURCE_DIRECTORY_STRING.  Otherwise the high bit is clear and the
  1097. // low-order 16-bits are the integer Id that identify this resource directory
  1098. // entry. If the directory entry is yet another resource directory (i.e. a
  1099. // subdirectory), then the high order bit of the offset field will be
  1100. // set to indicate this.  Otherwise the high bit is clear and the offset
  1101. // field points to a resource data entry.
  1102. */
  1103.  
  1104. typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
  1105.     union {
  1106.         struct {
  1107.             unsigned long NameOffset:31;
  1108.             unsigned long NameIsString:1;
  1109.         } s;
  1110.         unsigned long   Name;
  1111.         unsigned short    Id;
  1112.     } u1;
  1113.     union {
  1114.         unsigned long   OffsetToData;
  1115.         struct {
  1116.             unsigned long   OffsetToDirectory:31;
  1117.             unsigned long   DataIsDirectory:1;
  1118.         } s;
  1119.     } u2;
  1120. } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
  1121.  
  1122. /*
  1123. // For resource directory entries that have actual string names, the Name
  1124. // field of the directory entry points to an object of the following type.
  1125. // All of these string objects are stored together after the last resource
  1126. // directory entry and before the first resource data object.  This minimizes
  1127. // the impact of these variable length objects on the alignment of the fixed
  1128. // size directory entry objects.
  1129. */
  1130.  
  1131. typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
  1132.     unsigned short    Length;
  1133.     char              NameString[ 1 ];
  1134. } IMAGE_RESOURCE_DIRECTORY_STRING, *PIMAGE_RESOURCE_DIRECTORY_STRING;
  1135.  
  1136.  
  1137. typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
  1138.     unsigned short   Length;
  1139.     unsigned short   NameString[ 1 ];
  1140. } IMAGE_RESOURCE_DIR_STRING_U, *PIMAGE_RESOURCE_DIR_STRING_U;
  1141.  
  1142.  
  1143. /*
  1144. // Each resource data entry describes a leaf node in the resource directory
  1145. // tree.  It contains an offset, relative to the beginning of the resource
  1146. // directory of the data for the resource, a size field that gives the number
  1147. // of bytes of data at that offset, a CodePage that should be used when
  1148. // decoding code point values within the resource data.  Typically for new
  1149. // applications the code page would be the unicode code page.
  1150. */
  1151.  
  1152. typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
  1153.     unsigned long   OffsetToData;
  1154.     unsigned long   Size;
  1155.     unsigned long   CodePage;
  1156.     unsigned long   Reserved;
  1157. } IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY;
  1158.  
  1159. /*
  1160. // Load Configuration Directory Entry
  1161. */
  1162.  
  1163. typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
  1164.     unsigned long   Characteristics;
  1165.     unsigned long   TimeDateStamp;
  1166.     unsigned short    MajorVersion;
  1167.     unsigned short    MinorVersion;
  1168.     unsigned long   GlobalFlagsClear;
  1169.     unsigned long   GlobalFlagsSet;
  1170.     unsigned long   CriticalSectionDefaultTimeout;
  1171.     unsigned long   DeCommitFreeBlockThreshold;
  1172.     unsigned long   DeCommitTotalFreeThreshold;
  1173.     void*           LockPrefixTable;
  1174.     unsigned long   MaximumAllocationSize;
  1175.     unsigned long   VirtualMemoryThreshold;
  1176.     unsigned long   ProcessHeapFlags;
  1177.     unsigned long   Reserved[ 4 ];
  1178. } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
  1179.  
  1180.  
  1181. /*
  1182. // Function table entry format for MIPS/ALPHA images.  Function table is
  1183. // pointed to by the IMAGE_DIRECTORY_ENTRY_EXCEPTION directory entry.
  1184. // This definition duplicates ones in ntmips.h and ntalpha.h for use
  1185. // by portable image file mungers.
  1186. */
  1187.  
  1188. typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
  1189.     unsigned long BeginAddress;
  1190.     unsigned long EndAddress;
  1191.     void* ExceptionHandler;
  1192.     void* HandlerData;
  1193.     unsigned long PrologEndAddress;
  1194. } IMAGE_RUNTIME_FUNCTION_ENTRY, *PIMAGE_RUNTIME_FUNCTION_ENTRY;
  1195.  
  1196. /*
  1197. // Debug Format
  1198. */
  1199.  
  1200. typedef struct _IMAGE_DEBUG_DIRECTORY {
  1201.     unsigned long   Characteristics;
  1202.     unsigned long   TimeDateStamp;
  1203.     unsigned short    MajorVersion;
  1204.     unsigned short    MinorVersion;
  1205.     unsigned long   Type;
  1206.     unsigned long   SizeOfData;
  1207.     unsigned long   AddressOfRawData;
  1208.     unsigned long   PointerToRawData;
  1209. } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
  1210.  
  1211. #define IMAGE_DEBUG_TYPE_UNKNOWN          0
  1212. #define IMAGE_DEBUG_TYPE_COFF             1
  1213. #define IMAGE_DEBUG_TYPE_CODEVIEW         2
  1214. #define IMAGE_DEBUG_TYPE_FPO              3
  1215. #define IMAGE_DEBUG_TYPE_MISC             4
  1216. #define IMAGE_DEBUG_TYPE_EXCEPTION        5
  1217. #define IMAGE_DEBUG_TYPE_FIXUP            6
  1218. #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC      7
  1219. #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC    8
  1220.  
  1221. typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
  1222.     unsigned long   NumberOfSymbols;
  1223.     unsigned long   LvaToFirstSymbol;
  1224.     unsigned long   NumberOfLinenumbers;
  1225.     unsigned long   LvaToFirstLinenumber;
  1226.     unsigned long   RvaToFirstByteOfCode;
  1227.     unsigned long   RvaToLastByteOfCode;
  1228.     unsigned long   RvaToFirstByteOfData;
  1229.     unsigned long   RvaToLastByteOfData;
  1230. } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
  1231.  
  1232. #define FRAME_FPO       0
  1233. #define FRAME_TRAP      1
  1234. #define FRAME_TSS       2
  1235. #define FRAME_NONFPO    3
  1236.  
  1237. typedef struct _FPO_DATA {
  1238.     unsigned long       ulOffStart;      /* offset 1st byte of function code */
  1239.     unsigned long       cbProcSize;      /* # bytes in function */
  1240.     unsigned long       cdwLocals;       /* # bytes in locals/4 */
  1241.     unsigned short        cdwParams;     /* # bytes in params/4 */
  1242.     unsigned short        cbProlog : 8;  /* # bytes in prolog */
  1243.     unsigned short        cbRegs   : 3;  /* # regs saved */
  1244.     unsigned short        fHasSEH  : 1;  /* TRUE if SEH in func */
  1245.     unsigned short        fUseBP   : 1;  /* TRUE if EBP has been allocated */
  1246.     unsigned short        reserved : 1;  /* reserved for future use */
  1247.     unsigned short        cbFrame  : 2;  /* frame type */
  1248. } FPO_DATA, *PFPO_DATA;
  1249. #define SIZEOF_RFPO_DATA 16
  1250.  
  1251.  
  1252. #define IMAGE_DEBUG_MISC_EXENAME    1
  1253.  
  1254. typedef struct _IMAGE_DEBUG_MISC {
  1255.     unsigned long   DataType;   /* type of misc data, see defines */
  1256.     unsigned long   Length;     /* total length of record, rounded to four */
  1257.                                 /* byte multiple. */
  1258.     unsigned char   Unicode;    /* TRUE if data is unicode string */
  1259.     unsigned char   Reserved[ 3 ];
  1260.     unsigned char   Data[ 1 ];     /* Actual data */
  1261. } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
  1262.  
  1263.  
  1264. /*
  1265. // Function table extracted from MIPS/ALPHA images.  Does not contain
  1266. // information needed only for runtime support.  Just those fields for
  1267. // each entry needed by a debugger.
  1268. */
  1269.  
  1270. typedef struct _IMAGE_FUNCTION_ENTRY {
  1271.     unsigned long   StartingAddress;
  1272.     unsigned long   EndingAddress;
  1273.     unsigned long   EndOfPrologue;
  1274. } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
  1275.  
  1276. /*
  1277. // Debugging information can be stripped from an image file and placed
  1278. // in a separate .DBG file, whose file name part is the same as the
  1279. // image file name part (e.g. symbols for CMD.EXE could be stripped
  1280. // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
  1281. // flag in the Characteristics field of the file header.  The beginning of
  1282. // the .DBG file contains the following structure which captures certain
  1283. // information from the image file.  This allows a debug to proceed even if
  1284. // the original image file is not accessable.  This header is followed by
  1285. // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
  1286. // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
  1287. // the image file contain file offsets relative to the beginning of the
  1288. // .DBG file.
  1289. //
  1290. // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
  1291. // is left in the image file, but not mapped.  This allows a debugger to
  1292. // compute the name of the .DBG file, from the name of the image in the
  1293. // IMAGE_DEBUG_MISC structure.
  1294. */
  1295.  
  1296. typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
  1297.     unsigned short        Signature;
  1298.     unsigned short        Flags;
  1299.     unsigned short        Machine;
  1300.     unsigned short        Characteristics;
  1301.     unsigned long       TimeDateStamp;
  1302.     unsigned long       CheckSum;
  1303.     unsigned long       ImageBase;
  1304.     unsigned long       SizeOfImage;
  1305.     unsigned long       NumberOfSections;
  1306.     unsigned long       ExportedNamesSize;
  1307.     unsigned long       DebugDirectorySize;
  1308.     unsigned long       Reserved[ 3 ];/* Note: reserved[0] is 
  1309.                                         actually the section alignment */
  1310. } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
  1311.  
  1312. #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
  1313.  
  1314. /* ======================= ELF DEFS FROM LINUX ============================ */
  1315.  
  1316. #ifndef _LINUX_ELF_H
  1317. #define _LINUX_ELF_H
  1318.  
  1319. typedef unsigned long    Elf32_Addr;
  1320. typedef unsigned short    Elf32_Half;
  1321. typedef unsigned long    Elf32_Off;
  1322. typedef long            Elf32_Sword;
  1323. typedef unsigned long    Elf32_Word;
  1324.  
  1325. /* These constants are for the segment types stored in the image headers */
  1326. #define PT_NULL    0
  1327. #define PT_LOAD    1
  1328. #define PT_DYNAMIC 2
  1329. #define PT_INTERP  3
  1330. #define PT_NOTE    4
  1331. #define PT_SHLIB   5
  1332. #define PT_PHDR    6
  1333. #define PT_LOPROC  0x70000000
  1334. #define PT_HIPROC  0x7fffffff
  1335.  
  1336. /* These constants define the different elf file types */
  1337. #define ET_NONE   0
  1338. #define ET_REL    1
  1339. #define ET_EXEC   2
  1340. #define ET_DYN    3
  1341. #define ET_CORE   4
  1342. #define ET_LOPROC 5
  1343. #define ET_HIPROC 6
  1344.  
  1345. /* These constants define the various ELF target machines */
  1346. #define EM_NONE  0
  1347. #define EM_M32   1
  1348. #define EM_SPARC 2
  1349. #define EM_386   3
  1350. #define EM_68K   4
  1351. #define EM_88K   5
  1352. #define EM_486   6   /* Perhaps disused */
  1353. #define EM_860   7
  1354.  
  1355. /* This is the info that is needed to parse the dynamic section of the file */
  1356. #define DT_NULL        0
  1357. #define DT_NEEDED    1
  1358. #define DT_PLTRELSZ    2
  1359. #define DT_PLTGOT    3
  1360. #define DT_HASH        4
  1361. #define DT_STRTAB    5
  1362. #define DT_SYMTAB    6
  1363. #define DT_RELA        7
  1364. #define DT_RELASZ    8
  1365. #define DT_RELAENT    9
  1366. #define DT_STRSZ    10
  1367. #define DT_SYMENT    11
  1368. #define DT_INIT        12
  1369. #define DT_FINI        13
  1370. #define DT_SONAME    14
  1371. #define DT_RPATH     15
  1372. #define DT_SYMBOLIC    16
  1373. #define DT_REL        17
  1374. #define DT_RELSZ    18
  1375. #define DT_RELENT    19
  1376. #define DT_PLTREL    20
  1377. #define DT_DEBUG    21
  1378. #define DT_TEXTREL    22
  1379. #define DT_JMPREL    23
  1380. #define DT_LOPROC    0x70000000
  1381. #define DT_HIPROC    0x7fffffff
  1382.  
  1383. /* This info is needed when parsing the symbol table */
  1384. #define STB_LOCAL  0
  1385. #define STB_GLOBAL 1
  1386. #define STB_WEAK   2
  1387.  
  1388. #define STT_NOTYPE  0
  1389. #define STT_OBJECT  1
  1390. #define STT_FUNC    2
  1391. #define STT_SECTION 3
  1392. #define STT_FILE    4
  1393.  
  1394. #define ELF32_ST_BIND(x) ((x) >> 4)
  1395. #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
  1396.  
  1397. typedef struct dynamic{
  1398.   Elf32_Sword   d_tag;
  1399.   union{
  1400.     Elf32_Sword    d_val;
  1401.     Elf32_Addr    d_ptr;
  1402.   } d_un;
  1403. } Elf32_Dyn;
  1404.  
  1405. extern Elf32_Dyn _DYNAMIC [];
  1406.  
  1407. /* The following are used with relocations */
  1408. #define ELF32_R_SYM(x) ((x) >> 8)
  1409. #define ELF32_R_TYPE(x) ((x) & 0xff)
  1410.  
  1411. #define R_386_NONE    0
  1412. #define R_386_32    1
  1413. #define R_386_PC32    2
  1414. #define R_386_GOT32    3
  1415. #define R_386_PLT32    4
  1416. #define R_386_COPY    5
  1417. #define R_386_GLOB_DAT    6
  1418. #define R_386_JMP_SLOT    7
  1419. #define R_386_RELATIVE    8
  1420. #define R_386_GOTOFF    9
  1421. #define R_386_GOTPC    10
  1422. #define R_386_NUM    11
  1423.  
  1424. typedef struct elf32_rel {
  1425.   Elf32_Addr    r_offset;
  1426.   Elf32_Word    r_info;
  1427. } Elf32_Rel;
  1428.  
  1429. typedef struct elf32_rela{
  1430.   Elf32_Addr    r_offset;
  1431.   Elf32_Word    r_info;
  1432.   Elf32_Sword    r_addend;
  1433. } Elf32_Rela;
  1434.  
  1435. typedef struct elf32_sym{
  1436.   Elf32_Word    st_name;
  1437.   Elf32_Addr    st_value;
  1438.   Elf32_Word    st_size;
  1439.   unsigned char    st_info;
  1440.   unsigned char    st_other;
  1441.   Elf32_Half    st_shndx;
  1442. } Elf32_Sym;
  1443.  
  1444.  
  1445. #define EI_NIDENT    16
  1446.  
  1447. typedef struct elfhdr{
  1448.   unsigned char    e_ident[EI_NIDENT];
  1449.   Elf32_Half    e_type;
  1450.   Elf32_Half    e_machine;
  1451.   Elf32_Word    e_version;
  1452.   Elf32_Addr    e_entry;  /* Entry point */
  1453.   Elf32_Off        e_phoff;
  1454.   Elf32_Off        e_shoff;
  1455.   Elf32_Word    e_flags;
  1456.   Elf32_Half    e_ehsize;
  1457.   Elf32_Half    e_phentsize;
  1458.   Elf32_Half    e_phnum;
  1459.   Elf32_Half    e_shentsize;
  1460.   Elf32_Half    e_shnum;
  1461.   Elf32_Half    e_shstrndx;
  1462. } Elf32_Ehdr;
  1463.  
  1464. typedef struct elf_phdr{
  1465.   Elf32_Word    p_type;
  1466.   Elf32_Off        p_offset;
  1467.   Elf32_Addr    p_vaddr;
  1468.   Elf32_Addr    p_paddr;
  1469.   Elf32_Word    p_filesz;
  1470.   Elf32_Word    p_memsz;
  1471.   Elf32_Word    p_flags;
  1472.   Elf32_Word    p_align;
  1473. } Elf32_Phdr;
  1474.  
  1475. /* sh_type */
  1476. #define SHT_NULL    0
  1477. #define SHT_PROGBITS    1
  1478. #define SHT_SYMTAB    2
  1479. #define SHT_STRTAB    3
  1480. #define SHT_RELA    4
  1481. #define SHT_HASH    5
  1482. #define SHT_DYNAMIC    6
  1483. #define SHT_NOTE    7
  1484. #define SHT_NOBITS    8
  1485. #define SHT_REL        9
  1486. #define SHT_SHLIB    10
  1487. #define SHT_DYNSYM    11
  1488. #define SHT_NUM        12
  1489. #define SHT_LOPROC    0x70000000
  1490. #define SHT_HIPROC    0x7fffffff
  1491. #define SHT_LOUSER    0x80000000
  1492. #define SHT_HIUSER    0xffffffff
  1493.  
  1494. /* sh_flags */
  1495. #define SHF_WRITE        0x1
  1496. #define SHF_ALLOC        0x2
  1497. #define SHF_EXECINSTR    0x4
  1498. #define SHF_MASKPROC    0xf0000000
  1499.  
  1500. /* special section indexes */
  1501. #define SHN_UNDEF    0
  1502. #define SHN_LORESERVE    0xff00
  1503. #define SHN_LOPROC    0xff00
  1504. #define SHN_HIPROC    0xff1f
  1505. #define SHN_ABS        0xfff1
  1506. #define SHN_COMMON    0xfff2
  1507. #define SHN_HIRESERVE    0xffff
  1508.  
  1509. typedef struct {
  1510.   Elf32_Word    sh_name;
  1511.   Elf32_Word    sh_type;
  1512.   Elf32_Word    sh_flags;
  1513.   Elf32_Addr    sh_addr;
  1514.   Elf32_Off        sh_offset;
  1515.   Elf32_Word    sh_size;
  1516.   Elf32_Word    sh_link;
  1517.   Elf32_Word    sh_info;
  1518.   Elf32_Word    sh_addralign;
  1519.   Elf32_Word    sh_entsize;
  1520. } Elf32_Shdr;
  1521.  
  1522. #define    EI_MAG0        0        /* e_ident[] indexes */
  1523. #define    EI_MAG1        1
  1524. #define    EI_MAG2        2
  1525. #define    EI_MAG3        3
  1526. #define    EI_CLASS    4
  1527. #define    EI_DATA        5
  1528. #define    EI_VERSION    6
  1529. #define    EI_PAD        7
  1530.  
  1531. #define    ELFMAG0        0x7f        /* EI_MAG */
  1532. #define    ELFMAG1        'E'
  1533. #define    ELFMAG2        'L'
  1534. #define    ELFMAG3        'F'
  1535. #define    ELFMAG        "\177ELF"
  1536. #define    SELFMAG        4
  1537.  
  1538. #define    ELFCLASSNONE    0        /* EI_CLASS */
  1539. #define    ELFCLASS32    1
  1540. #define    ELFCLASS64    2
  1541. #define    ELFCLASSNUM    3
  1542.  
  1543. #define ELFDATANONE    0        /* e_ident[EI_DATA] */
  1544. #define ELFDATA2LSB    1
  1545. #define ELFDATA2MSB    2
  1546.  
  1547. #define EV_NONE        0        /* e_version, EI_VERSION */
  1548. #define EV_CURRENT    1
  1549. #define EV_NUM        2
  1550.  
  1551. #define ELF_START_MMAP 0x80000000
  1552.  
  1553. #endif /* _LINUX_ELF_H */
  1554.  
  1555. /* whole file */
  1556.  
  1557.