readelf.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * readelf.h
  3. * @(#)$Id: readelf.h,v 1.7 1999/02/14 17:16:11 christos Exp $
  4. *
  5. * Provide elf data structures for non-elf machines, allowing file
  6. * non-elf hosts to determine if an elf binary is stripped.
  7. * Note: cobbled from the linux header file, with modifications
  8. */
  9. #ifndef __fake_elf_h__
  10. #define __fake_elf_h__
  11. typedef uint32_t Elf32_Addr;
  12. typedef uint32_t Elf32_Off;
  13. typedef uint16_t Elf32_Half;
  14. typedef uint32_t Elf32_Word;
  15. typedef uint8_t Elf32_Char;
  16. #if SIZEOF_UINT64_T != 8
  17. #define USE_ARRAY_FOR_64BIT_TYPES
  18. typedef uint32_t Elf64_Addr[2];
  19. typedef uint32_t Elf64_Off[2];
  20. typedef uint32_t Elf64_Xword[2];
  21. #else
  22. typedef uint64_t Elf64_Addr;
  23. typedef uint64_t Elf64_Off;
  24. typedef uint64_t Elf64_Xword;
  25. #endif
  26. typedef uint16_t Elf64_Half;
  27. typedef uint32_t Elf64_Word;
  28. typedef uint8_t Elf64_Char;
  29. #define EI_NIDENT 16
  30. typedef struct {
  31. Elf32_Char e_ident[EI_NIDENT];
  32. Elf32_Half e_type;
  33. Elf32_Half e_machine;
  34. Elf32_Word e_version;
  35. Elf32_Addr e_entry; /* Entry point */
  36. Elf32_Off e_phoff;
  37. Elf32_Off e_shoff;
  38. Elf32_Word e_flags;
  39. Elf32_Half e_ehsize;
  40. Elf32_Half e_phentsize;
  41. Elf32_Half e_phnum;
  42. Elf32_Half e_shentsize;
  43. Elf32_Half e_shnum;
  44. Elf32_Half e_shstrndx;
  45. } Elf32_Ehdr;
  46. typedef struct {
  47. Elf64_Char e_ident[EI_NIDENT];
  48. Elf64_Half e_type;
  49. Elf64_Half e_machine;
  50. Elf64_Word e_version;
  51. Elf64_Addr e_entry; /* Entry point */
  52. Elf64_Off e_phoff;
  53. Elf64_Off e_shoff;
  54. Elf64_Word e_flags;
  55. Elf64_Half e_ehsize;
  56. Elf64_Half e_phentsize;
  57. Elf64_Half e_phnum;
  58. Elf64_Half e_shentsize;
  59. Elf64_Half e_shnum;
  60. Elf64_Half e_shstrndx;
  61. } Elf64_Ehdr;
  62. /* e_type */
  63. #define ET_EXEC 2
  64. #define ET_CORE 4
  65. /* sh_type */
  66. #define SHT_SYMTAB 2
  67. #define SHT_NOTE 7
  68. #define SHT_DYNSYM 11
  69. /* elf type */
  70. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  71. #define ELFDATA2LSB 1
  72. #define ELFDATA2MSB 2
  73. /* elf class */
  74. #define ELFCLASSNONE 0
  75. #define ELFCLASS32 1
  76. #define ELFCLASS64 2
  77. /* magic number */
  78. #define EI_MAG0 0 /* e_ident[] indexes */
  79. #define EI_MAG1 1
  80. #define EI_MAG2 2
  81. #define EI_MAG3 3
  82. #define EI_CLASS 4
  83. #define EI_DATA 5
  84. #define EI_VERSION 6
  85. #define EI_PAD 7
  86. #define ELFMAG0 0x7f /* EI_MAG */
  87. #define ELFMAG1 'E'
  88. #define ELFMAG2 'L'
  89. #define ELFMAG3 'F'
  90. #define ELFMAG "\177ELF"
  91. #define OLFMAG1 'O'
  92. #define OLFMAG "\177OLF"
  93. typedef struct {
  94. Elf32_Word p_type;
  95. Elf32_Off p_offset;
  96. Elf32_Addr p_vaddr;
  97. Elf32_Addr p_paddr;
  98. Elf32_Word p_filesz;
  99. Elf32_Word p_memsz;
  100. Elf32_Word p_flags;
  101. Elf32_Word p_align;
  102. } Elf32_Phdr;
  103. typedef struct {
  104. Elf64_Word p_type;
  105. Elf64_Word p_flags;
  106. Elf64_Off p_offset;
  107. Elf64_Addr p_vaddr;
  108. Elf64_Addr p_paddr;
  109. Elf64_Xword p_filesz;
  110. Elf64_Xword p_memsz;
  111. Elf64_Xword p_align;
  112. } Elf64_Phdr;
  113. #define PT_NULL 0 /* p_type */
  114. #define PT_LOAD 1
  115. #define PT_DYNAMIC 2
  116. #define PT_INTERP 3
  117. #define PT_NOTE 4
  118. #define PT_SHLIB 5
  119. #define PT_PHDR 6
  120. #define PT_NUM 7
  121. typedef struct {
  122. Elf32_Word sh_name;
  123. Elf32_Word sh_type;
  124. Elf32_Word sh_flags;
  125. Elf32_Addr sh_addr;
  126. Elf32_Off sh_offset;
  127. Elf32_Word sh_size;
  128. Elf32_Word sh_link;
  129. Elf32_Word sh_info;
  130. Elf32_Word sh_addralign;
  131. Elf32_Word sh_entsize;
  132. } Elf32_Shdr;
  133. typedef struct {
  134. Elf64_Word sh_name;
  135. Elf64_Word sh_type;
  136. Elf64_Off sh_flags;
  137. Elf64_Addr sh_addr;
  138. Elf64_Off sh_offset;
  139. Elf64_Off sh_size;
  140. Elf64_Word sh_link;
  141. Elf64_Word sh_info;
  142. Elf64_Off sh_addralign;
  143. Elf64_Off sh_entsize;
  144. } Elf64_Shdr;
  145. /* Notes used in ET_CORE */
  146. #define NT_PRSTATUS 1
  147. #define NT_PRFPREG 2
  148. #define NT_PRPSINFO 3
  149. #define NT_TASKSTRUCT 4
  150. /* Note header in a PT_NOTE section */
  151. typedef struct elf_note {
  152. Elf32_Word n_namesz; /* Name size */
  153. Elf32_Word n_descsz; /* Content size */
  154. Elf32_Word n_type; /* Content type */
  155. } Elf32_Nhdr;
  156. typedef struct {
  157. Elf64_Word n_namesz;
  158. Elf64_Word n_descsz;
  159. Elf64_Word n_type;
  160. } Elf64_Nhdr;
  161. #define NT_PRSTATUS 1
  162. #define NT_PRFPREG 2
  163. #define NT_PRPSINFO 3
  164. #define NT_PRXREG 4
  165. #define NT_PLATFORM 5
  166. #define NT_AUXV 6
  167. #endif