home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / LRTLSRC.RAR / PE2ELF / ELFDEF.PAS < prev    next >
Pascal/Delphi Source File  |  2000-08-15  |  7KB  |  226 lines

  1. (*$Use32+*)
  2. unit elfdef;
  3.  
  4. // 1999.07.28 Veit Kannegieser
  5.  
  6. interface
  7.  
  8. type
  9.   Elf32_Ehdr_type=
  10.     packed record
  11.       magic0123         :array[0..3] of char;
  12.       file_class        :byte;
  13.       data_encoding     :byte;
  14.       file_version      :byte;
  15.       padding           :array[$07..$0f] of byte;
  16.       e_type            :smallword;
  17.       e_machine         :smallword;
  18.       e_version         :word;
  19.       e_entry           :word;                  // entrypoint
  20.       e_phoff           :word;                  // program header offset
  21.       e_shoff           :word;                  // sections header offset
  22.       e_flags           :word;
  23.       e_ehsize          :smallword;             // elf header size in bytes
  24.       e_phentsize       :smallword;             // size of an entry in the program header array
  25.       e_phnum           :smallword;             // 0..e_phnum-1 of entrys
  26.       e_shentsize       :smallword;             // size of an entry in sections header array
  27.       e_shnum           :smallword;             // 0..e_shnum-1 of entrys
  28.       e_shstrndx        :smallword;             // index of string section header
  29.     end;
  30.  
  31. const
  32.   magic0123_elf         =#$7f'ELF';
  33.   file_class__32bit     =1;
  34.   ELFDATA2LSB           =1;
  35.   e_type__exec          =2; // executable file
  36.   e_machine__intel386   =3;
  37.   e_version__current    =1;
  38.  
  39. type
  40.   section_header_type=                  // Seite 26
  41.     packed record
  42.       sh_name           :word;
  43.       sh_type           :word;
  44.       sh_flags          :word;
  45.       sh_addr           :word;
  46.       sh_offset         :word;
  47.       sh_size           :word;
  48.       sh_link           :word;
  49.       sh_info           :word;
  50.       sh_addralign      :word;
  51.       sh_entsize        :word;
  52.     end;
  53.  
  54. const
  55.   // sh_type
  56.   SHT_NULL              = 0;
  57.   SHT_PROGBITS          = 1;
  58.   SHT_SYMTAB            = 2;
  59.   SHT_STRTAB            = 3;
  60.   SHT_RELA              = 4;
  61.   SHT_HASH              = 5;
  62.   SHT_DYNAMIC           = 6;
  63.   SHT_NOTE              = 7;
  64.   SHT_NOBITS            = 8;
  65.   SHT_REL               = 9;
  66.   SHT_SHLIB             = 10;
  67.   SHT_DYNSYM            = 11;
  68.   SHT_LOPROC            = $70000000;
  69.   SHT_HIPROC            = $7fffffff;
  70.   SHT_LOUSER            = $80000000;
  71.   SHT_HIUSER            = $ffffffff;
  72.  
  73.   // sh_flags
  74.   SHF_WRITE             = $00000001;
  75.   SHF_ALLOC             = $00000002;
  76.   SHF_EXECINSTR         = $00000004;
  77.   SHF_MASKPROC          = $f0000000;
  78.  
  79.  
  80.   // Seite 23, Verweise in .dynsym
  81.   SHN_UNDEF             = $0000;
  82.   SHN_LORESERVE         = $ff00;
  83.   SHN_LOPROC            = $ff00;
  84.   SHN_HIPROC            = $ff1f;
  85.   SHN_ABS               = $fff1;
  86.   SHN_COMMON            = $fff2;
  87.   SHN_HIRESERVE         = $ffff;
  88.  
  89. type
  90.   Elf32_Rel_type=
  91.     packed record
  92.       r_offset          :word;
  93.       r_info            :word;
  94.     end;
  95.  
  96.   Elf32_Rela_type=
  97.     packed record
  98.       r_offset          :word;
  99.       r_info            :word;
  100.       r_addend          :integer;
  101.     end;
  102.  
  103. const
  104.   // Seite 58
  105.   R_386_NONE            =  0;
  106.   R_386_32              =  1;
  107.   R_386_PC32            =  2;
  108.   // Seite 93
  109.   R_386_GOT32           =  3;
  110.   R_386_PLT32           =  4;
  111.   R_386_COPY            =  5;
  112.   R_386_GLOB_DAT        =  6;
  113.   R_386_JMP_SLOT        =  7;
  114.   R_386_RELATIVE        =  8;
  115.   R_386_GOTOFF          =  9;
  116.   R_386_GOTPC           = 10;
  117.  
  118.  
  119.  
  120. type
  121.   program_header_type=
  122.     packed record
  123.       p_type            :word;
  124.       p_offset          :word;
  125.       p_vaddr           :word;
  126.       p_paddr           :word;
  127.       p_filesz          :word;
  128.       p_memsz           :word;
  129.       p_flags           :word;
  130.       p_align           :word;
  131.     end;
  132.  
  133. const
  134.   // p_type
  135.   PT_NULL               = 0;
  136.   PT_LOAD               = 1;
  137.   PT_DYNAMIC            = 2;
  138.   PT_INTERP             = 3;
  139.   PT_NOTE               = 4;
  140.   PT_SHLIB              = 5;
  141.   PT_PHDR               = 6;
  142.   PT_LOPROC             = $70000000;
  143.   PT_HIPROC             = $7fffffff;
  144.  
  145.   // p_flags
  146.   PF_X                  = $00000001; // Execute
  147.   PF_W                  = $00000002; // Write
  148.   PF_R                  = $00000004; // Read
  149.   PF_MASKPROC           = $f0000000; // Unspecified
  150.  
  151.  
  152. type // Seite 32
  153.   Elf32_Sym_type=
  154.     packed record
  155.       st_name           :word;
  156.       st_value          :word;
  157.       st_size           :word;
  158.       st_info           :byte;
  159.       st_other          :byte;
  160.       st_shndx          :smallword;
  161.     end;
  162.  
  163. const
  164.   // Seite 33 (st_info shr 4)
  165.   STB_LOCAL             =  0;
  166.   STB_GLOBAL            =  1;
  167.   STB_WEAK              =  2;
  168.   STB_LOPROC            = 13;
  169.   STB_HIPROC            = 15;
  170.  
  171.   // Seite 34 (st_info and $f)
  172.   STT_NOTYPE            =  0;
  173.   STT_OBJECT            =  1;
  174.   STT_FUNC              =  2;
  175.   STT_SECTION           =  3;
  176.   STT_FILE              =  4;
  177.   STT_LOPROC            = 13;
  178.   STT_HIPROC            = 15;
  179.  
  180.  
  181.  
  182. type
  183.   Elf32_Dyn_type=
  184.     packed record
  185.       d_tag             :word;
  186.       case integer of
  187.         0:(d_val        :word);
  188.         1:(d_ptr        :word);
  189.     end;
  190.  
  191. const
  192.   // Seite 80
  193.   // d_tag Name              Value      d_un       Executable   Shared Object
  194.   DT_NULL               =        0; // ignored     mandatory    mandatory
  195.   DT_NEEDED             =        1; // d_val       optional     optional
  196.   DT_PLTRELSZ           =        2; // d_val       optional     optional
  197.   DT_PLTGOT             =        3; // d_ptr       optional     optional
  198.   DT_HASH               =        4; // d_ptr       mandatory    mandatory
  199.   DT_STRTAB             =        5; // d_ptr       mandatory    mandatory
  200.   DT_SYMTAB             =        6; // d_ptr       mandatory    mandatory
  201.   DT_RELA               =        7; // d_ptr       mandatory    optional
  202.   DT_RELASZ             =        8; // d_val       mandatory    optional
  203.   DT_RELAENT            =        9; // d_val       mandatory    optional
  204.   DT_STRSZ              =       10; // d_val       mandatory    mandatory
  205.   DT_SYMENT             =       11; // d_val       mandatory    mandatory
  206.   DT_INIT               =       12; // d_ptr       optional    optional
  207.   DT_FINI               =       13; // d_ptr       optional    optional
  208.   DT_SONAME             =       14; // d_val       ignored     optional
  209.   DT_RPATH              =       15; // d_val       optional    ignored
  210.   DT_SYMBOLIC           =       16; // ignored     ignored     optional
  211.   DT_REL                =       17; // d_ptr       mandatory   optional
  212.   DT_RELSZ              =       18; // d_val       mandatory   optional
  213.   DT_RELENT             =       19; // d_val       mandatory   optional
  214.   DT_PLTREL             =       20; // d_val       optional    optional
  215.   DT_DEBUG              =       21; // d_ptr       optional    ignored
  216.   DT_TEXTREL            =       22; // ignored     optional    optional
  217.   DT_JMPREL             =       23; // d_ptr       optional    optional
  218.   DT_BIND_NOW           =       24; // ignored     optional    optional
  219.   DT_LOPROC             =$70000000; // unspecified unspecified unspecified
  220.   DT_HIPROC             =$7fffffff; // unspecified unspecified unspecified
  221.  
  222. implementation
  223.  
  224. end.
  225.  
  226.