Ejemplo n.º 1
0
        /// <summary>
        /// Decompresses the inputBytes from Lzma
        /// </summary>
        /// <param name="inputBytes">bytes to decompress</param>
        /// <returns>Decompressed bytes</returns>
        public static byte[] Decompress(byte[] inputBytes)
        {
            if (inputBytes != null)
            {
                MemoryStream newInStream = new MemoryStream(inputBytes);

                Unity3DDisassembler.Compression.LZMA.Decoder decoder = new Unity3DDisassembler.Compression.LZMA.Decoder();

                newInStream.Seek(0, 0);
                MemoryStream newOutStream = new MemoryStream();

                byte[] properties2 = new byte[5];
                if (newInStream.Read(properties2, 0, 5) != 5)
                {
                    throw (new Exception("input .lzma is too short"));
                }
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = newInStream.ReadByte();
                    if (v < 0)
                    {
                        throw (new Exception("Can't Read 1"));
                    }
                    outSize |= ((long)(byte)v) << (8 * i);
                }
                decoder.SetDecoderProperties(properties2);
                long compressedSize = newInStream.Length - newInStream.Position;
                decoder.Code(newInStream, newOutStream, compressedSize, outSize, null);

                //Clear Memory
                properties2 = null;
                newInStream.Dispose();
                decoder = null;

                return(newOutStream.ToArray());
            }
            else
            {
                throw new ArgumentNullException("inputBytes", "inputBytes was null. :[");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decompresses the inputBytes from Lzma
        /// </summary>
        /// <param name="inputBytes">bytes to decompress</param>
        /// <returns>Decompressed bytes</returns>
        public static byte[] Decompress(byte[] inputBytes)
        {
            if (inputBytes != null)
            {
                MemoryStream newInStream = new MemoryStream(inputBytes);

                Unity3DDisassembler.Compression.LZMA.Decoder decoder = new Unity3DDisassembler.Compression.LZMA.Decoder();

                newInStream.Seek(0, 0);
                MemoryStream newOutStream = new MemoryStream();

                byte[] properties2 = new byte[5];
                if (newInStream.Read(properties2, 0, 5) != 5)
                    throw (new Exception("input .lzma is too short"));
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = newInStream.ReadByte();
                    if (v < 0)
                        throw (new Exception("Can't Read 1"));
                    outSize |= ((long)(byte)v) << (8 * i);
                }
                decoder.SetDecoderProperties(properties2);
                long compressedSize = newInStream.Length - newInStream.Position;
                decoder.Code(newInStream, newOutStream, compressedSize, outSize, null);

                //Clear Memory
                properties2 = null;
                newInStream.Dispose();
                decoder = null;

                return newOutStream.ToArray();
            }
            else
            {
                throw new ArgumentNullException("inputBytes", "inputBytes was null. :[");
            }
        }