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()); }
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(); }
/// <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)); } } } }
/// <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; }