@@ -18,7 +18,7 @@ public partial class MainForm : Form
1818    { 
1919        private  CancellationTokenSource  _cts ; 
2020        private  HashSet < string >  _files ; 
21-         private  HashSet < PcapAnalyzer . NetworkConnection >   _connections ; 
21+         private  CommonUi . NetworkContext   _networkContext ; 
2222        private  PcapProcessor . Processor  _processor ; 
2323        private  PcapProcessor . Sniffer  _sniffer ; 
2424        private  PcapAnalyzer . Analyzer  _analyzer ; 
@@ -38,7 +38,7 @@ public MainForm()
3838
3939            _files  =  new  HashSet < string > ( ) ; 
4040            _cts  =  new  CancellationTokenSource ( ) ; 
41-             _connections  =  new  HashSet < PcapAnalyzer . NetworkConnection > ( ) ; 
41+             _networkContext  =  new  CommonUi . NetworkContext ( ) ; 
4242
4343            // Create the DAL and BLL objects. 
4444            _processor  =  new  PcapProcessor . Processor ( ) ; 
@@ -51,13 +51,13 @@ public MainForm()
5151            _sniffer . UdpPacketArived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorUdpPacketToAnalyzerUdpPacket ( e . Packet ) ) ; 
5252            _sniffer . TcpPacketArived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorTcpPacketToAnalyzerTcpPacket ( e . Packet ) ) ; 
5353            _sniffer . TcpSessionArrived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorTcpSessionToAnalyzerTcpSession ( e . TcpSession ) ) ; 
54-             _sniffer . TcpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( Casting . CastProcessorTcpSessionToBruteSharkDesktopTcpSession ( e . TcpSession ) ) ) ; 
55-             _sniffer . UdpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( Casting . CastProcessorUdpSessionToBruteSharkDesktopUdpSession ( e . UdpSession ) ) ) ; 
54+             _sniffer . TcpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( e . TcpSession ) ) ; 
55+             _sniffer . UdpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( e . UdpSession ) ) ; 
5656            _processor . UdpPacketArived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorUdpPacketToAnalyzerUdpPacket ( e . Packet ) ) ; 
5757            _processor . TcpPacketArived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorTcpPacketToAnalyzerTcpPacket ( e . Packet ) ) ; 
5858            _processor . TcpSessionArrived  +=  ( s ,  e )  =>  _analyzer . Analyze ( CommonUi . Casting . CastProcessorTcpSessionToAnalyzerTcpSession ( e . TcpSession ) ) ; 
59-             _processor . TcpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( Casting . CastProcessorTcpSessionToBruteSharkDesktopTcpSession ( e . TcpSession ) ) ) ; 
60-             _processor . UdpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( Casting . CastProcessorUdpSessionToBruteSharkDesktopUdpSession ( e . UdpSession ) ) ) ; 
59+             _processor . TcpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( e . TcpSession ) ) ; 
60+             _processor . UdpSessionArrived  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnSessionArived ( e . UdpSession ) ) ; 
6161            _processor . FileProcessingStatusChanged  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnFileProcessingStatusChanged ( s ,  e ) ) ; 
6262            _processor . ProcessingPrecentsChanged  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnProcessingPrecentsChanged ( s ,  e ) ) ; 
6363            _processor . ProcessingFinished  +=  ( s ,  e )  =>  SwitchToMainThreadContext ( ( )  =>  OnProcessingFinished ( s ,  e ) ) ; 
@@ -73,9 +73,9 @@ public MainForm()
7373
7474        private  void  InitilizeModulesUserControls ( ) 
7575        { 
76-             _networkMapUserControl  =  new  NetworkMapUserControl ( ) ; 
76+             _networkMapUserControl  =  new  NetworkMapUserControl ( _networkContext ) ; 
7777            _networkMapUserControl . Dock  =  DockStyle . Fill ; 
78-             _sessionsExplorerUserControl  =  new  SessionsExplorerUserControl ( ) ; 
78+             _sessionsExplorerUserControl  =  new  SessionsExplorerUserControl ( _networkContext ) ; 
7979            _sessionsExplorerUserControl . Dock  =  DockStyle . Fill ; 
8080            _hashesUserControl  =  new  HashesUserControl ( ) ; 
8181            _hashesUserControl . Dock  =  DockStyle . Fill ; 
@@ -134,7 +134,13 @@ private void HandleFailedFiles()
134134            } 
135135        } 
136136
137-         private  void  OnSessionArived ( TransportLayerSession  session ) 
137+         private  void  OnSessionArived ( PcapProcessor . TcpSession  session ) 
138+         { 
139+             _sessionsExplorerUserControl . AddSession ( session ) ; 
140+             this . modulesTreeView . Nodes [ "NetworkNode" ] . Nodes [ "SessionsNode" ] . Text  =  $ "Sessions ({ _sessionsExplorerUserControl . SessionsCount } )"; 
141+         } 
142+ 
143+         private  void  OnSessionArived ( PcapProcessor . UdpSession  session ) 
138144        { 
139145            _sessionsExplorerUserControl . AddSession ( session ) ; 
140146            this . modulesTreeView . Nodes [ "NetworkNode" ] . Nodes [ "SessionsNode" ] . Text  =  $ "Sessions ({ _sessionsExplorerUserControl . SessionsCount } )"; 
@@ -219,7 +225,7 @@ private void OnParsedItemDetected(object sender, PcapAnalyzer.ParsedItemDetected
219225            else  if  ( e . ParsedItem  is  PcapAnalyzer . NetworkConnection ) 
220226            { 
221227                var  connection  =  e . ParsedItem  as  PcapAnalyzer . NetworkConnection ; 
222-                 _connections . Add ( connection ) ; 
228+                 _networkContext . HandleNetworkConection ( connection ) ; 
223229                _networkMapUserControl . AddEdge ( connection . Source ,  connection . Destination ) ; 
224230                this . modulesTreeView . Nodes [ "NetworkNode" ] . Nodes [ "NetworkMapNode" ] . Text  =  $ "Network Map ({ _networkMapUserControl . NodesCount } )"; 
225231            } 
@@ -386,7 +392,7 @@ private void BuildUdpSessionsCheckBox_CheckedChanged(object sender, EventArgs e)
386392
387393        private  void  MessageOnBuildSessionsConfigurationChanged ( ) 
388394        { 
389-             ShowInfoMessageBox ( @"NOTE, Disabling sessions reconstruction means that BruteShark will not analyze full sessions, 
395+             Utilities . ShowInfoMessageBox ( @"NOTE, Disabling sessions reconstruction means that BruteShark will not analyze full sessions, 
390396This means a faster processing but also that some obects may not be extracted." ) ; 
391397        } 
392398
@@ -427,27 +433,14 @@ private async void StartLiveCaptureAsync()
427433            // We wait here until the sniffing will be stoped (by the stop button). 
428434            this . progressBar . CustomText  =  string . Empty ; 
429435            this . progressBar . Refresh ( ) ; 
430-             ShowInfoMessageBox ( "Capture Stoped" ) ; 
436+             Utilities . ShowInfoMessageBox ( "Capture Stoped" ) ; 
431437        } 
432438
433439        private  void  StopCaptureButton_Click ( object  sender ,  EventArgs  e ) 
434440        { 
435441            _cts . Cancel ( ) ; 
436442        } 
437443
438-         private  void  ShowInfoMessageBox ( string  text ) 
439-         { 
440-             // NOTE: Info message box is also set up at front of the form, it solves the  
441-             // problem of message box that is hidden under the form. 
442-             MessageBox . Show ( 
443-                 text :  text ,  
444-                 caption :  "Info" ,  
445-                 buttons :  MessageBoxButtons . OK ,  
446-                 icon :  MessageBoxIcon . Information , 
447-                 defaultButton :  MessageBoxDefaultButton . Button1 ,  
448-                 options :  MessageBoxOptions . DefaultDesktopOnly ) ; 
449-         } 
450- 
451444        private  void  promiscuousCheckBox_CheckStateChanged ( object  sender ,  EventArgs  e ) 
452445        { 
453446            if  ( promiscuousCheckBox . CheckState  ==  CheckState . Checked ) 
@@ -485,8 +478,9 @@ private void exportResutlsButton_Click(object sender, EventArgs e)
485478                    this . progressBar . CustomText  =  $ "Exporting results to output folder: { outputDirectoryPath } ..."; 
486479                    this . progressBar . Refresh ( ) ; 
487480                    CommonUi . Exporting . ExportFiles ( outputDirectoryPath ,  _filesUserControl . Files ) ; 
488-                     CommonUi . Exporting . ExportNetworkMap ( outputDirectoryPath ,  _connections ) ; 
481+                     CommonUi . Exporting . ExportNetworkMap ( outputDirectoryPath ,  _networkContext . Connections ) ; 
489482                    CommonUi . Exporting . ExportVoipCalls ( outputDirectoryPath ,  _voipCallsUserControl . VoipCalls ) ; 
483+                     CommonUi . Exporting . ExportNetworkNodesData ( outputDirectoryPath ,  _networkContext . GetAllNodes ( ) ) ; 
490484                    this . progressBar . CustomText  =  string . Empty ; 
491485
492486                    MessageBox . Show ( $ "Successfully exported results") ; 
@@ -501,14 +495,14 @@ private void exportResutlsButton_Click(object sender, EventArgs e)
501495
502496        private  void  clearResutlsButton_Click ( object  sender ,  EventArgs  e ) 
503497        { 
504-             _connections  =  new  HashSet < PcapAnalyzer . NetworkConnection > ( ) ; 
498+             _networkContext  =  new  CommonUi . NetworkContext ( ) ; 
505499            _analyzer . Clear ( ) ; 
506500
507501            // Clear all modules user controls by recreating them.  
508502            InitilizeModulesUserControls ( ) ; 
509503
510504            // Remove the items count of each module from the tree view (e.g "DNS (13)" -> "DNS"). 
511-             foreach  ( var  node  in  IterateAllNodes ( modulesTreeView . Nodes ) ) 
505+             foreach  ( var  node  in  Utilities . IterateAllNodes ( modulesTreeView . Nodes ) ) 
512506            { 
513507                var  index  =  node . Text . LastIndexOf ( '(' ) ; 
514508
@@ -517,18 +511,9 @@ private void clearResutlsButton_Click(object sender, EventArgs e)
517511                    node . Text  =  node . Text . Substring ( 0 ,  index ) ; 
518512                } 
519513            } 
520-         } 
521- 
522-         IEnumerable < TreeNode >  IterateAllNodes ( TreeNodeCollection  nodes ) 
523-         { 
524-             // Recursively iterate over all nodes and sub nodes. 
525-             foreach  ( TreeNode  node  in  nodes ) 
526-             { 
527-                 yield  return  node ; 
528514
529-                 foreach  ( var  child  in  IterateAllNodes ( node . Nodes ) ) 
530-                     yield  return  child ; 
531-             } 
515+             // Select the head of the modules tree view to force refreshing of the current user control. 
516+             modulesTreeView . SelectedNode  =  modulesTreeView . Nodes [ 0 ] ; 
532517        } 
533518
534519    } 
0 commit comments