readelf.h 3.6 KB

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