From ef043383fc981a8f14200d5f6cfa1320dad0aead Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 14 Jul 2020 16:56:30 +0200 Subject: [PATCH] AppModel: Handle .NET unmapped pointer type definitions --- .../Cpp/CppTypeCollection.cs | 4 ++-- Il2CppInspector.Common/Model/AppModel.cs | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector.Common/Cpp/CppTypeCollection.cs b/Il2CppInspector.Common/Cpp/CppTypeCollection.cs index 3c58b1d..b988acc 100644 --- a/Il2CppInspector.Common/Cpp/CppTypeCollection.cs +++ b/Il2CppInspector.Common/Cpp/CppTypeCollection.cs @@ -518,8 +518,8 @@ namespace Il2CppInspector.Cpp // Get all of the types in a logical group public IEnumerable GetTypeGroup(string groupName) => Types.Values.Where(t => t.Group == groupName); - // Add a type externally - public void Add(CppType type) { + // Add a type + private void Add(CppType type) { type.Group = currentGroup; Types.Add(type.Name, type); } diff --git a/Il2CppInspector.Common/Model/AppModel.cs b/Il2CppInspector.Common/Model/AppModel.cs index 4a53f1f..6480185 100644 --- a/Il2CppInspector.Common/Model/AppModel.cs +++ b/Il2CppInspector.Common/Model/AppModel.cs @@ -7,6 +7,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Aron.Weiler; using Il2CppInspector.Cpp; @@ -160,9 +161,25 @@ namespace Il2CppInspector.Model AddTypes(declarationGenerator.GenerateRemainingTypeDeclarations()); if (usage.Type == MetadataUsageType.TypeInfo) - Types[type].TypeClassAddress = address; + // .NET unsafe pointer type that has not been mapped by IL2CPP to a C type + // (often void* or byte* in metadata v23 and v24.0) + if (!Types.ContainsKey(type)) { + Debug.Assert(type.IsPointer); + + // TODO: This should really be handled by CppDeclarationGenerator, and doesn't generate the full definition + var cppType = CppTypeCollection.Struct(declarationGenerator.TypeNamer.GetName(type) + "__TypeInfo"); + var cppObjectType = (CppComplexType) CppTypeCollection["Il2CppObject"]; + cppType.Fields = new SortedDictionary>(cppObjectType.Fields); + + DependencyOrderedCppTypes.Add(cppType); + Types.Add(type, cppType, new AppType(type, cppType, cppClassPtr: address)); + } + else + // Regular type definition + Types[type].TypeClassAddress = address; + else if (!Types.ContainsKey(type)) - // Generic type definition has no associated C++ type, therefore no dictionary subkey + // Generic type definition has no associated C++ type, therefore no dictionary sub-key Types.Add(type, new AppType(type, null, cppTypeRefPtr: address)); else // Regular type reference