diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd467c..78d0e43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,9 @@ set(CMAKE_CXX_STANDARD 20) add_executable(Compiler src/ELF.cpp include/ELF.h + src/ELF64_Section.cpp include/ELF64_Section.h + src/ELF64_Program.cpp include/ELF64_Program.h + src/ELF64.cpp include/ELF64.h src/main.cpp ) diff --git a/include/ELF64.h b/include/ELF64.h new file mode 100644 index 0000000..3fc2594 --- /dev/null +++ b/include/ELF64.h @@ -0,0 +1,95 @@ +#pragma once + +#include "ELF64_Section.h" +#include "ELF64_Program.h" + +#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 + +class ELF64 +{ +private: + ehs::UInt_8 subArch; + ehs::UInt_8 endianness; + ehs::UInt_8 elfV1; + ehs::UInt_8 targetABI; + ehs::UInt_8 abiV; + ehs::UInt_16 type; + ehs::UInt_16 arch; + 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; + ehs::Vector programs; + ehs::Vector sections; + +public: + ELF64(); + + ELF64(ehs::UInt_8& subArch, ehs::UInt_8& end, ehs::UInt_8& abi, ehs::UInt_16& type, ehs::UInt_16& arch); + + ELF64(ehs::Serializer& data); + + ehs::UInt_8 GetSubArchitecture() const; + + ehs::UInt_8 GetEndianness() const; + + ehs::UInt_8 GetABI() const; + + ehs::UInt_16 GetType() const; + + ehs::UInt_16 GetArchitecture() const; + + void SetEntryPoint(ehs::UInt_64 newEntryPoint); + + ehs::UInt_64 GetEntryPoint() const; + + ehs::Serializer Serialize() const; +}; \ No newline at end of file diff --git a/include/ELF64_Program.h b/include/ELF64_Program.h new file mode 100644 index 0000000..828d17e --- /dev/null +++ b/include/ELF64_Program.h @@ -0,0 +1,5 @@ +#pragma once + +class ELF64_Program +{ +}; \ No newline at end of file diff --git a/include/ELF64_Section.h b/include/ELF64_Section.h new file mode 100644 index 0000000..025c3f2 --- /dev/null +++ b/include/ELF64_Section.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +class ELF64_Section +{ +private: + friend class ELF64; + + ehs::Str_8 name; + ehs::UInt_32 nameIndex; + ehs::UInt_32 type; + ehs::UInt_64 flags; + ehs::UInt_64 vAddr; + ehs::UInt_64 segmentOffset; + ehs::UInt_64 segmentSize; + ehs::UInt_32 associatedIndex; + ehs::UInt_32 info; + ehs::UInt_64 align; + ehs::UInt_64 entrySize; + +public: + ELF64_Section(); + + ELF64_Section(); +}; \ No newline at end of file diff --git a/src/ELF64.cpp b/src/ELF64.cpp new file mode 100644 index 0000000..e78a092 --- /dev/null +++ b/src/ELF64.cpp @@ -0,0 +1,3 @@ +// +// Created by karutoh on 2/14/24. +// diff --git a/src/ELF64_Program.cpp b/src/ELF64_Program.cpp new file mode 100644 index 0000000..e78a092 --- /dev/null +++ b/src/ELF64_Program.cpp @@ -0,0 +1,3 @@ +// +// Created by karutoh on 2/14/24. +// diff --git a/src/ELF64_Section.cpp b/src/ELF64_Section.cpp new file mode 100644 index 0000000..e78a092 --- /dev/null +++ b/src/ELF64_Section.cpp @@ -0,0 +1,3 @@ +// +// Created by karutoh on 2/14/24. +//