aboutsummaryrefslogtreecommitdiffstats
path: root/misc-host/ELF/ELF-loader-test/elfinfoprint.cpp
diff options
context:
space:
mode:
authorGravatar ornitorrincos 2026-08-18 12:15:05 +0200
committerGravatar ornitorrincos 2026-08-18 12:15:05 +0200
commit132d3236bb884433bf94e961f6d32264e0334aec (patch)
tree06638976b06f019ea4037175ff228f8271057c44 /misc-host/ELF/ELF-loader-test/elfinfoprint.cpp
Diffstat (limited to 'misc-host/ELF/ELF-loader-test/elfinfoprint.cpp')
-rw-r--r--misc-host/ELF/ELF-loader-test/elfinfoprint.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/misc-host/ELF/ELF-loader-test/elfinfoprint.cpp b/misc-host/ELF/ELF-loader-test/elfinfoprint.cpp
new file mode 100644
index 0000000..d5dcbfd
--- /dev/null
+++ b/misc-host/ELF/ELF-loader-test/elfinfoprint.cpp
@@ -0,0 +1,74 @@
+#include "elfinfoprint.h"
+
+#include "bootloader_compat.h"
+
+
+bool IsElf(Elf64_Ehdr * header)
+{
+ if(!header)
+ {
+ return false;
+ }
+
+ if(header->e_ident[EI_MAG0] != ELFMAG0) {
+ return false;
+ }
+ if(header->e_ident[EI_MAG1] != ELFMAG1) {
+ return false;
+ }
+ if(header->e_ident[EI_MAG2] != ELFMAG2) {
+ return false;
+ }
+ if(header->e_ident[EI_MAG3] != ELFMAG3) {
+ return false;
+ }
+
+ return true;
+}
+
+void ElfInfoPrint(Elf64_Ehdr * header)
+{
+ // check if actual elf file
+ if(!IsElf(header))
+ {
+ Print(L"Not an ELF File\n");
+ return;
+ }
+
+ if(header->e_type == ET_EXEC)
+ {
+ Print(L"Executable file\n");
+ }
+
+ if(header->e_machine == EM_X86_64)
+ {
+ Print(L"AMD64 Machine\n");
+ } else
+ {
+ Print(L"Unrecorginzed Machine\n");
+ }
+
+ Print(L"Entry point: hx%x\n", header->e_entry);
+
+
+ char * strtable = elf_str_table(header);
+ Print(L"%s\n", strtable);
+}
+
+// functions to access section headers
+Elf64_Shdr *elf_sheader(Elf64_Ehdr *hdr)
+{
+ return (Elf64_Shdr *)((uintptr_t)hdr + hdr->e_shoff);
+}
+
+Elf64_Shdr *elf_section(Elf64_Ehdr *hdr, int idx)
+{
+ return &elf_sheader(hdr)[idx];
+}
+
+char *elf_str_table(Elf64_Ehdr *hdr)
+{
+ if(hdr->e_shstrndx == SHN_UNDEF) return NULL;
+ return (char *)hdr + elf_section(hdr, hdr->e_shstrndx)->sh_offset;
+}
+