コード例 #1
0
        private void ProcessPacketQueue()
        {
            List <RawCapture> curQueue;

            lock (packetQueue) {
                curQueue    = packetQueue;
                packetQueue = new List <RawCapture>();
            }

            foreach (RawCapture packet in curQueue)
            {
                if (!sniffEnabled)
                {
                    continue;
                }

                var         tcpPacket = Packet.ParsePacket(packet.LinkLayerType, packet.Data).Extract <TcpPacket>();
                SessionForm session   = null;
                try {
                    SessionForm.Results?result;
                    if (tcpPacket.Synchronize && !tcpPacket.Acknowledgment && InPortRange(tcpPacket.DestinationPort))
                    {
                        session = NewSession();
                        result  = session.BufferTcpPacket(tcpPacket, packet.Timeval.Date);
                    }
                    else
                    {
                        session = sessions.FirstOrDefault(s => s.MatchTcpPacket(tcpPacket));
                        if (session == null)
                        {
                            continue;
                        }

                        result = session?.BufferTcpPacket(tcpPacket, packet.Timeval.Date);
                    }

                    switch (result)
                    {
                    case SessionForm.Results.Show:
                        StructureForm.InitEngine(session.Locale, session.Build);
                        session.Show(mDockPanel, DockState.Document);
                        break;

                    case SessionForm.Results.CloseMe:
                        session.Close();
                        break;
                    }
                } catch (Exception ex) {
                    logger.Fatal(ex, "Exception while processing packet queue");
                    session?.Close();
                }
            }
        }
コード例 #2
0
        private void LoadPcapFile(string fileName)
        {
            PcapDevice fileDevice = new CaptureFileReaderDevice(fileName);

            fileDevice.Open();

            SessionForm session = null;

            while (fileDevice.GetNextPacket(out PacketCapture capture) != 0)
            {
                RawCapture packet = capture.GetPacket();
                if (packet == null)
                {
                    continue;
                }

                var tcpPacket = Packet.ParsePacket(packet.LinkLayerType, packet.Data).Extract <TcpPacket>();
                if (tcpPacket == null)
                {
                    continue;
                }
                if (!InPortRange(tcpPacket.SourcePort) && !InPortRange(tcpPacket.DestinationPort))
                {
                    continue;
                }

                try {
                    if (tcpPacket.Synchronize && !tcpPacket.Acknowledgment)
                    {
                        session = NewSession();
                    }
                    else if (session == null || !session.MatchTcpPacket(tcpPacket))
                    {
                        continue;
                    }

                    SessionForm.Results result = session.BufferTcpPacket(tcpPacket, packet.Timeval.Date);
                    if (result == SessionForm.Results.CloseMe)
                    {
                        session.Close();
                        session = null;
                    }
                } catch (Exception ex) {
                    logger.Fatal(ex, $"Exception while parsing logfile: {fileName}");
                    session?.Close();
                    session = null;
                }
            }

            session?.Show(mDockPanel, DockState.Document);
        }