elfbfd.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {$ifdef fpc}
  2. {$mode objfpc}
  3. {$endif}
  4. {$H+}
  5. unit elfbfd;
  6. {ELF Binary Format Description. 32/64 bit definitions }
  7. interface
  8. const
  9. SHT_NULL = 0;
  10. SHT_PROGBITS = 1;
  11. SHT_SYMTAB = 2;
  12. SHT_STRTAB = 3;
  13. SHT_RELA = 4;
  14. SHT_HASH = 5;
  15. SHT_DYNAMIC = 6;
  16. SHT_NOTE = 7;
  17. SHT_NOBITS = 8;
  18. SHT_REL = 9;
  19. SHT_SHLIB = 10;
  20. SHT_DYNSYM = 11;
  21. SHF_WRITE = 1;
  22. SHF_ALLOC = 2;
  23. SHF_EXECINSTR = 4;
  24. PT_NULL = 0;
  25. PT_LOAD = 1;
  26. PT_DYNAMIC = 2;
  27. PT_INTERP = 3;
  28. PT_NOTE = 4;
  29. PT_SHLIB = 5;
  30. PT_PHDR = 6;
  31. PT_LOOS = $60000000;
  32. PT_HIOS = $6fffffff;
  33. PT_LOPROC = $70000000;
  34. PT_HIPROC = $7fffffff;
  35. Type
  36. TElf32header = packed record
  37. magic0123: longint;
  38. file_class: byte;
  39. data_encoding: byte;
  40. file_version: byte;
  41. padding: array[$07..$0F] of byte;
  42. e_type: word;
  43. e_machine: word;
  44. e_version: longint;
  45. e_entry: longint; { entrypoint }
  46. e_phoff: longint; { program header offset }
  47. e_shoff: longint; { sections header offset }
  48. e_flags: longint;
  49. e_ehsize: word; { elf header size in bytes }
  50. e_phentsize: word; { size of an entry in the program header array }
  51. e_phnum: word; { 0..e_phnum-1 of entrys }
  52. e_shentsize: word; { size of an entry in sections header array }
  53. e_shnum: word; { 0..e_shnum-1 of entrys }
  54. e_shstrndx: word; { index of string section header }
  55. end;
  56. TElf64header = packed record
  57. magic0123: longint;
  58. file_class: byte;
  59. data_encoding: byte;
  60. file_version: byte;
  61. padding: array[$07..$0F] of byte;
  62. e_type: word;
  63. e_machine: word;
  64. e_version: longint;
  65. e_entry: int64; { entrypoint }
  66. e_phoff: int64; { program header offset }
  67. e_shoff: int64; { sections header offset }
  68. e_flags: longint;
  69. e_ehsize: word; { elf header size in bytes }
  70. e_phentsize: word; { size of an entry in the program header array }
  71. e_phnum: word; { 0..e_phnum-1 of entrys }
  72. e_shentsize: word; { size of an entry in sections header array }
  73. e_shnum: word; { 0..e_shnum-1 of entrys }
  74. e_shstrndx: word; { index of string section header }
  75. end;
  76. TElf32sechdr = packed record
  77. sh_name: longint;
  78. sh_type: longint;
  79. sh_flags: longint;
  80. sh_addr: longint;
  81. sh_offset: longint;
  82. sh_size: longint;
  83. sh_link: longint;
  84. sh_info: longint;
  85. sh_addralign: longint;
  86. sh_entsize: longint;
  87. end;
  88. TElf64sechdr = packed record
  89. sh_name: longint;
  90. sh_type: longint;
  91. sh_flags: longint;
  92. sh_addr: int64;
  93. sh_offset: int64;
  94. sh_size: int64;
  95. sh_link: longint;
  96. sh_info: longint;
  97. sh_addralign: int64;
  98. sh_entsize: int64;
  99. end;
  100. { FPC resources }
  101. TELF32ResourceSectionInfo = packed record
  102. ptr: longint;
  103. size: longint;
  104. end;
  105. TELF64ResourceSectionInfo = packed record
  106. ptr: int64;
  107. size: int64;
  108. end;
  109. TELF32ResourceInfo = packed record
  110. reshash: longint; // always 32bit, contains an ELF hash of the resource entries name
  111. restype: longint; // always 32bit, contains the resource type ID compatible with Windows RES IDs
  112. ptr: longint; // Byte offset to the resource inside the resdata section.
  113. name: longint; // Byte offset to the the resource name inside the ressym section.
  114. size: longint; // The size of the resource entry
  115. end;
  116. TELF64ResourceInfo = packed record
  117. reshash: longint; // always 32bit, contains an ELF hash of the resource entries name
  118. restype: longint; // always 32bit, contains the resource type ID compatible with Windows RES IDs
  119. ptr: int64; // Byte offset to the resource inside the resdata section.
  120. name: int64; // Byte offset to the the resource name inside the ressym section.
  121. size: int64; // The size of the resource entry
  122. end;
  123. TELF32ResourceSectionTable = packed record
  124. version: integer;
  125. resentries: integer;
  126. ressym: TELF32ResourceSectionInfo;
  127. reshash: TELF32ResourceSectionInfo;
  128. resdata: TELF32ResourceSectionInfo;
  129. resspare: TELF32ResourceSectionInfo;
  130. resstr: TELF32ResourceSectionInfo;
  131. end;
  132. implementation
  133. end.