Ejemplo n.º 1
0
        public SerializedObject DeserializeFromByteArray(byte[] bytData)
        {
            if (bytData == null)
            {
                throw new ArgumentNullException("bytData", "A valid non-null byte[] is required.");
            }

            byte[] bytDecompressedData = bytData;
            if (QuickLZ.headerLen(bytDecompressedData) == QuickLZ.DEFAULT_HEADERLEN)
            {
                bytDecompressedData = QuickLZ.decompress(bytDecompressedData);
            }

            SerializedObject objSerializedObject = null;

            using (MemoryStream objMemoryStream = new MemoryStream(bytDecompressedData))
            {
                using (BinaryReader objBinaryReader = new BinaryReader(objMemoryStream))
                {
                    BinaryFormatterKeyManager objKeyManager = new BinaryFormatterKeyManager(objBinaryReader);
                    objSerializedObject = Deserialize(objBinaryReader, objKeyManager);
                }
            }

            return(objSerializedObject);
        }
Ejemplo n.º 2
0
 public static int sizeCompressed(byte[] source)
 {
     if (QuickLZ.headerLen(source) == 9)
     {
         return((int)source[1] | (int)source[2] << 8 | (int)source[3] << 16 | (int)source[4] << 24);
     }
     return((int)source[1]);
 }
Ejemplo n.º 3
0
 public static int sizeDecompressed(byte[] source)
 {
     if (QuickLZ.headerLen(source) == 9)
     {
         return((int)source[5] | (int)source[6] << 8 | (int)source[7] << 16 | (int)source[8] << 24);
     }
     return((int)source[2]);
 }
Ejemplo n.º 4
0
        public static ITransportableObject Expand(byte[] bytData)
        {
            if (bytData == null)
            {
                throw new ArgumentNullException("bytData", "A valid non-null byte[] is required.");
            }

            byte[] bytDecompressedData = bytData;
            if (QuickLZ.headerLen(bytDecompressedData) == QuickLZ.DEFAULT_HEADERLEN)
            {
                bytDecompressedData = QuickLZ.decompress(bytDecompressedData);
            }

            ITransportableObject objTransportableObject = null;

            using (MemoryStream objMemoryStream = new MemoryStream(bytDecompressedData))
            {
                objTransportableObject = Expand(objMemoryStream);
            }

            return(objTransportableObject);
        }
Ejemplo n.º 5
0
        public static TTransportableObjectType Expand <TTransportableObjectType>(byte[] bytData)
            where TTransportableObjectType : TransportableObject
        {
            if (bytData == null)
            {
                throw new ArgumentNullException("bytData", "A valid non-null byte[] is required.");
            }

            byte[] bytDecompressedData = bytData;
            if (QuickLZ.headerLen(bytDecompressedData) == QuickLZ.DEFAULT_HEADERLEN)
            {
                bytDecompressedData = QuickLZ.decompress(bytDecompressedData);
            }

            TTransportableObjectType objTransportableObject = default(TTransportableObjectType);

            using (MemoryStream objMemoryStream = new MemoryStream(bytDecompressedData))
            {
                objTransportableObject = Expand <TTransportableObjectType>(objMemoryStream);
            }

            return(objTransportableObject);
        }
