123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #pragma once
- #include <common/glib.h>
- typedef uint32_t Elf32_Addr;
- typedef uint16_t Elf32_Half;
- typedef uint32_t Elf32_Off;
- typedef uint32_t Elf32_SWord;
- typedef uint32_t Elf32_Word;
- typedef uint64_t Elf64_Addr;
- typedef uint16_t Elf64_Half;
- typedef uint64_t Elf64_Off;
- typedef uint32_t Elf64_Sword;
- typedef uint32_t Elf64_Word;
- typedef uint64_t Elf64_Xword;
- typedef uint64_t Elf64_Sxword;
- #define EI_MAG0 0
- #define EI_MAG1 1
- #define EI_MAG2 2
- #define EI_MAG3 3
- #define EI_CLASS 4
- #define EI_DATA 5
- #define EI_VERSION 6
- #define EI_OSABI 7
- #define EI_ABIVERSION 8
- #define EI_PAD 9
- #define EI_NIDENT 16
- #define ELFMAG0 0x7f
- #define ELFMAG1 'E'
- #define ELFMAG2 'L'
- #define ELFMAG3 'F'
- #define ELFCLASSNONE 0
- #define ELFCLASS32 1
- #define ELFCLASS64 2
- #define ELFDATANONE 0
- #define ELFDATA2LSB 1
- #define ELFDATA2MSB 2
- #define ET_NONE 0
- #define ET_REL 1
- #define ET_EXEC 2
- #define ET_DYN 3
- #define ET_CORE 4
- #define ET_LOPROC 0xff00
- #define ET_HIPROC 0xffff
- #define EM_NONE 0
- #define EM_SPARC 2
- #define EM_386 3
- #define EM_SPARC32PLUS 18
- #define EM_SPARCV9 43
- #define EM_AMD64 62
- #define EV_NONE 0
- #define EF_SPARC_EXT_MASK 0xffff00
- #define EF_SPARC_32PLUS 0x000100
- #define EF_SPARC_SUN_US1 0x000200
- #define EF_SPARC_HAL_R1 0x000400
- #define EF_SPARC_SUN_US3 0x000800
- #define EF_SPARCV9_MM 0x3
- #define EF_SPARCV9_TSO 0x0
- #define EF_SPARCV9_PSO 0x1
- #define EF_SPARCV9_RMO 0x2
- #define PN_XNUM 0xffff
- typedef struct
- {
- unsigned char e_ident[EI_NIDENT];
- Elf32_Half e_type;
- Elf32_Half e_machine;
- Elf32_Word e_version;
- Elf32_Addr e_entry;
- Elf32_Off e_phoff;
- Elf32_Off e_shoff;
- Elf32_Word e_flags;
- Elf32_Half e_ehsize;
- Elf32_Half e_phentsize;
- Elf32_Half e_phnum;
- Elf32_Half e_shentsize;
- Elf32_Half e_shnum;
- Elf32_Half e_shstrndx;
- } Elf32_Ehdr;
- typedef struct
- {
- unsigned char e_ident[EI_NIDENT];
- Elf64_Half e_type;
- Elf64_Half e_machine;
- Elf64_Word e_version;
- Elf64_Addr e_entry;
- Elf64_Off e_phoff;
- Elf64_Off e_shoff;
- Elf64_Word e_flags;
- Elf64_Half e_ehsize;
- Elf64_Half e_phentsize;
- Elf64_Half e_phnum;
-
-
-
-
- Elf64_Half e_shentsize;
-
- Elf64_Half e_shnum;
-
-
-
-
- Elf64_Half e_shstrndx;
-
-
-
-
- } Elf64_Ehdr;
- #define SHN_UNDEF 0
- #define SHN_LORESERVE 0xff00
-
- #define SHN_LOPROC 0xff00
- #define SHN_BEFORE 0xff00
- #define SHN_AFTER 0xff01
- #define SHN_AMD64_LCOMMON 0xff02
- #define SHN_HIPROC 0xff1f
- #define SHN_LOOS 0xff20
- #define SHN_LOSUNW 0xff3f
- #define SHN_SUNW_IGNORE 0xff3f
- #define SHN_HISUNW 0xff3f
- #define SHN_HIOS 0xff3f
- #define SHN_ABS 0xfff1
- #define SHN_COMMON 0xfff2
- #define SHN_XINDEX 0xffff
- #define SHN_HIRESERVE 0xffff
- typedef struct
- {
- Elf32_Word sh_name;
- Elf32_Word sh_type;
- Elf32_Word sh_flags;
- Elf32_Addr sh_addr;
- Elf32_Off sh_offset;
- Elf32_Word sh_size;
- Elf32_Word sh_link;
- Elf32_Word sh_info;
- Elf32_Word sh_addralign;
- Elf32_Word sh_entsize;
- } Elf32_Shdr;
- typedef struct
- {
- Elf64_Word sh_name;
- Elf64_Word sh_type;
- Elf64_Xword sh_flags;
- Elf64_Addr sh_addr;
- Elf64_Off sh_offset;
-
- Elf64_Xword sh_size;
- Elf64_Word sh_link;
- Elf64_Word sh_info;
- Elf64_Xword sh_addralign;
- Elf64_Xword sh_entsize;
- } Elf64_Shdr;
- #define SHT_NULL 0
- #define SHT_PROGBITS 1
- #define SHT_SYMTAB 2
- #define SHT_STRTAB 3
- #define SHT_RELA 4
- #define SHT_HASH 5
- #define SHT_DYNAMIC 6
- #define SHT_NOTE 7
- #define SHT_NOBITS 8
- #define SHT_REL 9
- #define SHT_SHLIB 10
- #define SHT_DYNSYM 11
- #define SHT_INIT_ARRAY 14
- #define SHT_FINI_ARRAY 15
- #define SHT_PREINIT_ARRAY 16
- #define SHT_GROUP 17
- #define SHT_SYMTAB_SHNDX 18
- #define SHT_LOOS 0x60000000
- #define SHT_LOSUNW 0x6fffffef
- #define SHT_SUNW_capchain 0x6fffffef
- #define SHT_SUNW_capinfo 0x6ffffff0
- #define SHT_SUNW_symsort 0x6ffffff1
- #define SHT_SUNW_tlssort 0x6ffffff2
- #define SHT_SUNW_LDYNSYM 0x6ffffff3
- #define SHT_SUNW_dof 0x6ffffff4
- #define SHT_SUNW_cap 0x6ffffff5
- #define SHT_SUNW_SIGNATURE 0x6ffffff6
- #define SHT_SUNW_ANNOTATE 0x6ffffff7
- #define SHT_SUNW_DEBUGSTR 0x6ffffff8
- #define SHT_SUNW_DEBUG 0x6ffffff9
- #define SHT_SUNW_move 0x6ffffffa
- #define SHT_SUNW_COMDAT 0x6ffffffb
- #define SHT_SUNW_syminfo 0x6ffffffc
- #define SHT_SUNW_verdef 0x6ffffffd
- #define SHT_SUNW_verneed 0x6ffffffe
- #define SHT_SUNW_versym 0x6fffffff
- #define SHT_HISUNW 0x6fffffff
- #define SHT_HIOS 0x6fffffff
- #define SHT_LOPROC 0x70000000
- #define SHT_SPARC_GOTDATA 0x70000000
- #define SHT_AMD64_UNWIND 0x70000001
- #define SHT_HIPROC 0x7fffffff
- #define SHT_LOUSER 0x80000000
- #define SHT_HIUSER 0xffffffff
- #define SHF_WRITE 0x1
- #define SHF_ALLOC 0x2
- #define SHF_EXECINSTR 0x4
- #define SHF_MERGE 0x10
- #define SHF_STRINGS 0x20
- #define SHF_INFO_LINK 0x40
- #define SHF_LINK_ORDER 0x80
- #define SHF_OS_NONCONFORMING 0x100
- #define SHF_GROUP 0x200
- #define SHF_TLS 0x400
- #define SHF_MASKOS 0x0ff00000
- #define SHF_AMD64_LARGE 0x10000000
- #define SHF_ORDERED 0x40000000
- #define SHF_EXCLUDE 0x80000000
- #define SHF_MASKPROC 0xf0000000
- typedef struct
- {
- Elf32_Word st_name;
- Elf32_Addr st_value;
- Elf32_Word st_size;
- unsigned char st_info;
- unsigned char st_other;
- Elf32_Half st_shndx;
- } Elf32_Sym;
- typedef struct
- {
- Elf64_Word st_name;
- unsigned char st_info;
- unsigned char st_other;
- Elf64_Half st_shndx;
- Elf64_Addr st_value;
- Elf64_Xword st_size;
- } Elf64_Sym;
- typedef struct
- {
- Elf32_Word p_type;
- Elf32_Off p_offset;
- Elf32_Addr p_vaddr;
- Elf32_Addr p_paddr;
- Elf32_Word p_filesz;
- Elf32_Word p_memsz;
- Elf32_Word p_flags;
- Elf32_Word p_align;
- } Elf32_Phdr;
- typedef struct
- {
- Elf64_Word p_type;
- Elf64_Word p_flags;
- Elf64_Off p_offset;
- Elf64_Addr p_vaddr;
- Elf64_Addr p_paddr;
- Elf64_Xword p_filesz;
- Elf64_Xword p_memsz;
- Elf64_Xword p_align;
- } Elf64_Phdr;
- #define PT_NULL 0
- #define PT_LOAD 1
- #define PT_DYNAMIC 2
- #define PT_INTERP 3
- #define PT_NOTE 4
- #define PT_SHLIB 5
- #define PT_PHDR 6
- #define PT_TLS 7
- #define PT_LOOS 0x60000000
- #define PT_SUNW_UNWIND 0x6464e550
- #define PT_SUNW_EH_FRAME 0x6474e550
- #define PT_LOSUNW 0x6ffffffa
- #define PT_SUNWBSS 0x6ffffffa
- #define PT_SUNWSTACK 0x6ffffffb
- #define PT_SUNWDTRACE 0x6ffffffc
- #define PT_SUNWCAP 0x6ffffffd
- #define PT_HISUNW 0x6fffffff
- #define PT_HIOS 0x6fffffff
- #define PT_LOPROC 0x70000000
- #define PT_HIPROC 0x7fffffff
- #define PF_X 0x1
- #define PF_W 0x2
- #define PF_R 0x4
- #define PF_MASKPROC 0xf0000000
- bool elf_check(void * ehdr);
|