elf.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. struct ELF_h1 {
  2. uint8_t magic[4]; // 7F 45 4c 46
  3. uint8_t class; // 1 = 32bit, 2 = 64bit
  4. uint8_t endianness; // 1 = little, 2 = dumb
  5. uint8_t version;
  6. uint8_t os_abi;
  7. uint8_t abi_version;
  8. uint8_t pad[7];
  9. } __attribute__ ((packed));
  10. // fields from here on are affected by endianness.
  11. struct ELF_h2_64 {
  12. uint16_t type;
  13. uint16_t machine; // x64 = 0x3E
  14. uint32_t version;
  15. uint64_t entry;
  16. uint64_t program_h_off;
  17. uint64_t section_h_off;
  18. uint32_t flags;
  19. uint16_t hsz;
  20. uint16_t program_h_sz;
  21. uint16_t program_h_num;
  22. uint16_t section_h_entry_sz;
  23. uint16_t section_h_num;
  24. uint16_t section_name_index;
  25. } __attribute__ ((packed));
  26. typedef struct ELF_sh_64 {
  27. uint32_t name;
  28. uint32_t type;
  29. uint64_t flags;
  30. uint64_t loaded_vma;
  31. uint64_t file_offset;
  32. uint64_t size;
  33. uint32_t link;
  34. uint32_t info;
  35. uint64_t addr_align;
  36. uint64_t entry_sz;
  37. } __attribute__ ((packed)) ELF_sh_64;
  38. typedef struct ELF {
  39. int fd;
  40. void* m;
  41. struct ELF_h1* h1;
  42. struct ELF_h2_64* h2;
  43. int shl_cnt;
  44. ELF_sh_64* shl; // section header list
  45. char* names;
  46. void* dw_info;
  47. size_t dw_info_sz;
  48. void* dw_line;
  49. size_t dw_line_sz;
  50. } ELF;