#ifndef _LIBELF_ELF_H #define _LIBELF_ELF_H 1 #include #define ET_NONE 0 #define ET_REL 1 #define ET_EXEC 2 #define ET_DYN 3 #define ET_CORE 4 #define EM_X86_64 62 #define EI_NIDENT 16 #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 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 ELFOSABI_NONE 0 #define ELFOSABI_JOVE 15 #define EV_NONE 0 #define EV_CURRENT 1 typedef struct { unsigned char e_ident[EI_NIDENT]; uint16_t e_type; uint16_t e_machine; uint32_t e_version; uintptr_t e_entry; intptr_t e_phoff; intptr_t e_shoff; uint32_t e_flags; uint16_t e_ehsize; uint16_t e_phentsize; uint16_t e_phnum; uint16_t e_shentsize; uint16_t e_shnum; uint16_t e_shstrndx; } Elf64_Ehdr; #define SHT_NULL 0 #define SHT_PROGBITS 1 #define SHT_SYMTAB 2 #define SHT_STRTAB 3 #define SHT_NOBITS 8 #define SHT_DYNSYM 11 #define SHT_INIT_ARRAY 14 #define SHT_FINI_ARRAY 15 #define SHT_PREINIT_ARRAY 16 #define SHT_SYMTAB_SHNDX 18 #define SHF_WRITE 0b1 #define SHF_ALLOC 0b10 #define SHF_EXECINSTR 0b100 #define SHF_MERGE 0b1000 #define SHF_STRINGS 0b10000 #define SHF_INFO_LINK 0b100000 #define SHF_LINK_ORDER 0b1000000 #define SHF_OS_NONCONF 0b10000000 #define SHF_GROUP 0b100000000 #define SHF_TLS 0b1000000000 #define SHF_MASKOS 0x0FF00000 #define SHF_MASKPROC 0xF0000000 typedef struct { uint32_t sh_name; uint32_t sh_type; uint64_t sh_flags; uintptr_t sh_addr; intptr_t sh_offset; uint64_t sh_size; uint32_t sh_link; uint32_t sh_info; uint64_t sh_addralign; uint64_t sh_entsize; } Elf64_Shdr; #define ELF64_ST_BIND(i) ((i) >> 4) #define ELF64_ST_TYPE(i) ((i)&0xF) #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xF)) #define ELF64_ST_VISIBILITY(o) ((o)&0x3) #define STB_LOCAL 0 #define STB_GLOBAL 1 #define STB_WEAK 2 #define STT_NOTYPE 0 #define STT_OBJECT 1 #define STT_FUNC 2 #define STT_SECTION 3 #define STT_FILE 4 #define STT_COMMON 5 #define STT_TLS 6 #define STV_DEFAULT 0 #define STV_INTERNAL 1 #define STV_HIDDEN 2 #define STV_PROTECTED 3 typedef struct { uint32_t st_name; unsigned char st_info; unsigned char st_other; uint16_t st_shndx; uintptr_t st_value; uint64_t st_size; } Elf64_Sym; #endif