Exemplo n.º 1
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                byte[] data = Decompress(File.ReadAllBytes(openFileDialog1.FileName));

                List <XYBuffer> item = DeserializeObject <List <XYBuffer> >(data);

                foreach (var p in item)
                {
                    if (p.Data != null)
                    {
                        p.HexString = GetHexString(p.Data).ToString().Replace("\r\n", "").Replace('\r', ' ').Replace('\n', ' ');
                    }
                    if (p.DeData != null)
                    {
                        p.DeHexString = GetHexString(p.DeData).ToString().Replace("\r\n", "").Replace('\r', ' ').Replace('\n', ' ');
                    }


                    XYBuffer x = DeCode(p);
                    InsertList(x);
                }
            }
        }
Exemplo n.º 2
0
        public XYBuffer DeCode(XYBuffer data)
        {
            if (DeInterFace != null && data.Data.Length != 0 && data.DeData == null)
            {
                string        msg;
                List <byte[]> datalist = new List <byte[]>();

                int type = 2;
                if (data.DestIP != BindIp)
                {
                    type = 1;
                }

                if (DeInterFace.DataDe(data.Data, type, out datalist, out msg))
                {
                    List <byte> tmpdata = new List <byte>();

                    foreach (var b in datalist)
                    {
                        foreach (var c in b)
                        {
                            tmpdata.Add(c);
                        }
                    }

                    data.DeData = tmpdata.ToArray();

                    data.DeHexString = GetHexString(data.DeData).ToString().Replace("\r\n", "").Replace('\r', ' ').Replace('\n', ' ');
                }
                else
                {
                    data.DeData = null;
                    this.richTextBox5.BeginInvoke(new EventHandler((a, b) =>
                    {
                        this.richTextBox5.AppendText((Count - 1) + "--> Error:" + msg + "\r\n");
                    }));
                }
            }

            return(data);
        }
Exemplo n.º 3
0
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                List <XYBuffer> item = new List <XYBuffer>();

                foreach (ListViewItem p in listViewEx1.Items)
                {
                    XYBuffer c = p.Tag as XYBuffer;

                    if (c != null)
                    {
                        c.HexString   = null;
                        c.DeHexString = null;
                        item.Add(c);
                    }
                }

                File.WriteAllBytes(saveFileDialog1.FileName, Compress(SerializeObject(item)));
            }
        }
Exemplo n.º 4
0
        private void listViewEx1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewEx1.SelectedItems.Count > 0)
            {
                ListViewItem item = listViewEx1.SelectedItems[0];

                XYBuffer buff = item.Tag as XYBuffer;

                if (buff != null)
                {
                    this.richTextBox1.Text = ByteArrayToHexString(buff.Data);
                    this.richTextBox2.Text = GetHexString(buff.Data).ToString();

                    if (buff.DeData != null)
                    {
                        this.richTextBox3.Text = ByteArrayToHexString(buff.DeData);
                        this.richTextBox4.Text = GetHexString(buff.DeData);
                    }
                }
            }
        }
Exemplo n.º 5
0
        void IPBufferSwitch(byte[] data, int lengt)
        {
            IPHeader iphander = new IPHeader(data, lengt);

            switch (iphander.ProtocolType)
            {
            case Protocol.TCP:
            {
                TCPHeader tcphander = new TCPHeader(iphander.Data, iphander.Data.Length);

                if (iphander.Data.Length >= tcphander.HeaderLength)
                {
                    int    lengtz = iphander.Data.Length - tcphander.HeaderLength;
                    byte[] datax;
                    if (lengtz > 0)
                    {
                        datax = new byte[iphander.Data.Length - tcphander.HeaderLength];

                        Array.Copy(iphander.Data, tcphander.HeaderLength, datax, 0, datax.Length);
                    }
                    else
                    {
                        datax = new byte[0];
                    }

                    XYBuffer buff = new XYBuffer()
                    {
                        Data       = datax,
                        DestIP     = iphander.DestinationAddress.ToString(),
                        DestPort   = tcphander.DestinationPort,
                        SourceIP   = iphander.SourceAddress.ToString(),
                        SourcePort = tcphander.SourcePort,
                        Type       = Protocol.TCP
                    };
                    Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                if (XYBufferIn != null)
                                {
                                    XYBufferIn(buff);
                                }
                            }
                            catch
                            {
                            }
                        });
                }
            }
            break;

            case Protocol.UDP:
            {
                UDPHeader udphander = new UDPHeader(iphander.Data, iphander.Data.Length);
                if (iphander.Data.Length >= udphander.HanderLength)
                {
                    int    lengtz = iphander.Data.Length - udphander.HanderLength;
                    byte[] datax;
                    if (lengtz > 0)
                    {
                        datax = new byte[lengtz];
                        Array.Copy(iphander.Data, udphander.HanderLength, datax, 0, datax.Length);
                    }
                    else
                    {
                        datax = new byte[0];
                    }
                    XYBuffer buff = new XYBuffer()
                    {
                        Data       = datax,
                        DestIP     = iphander.DestinationAddress.ToString(),
                        DestPort   = udphander.DestinationPort,
                        SourceIP   = iphander.SourceAddress.ToString(),
                        SourcePort = udphander.SourcePort,
                        Type       = Protocol.UDP
                    };
                    Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                if (XYBufferIn != null)
                                {
                                    XYBufferIn(buff);
                                }
                            }
                            catch
                            {
                            }
                        });
                }
            }
            break;

            case Protocol.Unknown:

                break;
            }
        }
Exemplo n.º 6
0
 void InsertList(XYBuffer buff)
 {
     queue.Enqueue(buff);
 }
Exemplo n.º 7
0
        void sinffer_XYBufferIn(XYBuffer data)
        {
            if (!isStop)
            {
                AllCount = Interlocked.Increment(ref AllCount);

                switch (BuffType)
                {
                case Protocol.TCP:
                {
                    if (data.Type != Protocol.TCP)
                    {
                        return;
                    }
                }
                break;

                case Protocol.UDP:
                {
                    if (data.Type != Protocol.UDP)
                    {
                        return;
                    }
                }
                break;
                }

                if (!AllIP)
                {
                    //if (!data.SourceIP.Equals(Ipaddress, StringComparison.Ordinal) && !data.DestIP.Equals(Ipaddress, StringComparison.Ordinal))
                    //{
                    //    return;
                    //}

                    if (Ipaddress.Find(p => p.Equals(data.SourceIP, StringComparison.Ordinal) || p.Equals(data.DestIP, StringComparison.Ordinal)) == null)
                    {
                        return;
                    }
                }

                if (!AllPort)
                {
                    //if (data.DestPort != Port && data.SourcePort != Port)
                    //    return;

                    bool IsReturn = true;

                    foreach (int pt in Port)
                    {
                        if (data.DestPort == pt || data.SourcePort == pt)
                        {
                            IsReturn = false;
                            break;
                        }
                    }


                    if (IsReturn)
                    {
                        return;
                    }
                }


                data.Id = Count;
                Count   = Interlocked.Increment(ref Count);

                data.HexString = GetHexString(data.Data).ToString().Replace("\r\n", "").Replace('\r', ' ').Replace('\n', ' ');


                data = DeCode(data);


                InsertList(data);
            }
        }