Beispiel #1
0
        private void OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var tcp           = (TcpPacket)Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data).Extract(typeof(TcpPacket));
            var ipv4          = (IPv4Packet)tcp.ParentPacket;
            var sourceAddress = ipv4.SourceAddress.ToString();
            var data          = tcp.PayloadData;

            if (sourceAddress == _serverIp)
            {
                if (IsZlibStartPacket(data))
                {
                    _libFaolanCompression = new LibFaolanCompression();
                }

                if (_libFaolanCompression == null)
                {
                    throw new Exception("_libFaolanCompression == null");
                }

                var decompressedData = _libFaolanCompression.Inflate(data);
                if (decompressedData == null)
                {
                    throw new Exception("decompressedData == null");
                }
                if (decompressedData.Length == 0)
                {
                    return;
                }

                foreach (var cp in _serverWireProtocol.CreateMessages(decompressedData))
                {
                    _capturedPackets.Add(new PacketWrapper(_packetCounter++, ipv4, tcp.SourcePort, tcp.DestinationPort,
                                                           (ConanPacket)cp));
                }
            }
            else if (sourceAddress == _clientIp)
            {
                // Client sometimes sends the zlib start packet, but never actually uses compression (anymore)
                if (IsZlibStartPacket(data))
                {
                    Console.WriteLine("Client send zlib start packet");
                    return;
                }

                foreach (var cp in _clientWireProtocol.CreateMessages(data))
                {
                    _capturedPackets.Add(new PacketWrapper(_packetCounter++, ipv4, tcp.SourcePort, tcp.DestinationPort,
                                                           (ConanPacket)cp));
                }
            }
            else
            {
                throw new Exception("Weird stuff is happening");
            }
        }
Beispiel #2
0
        private void OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var tcp = (TcpPacket) Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data).Extract(typeof (TcpPacket));
            var ipv4 = (IPv4Packet) tcp.ParentPacket;
            var sourceAddress = ipv4.SourceAddress.ToString();
            var data = tcp.PayloadData;

            if (sourceAddress == _serverIp)
            {
                if (IsZlibStartPacket(data))
                    _libFaolanCompression = new LibFaolanCompression();

                if (_libFaolanCompression == null)
                    throw new Exception("_libFaolanCompression == null");

                var decompressedData = _libFaolanCompression.Inflate(data);
                if (decompressedData == null)
                    throw new Exception("decompressedData == null");
                if (decompressedData.Length == 0)
                    return;

                foreach (var cp in _serverWireProtocol.CreateMessages(decompressedData))
                    _capturedPackets.Add(new PacketWrapper(_packetCounter++, ipv4, tcp.SourcePort, tcp.DestinationPort,
                        (ConanPacket) cp));
            }
            else if (sourceAddress == _clientIp)
            {
                // Client sometimes sends the zlib start packet, but never actually uses compression (anymore)
                if (IsZlibStartPacket(data))
                {
                    Console.WriteLine("Client send zlib start packet");
                    return;
                }

                foreach (var cp in _clientWireProtocol.CreateMessages(data))
                    _capturedPackets.Add(new PacketWrapper(_packetCounter++, ipv4, tcp.SourcePort, tcp.DestinationPort,
                        (ConanPacket) cp));
            }
            else
                throw new Exception("Weird stuff is happening");
        }