Beispiel #1
0
        public static bool AreStreamsEqual(Stream left, Stream right)
        {
            if (left == null)
            {
                return(right == null);
            }
            if (right == null)
            {
                return(false);
            }
            if (!left.CanRead || !right.CanRead)
            {
                throw new NotSupportedException("The streams can't be read for comparison");
            }
            if (left.Length != right.Length)
            {
                return(false);
            }
            int num = (int)left.Length;

            left.Position  = 0L;
            right.Position = 0L;
            int i    = 0;
            int num2 = 0;

            byte[]   array     = new byte[512];
            byte[]   array2    = new byte[512];
            GCHandle gchandle  = GCHandle.Alloc(array, GCHandleType.Pinned);
            IntPtr   left2     = gchandle.AddrOfPinnedObject();
            GCHandle gchandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned);
            IntPtr   right2    = gchandle2.AddrOfPinnedObject();
            bool     result;

            try
            {
                while (i < num)
                {
                    int num3 = left.Read(array, 0, array.Length);
                    int num4 = right.Read(array2, 0, array2.Length);
                    if (num3 != num4)
                    {
                        return(false);
                    }
                    if (!Utility._MemCmp(left2, right2, (long)num3))
                    {
                        return(false);
                    }
                    i    += num3;
                    num2 += num4;
                }
                result = true;
            }
            finally
            {
                gchandle.Free();
                gchandle2.Free();
            }
            return(result);
        }
Beispiel #2
0
        public static bool MemCmp(byte[] left, byte[] right, int cb)
        {
            GCHandle gCHandle  = GCHandle.Alloc(left, GCHandleType.Pinned);
            IntPtr   intPtr    = gCHandle.AddrOfPinnedObject();
            GCHandle gCHandle1 = GCHandle.Alloc(right, GCHandleType.Pinned);
            IntPtr   intPtr1   = gCHandle1.AddrOfPinnedObject();
            bool     flag      = Utility._MemCmp(intPtr, intPtr1, (long)cb);

            gCHandle.Free();
            gCHandle1.Free();
            return(flag);
        }
Beispiel #3
0
        public static bool MemCmp(byte[] left, byte[] right, int cb)
        {
            GCHandle gchandle  = GCHandle.Alloc(left, GCHandleType.Pinned);
            IntPtr   left2     = gchandle.AddrOfPinnedObject();
            GCHandle gchandle2 = GCHandle.Alloc(right, GCHandleType.Pinned);
            IntPtr   right2    = gchandle2.AddrOfPinnedObject();
            bool     result    = Utility._MemCmp(left2, right2, (long)cb);

            gchandle.Free();
            gchandle2.Free();
            return(result);
        }
Beispiel #4
0
        public static bool AreStreamsEqual(Stream left, Stream right)
        {
            bool flag;

            if (left == null)
            {
                return(right == null);
            }
            if (right == null)
            {
                return(false);
            }
            if (!left.CanRead || !right.CanRead)
            {
                throw new NotSupportedException("The streams can't be read for comparison");
            }
            if (left.Length != right.Length)
            {
                return(false);
            }
            int length = (int)left.Length;

            left.Position  = 0L;
            right.Position = 0L;
            int num  = 0;
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;

            byte[]   numArray  = new byte[512];
            byte[]   numArray1 = new byte[512];
            GCHandle gCHandle  = GCHandle.Alloc(numArray, GCHandleType.Pinned);
            IntPtr   intPtr    = gCHandle.AddrOfPinnedObject();
            GCHandle gCHandle1 = GCHandle.Alloc(numArray1, GCHandleType.Pinned);
            IntPtr   intPtr1   = gCHandle1.AddrOfPinnedObject();

            try
            {
                while (num < length)
                {
                    num2 = left.Read(numArray, 0, (int)numArray.Length);
                    num3 = right.Read(numArray1, 0, (int)numArray1.Length);
                    if (num2 != num3)
                    {
                        flag = false;
                        return(flag);
                    }
                    else if (!Utility._MemCmp(intPtr, intPtr1, (long)num2))
                    {
                        flag = false;
                        return(flag);
                    }
                    else
                    {
                        num  += num2;
                        num1 += num3;
                    }
                }
                flag = true;
            }
            finally
            {
                gCHandle.Free();
                gCHandle1.Free();
            }
            return(flag);
        }