3 * \brief ELF Exeutable Loader
\r
8 typedef Uint16 Elf64_Half;
\r
9 typedef Uint32 Elf64_Word;
\r
10 typedef Uint64 Elf64_Addr;
\r
11 typedef Uint64 Elf64_Off;
\r
12 typedef Uint64 Elf64_Xword;
\r
29 #define ELFCLASS32 1
\r
30 #define ELFCLASS64 2
\r
33 * \brief ELF File Header
\r
38 char ident[16]; //!< Identifier Bytes
\r
46 Uint16 filetype; //!< File Type
\r
47 Uint16 machine; //!< Machine / Arch
\r
48 Uint32 version; //!< Version (File?)
\r
49 Uint32 entrypoint; //!< Entry Point
\r
50 Uint32 phoff; //!< Program Header Offset
\r
51 Uint32 shoff; //!< Section Header Offset
\r
52 Uint32 flags; //!< Flags
\r
53 Uint16 headersize; //!< Header Size
\r
54 Uint16 phentsize; //!< Program Header Entry Size
\r
55 Uint16 phentcount; //!< Program Header Entry Count
\r
56 Uint16 shentsize; //!< Section Header Entry Size
\r
57 Uint16 shentcount; //!< Section Header Entry Count
\r
58 Uint16 shstrindex; //!< Section Header String Table Index
\r
59 } __attribute__ ((packed));
\r
63 unsigned char e_ident[16];
\r
65 Elf64_Half e_machine;
\r
66 Elf64_Word e_version;
\r
71 Elf64_Half e_ehsize;
\r
72 Elf64_Half e_phentsize;
\r
74 Elf64_Half e_shentsize;
\r
76 Elf64_Half e_shstrndx;
\r
80 * \brief Executable Types
\r
82 enum eElf32_ExecTypes
\r
84 ET_NONE = 0, //!< NULL Type
\r
85 ET_REL = 1, //!< Relocatable (Object)
\r
86 ET_EXEC = 2, //!< Executable
\r
87 ET_DYN = 3, //!< Dynamic Library
\r
88 ET_CORE = 4, //!< Core?
\r
89 ET_LOPROC = 0xFF00, //!< Low Impl Defined
\r
90 ET_HIPROC = 0xFFFF //!< High Impl Defined
\r
97 #define SHN_UNDEF 0 //!< Undefined Section
\r
98 #define SHN_LORESERVE 0xFF00 //!< Low Reserved
\r
99 #define SHN_LOPROC 0xFF00 //!< Low Impl Defined
\r
100 #define SHN_HIPROC 0xFF1F //!< High Impl Defined
\r
101 #define SHN_ABS 0xFFF1 //!< Absolute Address (Base: 0, Size: -1)
\r
102 #define SHN_COMMON 0xFFF2 //!< Common
\r
103 #define SHN_HIRESERVE 0xFFFF //!< High Reserved
\r
107 \enum eElfSectionTypes
\r
108 \brief ELF Section Types
\r
110 enum eElfSectionTypes {
\r
124 SHT_LOPROC = 0x70000000,
\r
125 SHT_HIPROC = 0x7fffffff,
\r
126 SHT_LOUSER = 0x80000000,
\r
127 SHT_HIUSER = 0xffffffff
\r
130 #define SHF_WRITE 0x1
\r
131 #define SHF_ALLOC 0x2
\r
132 #define SHF_EXECINSTR 0x4
\r
133 #define SHF_MASKPROC 0xf0000000
\r
135 struct sElf32_Shent {
\r
146 } __attribute__ ((packed)); //sizeof = 40
\r
150 Elf64_Word sh_name;
\r
151 Elf64_Word sh_type;
\r
152 Elf64_Xword sh_flags;
\r
153 Elf64_Addr sh_addr;
\r
154 Elf64_Off sh_offset;
\r
155 Elf64_Xword sh_size;
\r
156 Elf64_Word sh_link;
\r
157 Elf64_Word sh_info;
\r
158 Elf64_Xword sh_addralign;
\r
159 Elf64_Xword sh_entsize;
\r
167 Uint32 value; //Address
\r
172 } __attribute__ ((packed));
\r
173 #define STN_UNDEF 0 // Undefined Symbol
\r
183 PT_LOPROC = 0x70000000,
\r
184 PT_HIPROC = 0x7fffffff
\r
187 struct sElf32_Phdr {
\r
196 } __attribute__ ((packed));
\r
201 Elf64_Word p_flags;
\r
202 Elf64_Off p_offset;
\r
203 Elf64_Addr p_vaddr;
\r
204 Elf64_Addr p_paddr;
\r
205 Elf64_Xword p_filesz;
\r
206 Elf64_Xword p_memsz;
\r
207 Elf64_Xword p_align;
\r
214 struct elf32_rel_s {
\r
217 } __attribute__ ((packed));
\r
219 struct elf32_rela_s {
\r
223 } __attribute__ ((packed));
\r
226 R_386_NONE = 0, // none
\r
228 R_386_PC32, // S+A-P
\r
229 R_386_GOT32, // G+A-P
\r
230 R_386_PLT32, // L+A-P
\r
231 R_386_COPY, // none
\r
232 R_386_GLOB_DAT, // S
\r
233 R_386_JMP_SLOT, // S
\r
234 R_386_RELATIVE, // B+A
\r
235 R_386_GOTOFF, // S+A-GOT
\r
236 R_386_GOTPC, // GOT+A-P
\r
240 #define ELF32_R_SYM(i) ((i)>>8) // Takes an info value and returns a symbol index
\r
241 #define ELF32_R_TYPE(i) ((i)&0xFF) // Takes an info value and returns a type
\r
242 #define ELF32_R_INFO(s,t) (((s)<<8)+((t)&0xFF)) // Takes a type and symbol index and returns an info value
\r
244 struct elf32_dyn_s {
\r
246 Uint32 d_val; //Also d_ptr
\r
247 } __attribute__ ((packed));
\r
250 DT_NULL, //!< Marks End of list
\r
251 DT_NEEDED, //!< Offset in strtab to needed library
\r
252 DT_PLTRELSZ, //!< Size in bytes of PLT
\r
253 DT_PLTGOT, //!< Address of PLT/GOT
\r
254 DT_HASH, //!< Address of symbol hash table
\r
255 DT_STRTAB, //!< String Table address
\r
256 DT_SYMTAB, //!< Symbol Table address
\r
257 DT_RELA, //!< Relocation table address
\r
258 DT_RELASZ, //!< Size of relocation table
\r
259 DT_RELAENT, //!< Size of entry in relocation table
\r
260 DT_STRSZ, //!< Size of string table
\r
261 DT_SYMENT, //!< Size of symbol table entry
\r
262 DT_INIT, //!< Address of initialisation function
\r
263 DT_FINI, //!< Address of termination function
\r
264 DT_SONAME, //!< String table offset of so name
\r
265 DT_RPATH, //!< String table offset of library path
\r
266 DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable
\r
267 DT_REL, //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela)
\r
268 DT_RELSZ, //!< Size of above table (bytes)
\r
269 DT_RELENT, //!< Size of entry in above table
\r
270 DT_PLTREL, //!< Relocation entry of PLT
\r
271 DT_DEBUG, //!< Debugging Entry - Unknown contents
\r
272 DT_TEXTREL, //!< Indicates that modifcations to a non-writeable segment may occur
\r
273 DT_JMPREL, //!< Address of PLT only relocation entries
\r
274 DT_LOPROC = 0x70000000, //!< Low Definable
\r
275 DT_HIPROC = 0x7FFFFFFF //!< High Definable
\r
278 typedef struct sElf32_Ehdr Elf32_Ehdr;
\r
279 typedef struct sElf32_Phdr Elf32_Phdr;
\r
280 typedef struct sElf32_Shent Elf32_Shent;
\r
281 typedef struct elf_sym_s elf_symtab;
\r
282 typedef struct elf_sym_s Elf32_Sym;
\r
283 typedef struct elf32_rel_s Elf32_Rel;
\r
284 typedef struct elf32_rela_s Elf32_Rela;
\r
285 typedef struct elf32_dyn_s Elf32_Dyn;
\r
287 #endif // defined(_EXE_ELF_H)
\r