From bade38e1732277a5c209c7f0846ec9d060a0eddd Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 10 Dec 2022 06:43:37 +0200 Subject: [PATCH] Do not read the header if it's not "PT_LOAD" --- Execute/Spawn.cpp | 23 +++++++++++++---------- include/elf.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Execute/Spawn.cpp b/Execute/Spawn.cpp index 562c8d0..392daf5 100644 --- a/Execute/Spawn.cpp +++ b/Execute/Spawn.cpp @@ -183,18 +183,21 @@ namespace Execute uintptr_t MAddr; if (ItrProgramHeader.p_type == PT_LOAD) + { debug("PT_LOAD"); + MAddr = (ItrProgramHeader.p_vaddr - BaseAddress) + (uintptr_t)MemoryImage; + + memset(MemoryImage, 0, ItrProgramHeader.p_memsz); + memcpy(MemoryImage, (uint8_t *)BaseImage + ItrProgramHeader.p_offset, ItrProgramHeader.p_filesz); + debug("MemoryImage: %#lx", MemoryImage); + debug("MAddr: %#lx", MAddr); + debug("memset operation: 0 to %#lx for length %ld", MemoryImage + MAddr, ItrProgramHeader.p_memsz); + debug("memcpy operation: %#lx to %#lx for length %ld", (uint8_t *)BaseImage + ItrProgramHeader.p_offset, MemoryImage + MAddr, ItrProgramHeader.p_filesz); + } else - debug("Not PT_LOAD"); - - MAddr = (ItrProgramHeader.p_vaddr - BaseAddress) + (uintptr_t)MemoryImage; - - memset(MemoryImage, 0, ItrProgramHeader.p_memsz); - memcpy(MemoryImage, (uint8_t *)BaseImage + ItrProgramHeader.p_offset, ItrProgramHeader.p_filesz); - debug("MemoryImage: %#lx", MemoryImage); - debug("MAddr: %#lx", MAddr); - debug("memset operation: 0 to %#lx for length %ld", MemoryImage + MAddr, ItrProgramHeader.p_memsz); - debug("memcpy operation: %#lx to %#lx for length %ld", (uint8_t *)BaseImage + ItrProgramHeader.p_offset, MemoryImage + MAddr, ItrProgramHeader.p_filesz); + { + fixme("Not PT_LOAD (%ld)", ItrProgramHeader.p_type); + } } debug("Entry Point: %#lx", ELFHeader->e_entry); diff --git a/include/elf.h b/include/elf.h index 428c271..9c85aee 100644 --- a/include/elf.h +++ b/include/elf.h @@ -239,6 +239,7 @@ enum SegmentTypes PT_NOTE = 4, PT_SHLIB = 5, PT_PHDR = 6, + PT_TLS = 7, PT_LOSUNW = 0x6ffffffa, PT_SUNWBSS = 0x6ffffffb, PT_SUNWSTACK = 0x6ffffffa,