Пример #1
0
        public Document Get(int docId)
        {
            var bytes        = _db[docId];
            var decompressed = QuickLZ.decompress(bytes);

            return((Document)GraphSerializer.Serializer.Deserialize(new MemoryStream(decompressed)));
        }
Пример #2
0
        private T Deserialize(byte[] buffer)
        {
            var data = buffer;

            if (_isEncrypted)
            {
                try
                {
                    data = AesHelper.AesDecrypt(data, GetBytes(_encKey));
                }
                catch (CryptographicException)
                {
                    throw new ProtobufChannelEncryptionException(
                              "Object integrity invalid, maybe supplied wrong encryption key?");
                }
            }

            if (_isCompressed)
            {
                data = QuickLZ.decompress(data);
            }

            using (var ms = new MemoryStream(data))
            {
                return(Serializer.Deserialize <T>(ms));
            }
        }
Пример #3
0
        public static T Load(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            var timer = new Stopwatch();

            timer.Start();

            try
            {
                using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (var memStream = new MemoryStream())
                    {
                        fs.CopyTo(memStream);
                        var bytes        = memStream.ToArray();
                        var decompressed = QuickLZ.decompress(bytes);
                        var obj          = (T)Serializer.Deserialize(new MemoryStream(decompressed));

                        Log.DebugFormat("deserialized {0} in {1}", fileName, timer.Elapsed);

                        return(obj);
                    }
            }
            catch (FileNotFoundException)
            {
                return(default(T));
            }
        }
Пример #4
0
        public static string Decompress(string s)
        {
            var compressed   = Convert.FromBase64String(s);
            var uncompressed = QuickLZ.decompress(compressed);

            return(Encoding.Unicode.GetString(uncompressed, 0, uncompressed.Length));
        }
Пример #5
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);
        }
Пример #6
0
        public static IEnumerable <Field> DeserializeFields(Stream stream, int size, Compression compression, IDictionary <short, string> keyIndex)
        {
            var read = 0;

            while (read < size)
            {
                var keyIdBytes = new byte[sizeof(short)];

                stream.Read(keyIdBytes, 0, sizeof(short));

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(keyIdBytes);
                }

                var keyId = BitConverter.ToInt16(keyIdBytes, 0);

                string key = keyIndex[keyId];

                var valLengthBytes = new byte[sizeof(int)];

                stream.Read(valLengthBytes, 0, sizeof(int));

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valLengthBytes);
                }

                int valLength = BitConverter.ToInt32(valLengthBytes, 0);

                byte[] valBytes = new byte[valLength];

                stream.Read(valBytes, 0, valLength);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valBytes);
                }

                string value;

                if (compression == Compression.GZip)
                {
                    value = Encoding.GetString(Deflator.Deflate(valBytes));
                }
                else if (compression == Compression.Lz)
                {
                    value = Encoding.GetString(QuickLZ.decompress(valBytes));
                }
                else
                {
                    value = Encoding.GetString(valBytes);
                }

                read += sizeof(short) + sizeof(int) + valBytes.Length;

                yield return(new Field(key, value));
            }
        }
Пример #7
0
		public EmbeddedResource mergeResources() {
			if (encryptedResource.Resource == null)
				return null;
			DeobUtils.decryptAndAddResources(module, encryptedResource.Resource.Name, () => {
				return QuickLZ.decompress(encryptedResource.decrypt());
			});
			return encryptedResource.Resource;
		}
Пример #8
0
 static byte[] decompress(byte[] data)
 {
     if (!QuickLZ.isCompressed(data))
     {
         return(data);
     }
     return(QuickLZ.decompress(data));
 }
Пример #9
0
        public static IEnumerable <Field> DeserializeFields(Stream stream, bool deflate)
        {
            while (true)
            {
                var keyLengthBytes = new byte[sizeof(short)];

                var read = stream.Read(keyLengthBytes, 0, sizeof(short));

                if (read == 0)
                {
                    break;
                }

                short keyLength = BitConverter.ToInt16(keyLengthBytes, 0);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(keyLengthBytes);
                }

                byte[] keyBytes = new byte[keyLength];

                stream.Read(keyBytes, 0, keyLength);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(keyBytes);
                }

                string key = Encoding.GetString(keyBytes);

                var valLengthBytes = new byte[sizeof(int)];

                stream.Read(valLengthBytes, 0, sizeof(int));

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valLengthBytes);
                }

                int valLength = BitConverter.ToInt32(valLengthBytes, 0);

                byte[] valBytes = new byte[valLength];

                stream.Read(valBytes, 0, valLength);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valBytes);
                }

                string value = deflate ?
                               Encoding.GetString(Compressor.Decompress(valBytes)) :
                               Encoding.GetString(QuickLZ.decompress(valBytes));

                yield return(new Field(key, value));
            }
        }
