#pragma once #include /// Architecture's memory bit-depth. #define ELFH_ARCH_32 0x01 #define ELFH_ARCH_64 0x02 /// Architecture's endianness. #define ELFH_END_LE 0x01 #define ELFH_END_BE 0x02 /// OS' ABI Types. #define ELFH_ABI_SYSTEMV 0x00 /// ELF Binary Types. #define ELFH_TYPE_EXEC 0x02 #define ELFH_TYPE_DYN 0x03 /// Machine architectures. #define ELFH_MARCH_AMD_X86_64 0x003E /// Program types. #define PRGH_TYPE_LOAD 0x00000001 /// Program flags. #define PRGH_FLAG_EXEC 0x00000001 #define PRGH_FLAG_WRITE 0x00000002 #define PRGH_FLAG_READ 0x00000004 /// Section types. #define SECH_TYPE_NULL 0x00 #define SECH_TYPE_PROGBITS 0x01 #define SECH_TYPE_STRTAB 0x03 /// Section flags. #define SECH_FLAG_ALLOC 0x02 #define SECH_FLAG_EXEC 0x04 #define SECH_FLAG_STRINGS 0x20 /// True header sizes. #define ELFH_SIZE 64 #define PRGH_SIZE 56 #define SECH_SIZE 64 /// ELF Header struct ElfHeader { ehs::UInt_8 architecture; ehs::UInt_8 endianness; ehs::UInt_8 elfV1; ehs::UInt_8 targetABI; ehs::UInt_8 abiV; ehs::UInt_16 elfType; ehs::UInt_16 machineArch; ehs::UInt_32 elfV2; ehs::UInt_64 entryAddress; ehs::UInt_64 programsOffset; ehs::UInt_64 sectionsOffset; ehs::UInt_32 flags; ehs::UInt_16 headerSize; ehs::UInt_16 pHeaderSize; ehs::UInt_16 pEntries; ehs::UInt_16 sSize; ehs::UInt_16 sEntries; ehs::UInt_16 strTabIndex; }; /// ELF Program Header struct ElfPrgHeader { ehs::UInt_32 type; ehs::UInt_32 flags; ehs::UInt_64 offset; ehs::UInt_64 vAddr; ehs::UInt_64 pAddr; ehs::UInt_64 fileSize; ehs::UInt_64 memSize; ehs::UInt_64 align; }; /// ELF Section Header struct ElfSecHeader { ehs::UInt_32 index; ehs::UInt_32 type; ehs::UInt_64 flags; ehs::UInt_64 vAddr; ehs::UInt_64 offset; ehs::UInt_64 size; ehs::UInt_32 associatedIndex; ehs::UInt_32 info; ehs::UInt_64 align; ehs::UInt_64 entrySize; }; void WriteHeader(const ElfHeader& header, ehs::Serializer& data); void WriteHeader(const ElfPrgHeader& header, ehs::Serializer& data); void WriteHeader(const ElfSecHeader& header, ehs::Serializer& data);