/// <summary>
        /// 处理filecheck
        /// </summary>
        /// <param name="package"></param>
        /// <param name="write"></param>
        /// <returns></returns>
        private bool FileCheckHandle(PackagePlugin package, BinaryWriter toClientWriter, BinaryWriter toServerWriter)
        {
            // 如果本地文件存在, 就发送本地文件
            if (LocalData != null)
            {
                List <byte> unzipedBytes = new List <byte>();
                // 添加salt和hash列表
                unzipedBytes.Add(salt);
                unzipedBytes.AddRange(LocalData.FileHashBytes);
                byte[] zipedData = GzipUtil.Compress(unzipedBytes.ToArray());

                List <byte> buffers = new List <byte>();
                //type
                buffers.Add((byte)CatAntiCheatMessageType.CTSFileHash);
                //gzip数据长度
                buffers.AddRange(BitConverter.GetBytes((short)zipedData.Length).Reverse());
                //zip数据
                buffers.AddRange(zipedData);
                //sign
                buffers.AddRange(BitConverter.GetBytes((int)hashCode(zipedData)).Reverse());

                Console.WriteLine($"[CatAntiCheat]收到服务端FileCheck请求, 直接返回本地{fileName}中的数据!");

                PackagePlugin fakerPackage = new PackagePlugin(CTSPluginPackageId, package.ChannelName, buffers.ToArray(), Global.IsVersion1_12_2);
                toServerWriter.Write(fakerPackage.OriginData);
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        private byte[] ConvertRequestMessage(byte[] rawData)
        {
            byte[] fastinfosetData = null;
            byte[] compressedData  = null;

            //Fast Info Set
            if (isFastinfoset)
            {
                string message = Encoding.UTF8.GetString(rawData);
                fastinfosetData = FastinfosetUtil.GenerateFastInfoSet(message);
            }
            else
            {
                fastinfosetData = rawData;
            }

            //Gzip Compress
            if (isGzip)
            {
                compressedData = GzipUtil.Compress(fastinfosetData);
            }
            else
            {
                compressedData = fastinfosetData;
            }

            return(compressedData);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        public void Send(string message)
        {
            byte[] rawData         = Encoding.UTF8.GetBytes(message);
            byte[] fastinfosetData = null;
            byte[] compressedData  = null;

            //Fast Info Set
            if (httpRequest.CommonHeaders.Keys.Contains("Content-Type") &&
                httpRequest.CommonHeaders["Content-Type"].Contains("application/fastinfoset"))
            {
                fastinfosetData = FastinfosetUtil.GenerateFastInfoSet(message);
            }
            else
            {
                fastinfosetData = rawData;
            }

            //Gzip Compress
            if (httpRequest.CommonHeaders.Keys.Contains("Accept-Encoding") &&
                httpRequest.CommonHeaders["Accept-Encoding"].Equals("gzip"))
            {
                compressedData = GzipUtil.Compress(fastinfosetData);
            }
            else
            {
                compressedData = fastinfosetData;
            }
            httpRequest.CommonHeaders["Content-Length"] = compressedData.Length.ToString();
            httpRequest.CommonHeaders["Pragma"]         = "requestnum=\"" + requestSeq + "\"";
            requestSeq++;

            //Conbine the Header and message body

            byte[]            headerData = Encoding.UTF8.GetBytes(httpRequest.GetHeaderString());
            Collection <byte> totalData  = new Collection <byte>();

            for (int i = 0; i < headerData.Length; i++)
            {
                totalData.Add(headerData[i]);
            }
            for (int i = 0; i < compressedData.Length; i++)
            {
                totalData.Add(compressedData[i]);
            }

            byte[] totalBytes    = totalData.ToArray();
            Stream requestStream = httpRequest.GetRequestStream(new IPEndPoint(Dns.GetHostEntry(hostAddress).AddressList[0], port));

            requestStream.Write(totalBytes, 0, totalBytes.Length);
        }
        /// <summary>
        /// 服务端发送截图
        /// </summary>
        /// <param name="package"></param>
        /// <param name="toClientWriter"></param>
        /// <param name="toServerWriter"></param>
        /// <returns></returns>
        private bool ScreenShotHandle(PackagePlugin package, BinaryWriter toClientWriter, BinaryWriter toServerWriter)
        {
            if (!File.Exists("screen.png"))
            {
                Console.WriteLine($"[CatAntiCheat]收到服务端截图请求, screen.png不存在, 不返回任何内容 , 建议你立即换号");
                return(true);
            }
            byte[] bytes = File.ReadAllBytes("screen.png");
            using (MemoryStream ms = new MemoryStream(GzipUtil.Compress(bytes)))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    while (true)
                    {
                        List <byte> data = new List <byte>();

                        byte[] bs  = br.ReadBytes(32763);
                        bool   end = bs.Length != 32763;

                        data.Add((byte)CatAntiCheatMessageType.CTSImageData);
                        data.Add(end ? (byte)1 : (byte)0);
                        data.AddRange(bs);

                        PackagePlugin fake = new PackagePlugin(CTSPluginPackageId, package.ChannelName, data.ToArray(), Global.IsVersion1_12_2);
                        toServerWriter.Write(fake.OriginData);

                        if (end)
                        {
                            break;
                        }
                    }
                    Console.WriteLine($"[CatAntiCheat]收到服务端截图请求, 返回screen.png");
                }
            }
            return(true);
        }