Пример #1
0
        public void Ctor_Streams()
        {
            Assert.Throws<ArgumentException>(() => new PEReader(new TestStream(canRead: false, canSeek: false, canWrite: false)));
            Assert.Throws<ArgumentException>(() => new PEReader(new TestStream(canRead: true, canSeek: false, canWrite: false)));

            var s = new TestStream(canRead: true, canSeek: true, canWrite: false);

            new PEReader(s);
            new PEReader(s, PEStreamOptions.Default, 0);
            Assert.Throws<ArgumentOutOfRangeException>(() => new PEReader(s, PEStreamOptions.Default, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => new PEReader(s, PEStreamOptions.Default, 1));
        }
        public unsafe void CopyTo3()
        {
            const int bufferSize = 64;
            byte *    buffer     = (byte *)Marshal.AllocHGlobal(bufferSize);

            try
            {
                var s = new TestStream(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

                InvalidateMemory(buffer, bufferSize);
                s.CopyTo(buffer, 8);

                AssertEx.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, ReadBuffer(buffer, bufferSize));
            }
            finally
            {
                Marshal.FreeHGlobal((IntPtr)buffer);
            }
        }
Пример #3
0
        public void Ctor_Streams()
        {
            Assert.Throws<ArgumentException>(() => new PEHeaders(new TestStream(canRead: false, canSeek: false, canWrite: false)));
            Assert.Throws<ArgumentException>(() => new PEHeaders(new TestStream(canRead: true, canSeek: false, canWrite: false)));

            var s = new TestStream(canRead: true, canSeek: true, canWrite: false, buffer: Misc.Members);

            s.Position = 0;
            new PEHeaders(s);

            s.Position = 0;
            new PEHeaders(s, 0);

            s.Position = 0;
            Assert.Throws<ArgumentOutOfRangeException>(() => new PEHeaders(s, -1));
            Assert.Equal(0, s.Position);

            Assert.Throws<BadImageFormatException>(() => new PEHeaders(s, 1));
            Assert.Equal(0, s.Position);
        }
Пример #4
0
        public unsafe void CopyTo3()
        {
            const int bufferSize = 64;
            byte* buffer = (byte*)Marshal.AllocHGlobal(bufferSize);

            try
            {
                var s = new TestStream(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

                InvalidateMemory(buffer, bufferSize);
                s.CopyTo(buffer, 8);

                Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, ReadBuffer(buffer, bufferSize));
            }
            finally
            {
                Marshal.FreeHGlobal((IntPtr)buffer);
            }
        }