Пример #1
0
        /// <summary>
        /// Determines whether two array dimensions are considered equal according to their signature.
        /// </summary>
        /// <param name="dimension1">The first dimension to compare.</param>
        /// <param name="dimension2">The second dimension to compare.</param>
        /// <returns><c>True</c> if the dimensions are considered equal, <c>False</c> otherwise.</returns>
        public bool MatchArrayDimensions(ArrayDimension dimension1, ArrayDimension dimension2)
        {
            if (dimension1 == null && dimension2 == null)
                return true;
            if (dimension1 == null || dimension2 == null)
                return false;

            return dimension1.Size == dimension2.Size
                && dimension1.LowerBound == dimension2.LowerBound;
        }
Пример #2
0
        public static new ArrayTypeSignature FromReader(MetadataHeader header, IBinaryStreamReader reader)
        {
            long position = reader.Position;
            var signature = new ArrayTypeSignature(TypeSignature.FromReader(header, reader))
            {
                StartOffset = position
            };

            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;
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        private ArrayTypeSignature ImportArrayTypeSignature(ArrayTypeSignature signature)
        {
            var newSignature = new ArrayTypeSignature(ImportTypeSignature(signature.BaseType))
            {
                IsValueType = signature.IsValueType
            };

            foreach (var dimension in signature.Dimensions)
            {
                var newDimension = new ArrayDimension();
                if (dimension.Size.HasValue)
                    newDimension.Size = dimension.Size.Value;
                if (dimension.LowerBound.HasValue)
                    newDimension.LowerBound = dimension.LowerBound.Value;
                newSignature.Dimensions.Add(newDimension);
            }
            return newSignature;
        }