Example #1
0
    public void uncompressFile(string inFile, string outFile)
    {
        int data     = 0;
        int stopByte = -1;

        System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
        zlib.ZInputStream    inZStream     = new zlib.ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read));
        while (stopByte != (data = inZStream.Read()))
        {
            byte _dataByte = (byte)data;
            outFileStream.WriteByte(_dataByte);
        }
        inZStream.Close();
        outFileStream.Close();
    }
Example #2
0
        public static byte[] Inflate(byte[] CompressedStream)
        {
            List <byte> outByte  = new List <byte>();
            int         data     = 0;
            int         stopByte = -1;

            zlib.ZInputStream inZStream = new zlib.ZInputStream(new MemoryStream(CompressedStream));
            while (stopByte != (data = inZStream.Read()))
            {
                byte _dataByte = (byte)data;
                outByte.Add(_dataByte);
            }
            inZStream.Close();
            return(outByte.ToArray());
        }
Example #3
0
        private byte[] readCompressedBuffer(int zLength)
        {
            byte[] compressed = new byte[zLength];
            input.Read(compressed, 0, zLength);
            MemoryStream zinput       = new MemoryStream(compressed);
            MemoryStream uncompressed = new MemoryStream(zLength);

            using (var zstream = new zlib.ZInputStream(zinput))
            {
                byte[] buf = new byte[1024];
                int    len = 0;
                while ((len = zstream.read(buf, 0, buf.Length)) > 0)
                {
                    uncompressed.Write(buf, 0, len);
                }
                uncompressed.Flush();
            }
            return(uncompressed.ToArray());
        }
Example #4
0
        public static byte[] Decompress(byte[] input)
        {
            System.IO.MemoryStream os  = new System.IO.MemoryStream();
            zlib.ZInputStream      zis = new zlib.ZInputStream(new System.IO.MemoryStream(input));

            byte[] output = new byte[256];
            int    count  = 0;

            do
            {
                count = zis.read(output, 0, 256);
                if (count > 0)
                {
                    os.Write(output, 0, count);
                }
            }while (count > 0);
            output = os.ToArray();
            os.Close();
            return(output);
        }
 /// <summary>
 /// zlib.net 解压函数
 /// </summary>
 /// <param name="strSource">带解压数据源</param>
 /// <returns>解压后的数据</returns>
 public static string DeflateDecompress(string strSource)
 {
     byte[] Buffer = Convert.FromBase64String(strSource); // 解base64
     using (MemoryStream intms = new MemoryStream(Buffer))
     {
         using (zlib.ZInputStream inZStream = new zlib.ZInputStream(intms))
         {
             int    size   = short.MaxValue;
             byte[] buffer = new byte[size];
             using (MemoryStream ms = new MemoryStream())
             {
                 while ((size = inZStream.read(buffer, 0, size)) != -1)
                 {
                     ms.Write(buffer, 0, size);
                 }
                 inZStream.Close();
                 return(Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length));
             }
         }
     }
 }
Example #6
0
        /// <summary>
        /// All profile stuff: crd (u play credentials), LocalProfiles.json and profiles themselves
        /// Good for RS2014 and RS1
        /// </summary>
        /// <param name="str"></param>
        /// <param name="outStream"></param>
        public static void DecryptProfile(Stream str, Stream outStream)
        {
            var source = BigEndianBitConverter.Little;
            var dec    = EndianBitConverter.Big;

            using (var decrypted = new MemoryStream())
                using (EndianBinaryReader br = new EndianBinaryReader(source, str))
                    using (EndianBinaryReader brDec = new EndianBinaryReader(dec, decrypted))
                    {
                        //EVAS + header
                        br.ReadBytes(16);
                        byte[] key  = PCSaveKey;
                        uint   zLen = br.ReadUInt32(); //size
                        // baseStr.pos = 20
                        DecryptFile(br.BaseStream, decrypted, key);

                        //unZip
                        int bSize = 1;
                        brDec.BaseStream.Position = 0;
                        ushort xU = brDec.ReadUInt16();
                        //back to 0
                        brDec.BaseStream.Position -= 2;
                        if (xU == 30938)//LE 55928 //BE 30938
                        {
                            var z = new zlib.ZInputStream(brDec.BaseStream);
                            do
                            {
                                byte[] buf = new byte[bSize];
                                z.read(buf, 0, bSize);
                                outStream.Write(buf, 0, bSize);
                            } while (outStream.Length < (long)zLen);
                            z.Close();
                        }
                    }
            outStream.Flush();
            outStream.Position = 0;
        }
        /// <summary>
        /// All profile stuff: crd (u play credentials), LocalProfiles.json and profiles themselves
        /// Good for RS2014 and RS1
        /// </summary>
        /// <param name="str"></param>
        /// <param name="outStream"></param>
        public static void DecryptProfile(Stream str, Stream outStream)
        {
            var source = BigEndianBitConverter.Little;
            var dec = EndianBitConverter.Big;

            using (var decrypted = new MemoryStream())
            using (EndianBinaryReader br = new EndianBinaryReader(source, str))
            using (EndianBinaryReader brDec = new EndianBinaryReader(dec, decrypted))
            {
                //EVAS + header
                br.ReadBytes(16);
                byte[] key = PCSaveKey;
                uint zLen = br.ReadUInt32(); //size
                // baseStr.pos = 20
                DecryptFile(br.BaseStream, decrypted, key);

                //unZip
                int bSize = 1;
                brDec.BaseStream.Position = 0;
                ushort xU = brDec.ReadUInt16();
                //back to 0
                brDec.BaseStream.Position -= 2;
                if (xU == 30938)//LE 55928 //BE 30938
                {
                    var z = new zlib.ZInputStream(brDec.BaseStream);
                    do
                    {
                        byte[] buf = new byte[bSize];
                        z.read(buf, 0, bSize);
                        outStream.Write(buf, 0, bSize);
                    } while (outStream.Length < (long)zLen);
                    z.Close();
                }
            }
            outStream.Flush();
            outStream.Position = 0;
        }
Example #8
0
        public static byte[] Decompress(byte[] input)
        {
            System.IO.MemoryStream os = new System.IO.MemoryStream();
            zlib.ZInputStream zis = new zlib.ZInputStream(new System.IO.MemoryStream(input));

            byte[] output = new byte[256];
            int count = 0;
            do
            {
                count = zis.read(output, 0, 256);
                if (count > 0)
                {
                    os.Write(output, 0, count);
                }
            }
            while (count > 0);
            output = os.ToArray();
            os.Close();
            return output;
        }