Example #1
0
 public void addNewPacket(ref sPacket v)
 {
     addPacketDelegate dl = new addPacketDelegate(doAddNewPacket);
     object[] argv = new object[] { v };
     try
     {
         Invoke(dl, argv);
     }
     catch (InvalidOperationException e){
     }
 }
Example #2
0
 public void showStream(sPacket p)
 {
     try
     {
         myStream = new tcpStream(ref p);
     }
     catch (InvalidOperationException e)
     {
         MessageBox.Show("Error:" + e.ToString());
         return;
     }
     System.Net.IPEndPoint currentEndPoint;
     label1.Text = String.Format("TCP stream  Host:{0} Client{1}",new object[]{myStream.host.ToString(), myStream.client.ToString()});
     
     for (var segment = myStream.getNextSegment(out currentEndPoint); segment != null; segment = myStream.getNextSegment(out currentEndPoint))
     {
         if (currentEndPoint.Equals(myStream.host))
             richTextBox1.SelectionBackColor = Color.Lavender;
         else
             richTextBox1.SelectionBackColor = Color.Moccasin;
         richTextBox1.AppendText(System.Text.Encoding.UTF8.GetString(segment));
     }
     Show();
 }
Example #3
0
        void packetArrive(object sender, SharpPcap.CaptureEventArgs packet)
        {
            PacketDotNet.Packet v = PacketDotNet.Packet.ParsePacket(packet.Packet.LinkLayerType, packet.Packet.Data);
            sPacket pp = new sPacket(ref v);
            packList.Add(pp);
            var typeStr = pp.finalType.Name;
            foreach (var i in pyDissectorList)
                if (i.Key.pass(ref v))
                {
                    HLPacket tmpPacket;
                    if (i.Value.parsePacket(v, out tmpPacket))
                    {
                        pp.finalType = typeof(HLPacket);
                        typeStr = tmpPacket.packetType;
                    }
                }

            if (_packetTypeCnt.ContainsKey(typeStr))
                _packetTypeCnt[typeStr] += 1;
            else
                _packetTypeCnt[typeStr] = 1;

            if (onlineFilter == null || onlineFilter.pass(ref v))
                onParseComplete(ref pp);
        }
Example #4
0
 public void doAddNewPacket(ref sPacket v)
 {
     packViewItem pvi = new packViewItem(ref v);
     packList.Items.Add(pvi);
 }
Example #5
0
 public packViewItem(ref sPacket v)
 {
     pack = v;
     SubItems.Clear();
     SubItems[0].Text=v.timestamp.ToLocalTime().ToLongTimeString();
     if (v.finalType == typeof(HLPacket))
         SubItems.Add((v.packet.Extract(typeof(HLPacket)) as HLPacket).packetType);
     else
         SubItems.Add(v.finalType.Name);
     string srcaddr, destaddr;
     if (v.packet.PayloadPacket != null && v.packet.PayloadPacket is IpPacket)
     {
         IpPacket tmpP = (IpPacket)v.packet.PayloadPacket;
         srcaddr = tmpP.SourceAddress.ToString();
         destaddr = tmpP.DestinationAddress.ToString();
     }
     else
     {
         var tmpP = (EthernetPacket)v.packet;
         srcaddr = tmpP.SourceHwAddress.ToString();
         destaddr = tmpP.DestinationHwAddress.ToString();
     }
     SubItems.AddRange(new string[] { srcaddr, destaddr });
     SubItems.Add(v.packet.Bytes.Length.ToString());
     SubItems.Add(v.packet.Extract(v.finalType).ToString());
 }
Example #6
0
        public tcpStream(ref sPacket targetPacket)
        {
            //Setup filter
            var tcp = targetPacket.packet.Extract(typeof(PacketDotNet.TcpPacket)) as PacketDotNet.TcpPacket;
            var ip = targetPacket.packet.Extract(typeof(PacketDotNet.IpPacket)) as IpPacket;
            if (tcp == null || ip == null)
                throw new InvalidOperationException("Packet is not a TCP packet");
            streamFilter = (new tcpPortFilter(true, tcp.SourcePort) & new tcpPortFilter(false, tcp.DestinationPort) &
                new ipIpFilter(true, ip.SourceAddress) & new ipIpFilter(false, ip.DestinationAddress)) |
                ((new tcpPortFilter(false, tcp.SourcePort) & new tcpPortFilter(true, tcp.DestinationPort) &
                new ipIpFilter(false, ip.SourceAddress) & new ipIpFilter(true, ip.DestinationAddress)));
            viewer = new filterViewer(streamFilter);
            
            //Search for target packet
            int pindex = 0;
            foreach (var i in packetListener.Instance.packList)
            {
                if (i.Equals(targetPacket))
                    break;
                pindex++;
            }
            viewer.reset(pindex);

            //Search for handshake
            Queue<Packet> handshakeWindow = new Queue<Packet>(3);
            var p = viewer.getCurrent();
            for (; p != null; p = viewer.getForward())
            {
                handshakeWindow.Enqueue(p.packet);
                if (handshakeWindow.Count > 3)
                    handshakeWindow.Dequeue();
                if (isHandshake(ref handshakeWindow,out client,out  host))
                {
                    break;
                }
            }

            if (p == null)
            {
                throw new InvalidOperationException("TCP session is not complete");
            }

            //Skip handshake
            viewer.getNext();viewer.getNext();viewer.getNext();
        }