+++ /dev/null
-/**\r
- * \file elf.h\r
- * \brief ELF Exeutable Loader\r
- */\r
-#ifndef _BIN_ELF_H\r
-#define _BIN_ELF_H\r
-\r
-#include <stdint.h>\r
-\r
-/**\r
- * \brief ELF File Header\r
- */\r
-struct sElf32_Ehdr\r
-{\r
- union {\r
- char ident[16]; //!< Identifier Bytes\r
- struct {\r
- uint32_t Ident1;\r
- uint32_t Ident2;\r
- uint32_t HashTable;\r
- uint32_t SymTable;\r
- } misc;\r
- };\r
- uint16_t filetype; //!< File Type\r
- uint16_t machine; //!< Machine / Arch\r
- uint32_t version; //!< Version (File?)\r
- uint32_t entrypoint; //!< Entry Point\r
- uint32_t phoff; //!< Program Header Offset\r
- uint32_t shoff; //!< Section Header Offset\r
- uint32_t flags; //!< Flags\r
- uint16_t headersize; //!< Header Size\r
- uint16_t phentsize; //!< Program Header Entry Size\r
- uint16_t phentcount; //!< Program Header Entry Count\r
- uint16_t shentsize; //!< Section Header Entry Size\r
- uint16_t shentcount; //!< Section Header Entry Count\r
- uint16_t shstrindex; //!< Section Header String Table Index\r
-} __attribute__ ((packed));\r
-\r
-/**\r
- * \brief Executable Types\r
- */\r
-enum eElf32_ExecTypes\r
-{\r
- ET_NONE = 0, //!< NULL Type\r
- ET_REL = 1, //!< Relocatable (Object)\r
- ET_EXEC = 2, //!< Executable\r
- ET_DYN = 3, //!< Dynamic Library\r
- ET_CORE = 4, //!< Core?\r
- ET_LOPROC = 0xFF00, //!< Low Impl Defined\r
- ET_HIPROC = 0xFFFF //!< High Impl Defined\r
-};\r
-\r
-/**\r
- \name Section IDs\r
- \{\r
-*/\r
-#define SHN_UNDEF 0 //!< Undefined Section\r
-#define SHN_LORESERVE 0xFF00 //!< Low Reserved\r
-#define SHN_LOPROC 0xFF00 //!< Low Impl Defined\r
-#define SHN_HIPROC 0xFF1F //!< High Impl Defined\r
-#define SHN_ABS 0xFFF1 //!< Absolute Address (Base: 0, Size: -1)\r
-#define SHN_COMMON 0xFFF2 //!< Common\r
-#define SHN_HIRESERVE 0xFFFF //!< High Reserved\r
-//! \}\r
-\r
-/**\r
- \enum eElfSectionTypes\r
- \brief ELF Section Types\r
-*/\r
-enum eElfSectionTypes {\r
- SHT_NULL, //0\r
- SHT_PROGBITS, //1\r
- SHT_SYMTAB, //2\r
- SHT_STRTAB, //3\r
- SHT_RELA, //4\r
- SHT_HASH, //5\r
- SHT_DYNAMIC, //6\r
- SHT_NOTE, //7\r
- SHT_NOBITS, //8\r
- SHT_REL, //9\r
- SHT_SHLIB, //A\r
- SHT_DYNSYM, //B\r
- SHT_LAST, //C\r
- SHT_LOPROC = 0x70000000,\r
- SHT_HIPROC = 0x7fffffff,\r
- SHT_LOUSER = 0x80000000,\r
- SHT_HIUSER = 0xffffffff\r
-};\r
-\r
-#define SHF_WRITE 0x1\r
-#define SHF_ALLOC 0x2\r
-#define SHF_EXECINSTR 0x4\r
-#define SHF_MASKPROC 0xf0000000\r
-\r
-struct sElf32_Shent {\r
- uint32_t name;\r
- uint32_t type;\r
- uint32_t flags;\r
- uint32_t address;\r
- uint32_t offset;\r
- uint32_t size;\r
- uint32_t link;\r
- uint32_t info;\r
- uint32_t addralign;\r
- uint32_t entsize;\r
-} __attribute__ ((packed)); //sizeof = 40\r
-\r
-struct elf_sym_s {\r
- union {\r
- uint32_t nameOfs;\r
- uint32_t name;\r
- };\r
- uint32_t value; //Address\r
- uint32_t size;\r
- uint8_t info;\r
- uint8_t other;\r
- uint16_t shndx;\r
-} __attribute__ ((packed));\r
-#define STN_UNDEF 0 // Undefined Symbol\r
-\r
-enum {\r
- PT_NULL, //0\r
- PT_LOAD, //1\r
- PT_DYNAMIC, //2\r
- PT_INTERP, //3\r
- PT_NOTE, //4\r
- PT_SHLIB, //5\r
- PT_PHDR, //6\r
- PT_LOPROC = 0x70000000,\r
- PT_HIPROC = 0x7fffffff\r
-};\r
-\r
-struct sElf32_Phdr {\r
- uint32_t Type;\r
- uint32_t Offset;\r
- uint32_t VAddr;\r
- uint32_t PAddr;\r
- uint32_t FileSize;\r
- uint32_t MemSize;\r
- uint32_t Flags;\r
- uint32_t Align;\r
-} __attribute__ ((packed));\r
-\r
-struct elf32_rel_s {\r
- uint32_t r_offset;\r
- uint32_t r_info;\r
-} __attribute__ ((packed));\r
-\r
-struct elf32_rela_s {\r
- uint32_t r_offset;\r
- uint32_t r_info;\r
- int32_t r_addend;\r
-} __attribute__ ((packed));\r
-\r
-enum {\r
- R_386_NONE = 0, // none\r
- R_386_32, // S+A\r
- R_386_PC32, // S+A-P\r
- R_386_GOT32, // G+A-P\r
- R_386_PLT32, // L+A-P\r
- R_386_COPY, // none\r
- R_386_GLOB_DAT, // S\r
- R_386_JMP_SLOT, // S\r
- R_386_RELATIVE, // B+A\r
- R_386_GOTOFF, // S+A-GOT\r
- R_386_GOTPC, // GOT+A-P\r
- R_386_LAST // none\r
-};\r
-\r
-#define ELF32_R_SYM(i) ((i)>>8) // Takes an info value and returns a symbol index\r
-#define ELF32_R_TYPE(i) ((i)&0xFF) // Takes an info value and returns a type\r
-#define ELF32_R_INFO(s,t) (((s)<<8)+((t)&0xFF)) // Takes a type and symbol index and returns an info value\r
-\r
-struct elf32_dyn_s {\r
- uint32_t d_tag;\r
- uint32_t d_val; //Also d_ptr\r
-} __attribute__ ((packed));\r
-\r
-enum {\r
- DT_NULL, //!< Marks End of list\r
- DT_NEEDED, //!< Offset in strtab to needed library\r
- DT_PLTRELSZ, //!< Size in bytes of PLT\r
- DT_PLTGOT, //!< Address of PLT/GOT\r
- DT_HASH, //!< Address of symbol hash table\r
- DT_STRTAB, //!< String Table address\r
- DT_SYMTAB, //!< Symbol Table address\r
- DT_RELA, //!< Relocation table address\r
- DT_RELASZ, //!< Size of relocation table\r
- DT_RELAENT, //!< Size of entry in relocation table\r
- DT_STRSZ, //!< Size of string table\r
- DT_SYMENT, //!< Size of symbol table entry\r
- DT_INIT, //!< Address of initialisation function\r
- DT_FINI, //!< Address of termination function\r
- DT_SONAME, //!< String table offset of so name\r
- DT_RPATH, //!< String table offset of library path\r
- DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable\r
- DT_REL, //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela)\r
- DT_RELSZ, //!< Size of above table (bytes)\r
- DT_RELENT, //!< Size of entry in above table\r
- DT_PLTREL, //!< Relocation entry of PLT\r
- DT_DEBUG, //!< Debugging Entry - Unknown contents\r
- DT_TEXTREL, //!< Indicates that modifcations to a non-writeable segment may occur\r
- DT_JMPREL, //!< Address of PLT only relocation entries\r
- DT_LOPROC = 0x70000000, //!< Low Definable\r
- DT_HIPROC = 0x7FFFFFFF //!< High Definable\r
-};\r
-\r
-typedef struct sElf32_Ehdr Elf32_Ehdr;\r
-typedef struct sElf32_Phdr Elf32_Phdr;\r
-typedef struct sElf32_Shent Elf32_Shent;\r
-typedef struct elf_sym_s elf_symtab;\r
-typedef struct elf_sym_s Elf32_Sym;\r
-typedef struct elf32_rel_s Elf32_Rel;\r
-typedef struct elf32_rela_s Elf32_Rela;\r
-typedef struct elf32_dyn_s Elf32_Dyn;\r
-\r
-#endif // defined(_EXE_ELF_H)\r