From 26a4ee14e99e02e99f5139f146a55b9a5383984c Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 14 Aug 2020 02:53:39 +0200 Subject: [PATCH] AppModel: Wrap AddressMap TypeInfo/TypeRef/MethodInfo in AppReference --- Il2CppInspector.Common/Model/AddressMap.cs | 29 ++++++++++++++++++-- Il2CppInspector.Common/Model/AppReference.cs | 29 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 Il2CppInspector.Common/Model/AppReference.cs diff --git a/Il2CppInspector.Common/Model/AddressMap.cs b/Il2CppInspector.Common/Model/AddressMap.cs index c0ed195..eaa1177 100644 --- a/Il2CppInspector.Common/Model/AddressMap.cs +++ b/Il2CppInspector.Common/Model/AddressMap.cs @@ -22,6 +22,19 @@ namespace Il2CppInspector.Model public AppModel Model { get; } // Underlying collection + // Objects this can return (subject to change): + // - AppMethod (for method function body) + // - AppMethodReference (for MethodInfo *) + // - List (for custom attributes generator) + // - MethodInvoker (for a Method.Invoke think) + // - string (System.String) (for a string literal) + // - Il2CppCodeRegistration + // - Il2CppMetadataRegistration + // - Dictionary (for Il2CppCodeGenModules *[]) + // - Il2CppCodeGenModule + // - CppFnPtrType (for il2cpp_codegen_register, Il2CPP API exports, unknown functions) + // - Export (for exports) + // - Symbol (for symbols) public SortedDictionary Items { get; } = new SortedDictionary(); #region Surrogate implementation of IDictionary @@ -67,7 +80,11 @@ namespace Il2CppInspector.Model // Method reference (MethodInfo *) if (method.HasMethodInfo) - Add(method.MethodInfoPtrAddress, new CppField($"{method.CppFnPtrType.Name}__MethodInfo", methodInfoPtrType)); + Add(method.MethodInfoPtrAddress, + new AppMethodReference { + Field = new CppField($"{method.CppFnPtrType.Name}__MethodInfo", methodInfoPtrType), + Method = method + }); } // Add all custom attributes generators @@ -89,10 +106,16 @@ namespace Il2CppInspector.Model var classRefPtrType = cppTypes.GetType("Il2CppType *"); foreach (var type in Model.Types.Values) { if (type.TypeClassAddress != 0xffffffff_ffffffff) - Add(type.TypeClassAddress, new CppField($"{type.Name}__TypeInfo", classPtrType)); + Add(type.TypeClassAddress, new AppTypeReference { + Field = new CppField($"{type.Name}__TypeInfo", classPtrType), + Type = type + }); if (type.TypeRefPtrAddress != 0xffffffff_ffffffff) - Add(type.TypeRefPtrAddress, new CppField($"{type.Name}__TypeRef", classRefPtrType)); + Add(type.TypeRefPtrAddress, new AppTypeReference { + Field = new CppField($"{type.Name}__TypeRef", classRefPtrType), + Type = type + }); } // Internal metadata diff --git a/Il2CppInspector.Common/Model/AppReference.cs b/Il2CppInspector.Common/Model/AppReference.cs new file mode 100644 index 0000000..b39509b --- /dev/null +++ b/Il2CppInspector.Common/Model/AppReference.cs @@ -0,0 +1,29 @@ +/* + Copyright 2020 Katy Coe - http://www.djkaty.com - https://github.com/djkaty + + All rights reserved. +*/ + +using Il2CppInspector.Cpp; + +namespace Il2CppInspector.Model +{ + // Class that represents a single pointer in the address map which references a method or type + public class AppReference + { + public CppField Field { get; set; } + } + + // Reference to a method (MethodInfo *) + public class AppMethodReference : AppReference + { + public AppMethod Method { get; set; } + } + + // Reference to a type (Il2CppObject * or Il2CppType *, use Field to determine which) + public class AppTypeReference : AppReference + { + // The corresponding C++ function pointer type + public AppType Type { get; set; } + } +}