private void MainForm_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { if (!File.Exists(file)) { continue; } switch (Path.GetExtension(file)) { case ".msb": { SessionForm session = NewSession(); session.OpenReadOnly(file); StructureForm.InitEngine(session.Locale, session.Build); session.Show(mDockPanel, DockState.Document); break; } case ".pcap": { LoadPcapFile(file); break; } } } }
private SessionForm NewSession() { var session = new SessionForm(); session.OnTerminated += s => sessions.Remove(s); sessions.Add(session); return(session); }
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(); } } }
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); }
private void mFileOpenMenu_Click(object pSender, EventArgs pArgs) { if (mOpenDialog.ShowDialog(this) != DialogResult.OK) { return; } foreach (string path in mOpenDialog.FileNames) { SessionForm session = NewSession(); session.OpenReadOnly(path); StructureForm.InitEngine(session.Locale, session.Build); session.Show(mDockPanel, DockState.Document); } }
private void MainForm_Load(object pSender, EventArgs pArgs) { mDockPanel.Theme = Config.Instance.Theme.DockSuiteTheme; toolStripExtender.DefaultRenderer = new ToolStripProfessionalRenderer(); toolStripExtender.SetStyle(mMenu, VisualStudioToolStripExtender.VsVersion.Vs2015, mDockPanel.Theme); toolStripExtender.SetStyle(toolStrip, VisualStudioToolStripExtender.VsVersion.Vs2015, mDockPanel.Theme); try { mDockPanel.LoadFromXml(LAYOUT_FILE, GetContentFromPersistString); } catch { // If we fail to load, it will just use the default layout. logger.Debug("Using default layout"); LogForm.Show(mDockPanel); SearchForm.Show(mDockPanel); DataForm.Show(mDockPanel); StructureForm.Show(mDockPanel); PropertyForm.Show(mDockPanel); // Docking can only be done after adding to panel. StructureForm.DockState = DockState.DockRight; PropertyForm.DockState = DockState.DockRight; } LogForm.ApplyTheme(); SearchForm.ApplyTheme(); DataForm.ApplyTheme(); StructureForm.ApplyTheme(); PropertyForm.ApplyTheme(); SetupAdapter(); mTimer.Enabled = true; foreach (string arg in startupArguments) { SessionForm session = NewSession(); session.OpenReadOnly(arg); StructureForm.InitEngine(session.Locale, session.Build); session.Show(mDockPanel, DockState.Document); } }