Esempio n. 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            m_Packets = null;
            PacketList.SelectionChanged += PacketList_SelectionChanged;
            m_Packets = new List <ArcheAgePacket>();
            OpenFileDialog dial   = new OpenFileDialog();
            PacketFamily   family = null;

            try
            {
                using (var fs = new FileStream(System.IO.Path.Combine("PacketFamily.xml"), FileMode.Open, FileAccess.Read))
                    using (XmlReader reader = XmlReader.Create(fs))
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(PacketFamily));
                        family = ser.Deserialize(reader) as PacketFamily;
                    }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
            }
            m_CurrentFamily = family;
            AA_LOGINPORT    = 3724;
            bool router = true;

            if (dial.ShowDialog() != null)
            {
                string name = dial.FileName;
                if (String.IsNullOrEmpty(name))
                {
                    return;
                }
                PcapFile file = new PcapFile(name);
                foreach (PcapPacket packet in file)
                {
                    if (packet.Data.Length < 62)
                    {
                        continue;
                    }
                    BinaryReader reader = new BinaryReader(new MemoryStream(packet.Data));
                    reader.ReadBytes(router ? 26 : 34);

                    string SourceIp = reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte();
                    string DestIp   = reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte();

                    ushort Source      = ReverseShort(reader.ReadUInt16());
                    ushort Destination = ReverseShort(reader.ReadUInt16());

                    reader.ReadBytes(16);
                    //Now - Going Data =)

                    if ((reader.BaseStream.Length - reader.BaseStream.Position) > 2)
                    {
                        short len = BitConverter.ToInt16(new byte[] { packet.Data[reader.BaseStream.Position], packet.Data[(reader.BaseStream.Position) + 1] }, 0);
                        //if there's will be data with such length - its ArcheAge =)
                        try
                        {
                            reader.ReadInt16(); //old length :D
                            if (reader.BaseStream.Length - reader.BaseStream.Position == len)
                            {
                                //Construct Packet
                                byte[] data   = reader.ReadBytes(len);
                                string type   = "";
                                string direct = "";

                                //Set General IP Addresses =)
                                if (CLIENT_IP == null)
                                {
                                    if (Source == AA_LOGINPORT)
                                    {
                                        CLIENT_IP = SourceIp;
                                    }
                                    else
                                    {
                                        CLIENT_IP = DestIp;
                                    }
                                }

                                if (MINE_IP == null)
                                {
                                    if (Destination == AA_LOGINPORT)
                                    {
                                        MINE_IP = SourceIp;
                                    }
                                    else
                                    {
                                        MINE_IP = DestIp;
                                    }
                                }

                                short thisport;

                                //Proxies Will not work Correctly.
                                if (Source == AA_LOGINPORT || Destination == AA_LOGINPORT)
                                {
                                    direct   = "[LP]";
                                    thisport = AA_LOGINPORT;
                                }
                                else if (Source == AA_GAMEPORT || Destination == AA_GAMEPORT)
                                {
                                    direct   = "[GP]";
                                    thisport = AA_GAMEPORT;
                                }
                                else if (Source == AA_CHATPORT || Destination == AA_CHATPORT)
                                {
                                    direct   = "[CP]";
                                    thisport = AA_CHATPORT;
                                }
                                else
                                {
                                    continue; //Undefined
                                }
                                if (SourceIp == CLIENT_IP && DestIp == MINE_IP)
                                {
                                    type = "[S]";
                                }
                                else if (SourceIp == MINE_IP && DestIp == CLIENT_IP)
                                {
                                    type = "[C]";
                                }
                                else
                                {
                                    continue;
                                }

                                m_Packets.Add(new ArcheAgePacket(data, type, direct, thisport));
                            }
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
                file.Dispose();
                file = null;
                dial = null;

                RefreshListBox(true);
            }
            DefinePacket.IsEnabled = true;
        }
 public PcapPacketEnumerator(PcapFile file)
 {
     this.file = file;
 }