Beispiel #1
0
    /// <summary>
    /// 解压
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public static string Deompress(string param)
    {
        Debug.Log("11111111111111commonString:");
        string commonString = "";
        int    data         = 0;
        int    stopByte     = -1;

        byte[]       buffer = Convert.FromBase64String(param);// 解base64
        MemoryStream intms  = new MemoryStream(buffer);

        zlib.ZInputStream inZStream = new zlib.ZInputStream(intms);
        int count = 1024 * 1024;

        byte[] inByteList = new byte[count];
        int    i          = 0;

        while (stopByte != (data = inZStream.Read()))
        {
            inByteList[i] = (byte)data;
            i++;
        }
        inZStream.Close();
        commonString = System.Text.Encoding.UTF8.GetString(inByteList, 0, inByteList.Length);
        Debug.Log(commonString);
        Debug.Log("22222222222222commonString:");
        return(commonString);
    }
Beispiel #2
0
        public static void UnpackSng(Stream input, Stream output, Platform platform)
        {
            EndianBitConverter conv;

            switch (platform.platform)
            {
            case GamePlatform.Pc:
            case GamePlatform.Mac:
                // Desktop
                conv = EndianBitConverter.Little;
                break;

            case GamePlatform.XBox360:
            case GamePlatform.PS3:
                // Console
                conv = EndianBitConverter.Big;
                break;

            default:
                conv = EndianBitConverter.Little;
                break;
            }

            using (var decrypted = new MemoryStream())
                using (var br = new EndianBinaryReader(conv, input))
                    using (var brDec = new EndianBinaryReader(conv, decrypted)) {
                        byte[] key;
                        switch (platform.platform)
                        {
                        case GamePlatform.Mac:
                            key = RijndaelEncryptor.SngKeyMac;
                            break;

                        default: //PC
                            key = RijndaelEncryptor.SngKeyPC;
                            break;
                        }
                        RijndaelEncryptor.DecryptSngData(br.BaseStream, decrypted, key);

                        //unZip
                        int    bSize = 1;
                        uint   zLen  = brDec.ReadUInt32();
                        ushort xU    = brDec.ReadUInt16();
                        brDec.BaseStream.Position -= 2;
                        if (xU == 55928)//LE 55928 //BE 30938
                        {
                            var z = new zlib.ZInputStream(brDec.BaseStream);
                            do
                            {
                                byte[] buf = new byte[bSize];
                                z.read(buf, 0, bSize);
                                output.Write(buf, 0, bSize);
                            } while (output.Length < (long)zLen);
                            z.Close();
                        }
                    }
        }
        public static byte[] DecompressData(byte[] inData)
        {
            int data     = 0;
            int stopByte = -1;

            byte[]       Buffer = inData; // 解base64
            MemoryStream intms  = new MemoryStream(Buffer);

            zlib.ZInputStream inZStream = new zlib.ZInputStream(intms);
            int count = 1024 * 1024;

            byte[] inByteList = new byte[count];
            int    i          = 0;

            while (stopByte != (data = inZStream.Read()))
            {
                inByteList[i] = (byte)data;
                i++;
            }
            inZStream.Close();
            return(inByteList.Take(i).ToArray());
        }
 /// <summary>
 /// Unpacks zipped data.
 /// </summary>
 /// <param name="str">In Stream.</param>
 /// <param name="outStream">Out stream.</param>
 /// <param name = "plainLen">Data size after decompress.</param>
 /// <param name = "rewind">Manual control for stream seek position.</param>
 public static void Unzip(Stream str, Stream outStream, bool rewind = true)
 {
     int len;
     var buffer = new byte[65536];
     var zOutputStream = new ZInputStream(str);
     while ((len = zOutputStream.read(buffer, 0, buffer.Length)) > 0)
     {
         outStream.Write(buffer, 0, len);
     }
     zOutputStream.Close();
     buffer = null;
     if (rewind)
     {
         outStream.Position = 0;
         outStream.Flush();
     }
 }
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd = null;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using(ZInputStream zOut = new ZInputStream(msSinkUnCompressed))
                {
                    zOut.Read(input, 0, input.Length);
                    msSinkUnCompressed.Seek(0L, SeekOrigin.Begin);
                    osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    zOut.Close();
                }
            }

            return osd;
        }
Beispiel #6
0
        public byte[] DecompressPacket(byte[] Payload, int Offset)
        {
            MemoryStream ms = new MemoryStream(Payload.GetUpperBound(0) - Offset);

            ms.Write(Payload, Offset, Payload.GetUpperBound(0) - Offset);

            ms.Seek(0, System.IO.SeekOrigin.Begin);

            ZInputStream zs = new ZInputStream(ms);

            int UncompressedSize;

            byte[] Uncompressed = new byte[4096];

            try
            {
                UncompressedSize = zs.read(Uncompressed, 0, 4096);
            }
            catch
            {
                if(DEBUG)
                    Debug("DECOMPRESSION FAILURE");

                Array.Copy(Payload, Offset - 1, Uncompressed, 0, Payload.Length - (Offset - 1));

                UncompressedSize = Payload.Length - (Offset - 1);
            }

            zs.Close();

            zs.Dispose();

            ms.Close();

            ms.Dispose();

            Array.Resize(ref Uncompressed, UncompressedSize);

            return Uncompressed;
        }
        public static void UnpackSng(Stream input, Stream output, Platform platform)
        {
            EndianBitConverter conv;

            switch (platform.platform) {
                case GamePlatform.Pc:
                case GamePlatform.Mac:
                    // Desktop
                    conv = EndianBitConverter.Little;
                    break;
                case GamePlatform.XBox360:
                case GamePlatform.PS3:
                    // Console
                    conv = EndianBitConverter.Big;
                    break;
                default:
                    conv = EndianBitConverter.Little;
                    break;
            }

            using (var decrypted = new MemoryStream())
            using (var br = new EndianBinaryReader(conv, input))
            using (var brDec = new EndianBinaryReader(conv, decrypted)) {

                byte[] key;
                switch (platform.platform) {
                    case GamePlatform.Mac:
                        key = RijndaelEncryptor.SngKeyMac;
                        break;
                    default: //PC
                        key = RijndaelEncryptor.SngKeyPC;
                        break;
                }
                RijndaelEncryptor.DecryptSngData(br.BaseStream, decrypted, key);

                //unZip
                int bSize = 1;
                uint zLen = brDec.ReadUInt32();
                ushort xU = brDec.ReadUInt16();
                brDec.BaseStream.Position -= 2;
                if (xU == 55928) {//LE 55928 //BE 30938
                    var z = new zlib.ZInputStream(brDec.BaseStream);
                    do {
                        byte[] buf = new byte[bSize];
                        z.read(buf, 0, bSize);
                        output.Write(buf, 0, bSize);
                    } while (output.Length < (long)zLen);
                    z.Close();
                }
            }
        }