Ejemplo n.º 6
0
    public static byte[] decompress(byte[] source)
    {
        int  num  = QuickLZ.sizeDecompressed(source);
        int  num2 = QuickLZ.headerLen(source);
        int  i    = 0;
        uint num3 = 1u;

        byte[] array  = new byte[num];
        int[]  array2 = new int[4096];
        byte[] array3 = new byte[4096];
        int    num4   = num - 6 - 4 - 1;
        int    j      = -1;
        uint   num5   = 0u;
        int    num6   = source[0] >> 2 & 3;

        if (num6 != 1 && num6 != 3)
        {
            throw new ArgumentException("C# version only supports level 1 and 3");
        }
        if ((source[0] & 1) != 1)
        {
            byte[] array4 = new byte[num];
            Array.Copy(source, QuickLZ.headerLen(source), array4, 0, num);
            return(array4);
        }
        while (true)
        {
            if (num3 == 1u)
            {
                num3  = (uint)((int)source[num2] | (int)source[num2 + 1] << 8 | (int)source[num2 + 2] << 16 | (int)source[num2 + 3] << 24);
                num2 += 4;
                if (i <= num4)
                {
                    if (num6 == 1)
                    {
                        num5 = (uint)((int)source[num2] | (int)source[num2 + 1] << 8 | (int)source[num2 + 2] << 16);
                    }
                    else
                    {
                        num5 = (uint)((int)source[num2] | (int)source[num2 + 1] << 8 | (int)source[num2 + 2] << 16 | (int)source[num2 + 3] << 24);
                    }
                }
            }
            if ((num3 & 1u) == 1u)
            {
                num3 >>= 1;
                uint num8;
                uint num9;
                if (num6 == 1)
                {
                    int num7 = (int)num5 >> 4 & 4095;
                    num8 = (uint)array2[num7];
                    if ((num5 & 15u) != 0u)
                    {
                        num9  = (num5 & 15u) + 2u;
                        num2 += 2;
                    }
                    else
                    {
                        num9  = (uint)source[num2 + 2];
                        num2 += 3;
                    }
                }
                else
                {
                    uint num10;
                    if ((num5 & 3u) == 0u)
                    {
                        num10 = (num5 & 255u) >> 2;
                        num9  = 3u;
                        num2++;
                    }
                    else if ((num5 & 2u) == 0u)
                    {
                        num10 = (num5 & 65535u) >> 2;
                        num9  = 3u;
                        num2 += 2;
                    }
                    else if ((num5 & 1u) == 0u)
                    {
                        num10 = (num5 & 65535u) >> 6;
                        num9  = (num5 >> 2 & 15u) + 3u;
                        num2 += 2;
                    }
                    else if ((num5 & 127u) != 3u)
                    {
                        num10 = (num5 >> 7 & 131071u);
                        num9  = (num5 >> 2 & 31u) + 2u;
                        num2 += 3;
                    }
                    else
                    {
                        num10 = num5 >> 15;
                        num9  = (num5 >> 7 & 255u) + 3u;
                        num2 += 4;
                    }
                    num8 = (uint)((long)i - (long)((ulong)num10));
                }
                array[i]     = array[(int)((UIntPtr)num8)];
                array[i + 1] = array[(int)((UIntPtr)(num8 + 1u))];
                array[i + 2] = array[(int)((UIntPtr)(num8 + 2u))];
                int num11 = 3;
                while ((long)num11 < (long)((ulong)num9))
                {
                    array[i + num11] = array[(int)(checked ((IntPtr)(unchecked ((ulong)num8 + (ulong)((long)num11)))))];
                    num11++;
                }
                i += (int)num9;
                if (num6 == 1)
                {
                    num5 = (uint)((int)array[j + 1] | (int)array[j + 2] << 8 | (int)array[j + 3] << 16);
                    while ((long)j < (long)i - (long)((ulong)num9))
                    {
                        j++;
                        int num7 = (int)((num5 >> 12 ^ num5) & 4095u);
                        array2[num7] = j;
                        array3[num7] = 1;
                        num5         = (uint)((ulong)(num5 >> 8 & 65535u) | (ulong)((long)((long)array[j + 3] << 16)));
                    }
                    num5 = (uint)((int)source[num2] | (int)source[num2 + 1] << 8 | (int)source[num2 + 2] << 16);
                }
                else
                {
                    num5 = (uint)((int)source[num2] | (int)source[num2 + 1] << 8 | (int)source[num2 + 2] << 16 | (int)source[num2 + 3] << 24);
                }
                j = i - 1;
            }
            else
            {
                if (i > num4)
                {
                    break;
                }
                array[i] = source[num2];
                i++;
                num2++;
                num3 >>= 1;
                if (num6 == 1)
                {
                    while (j < i - 3)
                    {
                        j++;
                        int num12 = (int)array[j] | (int)array[j + 1] << 8 | (int)array[j + 2] << 16;
                        int num7  = (num12 >> 12 ^ num12) & 4095;
                        array2[num7] = j;
                        array3[num7] = 1;
                    }
                    num5 = (uint)((ulong)(num5 >> 8 & 65535u) | (ulong)((long)((long)source[num2 + 2] << 16)));
                }
                else
                {
                    num5 = (uint)((ulong)(num5 >> 8 & 65535u) | (ulong)((long)((long)source[num2 + 2] << 16)) | (ulong)((long)((long)source[num2 + 3] << 24)));
                }
            }
        }
        while (i <= num - 1)
        {
            if (num3 == 1u)
            {
                num2 += 4;
                num3  = 2147483648u;
            }
            array[i] = source[num2];
            i++;
            num2++;
            num3 >>= 1;
        }
        return(array);
    }