Fix incorrect use of GlobalOffset in ELF (WARNING: breaks some binaries from resolving)

This commit is contained in:
Katy Coe
2019-10-26 05:39:54 +02:00
parent a8a9bd121f
commit 2236764715
2 changed files with 12 additions and 7 deletions

View File

@@ -184,11 +184,9 @@ namespace Il2CppInspector
if (getProgramHeader(Elf.PT_DYNAMIC) is TPHdr PT_DYNAMIC)
dynamic_table = ReadArray<elf_dynamic<TWord>>(math.Long(PT_DYNAMIC.p_offset), (int) (math.Long(PT_DYNAMIC.p_filesz) / Sizeof(typeof(elf_dynamic<TWord>))));
// 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<ElfReloc>();

View File

@@ -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<uint>
@@ -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;