diff --git a/Il2CppInspector/FileFormatReaders/ElfReader.cs b/Il2CppInspector/FileFormatReaders/ElfReader.cs index 6c193f1..0ba18b8 100644 --- a/Il2CppInspector/FileFormatReaders/ElfReader.cs +++ b/Il2CppInspector/FileFormatReaders/ElfReader.cs @@ -184,11 +184,9 @@ namespace Il2CppInspector if (getProgramHeader(Elf.PT_DYNAMIC) is TPHdr PT_DYNAMIC) dynamic_table = ReadArray>(math.Long(PT_DYNAMIC.p_offset), (int) (math.Long(PT_DYNAMIC.p_filesz) / Sizeof(typeof(elf_dynamic)))); - // Get global offset table - var _GLOBAL_OFFSET_TABLE_ = getDynamic(Elf.DT_PLTGOT)?.d_un; - if (_GLOBAL_OFFSET_TABLE_ == null) - throw new InvalidOperationException("Unable to get GLOBAL_OFFSET_TABLE from PT_DYNAMIC"); - GlobalOffset = math.ULong((TWord) _GLOBAL_OFFSET_TABLE_); + // Get offset of code section + var codeSegment = program_header_table.First(x => ((Elf) x.p_flags & Elf.PF_X) == Elf.PF_X); + GlobalOffset = math.ULong(math.Sub(codeSegment.p_vaddr, codeSegment.p_offset)); // Find all relocations; target address => (rela header (rels are converted to rela), symbol table base address, is rela?) var rels = new HashSet(); diff --git a/Il2CppInspector/FileFormatReaders/FormatLayouts/Elf.cs b/Il2CppInspector/FileFormatReaders/FormatLayouts/Elf.cs index 9d64e93..fd483b0 100644 --- a/Il2CppInspector/FileFormatReaders/FormatLayouts/Elf.cs +++ b/Il2CppInspector/FileFormatReaders/FormatLayouts/Elf.cs @@ -5,10 +5,12 @@ All rights reserved. */ +using System; using NoisyCowStudios.Bin2Object; namespace Il2CppInspector { + [Flags] public enum Elf : uint { // elf_header.m_dwFormat @@ -28,6 +30,8 @@ namespace Il2CppInspector PT_DYNAMIC = 2, DT_PLTGOT = 3, + PF_X = 1, + // SHTs SHT_SYMTAB = 2, SHT_STRTAB = 3, @@ -122,6 +126,7 @@ namespace Il2CppInspector TWord p_offset { get; } TWord p_filesz { get; } TWord p_vaddr { get; } + uint p_flags { get; } } internal class elf_32_phdr : Ielf_phdr @@ -130,6 +135,7 @@ namespace Il2CppInspector public uint p_offset => f_p_offset; public uint p_filesz => f_p_filesz; public uint p_vaddr => f_p_vaddr; + public uint p_flags => f_p_flags; public uint f_p_type; public uint f_p_offset; @@ -137,7 +143,7 @@ namespace Il2CppInspector public uint p_paddr; public uint f_p_filesz; public uint p_memsz; - public uint p_flags; + public uint f_p_flags; public uint p_align; } @@ -147,9 +153,10 @@ namespace Il2CppInspector public ulong p_offset => f_p_offset; public ulong p_filesz => f_p_filesz; public ulong p_vaddr => f_p_vaddr; + public uint p_flags => f_p_flags; public uint f_p_type; - public uint p_flags; + public uint f_p_flags; public ulong f_p_offset; public ulong f_p_vaddr; public ulong p_paddr;