diff --git a/lib/elf/eheader.h b/lib/elf/eheader.h new file mode 100644 index 0000000..5b45703 --- /dev/null +++ b/lib/elf/eheader.h @@ -0,0 +1,71 @@ +/* The ELF header resides at the beginning of an ELF file. + * It identifies the file as an ELF file and contains the information + * necessary for interpreting the contents of the file and locating + * the other components of the file. + * REF: https://gabi.xinuos.com/elf/02-eheader.html#elf-header + */ +#ifndef BFPG_ELF_HEADER_H +# define BFPG_ELF_HEADER_H + +# include "eint.h" + +# define EI_NIDENT (16) + +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; + +/* == ElfXX_Ehdr.e_ident[] == + * EI_* macros define indexes into this this, and are followed + * by a series a macros defining legal values for that index. + */ +# define E_IDENT_DESC ( \ + "The initial bytes of an ELF file. Marking it as an object file " \ + "and providing machine-independent data with which to decode " \ + "and interpret the file’s contents." + +/* == ElfXX_Ehdr.e_type == */ +enum e_type_t : Elf64_Addr { + ET_NONE = 0, /* No file type */ + ET_REL = 1, /* Relocatable file */ + ET_EXEC = 2, /* Executable file */ + ET_DYN = 3, /* Shared object file */ + ET_CORE = 4, /* Core file */ + ET_LOOS = 0xfe00, /* OS-specific range start */ + ET_HIOS = 0xfeff, /* OS-specific range end */ + ET_LOPROC = 0xff00, /* Processor-specific range start */ + ET_HIPROC = 0xffff, /* Processor-specific range end */ +}; + + +#endif /* BFPG_ELF_HEADER_H */