C++: Output Il2CppClass* (TypeInfo) pointers

This commit is contained in:
Katy Coe
2020-07-18 21:23:23 +02:00
parent 7124149fef
commit 6d50ab7546
3 changed files with 22 additions and 2 deletions

View File

@@ -25,7 +25,8 @@ namespace Il2CppInspector
string Format { get; } string Format { get; }
string Arch { get; } string Arch { get; }
int Bits { get; } int Bits { get; }
ulong GlobalOffset { get; } ulong GlobalOffset { get; } // The virtual address where the code section (.text) would be loaded in memory
ulong ImageBase { get; } // The virtual address of where the image would be loaded in memory (same as GlobalOffset except for PE)
Dictionary<string, ulong> GetSymbolTable(); Dictionary<string, ulong> GetSymbolTable();
uint[] GetFunctionTable(); uint[] GetFunctionTable();
IEnumerable<Export> GetExports(); IEnumerable<Export> GetExports();
@@ -87,6 +88,8 @@ namespace Il2CppInspector
public ulong GlobalOffset { get; protected set; } public ulong GlobalOffset { get; protected set; }
public virtual ulong ImageBase => GlobalOffset;
public virtual string Format => throw new NotImplementedException(); public virtual string Format => throw new NotImplementedException();
public virtual string Arch => throw new NotImplementedException(); public virtual string Arch => throw new NotImplementedException();

View File

@@ -40,6 +40,8 @@ namespace Il2CppInspector
// Could also use coff.Characteristics (IMAGE_FILE_32BIT_MACHINE) or coff.Machine // Could also use coff.Characteristics (IMAGE_FILE_32BIT_MACHINE) or coff.Machine
public override int Bits => (PE) pe.Magic == PE.IMAGE_NT_OPTIONAL_HDR64_MAGIC ? 64 : 32; public override int Bits => (PE) pe.Magic == PE.IMAGE_NT_OPTIONAL_HDR64_MAGIC ? 64 : 32;
public override ulong ImageBase => pe.ImageBase;
protected override bool Init() { protected override bool Init() {
// Check for MZ signature "MZ" // Check for MZ signature "MZ"
if (ReadUInt16() != 0x5A4D) if (ReadUInt16() != 0x5A4D)

View File

@@ -61,7 +61,22 @@ namespace Il2CppInspector.Outputs
var exportRgx = new Regex(@"^_+"); var exportRgx = new Regex(@"^_+");
foreach (var export in exports) { foreach (var export in exports) {
writeCode($"#define {exportRgx.Replace(export.Name, "")}_ptr 0x{model.Package.BinaryImage.MapVATR(export.VirtualAddress):x8}"); writeCode($"#define {exportRgx.Replace(export.Name, "")}_ptr 0x{model.Package.BinaryImage.MapVATR(export.VirtualAddress):X8}");
}
writer.Close();
// Write application type definition addresses to il2cpp-type-ptr.h
var il2cppTypeInfoFile = Path.Combine(outputPath, "il2cpp-type-ptr.h");
using var fs3 = new FileStream(il2cppTypeInfoFile, FileMode.Create);
writer = new StreamWriter(fs3, Encoding.UTF8);
writeHeader();
writeSectionHeader("IL2CPP application-specific type definition addresses");
foreach (var type in model.Types.Values.Where(t => t.TypeClassAddress != 0xffffffff_ffffffff)) {
writeCode($"DO_TYPEDEF(0x{type.TypeClassAddress - model.Package.BinaryImage.ImageBase:X8}, {type.Name});");
} }
writer.Close(); writer.Close();