From c4378ffb140dbf51380a054b3bec62da414290b3 Mon Sep 17 00:00:00 2001 From: Shadlock0133 Date: Sat, 22 Mar 2025 13:47:43 +0100 Subject: [PATCH] patterns/elf: Use e_shstrndx to get section names instead of guessing (#357) --- patterns/elf.hexpat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/elf.hexpat b/patterns/elf.hexpat index 71616a6..77dc604 100644 --- a/patterns/elf.hexpat +++ b/patterns/elf.hexpat @@ -643,7 +643,6 @@ struct Elf32_Shdr { // Section has no data } else if (sh_type == SHT::STRTAB) { String stringTable[while($ < (sh_offset + sh_size))] @ sh_offset; - stringTableIndex = std::core::array_index(); } else if (sh_type == SHT::SYMTAB || sh_type == SHT::DYNSYM) { Elf32_Sym symbolTable[sh_size / sh_entsize] @ sh_offset; } else if (sh_type == SHT::INIT_ARRAY || sh_type == SHT::FINI_ARRAY) { @@ -703,7 +702,6 @@ struct Elf64_Shdr { // Section has no data } else if (sh_type == SHT::STRTAB) { String stringTable[while($ < (sh_offset + sh_size))] @ sh_offset; - stringTableIndex = std::core::array_index(); } else if (sh_type == SHT::SYMTAB || sh_type == SHT::DYNSYM) { Elf64_Sym symbolTable[sh_size / sh_entsize] @ sh_offset; } else if (sh_type == SHT::INIT_ARRAY || sh_type == SHT::FINI_ARRAY) { @@ -734,10 +732,12 @@ struct ELF { if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS32) { Elf32_Ehdr ehdr; + stringTableIndex = ehdr.e_shstrndx; Elf32_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff; Elf32_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff; } else if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS64) { Elf64_Ehdr ehdr; + stringTableIndex = ehdr.e_shstrndx; Elf64_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff; Elf64_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff; }