From f3ae5e79f2de0b214a498ee2d1028d22551a98ab Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sun, 6 Sep 2020 05:23:57 +0200 Subject: [PATCH] JSON: Add arrayMetadata entry (currently Il2CppCodeGenModule *[]) --- Il2CppInspector.Common/Model/AddressMap.cs | 1 + .../Outputs/JSONMetadata.cs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Il2CppInspector.Common/Model/AddressMap.cs b/Il2CppInspector.Common/Model/AddressMap.cs index eaa1177..50fd34e 100644 --- a/Il2CppInspector.Common/Model/AddressMap.cs +++ b/Il2CppInspector.Common/Model/AddressMap.cs @@ -124,6 +124,7 @@ namespace Il2CppInspector.Model Add(binary.MetadataRegistrationPointer, binary.MetadataRegistration); if (Model.Package.Version >= 24.2) { + // TODO: Add some kind of AppArray composite type for arrays as we'll be adding more later Add(binary.CodeRegistration.pcodeGenModules, binary.CodeGenModulePointers); foreach (var ptr in binary.CodeGenModulePointers) diff --git a/Il2CppInspector.Common/Outputs/JSONMetadata.cs b/Il2CppInspector.Common/Outputs/JSONMetadata.cs index 09c4a7b..8e32bee 100644 --- a/Il2CppInspector.Common/Outputs/JSONMetadata.cs +++ b/Il2CppInspector.Common/Outputs/JSONMetadata.cs @@ -147,16 +147,10 @@ namespace Il2CppInspector.Outputs private void writeMetadata() { var binary = model.Package.Binary; - // TODO: In the future, add struct definitions/fields, data ranges and the entire IL2CPP metadata tree writeArray("typeMetadata", () => { writeObject(() => writeTypedName(binary.CodeRegistrationPointer, "struct Il2CppCodeRegistration", "g_CodeRegistration")); writeObject(() => writeTypedName(binary.MetadataRegistrationPointer, "struct Il2CppMetadataRegistration", "g_MetadataRegistration")); - if (model.Package.Version >= 24.2) - writeObject(() => writeTypedName(binary.CodeRegistration.pcodeGenModules, - // Ghidra doesn't like *[x] or ** so use * * instead - $"struct Il2CppCodeGenModule * *", "g_CodeGenModules")); - foreach (var ptr in binary.CodeGenModulePointers) writeObject(() => writeTypedName(ptr.Value, "struct Il2CppCodeGenModule", $"g_{ptr.Key.Replace(".dll", "")}CodeGenModule")); }, "IL2CPP Type Metadata"); @@ -177,6 +171,13 @@ namespace Il2CppInspector.Outputs "void il2cpp_codegen_register(const Il2CppCodeRegistration* const codeRegistration, const Il2CppMetadataRegistration* const metadataRegistration)", "il2cpp_codegen_register")); }, "IL2CPP Function Metadata"); + + // TODO: In the future, add data ranges for the entire IL2CPP metadata tree + writeArray("arrayMetadata", () => { + if (model.Package.Version >= 24.2) { + writeObject(() => writeTypedArray(binary.CodeRegistration.pcodeGenModules, binary.Modules.Count, "struct Il2CppCodeGenModule *", "g_CodeGenModules")); + } + }, "IL2CPP Array Metadata"); } private void writeApis() { @@ -214,6 +215,7 @@ namespace Il2CppInspector.Outputs }, "Symbol table"); } + // JSON helpers private void writeObject(Action objectWriter) => writeObject(null, objectWriter); private void writeObject(string name, Action objectWriter, string description = null) { @@ -250,6 +252,11 @@ namespace Il2CppInspector.Outputs writer.WriteString("signature", type.ToEscapedString()); } + private void writeTypedArray(ulong address, int count, string type, string name) { + writeTypedName(address, type, name); + writer.WriteNumber("count", count); + } + private void writeDotNetSignature(MethodBase method) { writer.WriteString("dotNetSignature", method.ToString().ToEscapedString()); }