readelf.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * readelf.h
  3. * @(#)$Id: readelf.h,v 1.6 1998/09/12 13:21:01 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 unsigned int Elf32_Addr;
  12. typedef unsigned int Elf32_Off;
  13. typedef unsigned short Elf32_Half;
  14. typedef unsigned int Elf32_Word;
  15. typedef unsigned char Elf32_Char;
  16. #ifdef __GNUC__
  17. typedef unsigned long long Elf64_Addr;
  18. typedef unsigned long long Elf64_Off;
  19. #else
  20. /* XXX: We need 64 bit numbers here */
  21. typedef unsigned int Elf64_Addr[2];
  22. typedef unsigned int Elf64_Off[2];
  23. #endif
  24. typedef unsigned short Elf64_Half;
  25. typedef unsigned int Elf64_Word;
  26. typedef unsigned char Elf64_Char;
  27. #define EI_NIDENT 16
  28. typedef struct {
  29. Elf32_Char e_ident[EI_NIDENT];
  30. Elf32_Half e_type;
  31. Elf32_Half e_machine;
  32. Elf32_Word e_version;
  33. Elf32_Addr e_entry; /* Entry point */
  34. Elf32_Off e_phoff;
  35. Elf32_Off e_shoff;
  36. Elf32_Word e_flags;
  37. Elf32_Half e_ehsize;
  38. Elf32_Half e_phentsize;
  39. Elf32_Half e_phnum;
  40. Elf32_Half e_shentsize;
  41. Elf32_Half e_shnum;
  42. Elf32_Half e_shstrndx;
  43. } Elf32_Ehdr;
  44. typedef struct {
  45. Elf64_Char e_ident[EI_NIDENT];
  46. Elf64_Half e_type;
  47. Elf64_Half e_machine;
  48. Elf64_Word e_version;
  49. Elf64_Addr e_entry; /* Entry point */
  50. Elf64_Off e_phoff;
  51. Elf64_Off e_shoff;
  52. Elf64_Word e_flags;
  53. Elf64_Half e_ehsize;
  54. Elf64_Half e_phentsize;
  55. Elf64_Half e_phnum;
  56. Elf64_Half e_shentsize;
  57. Elf64_Half e_shnum;
  58. Elf64_Half e_shstrndx;
  59. } Elf64_Ehdr;
  60. /* e_type */
  61. #define ET_EXEC 2
  62. #define ET_CORE 4
  63. /* sh_type */
  64. #define SHT_SYMTAB 2
  65. #define SHT_NOTE 7
  66. /* elf type */
  67. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  68. #define ELFDATA2LSB 1
  69. #define ELFDATA2MSB 2
  70. /* elf class */
  71. #define ELFCLASSNONE 0
  72. #define ELFCLASS32 1
  73. #define ELFCLASS64 2
  74. /* magic number */
  75. #define EI_MAG0 0 /* e_ident[] indexes */
  76. #define EI_MAG1 1
  77. #define EI_MAG2 2
  78. #define EI_MAG3 3
  79. #define EI_CLASS 4
  80. #define EI_DATA 5
  81. #define EI_VERSION 6
  82. #define EI_PAD 7
  83. #define ELFMAG0 0x7f /* EI_MAG */
  84. #define ELFMAG1 'E'
  85. #define ELFMAG2 'L'
  86. #define ELFMAG3 'F'
  87. #define ELFMAG "\177ELF"
  88. #define OLFMAG1 'O'
  89. #define OLFMAG "\177OLF"
  90. typedef struct {
  91. Elf32_Word p_type;
  92. Elf32_Off p_offset;
  93. Elf32_Addr p_vaddr;
  94. Elf32_Addr p_paddr;
  95. Elf32_Word p_filesz;
  96. Elf32_Word p_memsz;
  97. Elf32_Word p_flags;
  98. Elf32_Word p_align;
  99. } Elf32_Phdr;
  100. #define PT_NULL 0 /* p_type */
  101. #define PT_LOAD 1
  102. #define PT_DYNAMIC 2
  103. #define PT_INTERP 3
  104. #define PT_NOTE 4
  105. #define PT_SHLIB 5
  106. #define PT_PHDR 6
  107. #define PT_NUM 7
  108. typedef struct {
  109. Elf32_Word sh_name;
  110. Elf32_Word sh_type;
  111. Elf32_Word sh_flags;
  112. Elf32_Addr sh_addr;
  113. Elf32_Off sh_offset;
  114. Elf32_Word sh_size;
  115. Elf32_Word sh_link;
  116. Elf32_Word sh_info;
  117. Elf32_Word sh_addralign;
  118. Elf32_Word sh_entsize;
  119. } Elf32_Shdr;
  120. typedef struct {
  121. Elf64_Word sh_name;
  122. Elf64_Word sh_type;
  123. Elf64_Off sh_flags;
  124. Elf64_Addr sh_addr;
  125. Elf64_Off sh_offset;
  126. Elf64_Off sh_size;
  127. Elf64_Word sh_link;
  128. Elf64_Word sh_info;
  129. Elf64_Off sh_addralign;
  130. Elf64_Off sh_entsize;
  131. } Elf64_Shdr;
  132. /* Notes used in ET_CORE */
  133. #define NT_PRSTATUS 1
  134. #define NT_PRFPREG 2
  135. #define NT_PRPSINFO 3
  136. #define NT_TASKSTRUCT 4
  137. /* Note header in a PT_NOTE section */
  138. typedef struct elf_note {
  139. Elf32_Word n_namesz; /* Name size */
  140. Elf32_Word n_descsz; /* Content size */
  141. Elf32_Word n_type; /* Content type */
  142. } Elf32_Nhdr;
  143. typedef struct {
  144. Elf64_Word n_namesz;
  145. Elf64_Word n_descsz;
  146. Elf64_Word n_type;
  147. } Elf64_Nhdr;
  148. #define NT_PRSTATUS 1
  149. #define NT_PRFPREG 2
  150. #define NT_PRPSINFO 3
  151. #define NT_PRXREG 4
  152. #define NT_PLATFORM 5
  153. #define NT_AUXV 6
  154. #endif