示例#1
0
        public byte[] PackPacketToBytes(IPirateXPackage requestPackage)
        {
            if (requestPackage == null)
            {
                return(null);
            }

            var headerbytes  = requestPackage.HeaderBytes;
            var contentbytes = requestPackage.ContentBytes;

            //信息头压缩
            headerbytes = ZipEnable ? Zip.Compress(headerbytes) : headerbytes;
            //数据体压缩
            contentbytes = ZipEnable ? Zip.Compress(contentbytes) : contentbytes;

            //8位,  每一位是一个加密标记位,1表示启用
            for (byte i = 0; i < 8; i++)
            {
                if (CryptoByte.GetBit(i))
                {
                    var crypto = CryptoFactory.GetCrypto(i);

                    if (crypto != null)
                    {
                        //信息头加密
                        headerbytes = crypto.Encode(headerbytes, PackKeys);
                        //数据体加密
                        if (contentbytes == null)
                        {
                            contentbytes = new byte[0];
                        }
                        else
                        {
                            contentbytes = crypto.Encode(contentbytes, PackKeys);
                        }
                    }
                }
            }

            var zipByte = new byte[1];

            zipByte[0] = ZipEnable ? (byte)Math.Pow(2, 7) : (byte)0;

            var headerLen  = headerbytes.Length;
            var contentLen = contentbytes?.Length ?? 0;

            using (var stream = new MemoryStream())
            {
                stream.Write(BitConverter.GetBytes(4 + 1 + 1 + 4 + headerLen + contentLen), 0, 4);
                stream.Write(zipByte, 0, 1);
                stream.Write(new[] { CryptoByte }, 0, 1);
                stream.Write(BitConverter.GetBytes(headerLen), 0, 4);
                stream.Write(headerbytes, 0, headerLen);
                if (contentbytes != null)
                {
                    stream.Write(contentbytes, 0, contentLen);
                }
                return(stream.ToArray());
            }
        }
示例#2
0
        public void NewOut(IPirateXPackage package)
        {
            var request = new PirateXRequestInfo(package);
            var text    = package.ContentBytes == null ? string.Empty : Encoding.UTF8.GetString(package.ContentBytes);

            _json = text;
            var viewitem = listViewOut.Items.Add(DateTime.Now.ToString());

            viewitem.SubItems.Add($"{string.Join("&", request.Headers.AllKeys.Select(a => a + "=" + request.Headers[a]))}");
            viewitem.SubItems.Add($"{string.Join("&", request.QueryString.AllKeys.Select(a => a + "=" + request.QueryString[a]))}");
        }
示例#3
0
 public PirateXRequestInfo(IPirateXPackage requestPackage) :
     this(requestPackage.HeaderBytes, requestPackage.ContentBytes)
 {
 }
示例#4
0
 public PirateXResponseInfo(IPirateXPackage responsePackage)
     : this(responsePackage.HeaderBytes)
 {
     this.ContentBytes = responsePackage.ContentBytes;
 }