diff --git a/src/AsmResolver.DotNet.Dynamic/DynamicTypeSignatureReader.cs b/src/AsmResolver.DotNet.Dynamic/DynamicTypeSignatureReader.cs index 969ef3f0a..9ebb00448 100644 --- a/src/AsmResolver.DotNet.Dynamic/DynamicTypeSignatureReader.cs +++ b/src/AsmResolver.DotNet.Dynamic/DynamicTypeSignatureReader.cs @@ -41,7 +41,7 @@ static DynamicTypeSignatureResolver() public static bool IsSupported => GetTypeFromHandleUnsafeMethod is not null; /// - public override TypeSignature ResolveRuntimeType(in BlobReadContext context, nint address) + public override TypeSignature ResolveRuntimeType(ref BlobReadContext context, nint address) { if (!IsSupported) throw new PlatformNotSupportedException("The current platform does not support the translation of raw type handles to System.Type instances."); diff --git a/src/AsmResolver.DotNet/Serialized/SerializedFieldDefinition.cs b/src/AsmResolver.DotNet/Serialized/SerializedFieldDefinition.cs index 083dd51e9..9af8ed262 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedFieldDefinition.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedFieldDefinition.cs @@ -47,7 +47,8 @@ public SerializedFieldDefinition(ModuleReaderContext context, MetadataToken toke $"Invalid signature blob index in field {MetadataToken.ToString()}."); } - return FieldSignature.FromReader(new BlobReadContext(_context), ref reader); + var context = new BlobReadContext(_context); + return FieldSignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedMemberReference.cs b/src/AsmResolver.DotNet/Serialized/SerializedMemberReference.cs index 1a867ef11..0064bfc53 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedMemberReference.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedMemberReference.cs @@ -60,7 +60,8 @@ public SerializedMemberReference( $"Invalid signature blob index in member reference {MetadataToken.ToString()}."); } - return CallingConventionSignature.FromReader(new BlobReadContext(_context), ref reader, true); + var context = new BlobReadContext(_context); + return CallingConventionSignature.FromReader(ref context, ref reader, true); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedMethodDefinition.cs b/src/AsmResolver.DotNet/Serialized/SerializedMethodDefinition.cs index 0d09b8e0a..4c55e60c1 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedMethodDefinition.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedMethodDefinition.cs @@ -52,7 +52,8 @@ public SerializedMethodDefinition(ModuleReaderContext context, MetadataToken tok $"Invalid signature blob index in method {MetadataToken.ToString()}."); } - return MethodSignature.FromReader(new BlobReadContext(_context), ref reader); + var context = new BlobReadContext(_context); + return MethodSignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedMethodSpecification.cs b/src/AsmResolver.DotNet/Serialized/SerializedMethodSpecification.cs index 929366651..0f8b7e3b6 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedMethodSpecification.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedMethodSpecification.cs @@ -52,7 +52,8 @@ public SerializedMethodSpecification(ModuleReaderContext context, MetadataToken $"Invalid instantiation blob index in method specification {MetadataToken.ToString()}."); } - return GenericInstanceMethodSignature.FromReader(new BlobReadContext(_context), ref reader); + var context = new BlobReadContext(_context); + return GenericInstanceMethodSignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedPropertyDefinition.cs b/src/AsmResolver.DotNet/Serialized/SerializedPropertyDefinition.cs index d2dd3ae74..5f051e158 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedPropertyDefinition.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedPropertyDefinition.cs @@ -48,7 +48,8 @@ public SerializedPropertyDefinition(ModuleReaderContext context, MetadataToken t $"Invalid signature blob index in property {MetadataToken.ToString()}."); } - return PropertySignature.FromReader(new BlobReadContext(_context), ref reader); + var context = new BlobReadContext(_context); + return PropertySignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedStandAloneSignature.cs b/src/AsmResolver.DotNet/Serialized/SerializedStandAloneSignature.cs index 49ab50915..e65329632 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedStandAloneSignature.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedStandAloneSignature.cs @@ -43,7 +43,8 @@ public SerializedStandAloneSignature( $"Invalid signature blob index in stand-alone signature {MetadataToken.ToString()}."); } - return CallingConventionSignature.FromReader(new BlobReadContext(_context), ref reader); + var context = new BlobReadContext(_context); + return CallingConventionSignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Serialized/SerializedTypeSpecification.cs b/src/AsmResolver.DotNet/Serialized/SerializedTypeSpecification.cs index 47f29d5ac..50107bbc0 100644 --- a/src/AsmResolver.DotNet/Serialized/SerializedTypeSpecification.cs +++ b/src/AsmResolver.DotNet/Serialized/SerializedTypeSpecification.cs @@ -42,8 +42,8 @@ public SerializedTypeSpecification(ModuleReaderContext context, MetadataToken to } var context = new BlobReadContext(_context); - context.TraversedTokens.Add(MetadataToken); - return TypeSignature.FromReader(context, ref reader); + context.StepInToken(MetadataToken); + return TypeSignature.FromReader(ref context, ref reader); } /// diff --git a/src/AsmResolver.DotNet/Signatures/BlobReadContext.cs b/src/AsmResolver.DotNet/Signatures/BlobReadContext.cs index 1af93d92d..f95f1f94f 100644 --- a/src/AsmResolver.DotNet/Signatures/BlobReadContext.cs +++ b/src/AsmResolver.DotNet/Signatures/BlobReadContext.cs @@ -10,14 +10,16 @@ namespace AsmResolver.DotNet.Signatures /// Provides a context in which a metadata blob parser exists in. This includes the original module reader context /// as well as a mechanism to protect against infinite recursion. /// - public readonly struct BlobReadContext + public struct BlobReadContext { + private Stack? _traversedTokens; + /// /// Creates a new instance of the structure. /// /// The original read context. public BlobReadContext(ModuleReaderContext readerContext) - : this(readerContext, PhysicalTypeSignatureResolver.Instance, Enumerable.Empty()) + : this(readerContext, PhysicalTypeSignatureResolver.Instance) { } @@ -27,8 +29,10 @@ public BlobReadContext(ModuleReaderContext readerContext) /// The original read context. /// The object responsible for resolving raw type metadata tokens and addresses. public BlobReadContext(ModuleReaderContext readerContext, ITypeSignatureResolver resolver) - : this(readerContext, resolver, Enumerable.Empty()) { + ReaderContext = readerContext; + TypeSignatureResolver = resolver; + _traversedTokens = null; } /// @@ -41,7 +45,7 @@ public BlobReadContext(ModuleReaderContext readerContext, ITypeSignatureResolver { ReaderContext = readerContext; TypeSignatureResolver = resolver; - TraversedTokens = new HashSet(traversedTokens); + _traversedTokens = new Stack(traversedTokens); } /// @@ -60,12 +64,15 @@ public ITypeSignatureResolver TypeSignatureResolver get; } - /// - /// Gets a collection of metadata tokens that were traversed during the parsing of metadata. - /// - public ISet TraversedTokens + public bool StepInToken(MetadataToken token) { - get; + _traversedTokens ??= new Stack(); + + if (_traversedTokens.Contains(token)) + return false; + + _traversedTokens.Push(token); + return true; } } } diff --git a/src/AsmResolver.DotNet/Signatures/CallingConventionSignature.cs b/src/AsmResolver.DotNet/Signatures/CallingConventionSignature.cs index 12d04b0e2..563ab5194 100644 --- a/src/AsmResolver.DotNet/Signatures/CallingConventionSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/CallingConventionSignature.cs @@ -20,11 +20,11 @@ public abstract class CallingConventionSignature : ExtendableBlobSignature, IImp /// put into the property. /// The read signature. public static CallingConventionSignature? FromReader( - in BlobReadContext context, + ref BlobReadContext context, ref BinaryStreamReader reader, bool readToEnd = true) { - var signature = ReadSignature(context, ref reader); + var signature = ReadSignature(ref context, ref reader); if (readToEnd) { byte[] extraData = reader.ReadToEnd(); @@ -35,7 +35,7 @@ public abstract class CallingConventionSignature : ExtendableBlobSignature, IImp return signature; } - private static CallingConventionSignature? ReadSignature(in BlobReadContext context, ref BinaryStreamReader reader) + private static CallingConventionSignature? ReadSignature(ref BlobReadContext context, ref BinaryStreamReader reader) { byte flag = reader.ReadByte(); reader.Offset--; @@ -50,19 +50,19 @@ public abstract class CallingConventionSignature : ExtendableBlobSignature, IImp case CallingConventionAttributes.ThisCall: case CallingConventionAttributes.VarArg: case CallingConventionAttributes.Unmanaged: - return MethodSignature.FromReader(context, ref reader); + return MethodSignature.FromReader(ref context, ref reader); case CallingConventionAttributes.Property: - return PropertySignature.FromReader(context, ref reader); + return PropertySignature.FromReader(ref context, ref reader); case CallingConventionAttributes.Local: - return LocalVariablesSignature.FromReader(context, ref reader); + return LocalVariablesSignature.FromReader(ref context, ref reader); case CallingConventionAttributes.GenericInstance: - return GenericInstanceMethodSignature.FromReader(context, ref reader); + return GenericInstanceMethodSignature.FromReader(ref context, ref reader); case CallingConventionAttributes.Field: - return FieldSignature.FromReader(context, ref reader); + return FieldSignature.FromReader(ref context, ref reader); } throw new NotSupportedException($"Invalid or unsupported calling convention signature header {flag:X2}."); diff --git a/src/AsmResolver.DotNet/Signatures/FieldSignature.cs b/src/AsmResolver.DotNet/Signatures/FieldSignature.cs index f1d69e005..581d58553 100644 --- a/src/AsmResolver.DotNet/Signatures/FieldSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/FieldSignature.cs @@ -37,11 +37,11 @@ public static FieldSignature CreateInstance(TypeSignature fieldType) /// The blob reader context. /// The blob input stream. /// The field signature. - public static FieldSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + public static FieldSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { return new( (CallingConventionAttributes) reader.ReadByte(), - TypeSignature.FromReader(context, ref reader)); + TypeSignature.FromReader(ref context, ref reader)); } /// diff --git a/src/AsmResolver.DotNet/Signatures/GenericInstanceMethodSignature.cs b/src/AsmResolver.DotNet/Signatures/GenericInstanceMethodSignature.cs index 33848a34d..23f9ec947 100644 --- a/src/AsmResolver.DotNet/Signatures/GenericInstanceMethodSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/GenericInstanceMethodSignature.cs @@ -11,7 +11,7 @@ namespace AsmResolver.DotNet.Signatures public class GenericInstanceMethodSignature : CallingConventionSignature, IGenericArgumentsProvider { internal static GenericInstanceMethodSignature? FromReader( - in BlobReadContext context, + ref BlobReadContext context, ref BinaryStreamReader reader) { if (!reader.CanRead(sizeof(byte))) @@ -30,7 +30,7 @@ public class GenericInstanceMethodSignature : CallingConventionSignature, IGener var result = new GenericInstanceMethodSignature(attributes, (int) count); for (int i = 0; i < count; i++) - result.TypeArguments.Add(TypeSignature.FromReader(context, ref reader)); + result.TypeArguments.Add(TypeSignature.FromReader(ref context, ref reader)); return result; } diff --git a/src/AsmResolver.DotNet/Signatures/LocalVariablesSignature.cs b/src/AsmResolver.DotNet/Signatures/LocalVariablesSignature.cs index 068dfc4a9..fe4044d0f 100644 --- a/src/AsmResolver.DotNet/Signatures/LocalVariablesSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/LocalVariablesSignature.cs @@ -16,7 +16,7 @@ public class LocalVariablesSignature : CallingConventionSignature /// The blob reader context. /// The input stream. /// The signature. - public static LocalVariablesSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + public static LocalVariablesSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { var result = new LocalVariablesSignature(); result.Attributes = (CallingConventionAttributes) reader.ReadByte(); @@ -28,7 +28,7 @@ public static LocalVariablesSignature FromReader(in BlobReadContext context, ref } for (int i = 0; i < count; i++) - result.VariableTypes.Add(TypeSignature.FromReader(context, ref reader)); + result.VariableTypes.Add(TypeSignature.FromReader(ref context, ref reader)); return result; } diff --git a/src/AsmResolver.DotNet/Signatures/MethodSignature.cs b/src/AsmResolver.DotNet/Signatures/MethodSignature.cs index 3600c6e32..2ec85f515 100644 --- a/src/AsmResolver.DotNet/Signatures/MethodSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/MethodSignature.cs @@ -18,7 +18,7 @@ public class MethodSignature : MethodSignatureBase /// The blob reader context. /// The blob input stream. /// The method signature. - public static MethodSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + public static MethodSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { var result = new MethodSignature( (CallingConventionAttributes) reader.ReadByte(), @@ -37,7 +37,7 @@ public static MethodSignature FromReader(in BlobReadContext context, ref BinaryS result.GenericParameterCount = (int) genericParameterCount; } - result.ReadParametersAndReturnType(context, ref reader); + result.ReadParametersAndReturnType(ref context, ref reader); return result; } diff --git a/src/AsmResolver.DotNet/Signatures/MethodSignatureBase.cs b/src/AsmResolver.DotNet/Signatures/MethodSignatureBase.cs index 191bc2710..f3ec25f94 100644 --- a/src/AsmResolver.DotNet/Signatures/MethodSignatureBase.cs +++ b/src/AsmResolver.DotNet/Signatures/MethodSignatureBase.cs @@ -106,7 +106,7 @@ public override bool IsImportedInModule(ModuleDefinition module) /// /// The blob reader context. /// The input stream. - protected void ReadParametersAndReturnType(in BlobReadContext context, ref BinaryStreamReader reader) + protected void ReadParametersAndReturnType(ref BlobReadContext context, ref BinaryStreamReader reader) { // Parameter count. if (!reader.TryReadCompressedUInt32(out uint parameterCount)) @@ -116,14 +116,14 @@ protected void ReadParametersAndReturnType(in BlobReadContext context, ref Binar } // Return type. - ReturnType = TypeSignature.FromReader(context, ref reader); + ReturnType = TypeSignature.FromReader(ref context, ref reader); // Parameter types. _parameterTypes.Capacity = (int) parameterCount; bool sentinel = false; for (int i = 0; i < parameterCount; i++) { - var parameterType = TypeSignature.FromReader(context, ref reader); + var parameterType = TypeSignature.FromReader(ref context, ref reader); if (parameterType.ElementType == ElementType.Sentinel) { diff --git a/src/AsmResolver.DotNet/Signatures/PropertySignature.cs b/src/AsmResolver.DotNet/Signatures/PropertySignature.cs index 15b01e0d1..ebbf719fd 100644 --- a/src/AsmResolver.DotNet/Signatures/PropertySignature.cs +++ b/src/AsmResolver.DotNet/Signatures/PropertySignature.cs @@ -17,7 +17,7 @@ public class PropertySignature : MethodSignatureBase /// The blob reader context. /// The blob input stream. /// The property signature. - public static PropertySignature? FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + public static PropertySignature? FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { var attributes = (CallingConventionAttributes) reader.ReadByte(); if ((attributes & CallingConventionAttributes.Property) == 0) @@ -31,7 +31,7 @@ public class PropertySignature : MethodSignatureBase context.ReaderContext.ParentModule.CorLibTypeFactory.Object, Enumerable.Empty()); - result.ReadParametersAndReturnType(context, ref reader); + result.ReadParametersAndReturnType(ref context, ref reader); return result; } diff --git a/src/AsmResolver.DotNet/Signatures/Types/ArrayTypeSignature.cs b/src/AsmResolver.DotNet/Signatures/Types/ArrayTypeSignature.cs index 081ec88e2..3edc3e299 100644 --- a/src/AsmResolver.DotNet/Signatures/Types/ArrayTypeSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/Types/ArrayTypeSignature.cs @@ -69,9 +69,9 @@ public IList Dimensions get; } - internal new static ArrayTypeSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + internal new static ArrayTypeSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { - var signature = new ArrayTypeSignature(TypeSignature.FromReader(context, ref reader)); + var signature = new ArrayTypeSignature(TypeSignature.FromReader(ref context, ref reader)); // Rank if (!reader.TryReadCompressedUInt32(out uint rank)) diff --git a/src/AsmResolver.DotNet/Signatures/Types/GenericInstanceTypeSignature.cs b/src/AsmResolver.DotNet/Signatures/Types/GenericInstanceTypeSignature.cs index 33d588a03..1db5d1093 100644 --- a/src/AsmResolver.DotNet/Signatures/Types/GenericInstanceTypeSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/Types/GenericInstanceTypeSignature.cs @@ -14,9 +14,9 @@ public class GenericInstanceTypeSignature : TypeSignature, IGenericArgumentsProv private ITypeDefOrRef _genericType; private bool _isValueType; - internal new static GenericInstanceTypeSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + internal new static GenericInstanceTypeSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { - var genericType = TypeSignature.FromReader(context, ref reader); + var genericType = TypeSignature.FromReader(ref context, ref reader); var signature = new GenericInstanceTypeSignature(genericType.ToTypeDefOrRef(), genericType.ElementType == ElementType.ValueType); if (!reader.TryReadCompressedUInt32(out uint count)) @@ -27,7 +27,7 @@ public class GenericInstanceTypeSignature : TypeSignature, IGenericArgumentsProv signature._typeArguments.Capacity = (int) count; for (int i = 0; i < count; i++) - signature._typeArguments.Add(TypeSignature.FromReader(context, ref reader)); + signature._typeArguments.Add(TypeSignature.FromReader(ref context, ref reader)); return signature; } diff --git a/src/AsmResolver.DotNet/Signatures/Types/ITypeSignatureResolver.cs b/src/AsmResolver.DotNet/Signatures/Types/ITypeSignatureResolver.cs index 9b7faec67..4630add6d 100644 --- a/src/AsmResolver.DotNet/Signatures/Types/ITypeSignatureResolver.cs +++ b/src/AsmResolver.DotNet/Signatures/Types/ITypeSignatureResolver.cs @@ -13,7 +13,7 @@ public interface ITypeSignatureResolver /// The blob reading context the type is situated in. /// The token to resolve. /// The type. - ITypeDefOrRef ResolveToken(in BlobReadContext context, MetadataToken token); + ITypeDefOrRef ResolveToken(ref BlobReadContext context, MetadataToken token); /// /// Resolves an address to a runtime method table to a type signature. @@ -21,7 +21,7 @@ public interface ITypeSignatureResolver /// The blob reading context the type is situated in. /// The address to resolve. /// The type. - TypeSignature ResolveRuntimeType(in BlobReadContext context, nint address); + TypeSignature ResolveRuntimeType(ref BlobReadContext context, nint address); } } diff --git a/src/AsmResolver.DotNet/Signatures/Types/PhysicalTypeSignatureResolver.cs b/src/AsmResolver.DotNet/Signatures/Types/PhysicalTypeSignatureResolver.cs index b85f6b6aa..f819b3fb1 100644 --- a/src/AsmResolver.DotNet/Signatures/Types/PhysicalTypeSignatureResolver.cs +++ b/src/AsmResolver.DotNet/Signatures/Types/PhysicalTypeSignatureResolver.cs @@ -18,12 +18,12 @@ public static PhysicalTypeSignatureResolver Instance } = new(); /// - public virtual ITypeDefOrRef ResolveToken(in BlobReadContext context, MetadataToken token) + public virtual ITypeDefOrRef ResolveToken(ref BlobReadContext context, MetadataToken token) { switch (token.Table) { // Check for infinite recursion. - case TableIndex.TypeSpec when !context.TraversedTokens.Add(token): + case TableIndex.TypeSpec when !context.StepInToken(token): context.ReaderContext.BadImage("Infinite metadata loop was detected."); return InvalidTypeDefOrRef.Get(InvalidTypeSignatureError.MetadataLoop); @@ -47,7 +47,7 @@ public virtual ITypeDefOrRef ResolveToken(in BlobReadContext context, MetadataTo } /// - public virtual TypeSignature ResolveRuntimeType(in BlobReadContext context, nint address) + public virtual TypeSignature ResolveRuntimeType(ref BlobReadContext context, nint address) { throw new NotSupportedException( "Encountered an COR_ELEMENT_TYPE_INTERNAL type signature which is not supported by this " diff --git a/src/AsmResolver.DotNet/Signatures/Types/TypeSignature.cs b/src/AsmResolver.DotNet/Signatures/Types/TypeSignature.cs index 78ce8e2b9..e975197cd 100644 --- a/src/AsmResolver.DotNet/Signatures/Types/TypeSignature.cs +++ b/src/AsmResolver.DotNet/Signatures/Types/TypeSignature.cs @@ -63,7 +63,7 @@ public abstract ElementType ElementType /// The type signature. /// Occurs when the blob reader points to an element type that is /// invalid or unsupported. - public static TypeSignature FromReader(in BlobReadContext context, ref BinaryStreamReader reader) + public static TypeSignature FromReader(ref BlobReadContext context, ref BinaryStreamReader reader) { var elementType = (ElementType) reader.ReadByte(); switch (elementType) @@ -89,16 +89,16 @@ public static TypeSignature FromReader(in BlobReadContext context, ref BinaryStr return context.ReaderContext.ParentModule.CorLibTypeFactory.FromElementType(elementType)!; case ElementType.ValueType: - return new TypeDefOrRefSignature(ReadTypeDefOrRef(context, ref reader, false), true); + return new TypeDefOrRefSignature(ReadTypeDefOrRef(ref context, ref reader, false), true); case ElementType.Class: - return new TypeDefOrRefSignature(ReadTypeDefOrRef(context, ref reader, false), false); + return new TypeDefOrRefSignature(ReadTypeDefOrRef(ref context, ref reader, false), false); case ElementType.Ptr: - return new PointerTypeSignature(FromReader(context, ref reader)); + return new PointerTypeSignature(FromReader(ref context, ref reader)); case ElementType.ByRef: - return new ByReferenceTypeSignature(FromReader(context, ref reader)); + return new ByReferenceTypeSignature(FromReader(ref context, ref reader)); case ElementType.Var: return new GenericParameterSignature(context.ReaderContext.ParentModule, @@ -111,40 +111,40 @@ public static TypeSignature FromReader(in BlobReadContext context, ref BinaryStr (int) reader.ReadCompressedUInt32()); case ElementType.Array: - return ArrayTypeSignature.FromReader(context, ref reader); + return ArrayTypeSignature.FromReader(ref context, ref reader); case ElementType.GenericInst: - return GenericInstanceTypeSignature.FromReader(context, ref reader); + return GenericInstanceTypeSignature.FromReader(ref context, ref reader); case ElementType.FnPtr: - return new FunctionPointerTypeSignature(MethodSignature.FromReader(context, ref reader)); + return new FunctionPointerTypeSignature(MethodSignature.FromReader(ref context, ref reader)); case ElementType.SzArray: - return new SzArrayTypeSignature(FromReader(context, ref reader)); + return new SzArrayTypeSignature(FromReader(ref context, ref reader)); case ElementType.CModReqD: return new CustomModifierTypeSignature( - ReadTypeDefOrRef(context, ref reader, true), + ReadTypeDefOrRef(ref context, ref reader, true), true, - FromReader(context, ref reader)); + FromReader(ref context, ref reader)); case ElementType.CModOpt: return new CustomModifierTypeSignature( - ReadTypeDefOrRef(context, ref reader, true), + ReadTypeDefOrRef(ref context, ref reader, true), false, - FromReader(context, ref reader)); + FromReader(ref context, ref reader)); case ElementType.Sentinel: return new SentinelTypeSignature(); case ElementType.Pinned: - return new PinnedTypeSignature(FromReader(context, ref reader)); + return new PinnedTypeSignature(FromReader(ref context, ref reader)); case ElementType.Boxed: - return new BoxedTypeSignature(FromReader(context, ref reader)); + return new BoxedTypeSignature(FromReader(ref context, ref reader)); case ElementType.Internal: - return context.TypeSignatureResolver.ResolveRuntimeType(context, IntPtr.Size switch + return context.TypeSignatureResolver.ResolveRuntimeType(ref context, IntPtr.Size switch { 4 => new IntPtr(reader.ReadInt32()), _ => new IntPtr(reader.ReadInt64()) @@ -163,7 +163,7 @@ public static TypeSignature FromReader(in BlobReadContext context, ref BinaryStr /// Indicates the coded index to the type is allowed to be decoded to a member in /// the type specification table. /// The decoded and resolved type definition or reference. - protected static ITypeDefOrRef ReadTypeDefOrRef(in BlobReadContext context, ref BinaryStreamReader reader, bool allowTypeSpec) + protected static ITypeDefOrRef ReadTypeDefOrRef(ref BlobReadContext context, ref BinaryStreamReader reader, bool allowTypeSpec) { if (!reader.TryReadCompressedUInt32(out uint codedIndex)) return InvalidTypeDefOrRef.Get(InvalidTypeSignatureError.BlobTooShort); @@ -179,7 +179,7 @@ protected static ITypeDefOrRef ReadTypeDefOrRef(in BlobReadContext context, ref return InvalidTypeDefOrRef.Get(InvalidTypeSignatureError.IllegalTypeSpec); } - return context.TypeSignatureResolver.ResolveToken(context, token); + return context.TypeSignatureResolver.ResolveToken(ref context, token); } /// diff --git a/test/AsmResolver.DotNet.Tests/Signatures/MethodSignatureTest.cs b/test/AsmResolver.DotNet.Tests/Signatures/MethodSignatureTest.cs index 0b271d859..ed2b51265 100644 --- a/test/AsmResolver.DotNet.Tests/Signatures/MethodSignatureTest.cs +++ b/test/AsmResolver.DotNet.Tests/Signatures/MethodSignatureTest.cs @@ -1,4 +1,11 @@ +using System; +using System.Linq; +using AsmResolver.DotNet.Code.Cil; using AsmResolver.DotNet.Signatures; +using AsmResolver.DotNet.Signatures.Types; +using AsmResolver.PE.DotNet.Cil; +using AsmResolver.PE.DotNet.Metadata.Tables.Rows; +using AsmResolver.PE.File.Headers; using Xunit; namespace AsmResolver.DotNet.Tests.Signatures