From 37f43580e423f047933ab97dba7a79f6d68ce2e4 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Thu, 13 Feb 2020 18:03:53 +0100 Subject: [PATCH] ELF: Don't crash if there are no section names (part of #21) --- .../FileFormatReaders/ElfReader.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs b/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs index a6d0f9d..f144ca5 100644 --- a/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs +++ b/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs @@ -125,8 +125,6 @@ namespace Il2CppInspector public override int Bits => (elf_header.m_arch == (uint) Elf.ELFCLASS64) ? 64 : 32; - //public override event EventHandler OnStatusUpdate; - private elf_shdr getSection(Elf sectionIndex) => section_header_table.FirstOrDefault(x => x.sh_type == (uint) sectionIndex); private IEnumerable> getSections(Elf sectionIndex) => section_header_table.Where(x => x.sh_type == (uint) sectionIndex); private TPHdr getProgramHeader(Elf programIndex) => program_header_table.FirstOrDefault(x => x.p_type == (uint) programIndex); @@ -151,11 +149,13 @@ namespace Il2CppInspector program_header_table = ReadArray(conv.Long(elf_header.e_phoff), elf_header.e_phnum); section_header_table = ReadArray>(conv.Long(elf_header.e_shoff), elf_header.e_shnum); - // Get section name mappings - var pStrtab = section_header_table[elf_header.e_shtrndx].sh_offset; - foreach (var section in section_header_table) { - var name = ReadNullTerminatedString(conv.Long(pStrtab) + section.sh_name); - sectionByName.Add(name, section); + // Get section name mappings if there are any + if (elf_header.e_shtrndx < section_header_table.Length) { + var pStrtab = section_header_table[elf_header.e_shtrndx].sh_offset; + foreach (var section in section_header_table) { + var name = ReadNullTerminatedString(conv.Long(pStrtab) + section.sh_name); + sectionByName.Add(name, section); + } } // Get dynamic table if it exists