Ejemplo n.º 1
0
        private void SetSendMsg(uint key)
        {
            byte[] bs = SendDataCache.GetData(key);
            if (bs != null)
            {
                Encoding encode = Encoding.Default;
                if (this.rbtnUnicode.Checked)
                {
                    encode = Encoding.Unicode;
                }
                else if (this.rbtnAscii.Checked)
                {
                    encode = Encoding.ASCII;
                }
                else if (this.rbtnDefault.Checked)
                {
                    encode = Encoding.Default;
                }
                else if (this.rbtnutf8.Checked)
                {
                    encode = Encoding.UTF8;
                }
                else if (this.rbtnHex.Checked)
                {
                    // Hex
                }

                if (this.chkGzip.Checked)
                {
                    try
                    {
                        using (MemoryStream ms = new MemoryStream(bs))
                        {
                            using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress))
                            {
                                using (StreamReader sr = new StreamReader(gs, encode))
                                {
                                    this.txtEncode.Text = sr.ReadToEnd().Replace('\0', '.');
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        this.txtEncode.Text = ex.Message;
                    }
                }
                else
                {
                    this.txtEncode.Text = encode.GetString(bs).Replace('\0', '.');
                }
            }
        }
Ejemplo n.º 2
0
        void WinCapInstance_NotifyPacket(string protocol, string sourceIP, string sourcePort, string targetIP, string targetPort, string msg, uint key, byte[] bytes)
        {
            Regex hostRegex = new Regex(@"Host:\s*([^\s\r\n]+)");

            lock (lockObj)
            {
                if (bytes == null)
                {
                    return;
                }

                string host    = "";
                string content = Encoding.UTF8.GetString(bytes);
                host = hostRegex.Match(content).Groups[1].Value;
                if (!string.IsNullOrEmpty(host))
                {
                }
                if (sourceIP == this.wlanIp)
                {
                    this.Invoke(new Action <ListView>(p =>
                    {
                        p.BeginUpdate();
                        if (bytes != null)
                        {
                            SendDataCache.AddData(key, bytes);
                        }
                        else
                        {
                            return;
                        }

                        bool ok = false;
                        for (int i = 0; i < p.Items.Count; i++)
                        {
                            ListViewItem viewItem = p.Items[i];
                            string currentKey     = viewItem.SubItems[6].Text;
                            if (currentKey == key.ToString())
                            {
                                // 叠加
                                string text    = viewItem.Tag as string;
                                text          += "\r\n=========================\r\n";
                                text          += msg;
                                p.Items[i].Tag = text;
                                p.Items[i].SubItems[6].Text = bytes.Length.ToString();
                                if (!string.IsNullOrEmpty(host))
                                {
                                    p.Items[i].SubItems[7].Text = host;
                                }

                                ok = true;
                                break;
                            }
                        }

                        if (!ok)
                        {
                            ListViewItem item = new ListViewItem(index.ToString());
                            item.Tag          = msg;
                            index++;
                            item.SubItems.AddRange(new string[] { protocol, sourceIP, sourcePort, targetIP, targetPort,
                                                                  key.ToString(), host, SendDataCache.GetData(key).Length.ToString() });

                            p.Items.Add(item);
                        }

                        p.EndUpdate();
                    }), this.listView1);
                }
                else
                {
                    this.Invoke(new Action <ListView>(p =>
                    {
                        p.BeginUpdate();
                        if (bytes != null)
                        {
                            ReceiveDataCache.AddData(key, bytes);
                        }
                        else
                        {
                            return;
                        }

                        bool ok = false;
                        for (int i = 0; i < p.Items.Count; i++)
                        {
                            ListViewItem viewItem = p.Items[i];
                            string currentKey     = viewItem.SubItems[6].Text;
                            if (currentKey == key.ToString())
                            {
                                // 叠加
                                string text    = viewItem.Tag as string;
                                text          += "\r\n=========================\r\n";
                                text          += msg;
                                p.Items[i].Tag = text;
                                p.Items[i].SubItems[6].Text = bytes.Length.ToString();
                                if (!string.IsNullOrEmpty(host))
                                {
                                    p.Items[i].SubItems[7].Text = host;
                                }

                                ok = true;
                                break;
                            }
                        }

                        if (!ok)
                        {
                            ListViewItem item = new ListViewItem(index.ToString());
                            item.Tag          = msg;
                            index++;
                            item.SubItems.AddRange(new string[] { protocol, sourceIP, sourcePort, targetIP, targetPort,
                                                                  key.ToString(), host, ReceiveDataCache.GetData(key).Length.ToString() });

                            p.Items.Add(item);
                        }

                        p.EndUpdate();
                    }), this.listView2);
                }
            }
        }