Ejemplo n.º 1
0
 public PPacket(Packet packet, long packetNumber, TimeSpan relativeTime)
 {
     _packet = packet;
     _packetNumber = packetNumber;
     _relativeTime = relativeTime;
     EthernetDatagram ethernet = packet.Ethernet;
     if (ethernet != null)
     {
         _ethernetType = ethernet.EtherType;
         _ethernetTypeCode = GetEthernetTypeCode(ethernet.EtherType);
         //_ipv4 = packet.Ethernet.IpV4;
         //if (_ipv4 != null)
         if (ethernet.EtherType == PcapDotNet.Packets.Ethernet.EthernetType.IpV4)
         {
             _ipv4 = packet.Ethernet.IpV4;
             _source = _ipv4.Source;
             _destination = _ipv4.Destination;
             _ipProtocol = _ipv4.Protocol;
             _ipProtocolCode = GetIPProtocolCode(_ipv4.Protocol);
             //_tcp = _ipv4.Tcp;
             //if (_tcp != null)
             if (_ipv4.Protocol == IpV4Protocol.Tcp)
             {
                 _tcp = _ipv4.Tcp;
                 _sourcePort = _tcp.SourcePort;
                 _destinationPort = _tcp.DestinationPort;
             }
         }
     }
 }
 public static TreeViewItem TCPTreeViewItem(TcpDatagram tcpDatagram)
 {
     var item = new TreeViewItem
     {
         DataContext = tcpDatagram,
         HeaderTemplate = (Helpers.GetResourceItem()["TCPItem"] as DataTemplate)
     };
     item.Items.Add(new TreeViewItem { Header = string.Format("TCP Control Bits : {0}", tcpDatagram.ControlBits) });
     item.Items.Add(new TreeViewItem { Header = string.Format("Acknowledgement Number : {0}", tcpDatagram.AcknowledgmentNumber) });
     item.Items.Add(new TreeViewItem { Header = string.Format("Sequence Number : {0}", tcpDatagram.SequenceNumber) });
     item.Items.Add(new TreeViewItem { Header = string.Format("Header Length : {0} byte(s)", tcpDatagram.HeaderLength) });
     return item;
 }
Ejemplo n.º 3
0
		private static void ParseTcpPacket(TcpDatagram tcp, object ctrl)
		{
			if (tcp == null || ctrl == null) return;
			ListView f_details = (ListView)ctrl;

			List<ListViewItem> items = new List<ListViewItem>();

			ListViewItem item = new ListViewItem("Packet Type");
			item.SubItems.Add("TCP");
			items.Add(item);

			item = new ListViewItem("SrcPort");
			item.SubItems.Add(tcp.SourcePort.ToString());
			items.Add(item);

			item = new ListViewItem("DstPort");
			item.SubItems.Add(tcp.DestinationPort.ToString());
			items.Add(item);
			
			item = new ListViewItem("AcknowledgmentNumber");
			uint ack = tcp.AcknowledgmentNumber;
			string ack_str = string.Format("{0} (0x{1:X})", ack, ack);
			item.SubItems.Add(ack_str);
			items.Add(item);

			item = new ListViewItem("Checksum");
			string checksum = string.Format("0x{0:X}", tcp.Checksum);
			item.SubItems.Add(checksum);
			items.Add(item);

			item = new ListViewItem("ControlBits");
			item.SubItems.Add(tcp.ControlBits.ToString());
			items.Add(item);

			item = new ListViewItem("HeaderLength");
			item.SubItems.Add(tcp.HeaderLength.ToString());
			items.Add(item);

			item = new ListViewItem("NextSequenceNumber");
			uint next = tcp.NextSequenceNumber;
			string next_str = string.Format("{0} (0x{1:X})", next, next);
			item.SubItems.Add(next_str);
			items.Add(item);

			item = new ListViewItem("Options");
			string opt = tcp.Options.ToString();
			int start = opt.IndexOf("{");
			int end = opt.LastIndexOf("}");
			opt = opt.Substring(start + 1, end - start - 1);
			item.SubItems.Add(opt);
			items.Add(item);

			item = new ListViewItem("Payload Length");
			item.SubItems.Add(string.Format("{0} ({1:x})", tcp.Payload.Length, tcp.Payload.Length));
			items.Add(item);

			item = new ListViewItem("RealHeaderLength");
			item.SubItems.Add(tcp.RealHeaderLength.ToString());
			items.Add(item);

			item = new ListViewItem("SequenceNumber");
			uint sn = tcp.NextSequenceNumber;
			string sn_str = string.Format("{0} (0x{1:X})", sn, sn);
			item.SubItems.Add(sn_str);
			items.Add(item);

			item = new ListViewItem("UrgentPointer");
			item.SubItems.Add(tcp.UrgentPointer.ToString());
			items.Add(item);

			item = new ListViewItem("Window");
			item.SubItems.Add(tcp.Window.ToString());
			items.Add(item);

			object[] param = new object[2];
			param[0] = f_details;
			param[1] = items;
			f_details.BeginInvoke(new ParserHelper.UIHandler(ParserHelper.UpdateDetailsUI), param);
		}
Ejemplo n.º 4
0
		bool IsAuction(TcpDatagram tcp, bool inc)
			=> Ports.I.AuctionPorts.Contains(inc ? tcp.SourcePort : tcp.DestinationPort);
Ejemplo n.º 5
0
		bool IsChat(TcpDatagram tcp, bool inc)
			=> Ports.I.ChatPorts.Contains(inc ? tcp.SourcePort : tcp.DestinationPort);
Ejemplo n.º 6
0
		bool IsWorld(TcpDatagram tcp, bool inc) {
			for (int i = 0; i < Ports.I.WorldPortsStart.Count; i++) {
				if (inc) {
					if (tcp.SourcePort >= Ports.I.WorldPortsStart[i] && tcp.SourcePort <= Ports.I.WorldPortsEnd[i])
						return true;
				}
				else {
					if (tcp.DestinationPort >= Ports.I.WorldPortsStart[i] && tcp.DestinationPort <= Ports.I.WorldPortsEnd[i])
						return true;
				}
			}

			return false;
		}
Ejemplo n.º 7
0
		void AddPacket(TcpDatagram tcp, bool inc, PacketInfo.Daemon daemon, ushort port) {
			foreach (var p in packets) {
				if (p.Tcp.SequenceNumber == tcp.SequenceNumber) {
#if DEBUG
					Console.WriteLine("Dropping duplicate packet...");
#endif
					return;
				}
			}

			packets.Enqueue(new PacketClass(tcp, inc, daemon, port));

			if (packets.Count > 10) {
				var p = packets.Dequeue();
				var data = p.Tcp.Payload.ToMemoryStream();
				ProcessPacket(data.ToArray(), p.IsIncoming, p.Daemon, p.Port);
			}
		}
Ejemplo n.º 8
0
			public PacketClass(TcpDatagram tcp, bool inc, PacketInfo.Daemon daemon, ushort port) {
				Tcp = tcp;
				IsIncoming = inc;
				Daemon = daemon;
				Port = port;
			}