elf.h (2774B)
1 #ifndef __ELF_H__ 2 #define __ELF_H__ 3 4 #include <stdint.h> 5 6 enum { 7 ET_NONE, 8 ET_REL, 9 ET_EXEC, 10 ET_DYN, 11 ET_CORE, 12 ET_LOPROC = 0xff00, 13 ET_HIPROC = 0xffff 14 }; 15 16 enum { 17 EV_NONE, 18 EV_CURRENT 19 }; 20 21 enum { 22 EM_NONE, 23 EM_M32, 24 EM_SPARC, 25 EM_386, 26 EM_68K, 27 EM_88K, 28 EM_860, 29 EM_MIPS 30 }; 31 32 enum { 33 EI_MAG0, 34 EI_MAG1, 35 EI_MAG2, 36 EI_MAG3, 37 EI_CLASS, 38 EI_DATA, 39 EI_VERSION, 40 EI_PAD, 41 EI_NIDENT = 16 42 }; 43 44 enum { 45 ELFCLASSNONE, 46 ELFCLASS32, 47 ELFCLASS64 48 }; 49 50 enum { 51 ELFDATANONE, 52 ELFDATA2LSB, 53 ELFDATA2MSB 54 }; 55 56 enum { 57 SHT_NULL, 58 SHT_PROGBITS, 59 SHT_SYMTAB, 60 SHT_STRTAB, 61 SHT_RELA, 62 SHT_HASH, 63 SHT_DYNAMIC, 64 SHT_NOTE, 65 SHT_NOBITS, 66 SHT_REL, 67 SHT_SHLIB, 68 SHT_DYNSYM, 69 SHT_LOPROC = 0x70000000, 70 SHT_HIPROC = 0x7fffffff, 71 SHT_LOUSER = 0x80000000, 72 SHT_HIUSER = 0xffffffff 73 }; 74 75 enum { 76 SHF_WRITE = 0x1, 77 SHF_ALLOC = 0x2, 78 SHF_EXECINSTR = 0x4, 79 SHF_MASKPROC = 0xf0000000 80 }; 81 82 enum { 83 SHN_UNDEF, 84 SHN_LORESERVE = 0xff00, 85 SHN_LOPROC = 0xff00, 86 SHN_HIPROC = 0xff1f, 87 SHN_ABS = 0xfff1, 88 SHN_COMMON = 0xfff2, 89 SHN_HIRESERVE = 0xffff 90 }; 91 92 enum { 93 STB_LOCAL, 94 STB_GLOBAL, 95 STB_WEAK, 96 STB_LOPROC = 13, 97 STB_HIPROC = 15 98 }; 99 100 enum { 101 STT_NOTYPE, 102 STT_OBJECT, 103 STT_FUNC, 104 STT_SECTION, 105 STT_FILE, 106 STT_LOPROC = 13, 107 STT_HIPROC = 15 108 }; 109 110 typedef uint32_t Elf32_Addr; 111 typedef uint16_t Elf32_Half; 112 typedef uint32_t Elf32_Off; 113 typedef uint32_t Elf32_Word; 114 typedef int32_t Elf32_Sword; 115 116 typedef struct { 117 unsigned char e_ident[EI_NIDENT]; 118 Elf32_Half e_type; 119 Elf32_Half e_machine; 120 Elf32_Word e_version; 121 Elf32_Addr e_entry; 122 Elf32_Off e_phoff; 123 Elf32_Off e_shoff; 124 Elf32_Word e_flags; 125 Elf32_Half e_ehsize; 126 Elf32_Half e_phentsize; 127 Elf32_Half e_phnum; 128 Elf32_Half e_shentsize; 129 Elf32_Half e_shnum; 130 Elf32_Half e_shtrndx; 131 } Elf32_Ehdr; 132 133 typedef struct { 134 Elf32_Word sh_name; 135 Elf32_Word sh_type; 136 Elf32_Word sh_flags; 137 Elf32_Addr sh_addr; 138 Elf32_Off sh_offset; 139 Elf32_Word sh_size; 140 Elf32_Word sh_link; 141 Elf32_Word sh_info; 142 Elf32_Word sh_addralign; 143 Elf32_Word sh_entsize; 144 } Elf32_Shdr; 145 146 typedef struct { 147 Elf32_Word p_type; 148 Elf32_Off p_offset; 149 Elf32_Addr p_vaddr; 150 Elf32_Addr p_paddr; 151 Elf32_Word p_filesz; 152 Elf32_Word p_memsz; 153 Elf32_Word p_flags; 154 Elf32_Word p_align; 155 } Elf32_Phdr; 156 157 typedef struct { 158 Elf32_Word st_name; 159 Elf32_Addr st_value; 160 Elf32_Word st_size; 161 unsigned char st_info; 162 unsigned char st_other; 163 Elf32_Half st_shndx; 164 } Elf32_Sym; 165 166 typedef struct { 167 Elf32_Addr r_offset; 168 Elf32_Word r_info; 169 } Elf32_Rel; 170 171 typedef struct { 172 Elf32_Addr r_offset; 173 Elf32_Word r_info; 174 Elf32_Sword r_addend; 175 } Elf32_Rela; 176 177 extern int execve(const char *filename, char *const argv[], char *const envp[]); 178 extern int prepare_elf(void); 179 extern const char *find_symbol(uint32_t addr); 180 extern void elfdump(uint32_t base_addr); 181 182 #endif 183