Пример #10
0
        public byte[] dEncryption(byte[] sourceByteArr)
        {
            //  解密
            byte[] decryptByteArr = this.decryptionByteArr(sourceByteArr, tdes.Key, tdes.IV);
            //  解压
            byte[] unCompressByteArr = QuickLZ.decompress(decryptByteArr);

            return(unCompressByteArr);
        }
Пример #11
0
        public async Task <ResponseModel> Write(string collectionName, HttpRequest request)
        {
            try
            {
                var collectionId = collectionName.ToHash();
                var timer        = Stopwatch.StartNew();

                var payload = new MemoryStream();

                await request.Body.CopyToAsync(payload);

                if (request.ContentLength.Value != payload.Length)
                {
                    throw new DataMisalignedException();
                }

                var compressed = payload.ToArray();
                var messageBuf = QuickLZ.decompress(compressed);

                // A write request is either a request to write new data
                // or a request to concat two or more existing pages.

                this.Log(string.Format("serialized {0} bytes in {1}", messageBuf.Length, timer.Elapsed));

                timer.Restart();

                MemoryStream responseStream;

                lock (Sync)
                {
                    this.Log("waited for synchronization for {0}", timer.Elapsed);

                    timer.Restart();

                    responseStream = _data.Write(collectionId, messageBuf);

                    timer.Stop();

                    var t = timer.ElapsedMilliseconds > 0 ? timer.ElapsedMilliseconds : 1;

                    this.Log(string.Format(
                                 "wrote {0} bytes in {1}: {2} bytes/ms",
                                 messageBuf.Length, timer.Elapsed, messageBuf.Length / t));
                }

                return(new ResponseModel {
                    Stream = responseStream, MediaType = "application/octet-stream"
                });
            }
            catch (Exception ex)
            {
                this.Log(ex);

                throw;
            }
        }
Пример #12
0
 public EmbeddedResource mergeResources()
 {
     if (encryptedResource.Resource == null)
     {
         return(null);
     }
     DeobUtils.decryptAndAddResources(module, encryptedResource.Resource.Name.String, () => {
         return(QuickLZ.decompress(encryptedResource.decrypt()));
     });
     return(encryptedResource.Resource);
 }
Пример #13
0
        private void ExecuteBinder(Dictionary <string, string> options)
        {
            //QuickLZ

            string resource = options["r_k"];

            byte[] buffer = ReadResources(resource) as byte[];

            if (buffer == null)
            {
                return;
            }

#if ENCRYPTION
            byte[] key = Convert.FromBase64String(options["ek"]);
            byte[] iv  = Convert.FromBase64String(options["ei"]);

            using (RijndaelManaged rij = new RijndaelManaged())
            {
                rij.Key = key;
                rij.IV  = iv;
                using (ICryptoTransform ict = rij.CreateDecryptor())
                {
                    buffer = ict.TransformFinalBlock(buffer, 0, buffer.Length);
                }
            }
#endif

#if COMPRESSION
            buffer = QuickLZ.decompress(buffer);
#endif

            string path = ConstructPath(options);

            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch
                {
                    return;
                }
            }

            File.WriteAllBytes(path, buffer);

            if (options["e"] == "y") //execute = y
            {
                Process.Start(path);
            }
        }
Пример #14
0
 public static void DecompressProtoData(byte[] buffer, LuaFunction luaFunc)
 {
     if (luaFunc != null)
     {
         byte[] buf = QuickLZ.decompress(buffer);
         luaFunc.Call(new object[]
         {
             new LuaByteBuffer(buf)
         });
         luaFunc.Dispose();
         luaFunc = null;
     }
 }
Пример #15
0
        public static Graph Deserialize(string s)
        {
            try
            {
                var Ascii85    = new Ascii85();
                var compressed = Ascii85.Decode(s.Substring(Prefix.Length));
                var bytes      = QuickLZ.decompress(compressed);
                return(DeserializeFromByteArray(bytes));
            }
            catch { }

            return(null);
        }
