Ejemplo n.º 1
0
        public void DangerousCreateFromUnderlyingArrayNegativeTests()
        {
            byte[] array = null;
            ImmutableArray <byte> immutable = ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref array);

            Assert.True(immutable.IsDefault);
        }
Ejemplo n.º 2
0
        // internal for testing
        internal static unsafe ImmutableArray <byte> DecodeEmbeddedPortablePdbDebugDirectoryData(AbstractMemoryBlock block)
        {
            byte[] decompressed;

            const int headerSize = 2 * sizeof(int);

            var headerReader = new BlobReader(block.Pointer, headerSize);

            if (headerReader.ReadUInt32() != PortablePdbVersions.DebugDirectoryEmbeddedSignature)
            {
                throw new BadImageFormatException(SR.UnexpectedEmbeddedPortablePdbDataSignature);
            }

            int decompressedSize = headerReader.ReadInt32();

            try
            {
                decompressed = new byte[decompressedSize];
            }
            catch
            {
                throw new BadImageFormatException(SR.DataTooBig);
            }

            var compressed = new ReadOnlyUnmanagedMemoryStream(block.Pointer + headerSize, block.Size - headerSize);
            var deflate    = new DeflateStream(compressed, CompressionMode.Decompress, leaveOpen: true);

            if (decompressedSize > 0)
            {
                int actualLength;

                try
                {
                    actualLength = deflate.TryReadAll(decompressed, 0, decompressed.Length);
                }
                catch (InvalidDataException e)
                {
                    throw new BadImageFormatException(e.Message, e.InnerException);
                }

                if (actualLength != decompressed.Length)
                {
                    throw new BadImageFormatException(SR.SizeMismatch);
                }
            }

            // Check that there is no more compressed data left,
            // in case the decompressed size specified in the header is smaller
            // than the actual decompressed size of the data.
            if (deflate.ReadByte() != -1)
            {
                throw new BadImageFormatException(SR.SizeMismatch);
            }

            return(ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref decompressed));
        }
Ejemplo n.º 3
0
        public void DangerousGetUnderlyingArray()
        {
            ImmutableArray <byte> immutable = ImmutableArray.Create <byte>(1, 2, 3);

            byte[] array = ImmutableByteArrayInterop.DangerousGetUnderlyingArray(immutable);

            Assert.Equal(3, array.Length);
            Assert.Equal(1, array[0]);
            Assert.Equal(2, array[1]);
            Assert.Equal(3, array[2]);

            array[0] = 9;

            Assert.Equal(9, immutable[0]);
        }
Ejemplo n.º 4
0
        // internal for testing
        internal static PdbChecksumDebugDirectoryData DecodePdbChecksumDebugDirectoryData(AbstractMemoryBlock block)
        {
            var reader = block.GetReader();

            var algorithmName = reader.ReadUtf8NullTerminated();

            byte[]? checksum = reader.ReadBytes(reader.RemainingBytes);
            if (algorithmName.Length == 0 || checksum.Length == 0)
            {
                throw new BadImageFormatException(SR.InvalidPdbChecksumDataFormat);
            }

            return(new PdbChecksumDebugDirectoryData(
                       algorithmName,
                       ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref checksum)));
        }
Ejemplo n.º 5
0
        public void DangerousCreateFromUnderlyingArray()
        {
            byte[] array = new byte[3] {
                1, 2, 3
            };
            byte[] arrayCopy = array;
            ImmutableArray <byte> immutable = ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref array);

            // DangerousCreateFromUnderlyingArray clears the given parameter as a signal that
            // the mutable array should no longer be modified through mutable references.
            Assert.Null(array);

            Assert.Equal(3, immutable.Length);
            Assert.Equal(1, immutable[0]);
            Assert.Equal(2, immutable[1]);
            Assert.Equal(3, immutable[2]);

            arrayCopy[0] = 9;

            Assert.Equal(9, immutable[0]);
        }
Ejemplo n.º 6
0
 public ImmutableArray <byte> GetILContent()
 {
     byte[] bytes = GetILBytes();
     return(ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes));
 }
Ejemplo n.º 7
0
 public static BlobContentId FromHash(ImmutableArray <byte> hashCode)
 {
     return(FromHash(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(hashCode) !));
 }
Ejemplo n.º 8
0
 public BlobContentId(ImmutableArray <byte> id)
     : this(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(id) !)
 {
 }
Ejemplo n.º 9
0
 /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Range specified by <paramref name="start"/> and <paramref name="byteCount"/> falls outside of the bounds of the <paramref name="buffer"/>.</exception>
 /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception>
 public void WriteBytes(ImmutableArray <byte> buffer, int start, int byteCount)
 {
     WriteBytes(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(buffer), start, byteCount);
 }
Ejemplo n.º 10
0
        /// <exception cref="ArgumentOutOfRangeException">Range specified by <paramref name="start"/> and <paramref name="byteCount"/> falls outside of the bounds of the buffer content.</exception>
        /// <exception cref="InvalidOperationException">Content is not available, the builder has been linked with another one.</exception>
        public ImmutableArray <byte> ToImmutableArray(int start, int byteCount)
        {
            var array = ToArray(start, byteCount);

            return(ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref array));
        }
Ejemplo n.º 11
0
 public static ImmutableArray <byte> ReadImmutableBytes(byte *buffer, int byteCount)
 {
     byte[] bytes = ReadBytes(buffer, byteCount);
     return(ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes));
 }
Ejemplo n.º 12
0
        public void DangerousGetUnderlyingArrayNegativeTests()
        {
            ImmutableArray <byte> immutable = default(ImmutableArray <byte>);

            Assert.Null(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(immutable));
        }
Ejemplo n.º 13
0
 public PinnedBlob(ImmutableArray <byte> blob)
     : this(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(blob))
 {
 }