diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs index b4a1662..58f12ee 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppBinary.cs @@ -1,6 +1,6 @@ /* Copyright 2017 Perfare - https://github.com/Perfare/Il2CppDumper - Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com + Copyright 2017-2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty All rights reserved. */ @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; namespace Il2CppInspector { @@ -266,5 +267,24 @@ namespace Il2CppInspector GenericMethodInvokerIndices.Add(MethodSpecs[tableEntry.genericMethodIndex], tableEntry.indices.invokerIndex); } } + + // IL2CPP API exports + // This strips leading underscores and selects only il2cpp_* symbols which can be mapped into the binary + // (therefore ignoring extern imports) + public Dictionary GetAPIExports() { + var exports = Image.GetExports()?.Where(e => e.Name.StartsWith("il2cpp_") || e.Name.StartsWith("_il2cpp_") || e.Name.StartsWith("__il2cpp_")); + + if (exports == null) + return new Dictionary(); + + var exportRgx = new Regex(@"^_+"); + var il2cppExports = new Dictionary(); + + foreach (var export in exports) + if (Image.TryMapVATR(export.VirtualAddress, out _)) + il2cppExports.Add(exportRgx.Replace(export.Name, ""), export.VirtualAddress); + + return il2cppExports; + } } } diff --git a/Il2CppInspector.Common/Outputs/CppScaffolding.cs b/Il2CppInspector.Common/Outputs/CppScaffolding.cs index ecd5114..feab3b0 100644 --- a/Il2CppInspector.Common/Outputs/CppScaffolding.cs +++ b/Il2CppInspector.Common/Outputs/CppScaffolding.cs @@ -59,11 +59,11 @@ namespace Il2CppInspector.Outputs writeHeader(); writeSectionHeader("IL2CPP API function pointers"); - var exports = model.Exports.Where(e => e.Name.StartsWith("il2cpp_") || e.Name.StartsWith("_il2cpp_") || e.Name.StartsWith("__il2cpp_")); - var exportRgx = new Regex(@"^_+"); + // TODO: Use model.APIExports instead once it is implemented + var exports = model.Package.Binary.GetAPIExports(); foreach (var export in exports) { - writeCode($"#define {exportRgx.Replace(export.Name, "")}_ptr 0x{model.Package.BinaryImage.MapVATR(export.VirtualAddress):X8}"); + writeCode($"#define {export.Key}_ptr 0x{model.Package.BinaryImage.MapVATR(export.Value):X8}"); } writer.Close();