Output: Minor refactoring of attribute and address output

This commit is contained in:
Katy Coe
2019-11-04 17:34:21 +01:00
parent 6e93d83c8b
commit 9ceb1368e2
3 changed files with 37 additions and 33 deletions

View File

@@ -120,5 +120,9 @@ namespace Il2CppInspector.Reflection
var index = Array.FindIndex(Package.AttributeTypeRanges[imageRange], x => x.token == token);
return index == -1 ? -1 : index + image.customAttributeStart;
}
public static string FormatAddress(ulong address) => address <= 0xffff_ffff
? string.Format($"0x{(uint)address:X8}")
: string.Format($"0x{address:X16}");
}
}

View File

@@ -4,8 +4,10 @@
All rights reserved.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Il2CppInspector.Reflection
{
@@ -53,4 +55,21 @@ namespace Il2CppInspector.Reflection
public static IList<CustomAttributeData> GetCustomAttributes(PropertyInfo prop) => getCustomAttributes(prop.Assembly, prop.Definition.token, prop.Definition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(TypeInfo type) => getCustomAttributes(type.Assembly, type.Definition.token, type.Definition.customAttributeIndex);
}
public static class IEnumerableCustomAttributeDataExtensions
{
public static string ToString(this IEnumerable<CustomAttributeData> attributes, string linePrefix = "", string attributePrefix = "", bool inline = false) {
var sb = new StringBuilder();
foreach (var cad in attributes) {
var name = cad.AttributeType.CSharpName;
var suffix = name.LastIndexOf("Attribute", StringComparison.Ordinal);
if (suffix != -1)
name = name[..suffix];
sb.Append($"{linePrefix}[{attributePrefix}{name}] {(inline? "/*" : "//")} {Il2CppModel.FormatAddress((ulong)cad.VirtualAddress)}{(inline? " */ " : "\n")}");
}
return sb.ToString();
}
}
}