Пример #16
0
        public static Graph Deserialize(string s)
        {
            try
            {
                var Ascii85    = new Ascii85();
                var compressed = Ascii85.Decode(s.Substring(Prefix.Length));
                var bytes      = QuickLZ.decompress(compressed);
                return(DeserializeFromByteArray(bytes));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(null);
        }
Пример #17
0
        private void InternalUnpack()
        {
            foreach (var res in Globals.Context.TargetAssembly.MainModule.Resources)
            {
                if (res.Name == "X")
                {
                    File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(Globals.Context.OutPath), "Main.exe"),
                                       QuickLZ.decompress((res as EmbeddedResource).GetResourceData()));
                }
                else
                {
                    File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(Globals.Context.OutPath), res.Name.MangleName() + ".dll"),
                                       QuickLZ.decompress((res as EmbeddedResource).GetResourceData()));
                }

                Globals.Context.UIProvider.GlobalLog("Unpacked file: " + (res.Name == "X" ? "X (Main assembly)" : res.Name.MangleName() + ".dll"));
            }

            Console.ReadLine();
        }
Пример #18
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);
        }
Пример #19
0
        public static byte[] GetPayload()
        {
            byte[] k = null;
            byte[] p = null;

            if (Debugger.IsAttached)
            {
                return(null);
            }

            using (Stream stream = stubAssembly.GetManifestResourceStream(PayloadKey))
            {
                using (BinaryReader rdr = new BinaryReader(stream))
                    k = rdr.ReadBytes((int)stream.Length);
            }

            using (Stream stream = stubAssembly.GetManifestResourceStream(PayloadName))
            {
                using (StreamReader rdr = new StreamReader(stream))
                    p = Convert.FromBase64String(rdr.ReadToEnd());
            }

            if (IsDebuggerPresent())
            {
                k = new byte[k.Length];
                Random R = new Random();
                R.NextBytes(k);
            }

            // Sleep(1000 * 5);

            xor(p, k);

            p = QuickLZ.decompress(p);


            return(p);
        }
Пример #20
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);
        }
Пример #21
0
        static int SPICES_QCLZ_SIG = 0x3952534E;                // "9RSN"

        public static byte[] decompress(byte[] data)
        {
            if (read32(data, 0) == SPICES_QCLZ_SIG)
            {
                return(QuickLZ.decompress(data, SPICES_QCLZ_SIG));
            }

            int headerLength, decompressedLength, compressedLength;

            if ((data[0] & 2) != 0)
            {
                headerLength       = 9;
                compressedLength   = (int)read32(data, 1);
                decompressedLength = (int)read32(data, 5);
            }
            else
            {
                headerLength       = 3;
                compressedLength   = data[1];
                decompressedLength = data[2];
            }

            bool isCompressed = (data[0] & 1) != 0;

            byte[] decompressed = new byte[decompressedLength];
            if (isCompressed)
            {
                decompress(data, headerLength, decompressed);
            }
            else
            {
                copy(data, headerLength, decompressed, 0, decompressed.Length);
            }

            return(decompressed);
        }
Пример #22
0
        public static IEnumerable <Field> DeserializeFields(Stream stream, int documentId, Compression compression)
        {
            while (true)
            {
                var keyLengthBytes = new byte[sizeof(short)];

                var read = stream.Read(keyLengthBytes, 0, sizeof(short));

                if (read == 0)
                {
                    break;
                }

                short keyLength = BitConverter.ToInt16(keyLengthBytes, 0);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(keyLengthBytes);
                }

                byte[] keyBytes = new byte[keyLength];

                stream.Read(keyBytes, 0, keyLength);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(keyBytes);
                }

                string key = Encoding.GetString(keyBytes);

                var valLengthBytes = new byte[sizeof(int)];

                stream.Read(valLengthBytes, 0, sizeof(int));

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valLengthBytes);
                }

                int valLength = BitConverter.ToInt32(valLengthBytes, 0);

                byte[] valBytes = new byte[valLength];

                stream.Read(valBytes, 0, valLength);

                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(valBytes);
                }


                string value;

                if (compression == Compression.GZip)
                {
                    value = Encoding.GetString(Deflator.Deflate(valBytes));
                }
                else if (compression == Compression.Lz)
                {
                    value = Encoding.GetString(QuickLZ.decompress(valBytes));
                }
                else
                {
                    value = Encoding.GetString(valBytes);
                }


                yield return(new Field(documentId, key, value));
            }
        }
