#pragma once #include #include #include #define ELFMAG "\177ELF" #define SELFMAG 4 #define EI_CLASS 4 /* File class byte index */ #define ELFCLASS64 2 /* 64-bit objects */ #define EI_DATA 5 /* Data encoding byte index */ #define ELFDATA2LSB 1 /* 2's complement, little endian */ #define ET_EXEC 2 /* Executable file */ #define PT_LOAD 1 /* Loadable program segment */ #ifdef ARCH_X86_64 #define EM_MACH 62 /* AMD x86-64 architecture */ #else #error "Unknown architecture." #endif typedef struct { u8 e_ident[16]; /* Magic number and other info */ u16 e_type; /* Object file type */ u16 e_machine; /* Architecture */ u32 e_version; /* Object file version */ u64 e_entry; /* Entry point virtual address */ u64 e_phoff; /* Program header table file offset */ u64 e_shoff; /* Section header table file offset */ u32 e_flags; /* Processor-specific flags */ u16 e_ehsize; /* ELF header size in bytes */ u16 e_phentsize; /* Program header table entry size */ u16 e_phnum; /* Program header table entry count */ u16 e_shentsize; /* Section header table entry size */ u16 e_shnum; /* Section header table entry count */ u16 e_shstrndx; /* Section header string table index */ } Elf64_Ehdr; typedef struct { u32 p_type; /* Segment type */ u32 p_flags; /* Segment flags */ u64 p_offset; /* Segment file offset */ u64 p_vaddr; /* Segment virtual address */ u64 p_paddr; /* Segment physical address */ u64 p_filesz; /* Segment size in file */ u64 p_memsz; /* Segment size in memory */ u64 p_align; /* Segment alignment */ } Elf64_Phdr; struct ELFData { u64 entry; }; namespace ELFLoader { Result load(const TarStream::Entry& elf_entry, const TarStream& stream); };