FromReader() public static method

public static FromReader ( MetadataHeader header, IBinaryStreamReader reader ) : TypeSignature
header MetadataHeader
reader IBinaryStreamReader
return TypeSignature
 /// <summary>
 /// Reads a single pinned type signature at the current position of the provided stream reader.
 /// </summary>
 /// <param name="image">The image the signature resides in.</param>
 /// <param name="reader">The reader to use.</param>
 /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
 /// <returns>The read signature.</returns>
 public static PinnedTypeSignature FromReader(
     MetadataImage image,
     IBinaryStreamReader reader,
     RecursionProtection protection)
 {
     return(new PinnedTypeSignature(TypeSignature.FromReader(image, reader, false, protection)));
 }
        public new static GenericInstanceTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            if (!reader.CanRead(sizeof(byte)))
            {
                return(null);
            }

            var elementType = (ElementType)reader.ReadByte();

            var type = ReadTypeDefOrRef(header, reader);

            var signature = new GenericInstanceTypeSignature(type)
            {
                IsValueType = elementType == ElementType.ValueType
            };

            uint count;

            if (!reader.TryReadCompressedUInt32(out count))
            {
                return(signature);
            }

            for (int i = 0; i < count; i++)
            {
                signature.GenericArguments.Add(TypeSignature.FromReader(header, reader));
            }

            return(signature);
        }
Example #3
0
        public new static OptionalModifierSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            return(new OptionalModifierSignature(ReadTypeDefOrRef(image, reader),
                                                 TypeSignature.FromReader(image, reader)));
        }
Example #4
0
        /// <summary>
        /// Reads a single property signature at the current position of the provided stream reader.
        /// </summary>
        /// <param name="image">The image the signature resides in.</param>
        /// <param name="reader">The reader to use.</param>
        /// <param name="readToEnd">Determines whether any extra data after the signature should be read and
        /// put into the <see cref="ExtendableBlobSignature.ExtraData"/> property.</param>
        /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
        /// <returns>The read signature.</returns>
        public new static PropertySignature FromReader(
            MetadataImage image,
            IBinaryStreamReader reader,
            bool readToEnd,
            RecursionProtection protection)
        {
            var signature = new PropertySignature
            {
                Attributes = (CallingConventionAttributes)reader.ReadByte(),
            };

            if (!reader.TryReadCompressedUInt32(out uint paramCount))
            {
                return(null);
            }

            signature.PropertyType = TypeSignature.FromReader(image, reader, false, protection);

            for (int i = 0; i < paramCount; i++)
            {
                signature.Parameters.Add(ParameterSignature.FromReader(image, reader, protection));
            }

            if (readToEnd)
            {
                signature.ExtraData = reader.ReadToEnd();
            }

            return(signature);
        }
Example #5
0
 public static ParameterSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new ParameterSignature
     {
         ParameterType = TypeSignature.FromReader(header, reader),
     });
 }
Example #6
0
        /// <summary>
        /// Reads a single generic instance type signature at the current position of the provided stream reader.
        /// </summary>
        /// <param name="image">The image the signature was defined in.</param>
        /// <param name="reader">The reader to use.</param>
        /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
        /// <returns>The read signature.</returns>
        public static GenericInstanceTypeSignature FromReader(
            MetadataImage image,
            IBinaryStreamReader reader,
            RecursionProtection protection)
        {
            if (!reader.CanRead(sizeof(byte)))
            {
                return(null);
            }

            var elementType = (ElementType)reader.ReadByte();
            var type        = ReadTypeDefOrRef(image, reader, protection);

            var signature = new GenericInstanceTypeSignature(type)
            {
                IsValueType = elementType == ElementType.ValueType
            };

            if (!reader.TryReadCompressedUInt32(out uint count))
            {
                return(signature);
            }

            for (int i = 0; i < count; i++)
            {
                signature.GenericArguments.Add(TypeSignature.FromReader(image, reader, false, protection));
            }

            return(signature);
        }
 /// <summary>
 /// Reads a single annotated type signature at the current position of the provided stream reader.
 /// </summary>
 /// <param name="image">The image the signature resides in.</param>
 /// <param name="reader">The reader to use.</param>
 /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
 /// <returns>The read signature.</returns>
 public static RequiredModifierSignature FromReader(
     MetadataImage image,
     IBinaryStreamReader reader,
     RecursionProtection protection)
 {
     return(new RequiredModifierSignature(ReadTypeDefOrRef(image, reader, protection),
                                          TypeSignature.FromReader(image, reader, false, protection)));
 }
Example #8
0
 public new static FieldSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
 {
     return(new FieldSignature
     {
         Attributes = (CallingConventionAttributes)reader.ReadByte(),
         FieldType = TypeSignature.FromReader(image, reader),
     });
 }
Example #9
0
 public static ParameterSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new ParameterSignature
     {
         StartOffset = reader.Position,
         ParameterType = TypeSignature.FromReader(header, reader),
     });
 }