Пример #23
0
        // Token: 0x06006B13 RID: 27411 RVA: 0x001E0934 File Offset: 0x001DEB34
        public static object DecodeMessage(MessageBlock recvBuffer, IProtoProvider protoProvider, out int msgId, Func <Stream, Type, int, object> deserializeMessageAction = null)
        {
            int num = 4;

            msgId = 0;
            if (recvBuffer.Length < num)
            {
                return(null);
            }
            ushort num2 = recvBuffer.ReadUInt16();

            if ((int)num2 < num)
            {
                throw new ProtoException(string.Format("Hack stream, TotalLength={0}", num2));
            }
            int num3 = (int)num2 - num;

            if (recvBuffer.Length < num3 + 2)
            {
                recvBuffer.ReadPtr(-2);
                return(null);
            }
            ushort num4 = recvBuffer.ReadUInt16();
            bool   flag = num4 >> 15 == 1;
            ushort num5 = num4 & 32767;

            msgId = (int)num5;
            Type   typeById = protoProvider.GetTypeById((int)num5);
            object result;

            try
            {
                if (flag)
                {
                    using (MemoryStream readStream = recvBuffer.GetReadStream(num3))
                    {
                        byte[] array = QuickLZ.decompress(readStream.ToArray());
                        int    count = array.Length;
                        using (MemoryStream memoryStream = new MemoryStream(array, 0, count))
                        {
                            if (deserializeMessageAction != null)
                            {
                                result = deserializeMessageAction(memoryStream, typeById, msgId);
                            }
                            else
                            {
                                result = RuntimeTypeModel.Default.Deserialize(memoryStream, null, typeById, null);
                            }
                        }
                    }
                }
                else
                {
                    using (MemoryStream readStream2 = recvBuffer.GetReadStream(num3))
                    {
                        if (deserializeMessageAction != null)
                        {
                            result = deserializeMessageAction(readStream2, typeById, msgId);
                        }
                        else
                        {
                            result = RuntimeTypeModel.Default.Deserialize(readStream2, null, typeById, null);
                        }
                    }
                }
            }
            catch (Exception innerException)
            {
                throw new Exception(string.Format("msgId={0}, isCompressed={1} pakBodyLength={2}", msgId, flag, num3), innerException);
            }
            return(result);
        }
 public byte[] Decompress(byte[] source)
 {
     return(QuickLZ.decompress(source));
 }
Пример #25
0
        public object GetDataFromDataBytes(byte[] dataBytes, ushort[,] prevImageData, GetByteMode byteMode, int size, int startIndex)
        {
            byte[] bytes;
            int    readIndex = 0;

            if (!m_UsesCompression)
            {
                bytes     = dataBytes;
                readIndex = startIndex;
            }
            else if (m_Compression == AdvCompressionMethods.COMPR_QUICKLZ)
            {
                byte[] compressedBytes = new byte[size];
                Array.Copy(dataBytes, startIndex, compressedBytes, 0, size);

                readIndex = 0;
                bytes     = QuickLZ.decompress(compressedBytes);
            }
            else if (m_Compression == AdvCompressionMethods.COMPR_LAGARITH16)
            {
                byte[] compressedBytes = new byte[size];
                Array.Copy(dataBytes, startIndex, compressedBytes, 0, size);

                readIndex = 0;
                bytes     = TangraCore.Lagarith16Decompress(Width, Height, compressedBytes);
            }
            else
            {
                throw new NotSupportedException(string.Format("Don't know how to apply compression '{0}'", m_Compression));
            }


            ushort[,] imageData;
            bool crcOkay;

            if (BitsPerPixel == 12)
            {
                imageData = GetPixelsFrom12BitByteArray(bytes, prevImageData, byteMode, ref readIndex, out crcOkay);
            }
            else if (BitsPerPixel == 16)
            {
                if (m_IsRawDataLayout)
                {
                    imageData = GetPixelsFrom16BitByteArrayRawLayout(bytes, prevImageData, ref readIndex, out crcOkay);
                }
                else
                {
                    imageData = GetPixelsFrom16BitByteArrayDiffCorrLayout(bytes, prevImageData, ref readIndex, out crcOkay);
                }
            }
            else if (BitsPerPixel == 8)
            {
                if (m_IsRawDataLayout)
                {
                    imageData = GetPixelsFrom8BitByteArrayRawLayout(bytes, prevImageData, ref readIndex, out crcOkay);
                }
                else
                {
                    imageData = GetPixelsFrom8BitByteArrayDiffCorrLayout(bytes, prevImageData, ref readIndex, out crcOkay);
                }
            }
            else
            {
                throw new NotSupportedException();
            }

            return(new AdvImageData()
            {
                ImageData = imageData,
                CRCOkay = m_UsesCRC ? crcOkay : true,
                Bpp = m_ImageSection.BitsPerPixel
            });
        }