ELF: Add ability to fetch exports with GetExports()
This commit is contained in:
@@ -130,6 +130,9 @@ namespace Il2CppInspector
|
||||
private TPHdr getProgramHeader(Elf programIndex) => program_header_table.FirstOrDefault(x => x.p_type == (uint) programIndex);
|
||||
private elf_dynamic<TWord> getDynamic(Elf dynamicIndex) => dynamic_table?.FirstOrDefault(x => (Elf) conv.ULong(x.d_tag) == dynamicIndex);
|
||||
|
||||
private Dictionary<string, ulong> symbolTable = new Dictionary<string, ulong>();
|
||||
private List<Export> exports = new List<Export>();
|
||||
|
||||
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<string, ulong> GetSymbolTable() {
|
||||
public override Dictionary<string, ulong> GetSymbolTable() => symbolTable;
|
||||
public override IEnumerable<Export> 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<string, ulong>();
|
||||
symbolTable.Clear();
|
||||
var exportTable = new Dictionary<string, Export>();
|
||||
|
||||
foreach (var pTab in pTables) {
|
||||
var symbol_table = ReadArray<TSym>(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() {
|
||||
|
||||
@@ -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<uint>
|
||||
{
|
||||
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<ulong>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user