From d8a020dc7ad0ee870ca8129aa97d614b20bc8cac Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Mon, 4 Nov 2019 00:26:02 +0100 Subject: [PATCH] Inspector: Make custom attribute constructor pointers available --- Il2CppInspector/Il2CppBinary.cs | 6 ++++++ Il2CppInspector/Il2CppInspector.cs | 1 + Il2CppInspector/Reflection/CustomAttributeData.cs | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector/Il2CppBinary.cs b/Il2CppInspector/Il2CppBinary.cs index 66b5a35..2f5392c 100644 --- a/Il2CppInspector/Il2CppBinary.cs +++ b/Il2CppInspector/Il2CppBinary.cs @@ -34,6 +34,9 @@ namespace Il2CppInspector // Pointers to field offsets public long[] FieldOffsetPointers { get; private set; } + // Generated functions which call constructors on custom attributes + public long[] CustomAttributeGenerators { get; private set; } + // Every defined type public List Types { get; private set; } @@ -176,6 +179,9 @@ namespace Il2CppInspector // Type definitions (pointer array) Types = image.ReadMappedObjectPointerArray(MetadataRegistration.ptypes, (int) MetadataRegistration.typesCount); + + // Custom attribute constructors + CustomAttributeGenerators = Image.ReadMappedWordArray(CodeRegistration.customAttributeGenerators, (int) CodeRegistration.customAttributeCount); } } } diff --git a/Il2CppInspector/Il2CppInspector.cs b/Il2CppInspector/Il2CppInspector.cs index 25765ad..0ffc457 100644 --- a/Il2CppInspector/Il2CppInspector.cs +++ b/Il2CppInspector/Il2CppInspector.cs @@ -40,6 +40,7 @@ namespace Il2CppInspector public List FieldOffsets { get; } public List TypeUsages => Binary.Types; public Dictionary Modules => Binary.Modules; + public long[] CustomAttributeGenerators => Binary.CustomAttributeGenerators; // TODO: Finish all file access in the constructor and eliminate the need for this public IFileFormatReader BinaryImage => Binary.Image; diff --git a/Il2CppInspector/Reflection/CustomAttributeData.cs b/Il2CppInspector/Reflection/CustomAttributeData.cs index 695fc30..72a2918 100644 --- a/Il2CppInspector/Reflection/CustomAttributeData.cs +++ b/Il2CppInspector/Reflection/CustomAttributeData.cs @@ -12,10 +12,14 @@ namespace Il2CppInspector.Reflection // See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.customattributedata?view=netframework-4.8 public class CustomAttributeData { + // IL2CPP-specific data + private Il2CppInspector package => AttributeType.Assembly.Model.Package; + public int Index { get; set; } + // The type of the attribute public TypeInfo AttributeType { get; set; } - // TODO Constructor, ConstructorArguments, NamedArguments + public long VirtualAddress => package.CustomAttributeGenerators[Index]; public override string ToString() => "[" + AttributeType.FullName + "]"; @@ -33,7 +37,7 @@ namespace Il2CppInspector.Reflection var range = pkg.AttributeTypeRanges[customAttributeIndex]; for (var i = range.start; i < range.start + range.count; i++) { var typeIndex = pkg.AttributeTypeIndices[i]; - yield return new CustomAttributeData { AttributeType = asm.Model.GetTypeFromUsage(typeIndex) }; + yield return new CustomAttributeData { Index = customAttributeIndex, AttributeType = asm.Model.GetTypeFromUsage(typeIndex) }; } }