Esempio n. 1
0
        private static void Device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            Packet rawPacket;

            try
            {
                rawPacket = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            }
            catch
            {
                Console.WriteLine("parse packet fail " + e.Packet.LinkLayerType);
                rawPacket = new UdpPacket(1, 1);
                return;
            }
            //var ethernetPacket = (EthernetPacket)Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            if (rawPacket.PayloadPacket?.PayloadPacket is TcpPacket)
            {
                var ip  = (IPPacket)rawPacket.PayloadPacket;
                var tcp = (TcpPacket)rawPacket.PayloadPacket.PayloadPacket;
                if (ip.SourceAddress.ToString().StartsWith("204.2.229.") || ip.DestinationAddress.ToString().StartsWith("204.2.229."))
                //if (ip.SourceAddress.ToString().StartsWith("192") || ip.DestinationAddress.ToString().StartsWith("192"))
                {
                    if (tcp.PayloadData.Length < 4)
                    {
                        return;
                    }
                    if (captureFileWriter != null)
                    {
                        captureFileWriter.Write(rawPacket.Bytes);
                    }
                    var s2c     = !ip.SourceAddress.ToString().StartsWith("192");
                    var isLobby = s2c ? tcp.SourcePort == 54994 : tcp.DestinationPort == 54994;;
                    var channel = isLobby ? "Lobby" : "Game";
                    var p       = new PacketWrapper
                    {
                        S2C     = s2c,
                        Channel = channel,
                        Bytes   = tcp.PayloadData
                    };
                    PacketProcessor(p);
                }
            }
        }
Esempio n. 2
0
 public void test(PacketWrapper p)
 {
     BeginInvoke(new MethodInvoker(delegate
     {
         if (PacketsView.DataSource == null)
         {
             PacketsView.DataSource = Packets;
         }
         Parser.Stream = new MemoryStream(p.Bytes);
         var packets   = Parser.Test(p);
         foreach (var packet in packets)
         {
             var packetWrapper        = new PacketWrapper();
             packetWrapper.Channel    = p.Channel;
             packetWrapper.S2C        = p.S2C;
             packetWrapper.Bytes      = p.Bytes;
             packetWrapper.Packet     = packet;
             packetWrapper.PacketType = packet.GetType().Name;
             Packets.Add(packetWrapper);
         }
     }));
 }
Esempio n. 3
0
        public List <Packet> Test(PacketWrapper packetWrapper)
        {
            var packetBytes = ReadPacket();

            var packets = new List <Packet>();
            var offset  = 0;

            while (offset < packetBytes.Length - 3)
            //for (int i = 0; i < messageCount; i++)
            {
                var messageLength = BitConverter.ToInt32(packetBytes, offset);
                var source        = BitConverter.ToUInt32(packetBytes, offset + 4);
                var dest          = BitConverter.ToUInt32(packetBytes, offset + 8);
                var packetType    = (PacketId)BitConverter.ToUInt32(packetBytes, offset + 12);
                //var messageBytes = packetBytes.Skip(offset + 12).Take(messageLength - 12).ToArray();
                var messageBytes     = packetBytes.Skip(offset).Take(messageLength).ToArray();
                var origMessageBytes = messageBytes.ToList().ToArray();
                var origpacketType   = packetType;
                var packetEnum       = typeof(PacketId);

                /*try
                 * {
                 *  var packetName = typeof(PacketId).AssemblyQualifiedName.Replace(typeof(PacketId).Name, ((PacketId)packetType).ToString());
                 *  Packet packet = (Packet)Activator.CreateInstance(Type.GetType(packetName));
                 *  packet.Bytes = messageBytes;
                 *  packets.Add(packet);
                 * }
                 * catch
                 * {
                 *  packets.Add(new Packet { Bytes = packetBytes.Skip(offset).Take(messageLength).ToArray() });
                 * }*/
                if ((packetType == PacketId.Opcode || packetType == PacketId.LobbyS2CAuth))
                {
                    if (packetWrapper.Channel == "Lobby")
                    {
                        Key.Decipher(messageBytes, 4 + 12, messageBytes.Length - 8 - 16);
                    }
                    if (packetType == PacketId.Opcode)
                    {
                        packetEnum = typeof(WorldOpcode);
                    }
                    if (packetType != PacketId.LobbyS2CAuth)
                    {
                        messageBytes = messageBytes.Skip(4 + 12).ToArray();
                        packetType   = (PacketId)BitConverter.ToUInt32(messageBytes, 2);
                    }
                }
                var data = BitConverter.ToString(messageBytes);
                //Packet packet = new Packet();
                //Console.WriteLine("s " + GetType().Name + " : " + Type.GetType(packetName).Name);
                try
                {
                    var packetName = packetType.ToString();
                    if (packetEnum == typeof(WorldOpcode))
                    {
                        packetName = ((WorldOpcode)packetType).ToString();
                    }
                    else
                    {
                        Console.WriteLine("rawr");
                    }
                    packetName = packetEnum.AssemblyQualifiedName.Replace(packetEnum.Name, packetName);
                    Packet packet = (Packet)Activator.CreateInstance(Type.GetType(packetName));
                    packet.Bytes = messageBytes;
                    packets.Add(packet);
                }catch {
                    packets.Add(new Packet {
                        Bytes = packetBytes.Skip(offset).Take(messageLength).ToArray()
                    });
                }
                offset += messageLength;
            }
            return(packets);
        }