From 062182ec116022361ba186baf345f517b4d6b218 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Mon, 4 Nov 2019 19:33:18 +0100 Subject: [PATCH] Model and Output: Handle pointer types correctly --- Il2CppInspector/Reflection/TypeInfo.cs | 34 ++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index 9bcb1b8..58abeff 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -48,17 +48,17 @@ namespace Il2CppInspector.Reflection { n = ElementType.CSharpName; var g = (GenericTypeParameters != null ? "<" + string.Join(", ", GenericTypeParameters.Select(x => x.CSharpName)) + ">" : ""); g = (GenericTypeArguments != null ? "<" + string.Join(", ", GenericTypeArguments.Select(x => x.CSharpName)) + ">" : g); - return (IsPointer ? "void *" : "") + n + g + (IsArray ? "[]" : ""); + return n + g + (IsArray ? "[]" : "") + (IsPointer ? "*" : ""); } } // C# name as it would be written in a type declaration public string CSharpTypeDeclarationName => - (IsPointer ? "void *" : "") - + (base.Name.IndexOf("`", StringComparison.Ordinal) == -1 ? base.Name : base.Name.Remove(base.Name.IndexOf("`", StringComparison.Ordinal))) + (base.Name.IndexOf("`", StringComparison.Ordinal) == -1 ? base.Name : base.Name.Remove(base.Name.IndexOf("`", StringComparison.Ordinal))) + (GenericTypeParameters != null ? "<" + string.Join(", ", GenericTypeParameters.Select(x => x.Name)) + ">" : "") + (GenericTypeArguments != null ? "<" + string.Join(", ", GenericTypeArguments.Select(x => x.Name)) + ">" : "") - + (IsArray ? "[]" : ""); + + (IsArray ? "[]" : "") + + (IsPointer ? "*" : ""); // Custom attributes for this member public override IEnumerable CustomAttributes => CustomAttributeData.GetCustomAttributes(this); @@ -106,18 +106,19 @@ namespace Il2CppInspector.Reflection { // Type name including namespace public string FullName => IsGenericParameter? null : - (IsPointer? "void *" : "") - + (DeclaringType != null? DeclaringType.FullName + "+" : - Namespace + (Namespace.Length > 0? "." : "")) + (DeclaringType != null? DeclaringType.FullName + "+" : Namespace + (Namespace.Length > 0? "." : "")) + base.Name + (GenericTypeParameters != null ? "[" + string.Join(",", GenericTypeParameters.Select(x => x.FullName ?? x.Name)) + "]" : "") + (GenericTypeArguments != null ? "[" + string.Join(",", GenericTypeArguments.Select(x => x.FullName ?? x.Name)) + "]" : "") - + (IsArray? "[]" : ""); + + (IsArray? "[]" : "") + + (IsPointer? "*" : ""); public List GenericTypeParameters { get; } public List GenericTypeArguments { get; } + // True if an array, pointer or reference, otherwise false + // See: https://docs.microsoft.com/en-us/dotnet/api/system.type.haselementtype?view=netframework-4.8 public bool HasElementType => ElementType != null; private readonly int[] implementedInterfaceUsages; @@ -344,8 +345,8 @@ namespace Il2CppInspector.Reflection { arrayRank = descriptor.rank; } - // Dynamically allocated array - if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY) { + // Dynamically allocated array or pointer type + if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY || pType.type == Il2CppTypeEnum.IL2CPP_TYPE_PTR) { elementType = model.GetTypeFromVirtualAddress(pType.datapoint); Assembly = ElementType.Assembly; @@ -354,7 +355,8 @@ namespace Il2CppInspector.Reflection { Namespace = ElementType.Namespace; Name = ElementType.Name; - IsArray = true; + IsPointer = (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_PTR); + IsArray = !IsPointer; } // Generic type parameter @@ -389,10 +391,6 @@ namespace Il2CppInspector.Reflection { IsGenericType = false; IsGenericTypeDefinition = false; } - - // Pointer type - // TODO: Should set ElementType etc. - IsPointer = (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_PTR); } // Initialize a type that is a generic parameter of a generic type @@ -423,11 +421,11 @@ namespace Il2CppInspector.Reflection { // Display name of object public override string ToString() => IsGenericParameter ? Name : - (IsPointer ? "void *" : "") - + (DeclaringType != null ? DeclaringType.Name + "+" : "") + (DeclaringType != null ? DeclaringType.Name + "+" : "") + base.Name + (GenericTypeParameters != null ? "[" + string.Join(",", GenericTypeParameters.Select(x => x.Namespace != Namespace? x.FullName ?? x.Name : x.ToString())) + "]" : "") + (GenericTypeArguments != null ? "[" + string.Join(",", GenericTypeArguments.Select(x => x.Namespace != Namespace? x.FullName ?? x.Name : x.ToString())) + "]" : "") - + (IsArray ? "[]" : ""); + + (IsArray ? "[]" : "") + + (IsPointer ? "*" : ""); } } \ No newline at end of file