From dda58af124d6a57b6e8ed3c1bbecbba8a2f67431 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 22 Oct 2019 23:41:18 +0200 Subject: [PATCH] Add Mach-O relocation processing stub --- .../FileFormatReaders/FormatLayouts/MachO.cs | 14 +++++++++++++- Il2CppInspector/FileFormatReaders/MachOReader.cs | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector/FileFormatReaders/FormatLayouts/MachO.cs b/Il2CppInspector/FileFormatReaders/FormatLayouts/MachO.cs index cac1106..f177024 100644 --- a/Il2CppInspector/FileFormatReaders/FormatLayouts/MachO.cs +++ b/Il2CppInspector/FileFormatReaders/FormatLayouts/MachO.cs @@ -75,7 +75,7 @@ namespace Il2CppInspector public uint ImageOffset; public uint Align; public uint ImageRelocOffset; - public uint NumRelocEntries; + public int NumRelocEntries; public uint Flags; public uint Reserved1; public TWord Reserved2; @@ -104,4 +104,16 @@ namespace Il2CppInspector public ushort n_desc; public TWord n_value; } + + internal class MachO_relocation_info + { + public int r_address; + public uint r_data; + + public uint r_symbolnum => r_data & 0x00ffffff; + public bool r_pcrel => ((r_data >> 24) & 1) == 1; + public uint r_length => (r_data >> 25) & 3; + public bool r_extern => ((r_data >> 27) & 1) == 1; + public uint r_type => r_data >> 28; + } } diff --git a/Il2CppInspector/FileFormatReaders/MachOReader.cs b/Il2CppInspector/FileFormatReaders/MachOReader.cs index b7881e1..826ead9 100644 --- a/Il2CppInspector/FileFormatReaders/MachOReader.cs +++ b/Il2CppInspector/FileFormatReaders/MachOReader.cs @@ -129,7 +129,20 @@ namespace Il2CppInspector } // Must find LC_FUNCTION_STARTS load command - return (funcTab != null); + if (funcTab == null) + return false; + + // Process relocations + foreach (var section in sections) { + var rels = ReadArray(section.ImageRelocOffset, section.NumRelocEntries); + + // TODO: Implement + if (rels.Any()) { + Console.WriteLine("Mach-O file contains relocations (feature not yet implemented)"); + break; + } + } + return true; } public override uint[] GetFunctionTable() {