From f75e3614ebfd3ec594ee7b555dc52747011bb105 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Mon, 4 Nov 2019 00:02:14 +0100 Subject: [PATCH] Model: Fix crash on invalid attribute index --- Il2CppInspector/Reflection/CustomAttributeData.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Il2CppInspector/Reflection/CustomAttributeData.cs b/Il2CppInspector/Reflection/CustomAttributeData.cs index db626cc..695fc30 100644 --- a/Il2CppInspector/Reflection/CustomAttributeData.cs +++ b/Il2CppInspector/Reflection/CustomAttributeData.cs @@ -5,6 +5,7 @@ */ using System.Collections.Generic; +using System.Linq; namespace Il2CppInspector.Reflection { @@ -20,6 +21,9 @@ namespace Il2CppInspector.Reflection // Get all the custom attributes for a given assembly, type, member or parameter private static IEnumerable getCustomAttributes(Assembly asm, int customAttributeIndex) { + if (customAttributeIndex < 0) + yield break; + var pkg = asm.Model.Package; // Attribute type ranges weren't included before v21 (customASttributeGenerators was though) @@ -34,8 +38,9 @@ namespace Il2CppInspector.Reflection } private static IList getCustomAttributes(Assembly asm, uint token, int customAttributeIndex) - => (IList) getCustomAttributes(asm, asm.Model.GetCustomAttributeIndex(asm, token, customAttributeIndex)); + => getCustomAttributes(asm, asm.Model.GetCustomAttributeIndex(asm, token, customAttributeIndex)).ToList(); + // TODO: Get token or customAttributeIndex from Il2CppAssembly(Definition) public static IList GetCustomAttributes(Assembly asm) => getCustomAttributes(asm, asm.Definition.token, -1); public static IList GetCustomAttributes(EventInfo evt) => getCustomAttributes(evt.Assembly, evt.Definition.token, evt.Definition.customAttributeIndex); public static IList GetCustomAttributes(FieldInfo field) => getCustomAttributes(field.Assembly, field.Definition.token, field.Definition.customAttributeIndex);