Example #10
0
        public new static PinnedTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            long position = reader.StartPosition;

            return(new PinnedTypeSignature(TypeSignature.FromReader(header, reader))
            {
                StartOffset = reader.Position,
            });
        }
Example #11
0
        public static VariableSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            return(new VariableSignature(TypeSignature.FromReader(header, reader))
            {
                StartOffset = position
            });
        }
        public new static ByReferenceTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            return(new ByReferenceTypeSignature(TypeSignature.FromReader(header, reader))
            {
                StartOffset = position
            });
        }
Example #13
0
 public new static FieldSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new FieldSignature
     {
         StartOffset = reader.Position,
         Attributes = (CallingConventionAttributes)reader.ReadByte(),
         FieldType = TypeSignature.FromReader(header, reader),
     });
 }
        public new static RequiredModifierSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            return(new RequiredModifierSignature(ReadTypeDefOrRef(header, reader),
                                                 TypeSignature.FromReader(header, reader))
            {
                StartOffset = position
            });
        }
Example #15
0
 /// <summary>
 /// Reads a single field signature at the current position of the provided stream reader.
 /// </summary>
 /// <param name="image">The image the field is defined in.</param>
 /// <param name="reader">The reader to use.</param>
 /// <param name="readToEnd">Determines whether any extra data after the signature should be read and
 /// put into the <see cref="ExtendableBlobSignature.ExtraData"/> property.</param>
 /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
 /// <returns>The read signature.</returns>
 public new static FieldSignature FromReader(
     MetadataImage image,
     IBinaryStreamReader reader,
     bool readToEnd,
     RecursionProtection protection)
 {
     return(new FieldSignature
     {
         Attributes = (CallingConventionAttributes)reader.ReadByte(),
         FieldType = TypeSignature.FromReader(image, reader, false, protection),
         ExtraData = readToEnd ? reader.ReadToEnd() : null
     });
 }
Example #16
0
        /// <summary>
        /// Reads a single method signature at the current position of the provided stream reader.
        /// </summary>
        /// <param name="image">The image the field is defined in.</param>
        /// <param name="reader">The reader to use.</param>
        /// <param name="readToEnd">Determines whether any extra data after the signature should be read and
        /// put into the <see cref="ExtendableBlobSignature.ExtraData"/> property.</param>
        /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
        /// <returns>The read signature.</returns>
        public new static MethodSignature FromReader(
            MetadataImage image,
            IBinaryStreamReader reader,
            bool readToEnd,
            RecursionProtection protection)
        {
            if (!reader.CanRead(sizeof(byte)))
            {
                return(null);
            }

            var signature = new MethodSignature
            {
                Attributes = (CallingConventionAttributes)reader.ReadByte()
            };

            if (signature.IsGeneric)
            {
                if (!reader.TryReadCompressedUInt32(out uint genericParameterCount))
                {
                    return(signature);
                }
                signature.GenericParameterCount = (int)genericParameterCount;
            }

            if (!reader.TryReadCompressedUInt32(out uint parameterCount))
            {
                return(signature);
            }

            signature.ReturnType = TypeSignature.FromReader(image, reader);

            for (int i = 0; i < parameterCount; i++)
            {
                signature.Parameters.Add(ParameterSignature.FromReader(image, reader, protection));
            }

            if (readToEnd)
            {
                signature.ExtraData = reader.ReadToEnd();
            }

            return(signature);
        }
        public new static GenericInstanceMethodSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            var signature = new GenericInstanceMethodSignature
            {
                Attributes = (CallingConventionAttributes)reader.ReadByte()
            };

            uint count;

            if (!reader.TryReadCompressedUInt32(out count))
            {
                return(signature);
            }

            for (int i = 0; i < count; i++)
            {
                signature.GenericArguments.Add(TypeSignature.FromReader(image, reader));
            }

            return(signature);
        }
Example #18
0
        public new static MethodSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            if (!reader.CanRead(sizeof(byte)))
            {
                return(null);
            }

            var signature = new MethodSignature
            {
                StartOffset = reader.Position,
                Attributes  = (CallingConventionAttributes)reader.ReadByte()
            };

            if (signature.IsGeneric)
            {
                uint genericParameterCount;
                if (!reader.TryReadCompressedUInt32(out genericParameterCount))
                {
                    return(signature);
                }
                signature.GenericParameterCount = (int)genericParameterCount;
            }

            uint parameterCount;

            if (!reader.TryReadCompressedUInt32(out parameterCount))
            {
                return(signature);
            }

            signature.ReturnType = TypeSignature.FromReader(header, reader);
            for (int i = 0; i < parameterCount; i++)
            {
                signature.Parameters.Add(ParameterSignature.FromReader(header, reader));
            }

            return(signature);
        }
