private void ProcessLoop(TcpClient src, TcpClient dst, RC4 i, RC4 o, Queue <Tuple <byte, byte[]> > queue, HandlePacket cb) { try { var rdr = new NReader(src.GetStream()); NWriter writer = dst == null ? null : new NWriter(dst.GetStream()); while (true) { int len = rdr.ReadInt32(); byte id = rdr.ReadByte(); byte[] content = rdr.ReadBytes(len - 5); i.Crypt(content, 0, content.Length); bool send = true; if (id == PacketTable.HELLO) { HelloPacket helloPacket = HelloPacket.Read(new NBufferReader(content)); writer = OnHello(helloPacket); content = NWriter.Write(w => helloPacket.Write(w)); } send = cb(ref id, ref content); if (send) { o.Crypt(content, 0, content.Length); writer.Write(content.Length + 5); writer.Write(id); writer.Write(content); } if (queue.Count > 0) { lock (queue) { Tuple <byte, byte[]> packet; while (queue.Count > 0) { packet = queue.Dequeue(); o.Crypt(packet.Item2, 0, packet.Item2.Length); writer.Write(packet.Item2.Length + 5); writer.Write(packet.Item1); writer.Write(packet.Item2); } } } } } catch { } finally { OnDisconnected(src, dst); } Proxy.Stopped -= Kill; }
public SocketProxyWorker(SocketProxy proxy, string local, string dest, string serverName, TcpClient client) { this.client = client; this.local = local; destDns = dest; destPort = 2050; Proxy = proxy; ServerName = serverName; PacketTable = proxy.Tool.PacketTable; ReceiveKey1 = new RC4(new byte[] { 0x31, 0x1f, 0x80, 0x69, 0x14, 0x51, 0xc7, 0x1d, 0x09, 0xa1, 0x3a, 0x2a, 0x6e }); ReceiveKey2 = new RC4(new byte[] { 0x31, 0x1f, 0x80, 0x69, 0x14, 0x51, 0xc7, 0x1d, 0x09, 0xa1, 0x3a, 0x2a, 0x6e }); SendKey1 = new RC4(new byte[] { 0x72, 0xc5, 0x58, 0x3c, 0xaf, 0xb6, 0x81, 0x89, 0x95, 0xcd, 0xd7, 0x4b, 0x80 }); SendKey2 = new RC4(new byte[] { 0x72, 0xc5, 0x58, 0x3c, 0xaf, 0xb6, 0x81, 0x89, 0x95, 0xcd, 0xd7, 0x4b, 0x80 }); cliWkr = new Thread(() => ProcessLoop(client, null, ReceiveKey1, ReceiveKey2, sendServer, OnClientPacketReceived)); cliWkr.Start(); proxy.Stopped += Kill; }