From 3c1e2356a8ed3c8b9ed32fc2d8a6a6d1d0b42adf Mon Sep 17 00:00:00 2001 From: Jeremy Pritts <49847914+ds5678@users.noreply.github.com> Date: Fri, 13 Dec 2024 08:25:21 -0800 Subject: [PATCH] Include lower bounds when making array type signatures (#394) --- Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs | 11 ++++++++++- .../Utils/AsmResolver/ContextToTypeSignature.cs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs b/Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs index 6b7c1e4f..ab0aca00 100644 --- a/Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs +++ b/Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs @@ -91,7 +91,7 @@ public static TypeSignature GetTypeSignatureFromIl2CppType(ModuleDefinition modu break; case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: ret = GetTypeSignatureFromIl2CppType(module, il2CppType.GetArrayElementType()) - .MakeArrayType(il2CppType.GetArrayRank()); + .MakeArrayTypeWithLowerBounds(il2CppType.GetArrayRank()); break; case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: ret = GetTypeSignatureFromIl2CppType(module, il2CppType.GetEncapsulatedType()) @@ -340,4 +340,13 @@ public static ITypeDefOrRef ImportTypeIfNeeded(this ReferenceImporter importer, public static bool IsManagedMethodWithBody(this MethodDefinition managedMethod) => managedMethod.Managed && !managedMethod.IsAbstract && !managedMethod.IsPInvokeImpl && !managedMethod.IsInternalCall && !managedMethod.IsNative && !managedMethod.IsRuntime; + + internal static ArrayTypeSignature MakeArrayTypeWithLowerBounds(this TypeSignature elementType, int rank) + { + var result = new ArrayTypeSignature(elementType, rank); + for (var i = 0; i < rank; i++) + result.Dimensions[i] = new ArrayDimension(null, 0); + + return result; + } } diff --git a/Cpp2IL.Core/Utils/AsmResolver/ContextToTypeSignature.cs b/Cpp2IL.Core/Utils/AsmResolver/ContextToTypeSignature.cs index 90b98093..8d65d714 100644 --- a/Cpp2IL.Core/Utils/AsmResolver/ContextToTypeSignature.cs +++ b/Cpp2IL.Core/Utils/AsmResolver/ContextToTypeSignature.cs @@ -61,7 +61,7 @@ public static TypeSignature ToTypeSignature(this ByRefTypeAnalysisContext contex public static TypeSignature ToTypeSignature(this ArrayTypeAnalysisContext context, ModuleDefinition parentModule) { - return context.ElementType.ToTypeSignature(parentModule).MakeArrayType(context.Rank); + return context.ElementType.ToTypeSignature(parentModule).MakeArrayTypeWithLowerBounds(context.Rank); } public static TypeSignature ToTypeSignature(this ParameterAnalysisContext context, ModuleDefinition parentModule)