diff --git a/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs b/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs index aa9f737..c4c1597 100644 --- a/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs +++ b/Il2CppInspector.Common/FileFormatReaders/ElfReader.cs @@ -130,6 +130,9 @@ namespace Il2CppInspector private TPHdr getProgramHeader(Elf programIndex) => program_header_table.FirstOrDefault(x => x.p_type == (uint) programIndex); private elf_dynamic getDynamic(Elf dynamicIndex) => dynamic_table?.FirstOrDefault(x => (Elf) conv.ULong(x.d_tag) == dynamicIndex); + private Dictionary symbolTable = new Dictionary(); + private List exports = new List(); + protected abstract Elf ArchClass { get; } protected abstract void Write(BinaryWriter writer, TWord value); @@ -284,6 +287,9 @@ namespace Il2CppInspector throw new InvalidOperationException("This IL2CPP binary is packed in a way not currently supported by Il2CppInspector and cannot be loaded."); } + // Build symbol and export tables + processSymbols(); + return true; } @@ -301,7 +307,10 @@ namespace Il2CppInspector xorRange(conv.Int(section.sh_offset), conv.Int(section.sh_size), xorValue); } - public override Dictionary GetSymbolTable() { + public override Dictionary GetSymbolTable() => symbolTable; + public override IEnumerable GetExports() => exports; + + private void processSymbols() { // Three possible symbol tables in ELF files var pTables = new List<(TWord offset, TWord count, TWord strings)>(); @@ -337,7 +346,8 @@ namespace Il2CppInspector } // Now iterate through all of the symbol and string tables we found to build a full list - var symbolTable = new Dictionary(); + symbolTable.Clear(); + var exportTable = new Dictionary(); foreach (var pTab in pTables) { var symbol_table = ReadArray(conv.Long(pTab.offset), conv.Int(pTab.count)); @@ -347,10 +357,12 @@ namespace Il2CppInspector // Avoid duplicates symbolTable.TryAdd(name, conv.ULong(symbol.st_value)); + if (symbol.st_shndx != (ushort) Elf.SHN_UNDEF) + exportTable.TryAdd(name, new Export {Name = name, VirtualAddress = conv.ULong(symbol.st_value)}); } } - return symbolTable; + exports = exportTable.Values.ToList(); } public override uint[] GetFunctionTable() { diff --git a/Il2CppInspector.Common/FileFormatReaders/FormatLayouts/Elf.cs b/Il2CppInspector.Common/FileFormatReaders/FormatLayouts/Elf.cs index b232d8c..22b53c5 100644 --- a/Il2CppInspector.Common/FileFormatReaders/FormatLayouts/Elf.cs +++ b/Il2CppInspector.Common/FileFormatReaders/FormatLayouts/Elf.cs @@ -42,6 +42,9 @@ namespace Il2CppInspector SHT_REL = 9, SHT_DYNSYM = 11, + // SHNs + SHN_UNDEF = 0, + // dynamic sections DT_STRTAB = 5, DT_SYMTAB = 6, @@ -187,30 +190,33 @@ namespace Il2CppInspector { uint st_name { get; } TWord st_value { get; } + ushort st_shndx { get; } } internal class elf_32_sym : Ielf_sym { public uint st_name => f_st_name; public uint st_value => f_st_value; + public ushort st_shndx => f_st_shndx; public uint f_st_name; public uint f_st_value; public uint st_size; public byte st_info; public byte st_other; - public ushort st_shndx; + public ushort f_st_shndx; } internal class elf_64_sym : Ielf_sym { public uint st_name => f_st_name; public ulong st_value => f_st_value; + public ushort st_shndx => f_st_shndx; public uint f_st_name; public byte st_info; public byte st_other; - public ushort st_shndx; + public ushort f_st_shndx; public ulong f_st_value; public ulong st_size; }