diff --git a/Il2CppInspector.Common/FileFormatReaders/MachOReader.cs b/Il2CppInspector.Common/FileFormatReaders/MachOReader.cs index 2a3404c..259273b 100644 --- a/Il2CppInspector.Common/FileFormatReaders/MachOReader.cs +++ b/Il2CppInspector.Common/FileFormatReaders/MachOReader.cs @@ -25,12 +25,12 @@ namespace Il2CppInspector protected override MachO lc_Segment => MachO.LC_SEGMENT; public override uint MapVATR(ulong uiAddr) { - var section = sections.First(x => uiAddr >= x.Address && uiAddr <= x.Address + x.Size); + var section = machoSections.First(x => uiAddr >= x.Address && uiAddr <= x.Address + x.Size); return (uint) uiAddr - (section.Address - section.ImageOffset); } public override ulong MapFileOffsetToVA(uint offset) { - var section = sections.First(x => offset >= x.ImageOffset && offset < x.ImageOffset + x.Size); + var section = machoSections.First(x => offset >= x.ImageOffset && offset < x.ImageOffset + x.Size); return section.Address + offset - section.ImageOffset; } } @@ -47,12 +47,12 @@ namespace Il2CppInspector protected override MachO lc_Segment => MachO.LC_SEGMENT_64; public override uint MapVATR(ulong uiAddr) { - var section = sections.First(x => uiAddr >= x.Address && uiAddr <= x.Address + x.Size); + var section = machoSections.First(x => uiAddr >= x.Address && uiAddr <= x.Address + x.Size); return (uint) (uiAddr - (section.Address - section.ImageOffset)); } public override ulong MapFileOffsetToVA(uint offset) { - var section = sections.First(x => offset >= x.ImageOffset && offset < x.ImageOffset + x.Size); + var section = machoSections.First(x => offset >= x.ImageOffset && offset < x.ImageOffset + x.Size); return section.Address + offset - section.ImageOffset; } } @@ -67,7 +67,9 @@ namespace Il2CppInspector private readonly TConvert conv = new TConvert(); private MachOHeader header; - protected readonly List> sections = new List>(); + protected readonly List> machoSections = new List>(); + private List
sections = new List
(); + private MachOSection funcTab; private MachOSymtabCommand symTab; @@ -121,7 +123,23 @@ namespace Il2CppInspector if (segment.Name == "__TEXT" || segment.Name == "__DATA") { for (int s = 0; s < segment.NumSections; s++) { var section = ReadObject>(); - sections.Add(section); + machoSections.Add(section); + + // Create universal section + sections.Add(new Section { + VirtualStart = conv.ULong(section.Address), + VirtualEnd = conv.ULong(section.Address) + conv.ULong(section.Size) - 1, + ImageStart = section.ImageOffset, + ImageEnd = section.ImageOffset + (uint) conv.Int(section.Size) - 1, + + IsData = segment.Name == "__DATA" && section.Name != "__bss", + IsExec = segment.Name == "__TEXT", + IsBSS = segment.Name == "__DATA" && section.Name == "__bss", + + Name = section.Name + }); + + // First code section if (section.Name == "__text") { GlobalOffset = (ulong) Convert.ChangeType(section.Address, typeof(ulong)) - section.ImageOffset; } @@ -170,7 +188,7 @@ namespace Il2CppInspector return false; // Process relocations - foreach (var section in sections) { + foreach (var section in machoSections) { var rels = ReadArray(section.ImageRelocOffset, section.NumRelocEntries); // TODO: Implement Mach-O relocations @@ -275,5 +293,7 @@ namespace Il2CppInspector } public override IEnumerable GetExports() => exports; + + public override IEnumerable
GetSections() => sections; } } diff --git a/Il2CppInspector.Common/FileFormatReaders/PEReader.cs b/Il2CppInspector.Common/FileFormatReaders/PEReader.cs index 89fab10..dc3f473 100644 --- a/Il2CppInspector.Common/FileFormatReaders/PEReader.cs +++ b/Il2CppInspector.Common/FileFormatReaders/PEReader.cs @@ -167,5 +167,7 @@ namespace Il2CppInspector return pe.ImageBase + section.VirtualAddress + offset - section.PointerToRawData; } + + // TODO: PEReader.GetSections() } } diff --git a/Il2CppInspector.Common/FileFormatReaders/SElfReader.cs b/Il2CppInspector.Common/FileFormatReaders/SElfReader.cs index f8930a4..a7a2f60 100644 --- a/Il2CppInspector.Common/FileFormatReaders/SElfReader.cs +++ b/Il2CppInspector.Common/FileFormatReaders/SElfReader.cs @@ -124,5 +124,7 @@ namespace Il2CppInspector var segment = pht.First(x => offset >= x.p_offset && offset < x.p_offset + x.p_filesz); return segment.p_vaddr + offset - segment.p_offset; } + + // TODO: SElfReader.GetSections() } } \ No newline at end of file