Example #19
0
        public new static PropertySignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            var signature = new PropertySignature
            {
                Attributes = (CallingConventionAttributes)reader.ReadByte(),
            };

            uint paramCount;

            if (!reader.TryReadCompressedUInt32(out paramCount))
            {
                return(null);
            }

            signature.PropertyType = TypeSignature.FromReader(image, reader);

            for (int i = 0; i < paramCount; i++)
            {
                signature.Parameters.Add(ParameterSignature.FromReader(image, reader));
            }

            return(signature);
        }
Example #20
0
 public new static SzArrayTypeSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
 {
     return(new SzArrayTypeSignature(TypeSignature.FromReader(image, reader)));
 }
Example #21
0
 public new static PinnedTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new PinnedTypeSignature(TypeSignature.FromReader(header, reader)));
 }
Example #22
0
        public new static PointerTypeSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            long position = reader.Position;

            return(new PointerTypeSignature(TypeSignature.FromReader(image, reader)));
        }
Example #23
0
 public static ParameterSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
 {
     return(new ParameterSignature(TypeSignature.FromReader(image, reader)));
 }
Example #24
0
 public static VariableSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
 {
     return(new VariableSignature(TypeSignature.FromReader(image, reader)));
 }
 public new static ByReferenceTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new ByReferenceTypeSignature(TypeSignature.FromReader(header, reader)));
 }
Example #26
0
        /// <summary>
        /// Reads a single array type signature at the current position of the provided stream reader.
        /// </summary>
        /// <param name="image">The image the array was defined in.</param>
        /// <param name="reader">The reader to use.</param>
        /// <param name="protection">The recursion protection that is used to detect malicious loops in the metadata.</param>
        /// <returns>The read array.</returns>
        public static ArrayTypeSignature FromReader(MetadataImage image, IBinaryStreamReader reader, RecursionProtection protection)
        {
            var signature = new ArrayTypeSignature(TypeSignature.FromReader(image, reader, false, protection));

            // Rank
            if (!reader.TryReadCompressedUInt32(out uint rank))
            {
                return(signature);
            }

            // Sizes.
            if (!reader.TryReadCompressedUInt32(out uint numSizes))
            {
                return(signature);
            }

            var sizes = new List <uint>();

            for (int i = 0; i < numSizes; i++)
            {
                if (!reader.TryReadCompressedUInt32(out uint size))
                {
                    return(signature);
                }
                sizes.Add(size);
            }

            // Lower bounds.
            if (!reader.TryReadCompressedUInt32(out uint numLoBounds))
            {
                return(signature);
            }

            var loBounds = new List <uint>();

            for (int i = 0; i < numLoBounds; i++)
            {
                if (!reader.TryReadCompressedUInt32(out uint bound))
                {
                    return(signature);
                }
                loBounds.Add(bound);
            }

            // Create dimensions.
            for (int i = 0; i < rank; i++)
            {
                var dimension = new ArrayDimension();
                if (i < numSizes)
                {
                    dimension.Size = (int)sizes[i];
                }
                if (i < numLoBounds)
                {
                    dimension.LowerBound = (int)loBounds[i];
                }
                signature.Dimensions.Add(dimension);
            }

            return(signature);
        }
Example #27
0
        public new static ArrayTypeSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            long position  = reader.Position;
            var  signature = new ArrayTypeSignature(TypeSignature.FromReader(image, reader));

            uint rank;

            if (!reader.TryReadCompressedUInt32(out rank))
            {
                return(signature);
            }

            uint numSizes;

            if (!reader.TryReadCompressedUInt32(out numSizes))
            {
                return(signature);
            }

            var sizes = new uint[numSizes];

            for (int i = 0; i < numSizes; i++)
            {
                if (!reader.TryReadCompressedUInt32(out sizes[i]))
                {
                    return(signature);
                }
            }

            uint numLoBounds;

            if (!reader.TryReadCompressedUInt32(out numLoBounds))
            {
                return(signature);
            }

            var loBounds = new uint[numLoBounds];

            for (int i = 0; i < numLoBounds; i++)
            {
                if (!reader.TryReadCompressedUInt32(out loBounds[i]))
                {
                    return(signature);
                }
            }

            for (int i = 0; i < rank; i++)
            {
                var dimension = new ArrayDimension();
                if (i < numSizes)
                {
                    dimension.Size = (int)sizes[i];
                }
                if (i < numLoBounds)
                {
                    dimension.LowerBound = (int)loBounds[i];
                }
                signature.Dimensions.Add(dimension);
            }

            return(signature);
        }
Example #28
0
 public new static RequiredModifierSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new RequiredModifierSignature(ReadTypeDefOrRef(header, reader),
                                          TypeSignature.FromReader(header, reader)));
 }
Example #29
0
 public static VariableSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
 {
     return(new VariableSignature(TypeSignature.FromReader(header, reader)));
 }
Example #30
0
 public new static ByReferenceTypeSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
 {
     return(new ByReferenceTypeSignature(TypeSignature.FromReader(image, reader)));
 }