static void captureDevice_OnPacketArrival(object sender, CaptureEventArgs e) { lock (PacketProcessMutex) { TcpPacket tcpPacket = TcpPacket.GetEncapsulated(Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data) as EthernetPacket); if (tcpPacket.Psh) { PacketDirection direction = (tcpPacket.SourcePort == 8995 || (tcpPacket.SourcePort > 20050 && tcpPacket.SourcePort < 20100)) ? PacketDirection.Server2Client : PacketDirection.Client2Server; byte[] data = new byte[tcpPacket.Bytes.Length - tcpPacket.Header.Length]; Array.Copy(tcpPacket.Bytes, tcpPacket.Header.Length, data, 0, data.Length); // calculate session id int sessionid = tcpPacket.DestinationPort * tcpPacket.SourcePort; CaptureSession session = CaptureSessionList.Instance.Find(s => s.ID == sessionid); if (session == null) { bool login = false; if ((direction == PacketDirection.Server2Client && tcpPacket.SourcePort == 8995) || (direction == PacketDirection.Client2Server && tcpPacket.DestinationPort == 8995)) { login = true; } session = new CaptureSession(sessionid, (login ? (byte)0 : (byte)4)); CaptureSessionList.Instance.Add(session); } session.PacketReceived(data, direction); } } }
public TORCapturedPacket(int id, TORPacketType type, byte[] data, CaptureSession session, PacketDirection direction) { _id = id; _type = type; _data = data; _session = session; _direction = direction; }
public static XmlDocument CreateSessionDocument(CaptureSession session) { XmlDocument doc = new XmlDocument(); XmlElement root_element = doc.CreateElement("CaptureSession"); root_element.Attributes.Append(CreateAttribute(doc, "SaveTime", DateTime.Now.ToString())); foreach (TORCapturedPacket pkt in session.CapturedPackets) { root_element.AppendChild(CreatePacketElement(doc, pkt)); } doc.AppendChild(root_element); return doc; }
public static XmlDocument CreateSessionDocument(CaptureSession session) { XmlDocument doc = new XmlDocument(); XmlElement root_element = doc.CreateElement("CaptureSession"); root_element.Attributes.Append(CreateAttribute(doc, "SaveTime", DateTime.Now.ToString())); foreach (TORCapturedPacket pkt in session.CapturedPackets) { root_element.AppendChild(CreatePacketElement(doc, pkt)); } doc.AppendChild(root_element); return(doc); }
static void captureDevice_OnPacketArrival(object sender, CaptureEventArgs e) { lock (PacketProcessMutex) { TcpPacket tcpPacket = TcpPacket.GetEncapsulated(Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data) as EthernetPacket); if (tcpPacket.Psh) { PacketDirection direction = (tcpPacket.SourcePort == 8995 || (tcpPacket.SourcePort > 20050 && tcpPacket.SourcePort < 20100)) ? PacketDirection.Server2Client : PacketDirection.Client2Server; byte[] data = new byte[tcpPacket.Bytes.Length - tcpPacket.Header.Length]; Array.Copy(tcpPacket.Bytes, tcpPacket.Header.Length, data, 0, data.Length); // calculate session id int sessionid = tcpPacket.DestinationPort * tcpPacket.SourcePort; CaptureSession session = CaptureSessionList.Instance.Find(s => s.ID == sessionid); if (session == null) { bool login = false; if((direction == PacketDirection.Server2Client && tcpPacket.SourcePort == 8995) || (direction == PacketDirection.Client2Server && tcpPacket.DestinationPort == 8995)) login = true; session = new CaptureSession(sessionid, (login ? (byte)0 : (byte)4)); CaptureSessionList.Instance.Add(session); } session.PacketReceived(data, direction); } } }