From 6fff363c29be5df9405a39a692854d8737e1556c Mon Sep 17 00:00:00 2001 From: Robert Xiao Date: Fri, 19 Jun 2020 00:38:05 -0700 Subject: [PATCH] Fix bugs in testcase #11 and CSharp3. Bug #1 is that in 32-bit programs, typeDefinitionIndex might be 0xffff_ffff_ffff_ffff instead (32-bit -1 sign-extended to 64 bits), so we fix that by simply masking to get the low 32 bits. Bug #2 is that, if the TypeRef points to no generic instance, we return null, which wasn't being checked for in the IDAPythonScript generator. Since that's the only time we could get a null type in Types, we simply remove nulls from the Types collection. --- Il2CppInspector.Common/Reflection/Il2CppModel.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector.Common/Reflection/Il2CppModel.cs b/Il2CppInspector.Common/Reflection/Il2CppModel.cs index 57ed022..72f3e89 100644 --- a/Il2CppInspector.Common/Reflection/Il2CppModel.cs +++ b/Il2CppInspector.Common/Reflection/Il2CppModel.cs @@ -33,7 +33,7 @@ namespace Il2CppInspector.Reflection // Every type public IEnumerable Types => TypesByDefinitionIndex.Concat(TypesByReferenceIndex) - .Concat(GenericMethods.Values.Select(m => m.DeclaringType)).Distinct(); + .Concat(GenericMethods.Values.Select(m => m.DeclaringType)).Distinct().Where(t => t != null); // List of all methods ordered by their MethodDefinitionIndex public MethodBase[] MethodsByDefinitionIndex { get; } @@ -172,9 +172,10 @@ namespace Il2CppInspector.Reflection // TODO: Replace with array load from Il2CppMetadataRegistration.genericClasses var generic = image.ReadMappedObject(typeRef.datapoint); // Il2CppGenericClass * - // We have seen one test case where the TypeRef can point to no generic instance - // This is going to leave the TypeInfo in an undefined state - if (generic.typeDefinitionIndex == 0x0000_0000_ffff_ffff) + // It appears that TypeRef can be -1 if the generic depth recursion limit + // (--maximum-recursive-generic-depth=) is reached in Il2Cpp. In this case, + // no generic instance type is generated, so we just produce a null TypeInfo here. + if ((generic.typeDefinitionIndex & 0xffff_ffff) == 0x0000_0000_ffff_ffff) return null; var genericTypeDef = TypesByDefinitionIndex[generic.typeDefinitionIndex];