From 5fe25649fe73e8a961d6f91faf9f10f2bf9f9802 Mon Sep 17 00:00:00 2001 From: sven-n Date: Sun, 6 Oct 2024 15:23:54 +0200 Subject: [PATCH] Adaptions/improvements for the network analyzer --- src/Network/Analyzer/MainForm.Designer.cs | 709 +++++++++++----------- src/Network/Analyzer/MainForm.cs | 65 +- src/Network/Analyzer/MainForm.resx | 65 +- src/Network/Analyzer/Packet.cs | 128 +++- src/Network/Analyzer/PacketAnalyzer.cs | 180 +++++- src/Network/Analyzer/Program.cs | 6 + src/Network/Packets/EnumValue.cs | 2 +- 7 files changed, 747 insertions(+), 408 deletions(-) diff --git a/src/Network/Analyzer/MainForm.Designer.cs b/src/Network/Analyzer/MainForm.Designer.cs index b32f85490..5a74233ba 100644 --- a/src/Network/Analyzer/MainForm.Designer.cs +++ b/src/Network/Analyzer/MainForm.Designer.cs @@ -28,478 +28,454 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + components = new System.ComponentModel.Container(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); - this.packetGridView = new Zuby.ADGV.AdvancedDataGridView(); - this.packetBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.rawDataTextBox = new System.Windows.Forms.TextBox(); - this.packetInfoGroup = new System.Windows.Forms.GroupBox(); - this.extractedInfoTextBox = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.settingsGroup = new System.Windows.Forms.GroupBox(); - this.targetPortNumericUpDown = new System.Windows.Forms.NumericUpDown(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.targetHostTextBox = new System.Windows.Forms.TextBox(); - this.listenerPortNumericUpDown = new System.Windows.Forms.NumericUpDown(); - this.btnStartProxy = new System.Windows.Forms.Button(); - this.clientVersionComboBox = new System.Windows.Forms.ComboBox(); - this.connectedClientsGroup = new System.Windows.Forms.GroupBox(); - this.connectedClientsListBox = new System.Windows.Forms.ListBox(); - this.connectionContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.disconnectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openPacketSenderStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.clientBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.trafficGroup = new System.Windows.Forms.GroupBox(); - this.leftPanel = new System.Windows.Forms.Panel(); - this.Timestamp = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.PacketSize = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Type = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Code = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Direction = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.PacketData = new System.Windows.Forms.DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)(this.packetGridView)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.packetBindingSource)).BeginInit(); - this.packetInfoGroup.SuspendLayout(); - this.settingsGroup.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.targetPortNumericUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.listenerPortNumericUpDown)).BeginInit(); - this.connectedClientsGroup.SuspendLayout(); - this.connectionContextMenu.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.clientBindingSource)).BeginInit(); - this.trafficGroup.SuspendLayout(); - this.leftPanel.SuspendLayout(); - this.SuspendLayout(); + packetGridView = new Zuby.ADGV.AdvancedDataGridView(); + packetBindingSource = new System.Windows.Forms.BindingSource(components); + rawDataTextBox = new System.Windows.Forms.TextBox(); + packetInfoGroup = new System.Windows.Forms.GroupBox(); + extractedInfoTextBox = new System.Windows.Forms.TextBox(); + label3 = new System.Windows.Forms.Label(); + label1 = new System.Windows.Forms.Label(); + settingsGroup = new System.Windows.Forms.GroupBox(); + targetPortNumericUpDown = new System.Windows.Forms.NumericUpDown(); + label6 = new System.Windows.Forms.Label(); + label7 = new System.Windows.Forms.Label(); + label4 = new System.Windows.Forms.Label(); + label8 = new System.Windows.Forms.Label(); + targetHostTextBox = new System.Windows.Forms.TextBox(); + listenerPortNumericUpDown = new System.Windows.Forms.NumericUpDown(); + btnStartProxy = new System.Windows.Forms.Button(); + clientVersionComboBox = new System.Windows.Forms.ComboBox(); + connectedClientsGroup = new System.Windows.Forms.GroupBox(); + connectedClientsListBox = new System.Windows.Forms.ListBox(); + connectionContextMenu = new System.Windows.Forms.ContextMenuStrip(components); + disconnectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + openPacketSenderStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + clientBindingSource = new System.Windows.Forms.BindingSource(components); + trafficGroup = new System.Windows.Forms.GroupBox(); + leftPanel = new System.Windows.Forms.Panel(); + Timestamp = new System.Windows.Forms.DataGridViewTextBoxColumn(); + PacketSize = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Type = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Code = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Direction = new System.Windows.Forms.DataGridViewTextBoxColumn(); + Message = new System.Windows.Forms.DataGridViewTextBoxColumn(); + PacketData = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)packetGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)packetBindingSource).BeginInit(); + packetInfoGroup.SuspendLayout(); + settingsGroup.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)targetPortNumericUpDown).BeginInit(); + ((System.ComponentModel.ISupportInitialize)listenerPortNumericUpDown).BeginInit(); + connectedClientsGroup.SuspendLayout(); + connectionContextMenu.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)clientBindingSource).BeginInit(); + trafficGroup.SuspendLayout(); + leftPanel.SuspendLayout(); + SuspendLayout(); // // packetGridView // - this.packetGridView.AllowUserToAddRows = false; - this.packetGridView.AllowUserToOrderColumns = true; - this.packetGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.packetGridView.AutoGenerateColumns = false; - this.packetGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.packetGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Timestamp, - this.PacketSize, - this.Type, - this.Code, - this.Direction, - this.PacketData}); - this.packetGridView.DataSource = this.packetBindingSource; - this.packetGridView.FilterAndSortEnabled = true; - this.packetGridView.Location = new System.Drawing.Point(4, 18); - this.packetGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.packetGridView.MultiSelect = false; - this.packetGridView.Name = "packetGridView"; - this.packetGridView.ReadOnly = true; - this.packetGridView.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.packetGridView.RowHeadersWidth = 20; - this.packetGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.packetGridView.Size = new System.Drawing.Size(595, 689); - this.packetGridView.TabIndex = 27; - this.packetGridView.SelectionChanged += new System.EventHandler(this.OnPacketSelected); + packetGridView.AllowUserToAddRows = false; + packetGridView.AllowUserToOrderColumns = true; + packetGridView.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + packetGridView.AutoGenerateColumns = false; + packetGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + packetGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { Timestamp, PacketSize, Type, Code, Direction, Message, PacketData }); + packetGridView.DataSource = packetBindingSource; + packetGridView.FilterAndSortEnabled = true; + packetGridView.FilterStringChangedInvokeBeforeDatasourceUpdate = true; + packetGridView.Location = new System.Drawing.Point(4, 18); + packetGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + packetGridView.MaxFilterButtonImageHeight = 23; + packetGridView.MultiSelect = false; + packetGridView.Name = "packetGridView"; + packetGridView.ReadOnly = true; + packetGridView.RightToLeft = System.Windows.Forms.RightToLeft.No; + packetGridView.RowHeadersWidth = 20; + packetGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + packetGridView.Size = new System.Drawing.Size(595, 689); + packetGridView.SortStringChangedInvokeBeforeDatasourceUpdate = true; + packetGridView.TabIndex = 27; + packetGridView.SelectionChanged += OnPacketSelected; // // packetBindingSource // - this.packetBindingSource.AllowNew = false; + packetBindingSource.AllowNew = false; // // rawDataTextBox // - this.rawDataTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.rawDataTextBox.Location = new System.Drawing.Point(7, 320); - this.rawDataTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.rawDataTextBox.Multiline = true; - this.rawDataTextBox.Name = "rawDataTextBox"; - this.rawDataTextBox.ReadOnly = true; - this.rawDataTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.rawDataTextBox.Size = new System.Drawing.Size(412, 363); - this.rawDataTextBox.TabIndex = 29; + rawDataTextBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; + rawDataTextBox.Location = new System.Drawing.Point(7, 320); + rawDataTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + rawDataTextBox.Multiline = true; + rawDataTextBox.Name = "rawDataTextBox"; + rawDataTextBox.ReadOnly = true; + rawDataTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + rawDataTextBox.Size = new System.Drawing.Size(412, 363); + rawDataTextBox.TabIndex = 29; // // packetInfoGroup // - this.packetInfoGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Right))); - this.packetInfoGroup.Controls.Add(this.extractedInfoTextBox); - this.packetInfoGroup.Controls.Add(this.label3); - this.packetInfoGroup.Controls.Add(this.label1); - this.packetInfoGroup.Controls.Add(this.rawDataTextBox); - this.packetInfoGroup.Location = new System.Drawing.Point(605, 18); - this.packetInfoGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.packetInfoGroup.Name = "packetInfoGroup"; - this.packetInfoGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.packetInfoGroup.Size = new System.Drawing.Size(427, 689); - this.packetInfoGroup.TabIndex = 30; - this.packetInfoGroup.TabStop = false; - this.packetInfoGroup.Text = "Packet Info"; + packetInfoGroup.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; + packetInfoGroup.Controls.Add(extractedInfoTextBox); + packetInfoGroup.Controls.Add(label3); + packetInfoGroup.Controls.Add(label1); + packetInfoGroup.Controls.Add(rawDataTextBox); + packetInfoGroup.Location = new System.Drawing.Point(605, 18); + packetInfoGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + packetInfoGroup.Name = "packetInfoGroup"; + packetInfoGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + packetInfoGroup.Size = new System.Drawing.Size(427, 689); + packetInfoGroup.TabIndex = 30; + packetInfoGroup.TabStop = false; + packetInfoGroup.Text = "Packet Info"; // // extractedInfoTextBox // - this.extractedInfoTextBox.Location = new System.Drawing.Point(7, 37); - this.extractedInfoTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.extractedInfoTextBox.Multiline = true; - this.extractedInfoTextBox.Name = "extractedInfoTextBox"; - this.extractedInfoTextBox.ReadOnly = true; - this.extractedInfoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.extractedInfoTextBox.Size = new System.Drawing.Size(412, 230); - this.extractedInfoTextBox.TabIndex = 33; + extractedInfoTextBox.Location = new System.Drawing.Point(7, 37); + extractedInfoTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + extractedInfoTextBox.Multiline = true; + extractedInfoTextBox.Name = "extractedInfoTextBox"; + extractedInfoTextBox.ReadOnly = true; + extractedInfoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + extractedInfoTextBox.Size = new System.Drawing.Size(412, 230); + extractedInfoTextBox.TabIndex = 33; // // label3 // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(7, 18); - this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(125, 15); - this.label3.TabIndex = 32; - this.label3.Text = "Extracted Information:"; + label3.AutoSize = true; + label3.Location = new System.Drawing.Point(7, 18); + label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label3.Name = "label3"; + label3.Size = new System.Drawing.Size(125, 15); + label3.TabIndex = 32; + label3.Text = "Extracted Information:"; // // label1 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(4, 301); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(59, 15); - this.label1.TabIndex = 30; - this.label1.Text = "Raw Data:"; + label1.AutoSize = true; + label1.Location = new System.Drawing.Point(4, 301); + label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(59, 15); + label1.TabIndex = 30; + label1.Text = "Raw Data:"; // // settingsGroup // - this.settingsGroup.Controls.Add(this.targetPortNumericUpDown); - this.settingsGroup.Controls.Add(this.label6); - this.settingsGroup.Controls.Add(this.label7); - this.settingsGroup.Controls.Add(this.label4); - this.settingsGroup.Controls.Add(this.label8); - this.settingsGroup.Controls.Add(this.targetHostTextBox); - this.settingsGroup.Controls.Add(this.listenerPortNumericUpDown); - this.settingsGroup.Controls.Add(this.btnStartProxy); - this.settingsGroup.Controls.Add(this.clientVersionComboBox); - this.settingsGroup.Dock = System.Windows.Forms.DockStyle.Top; - this.settingsGroup.Location = new System.Drawing.Point(0, 0); - this.settingsGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.settingsGroup.Name = "settingsGroup"; - this.settingsGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.settingsGroup.Size = new System.Drawing.Size(233, 185); - this.settingsGroup.TabIndex = 32; - this.settingsGroup.TabStop = false; - this.settingsGroup.Text = "Settings"; + settingsGroup.Controls.Add(targetPortNumericUpDown); + settingsGroup.Controls.Add(label6); + settingsGroup.Controls.Add(label7); + settingsGroup.Controls.Add(label4); + settingsGroup.Controls.Add(label8); + settingsGroup.Controls.Add(targetHostTextBox); + settingsGroup.Controls.Add(listenerPortNumericUpDown); + settingsGroup.Controls.Add(btnStartProxy); + settingsGroup.Controls.Add(clientVersionComboBox); + settingsGroup.Dock = System.Windows.Forms.DockStyle.Top; + settingsGroup.Location = new System.Drawing.Point(0, 0); + settingsGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + settingsGroup.Name = "settingsGroup"; + settingsGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + settingsGroup.Size = new System.Drawing.Size(233, 185); + settingsGroup.TabIndex = 32; + settingsGroup.TabStop = false; + settingsGroup.Text = "Settings"; // // targetPortNumericUpDown // - this.targetPortNumericUpDown.Location = new System.Drawing.Point(85, 52); - this.targetPortNumericUpDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.targetPortNumericUpDown.Maximum = new decimal(new int[] { - 65536, - 0, - 0, - 0}); - this.targetPortNumericUpDown.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.targetPortNumericUpDown.Name = "targetPortNumericUpDown"; - this.targetPortNumericUpDown.Size = new System.Drawing.Size(92, 23); - this.targetPortNumericUpDown.TabIndex = 3; - this.targetPortNumericUpDown.Value = new decimal(new int[] { - 55901, - 0, - 0, - 0}); + targetPortNumericUpDown.Location = new System.Drawing.Point(85, 52); + targetPortNumericUpDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + targetPortNumericUpDown.Maximum = new decimal(new int[] { 65536, 0, 0, 0 }); + targetPortNumericUpDown.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + targetPortNumericUpDown.Name = "targetPortNumericUpDown"; + targetPortNumericUpDown.Size = new System.Drawing.Size(92, 23); + targetPortNumericUpDown.TabIndex = 3; + targetPortNumericUpDown.Value = new decimal(new int[] { 55901, 0, 0, 0 }); // // label6 // - this.label6.AutoSize = true; - this.label6.ForeColor = System.Drawing.SystemColors.ControlText; - this.label6.Location = new System.Drawing.Point(7, 25); - this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(55, 15); - this.label6.TabIndex = 0; - this.label6.Text = "Target IP:"; + label6.AutoSize = true; + label6.ForeColor = System.Drawing.SystemColors.ControlText; + label6.Location = new System.Drawing.Point(7, 25); + label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label6.Name = "label6"; + label6.Size = new System.Drawing.Size(55, 15); + label6.TabIndex = 0; + label6.Text = "Target IP:"; // // label7 // - this.label7.AutoSize = true; - this.label7.ForeColor = System.Drawing.SystemColors.ControlText; - this.label7.Location = new System.Drawing.Point(7, 54); - this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(67, 15); - this.label7.TabIndex = 2; - this.label7.Text = "Target Port:"; + label7.AutoSize = true; + label7.ForeColor = System.Drawing.SystemColors.ControlText; + label7.Location = new System.Drawing.Point(7, 54); + label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label7.Name = "label7"; + label7.Size = new System.Drawing.Size(67, 15); + label7.TabIndex = 2; + label7.Text = "Target Port:"; // // label4 // - this.label4.AutoSize = true; - this.label4.ForeColor = System.Drawing.SystemColors.ControlText; - this.label4.Location = new System.Drawing.Point(7, 84); - this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(63, 15); - this.label4.TabIndex = 2; - this.label4.Text = "Local Port:"; + label4.AutoSize = true; + label4.ForeColor = System.Drawing.SystemColors.ControlText; + label4.Location = new System.Drawing.Point(7, 84); + label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label4.Name = "label4"; + label4.Size = new System.Drawing.Size(63, 15); + label4.TabIndex = 2; + label4.Text = "Local Port:"; // // label8 // - this.label8.AutoSize = true; - this.label8.ForeColor = System.Drawing.SystemColors.ControlText; - this.label8.Location = new System.Drawing.Point(7, 114); - this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(70, 15); - this.label8.TabIndex = 2; - this.label8.Text = "MU Version:"; + label8.AutoSize = true; + label8.ForeColor = System.Drawing.SystemColors.ControlText; + label8.Location = new System.Drawing.Point(7, 114); + label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + label8.Name = "label8"; + label8.Size = new System.Drawing.Size(70, 15); + label8.TabIndex = 2; + label8.Text = "MU Version:"; // // targetHostTextBox // - this.targetHostTextBox.Location = new System.Drawing.Point(85, 22); - this.targetHostTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.targetHostTextBox.MaxLength = 15; - this.targetHostTextBox.Name = "targetHostTextBox"; - this.targetHostTextBox.Size = new System.Drawing.Size(110, 23); - this.targetHostTextBox.TabIndex = 1; - this.targetHostTextBox.Text = "127.127.127.127"; + targetHostTextBox.Location = new System.Drawing.Point(85, 22); + targetHostTextBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + targetHostTextBox.MaxLength = 15; + targetHostTextBox.Name = "targetHostTextBox"; + targetHostTextBox.Size = new System.Drawing.Size(140, 23); + targetHostTextBox.TabIndex = 1; + targetHostTextBox.Text = "127.127.127.127"; // // listenerPortNumericUpDown // - this.listenerPortNumericUpDown.Location = new System.Drawing.Point(85, 82); - this.listenerPortNumericUpDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.listenerPortNumericUpDown.Maximum = new decimal(new int[] { - 65536, - 0, - 0, - 0}); - this.listenerPortNumericUpDown.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 0}); - this.listenerPortNumericUpDown.Name = "listenerPortNumericUpDown"; - this.listenerPortNumericUpDown.Size = new System.Drawing.Size(92, 23); - this.listenerPortNumericUpDown.TabIndex = 3; - this.listenerPortNumericUpDown.Value = new decimal(new int[] { - 55900, - 0, - 0, - 0}); + listenerPortNumericUpDown.Location = new System.Drawing.Point(85, 82); + listenerPortNumericUpDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + listenerPortNumericUpDown.Maximum = new decimal(new int[] { 65536, 0, 0, 0 }); + listenerPortNumericUpDown.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + listenerPortNumericUpDown.Name = "listenerPortNumericUpDown"; + listenerPortNumericUpDown.Size = new System.Drawing.Size(92, 23); + listenerPortNumericUpDown.TabIndex = 3; + listenerPortNumericUpDown.Value = new decimal(new int[] { 55900, 0, 0, 0 }); // // btnStartProxy // - this.btnStartProxy.ForeColor = System.Drawing.SystemColors.ControlText; - this.btnStartProxy.Location = new System.Drawing.Point(85, 142); - this.btnStartProxy.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.btnStartProxy.Name = "btnStartProxy"; - this.btnStartProxy.Size = new System.Drawing.Size(92, 27); - this.btnStartProxy.TabIndex = 5; - this.btnStartProxy.Text = "Start Proxy"; - this.btnStartProxy.UseVisualStyleBackColor = true; - this.btnStartProxy.Click += new System.EventHandler(this.StartProxy); + btnStartProxy.ForeColor = System.Drawing.SystemColors.ControlText; + btnStartProxy.Location = new System.Drawing.Point(85, 142); + btnStartProxy.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnStartProxy.Name = "btnStartProxy"; + btnStartProxy.Size = new System.Drawing.Size(92, 27); + btnStartProxy.TabIndex = 5; + btnStartProxy.Text = "Start Proxy"; + btnStartProxy.UseVisualStyleBackColor = true; + btnStartProxy.Click += StartProxy; // // clientVersionComboBox // - this.clientVersionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.clientVersionComboBox.Location = new System.Drawing.Point(85, 112); - this.clientVersionComboBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.clientVersionComboBox.Name = "clientVersionComboBox"; - this.clientVersionComboBox.Size = new System.Drawing.Size(116, 23); - this.clientVersionComboBox.TabIndex = 4; + clientVersionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + clientVersionComboBox.Location = new System.Drawing.Point(85, 112); + clientVersionComboBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + clientVersionComboBox.Name = "clientVersionComboBox"; + clientVersionComboBox.Size = new System.Drawing.Size(140, 23); + clientVersionComboBox.TabIndex = 4; // // connectedClientsGroup // - this.connectedClientsGroup.Controls.Add(this.connectedClientsListBox); - this.connectedClientsGroup.Dock = System.Windows.Forms.DockStyle.Fill; - this.connectedClientsGroup.Location = new System.Drawing.Point(0, 185); - this.connectedClientsGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.connectedClientsGroup.Name = "connectedClientsGroup"; - this.connectedClientsGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.connectedClientsGroup.Size = new System.Drawing.Size(233, 529); - this.connectedClientsGroup.TabIndex = 33; - this.connectedClientsGroup.TabStop = false; - this.connectedClientsGroup.Text = "Connected Clients"; + connectedClientsGroup.Controls.Add(connectedClientsListBox); + connectedClientsGroup.Dock = System.Windows.Forms.DockStyle.Fill; + connectedClientsGroup.Location = new System.Drawing.Point(0, 185); + connectedClientsGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + connectedClientsGroup.Name = "connectedClientsGroup"; + connectedClientsGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + connectedClientsGroup.Size = new System.Drawing.Size(233, 529); + connectedClientsGroup.TabIndex = 33; + connectedClientsGroup.TabStop = false; + connectedClientsGroup.Text = "Connected Clients"; // // connectedClientsListBox // - this.connectedClientsListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.connectedClientsListBox.ContextMenuStrip = this.connectionContextMenu; - this.connectedClientsListBox.DataSource = this.clientBindingSource; - this.connectedClientsListBox.FormattingEnabled = true; - this.connectedClientsListBox.ItemHeight = 15; - this.connectedClientsListBox.Location = new System.Drawing.Point(4, 18); - this.connectedClientsListBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.connectedClientsListBox.Name = "connectedClientsListBox"; - this.connectedClientsListBox.Size = new System.Drawing.Size(229, 499); - this.connectedClientsListBox.TabIndex = 0; - this.connectedClientsListBox.SelectedIndexChanged += new System.EventHandler(this.OnConnectionSelected); + connectedClientsListBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; + connectedClientsListBox.ContextMenuStrip = connectionContextMenu; + connectedClientsListBox.DataSource = clientBindingSource; + connectedClientsListBox.FormattingEnabled = true; + connectedClientsListBox.ItemHeight = 15; + connectedClientsListBox.Location = new System.Drawing.Point(4, 18); + connectedClientsListBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + connectedClientsListBox.Name = "connectedClientsListBox"; + connectedClientsListBox.Size = new System.Drawing.Size(229, 499); + connectedClientsListBox.TabIndex = 0; + connectedClientsListBox.SelectedIndexChanged += OnConnectionSelected; // // connectionContextMenu // - this.connectionContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.disconnectToolStripMenuItem, - this.loadToolStripMenuItem, - this.saveToolStripMenuItem, - this.openPacketSenderStripMenuItem}); - this.connectionContextMenu.Name = "connectionContextMenu"; - this.connectionContextMenu.Size = new System.Drawing.Size(149, 92); - this.connectionContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.OnBeforeContextMenuOpens); + connectionContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { disconnectToolStripMenuItem, loadToolStripMenuItem, saveToolStripMenuItem, openPacketSenderStripMenuItem }); + connectionContextMenu.Name = "connectionContextMenu"; + connectionContextMenu.Size = new System.Drawing.Size(149, 92); + connectionContextMenu.Opening += OnBeforeContextMenuOpens; // // disconnectToolStripMenuItem // - this.disconnectToolStripMenuItem.Name = "disconnectToolStripMenuItem"; - this.disconnectToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.disconnectToolStripMenuItem.Text = "Disconnect"; - this.disconnectToolStripMenuItem.Click += new System.EventHandler(this.OnDisconnectClientClick); + disconnectToolStripMenuItem.Name = "disconnectToolStripMenuItem"; + disconnectToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + disconnectToolStripMenuItem.Text = "Disconnect"; + disconnectToolStripMenuItem.Click += OnDisconnectClientClick; // // loadToolStripMenuItem // - this.loadToolStripMenuItem.Name = "loadToolStripMenuItem"; - this.loadToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.loadToolStripMenuItem.Text = "Load from file"; - this.loadToolStripMenuItem.Click += new System.EventHandler(this.OnLoadFromFileClick); + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + loadToolStripMenuItem.Text = "Load from file"; + loadToolStripMenuItem.Click += OnLoadFromFileClick; // // saveToolStripMenuItem // - this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.saveToolStripMenuItem.Text = "Save to file"; - this.saveToolStripMenuItem.Click += new System.EventHandler(this.OnSaveToFileClick); + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + saveToolStripMenuItem.Text = "Save to file"; + saveToolStripMenuItem.Click += OnSaveToFileClick; // // openPacketSenderStripMenuItem // - this.openPacketSenderStripMenuItem.Name = "openPacketSenderStripMenuItem"; - this.openPacketSenderStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.openPacketSenderStripMenuItem.Text = "Packet Sender"; - this.openPacketSenderStripMenuItem.Click += new System.EventHandler(this.OnSendPacketClick); + openPacketSenderStripMenuItem.Name = "openPacketSenderStripMenuItem"; + openPacketSenderStripMenuItem.Size = new System.Drawing.Size(148, 22); + openPacketSenderStripMenuItem.Text = "Packet Sender"; + openPacketSenderStripMenuItem.Click += OnSendPacketClick; // // trafficGroup // - this.trafficGroup.Controls.Add(this.packetInfoGroup); - this.trafficGroup.Controls.Add(this.packetGridView); - this.trafficGroup.Dock = System.Windows.Forms.DockStyle.Fill; - this.trafficGroup.Enabled = false; - this.trafficGroup.Location = new System.Drawing.Point(233, 0); - this.trafficGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.trafficGroup.Name = "trafficGroup"; - this.trafficGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.trafficGroup.Size = new System.Drawing.Size(1039, 714); - this.trafficGroup.TabIndex = 34; - this.trafficGroup.TabStop = false; - this.trafficGroup.Text = "Traffic"; + trafficGroup.Controls.Add(packetInfoGroup); + trafficGroup.Controls.Add(packetGridView); + trafficGroup.Dock = System.Windows.Forms.DockStyle.Fill; + trafficGroup.Enabled = false; + trafficGroup.Location = new System.Drawing.Point(233, 0); + trafficGroup.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + trafficGroup.Name = "trafficGroup"; + trafficGroup.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); + trafficGroup.Size = new System.Drawing.Size(1039, 714); + trafficGroup.TabIndex = 34; + trafficGroup.TabStop = false; + trafficGroup.Text = "Traffic"; // // leftPanel // - this.leftPanel.Controls.Add(this.connectedClientsGroup); - this.leftPanel.Controls.Add(this.settingsGroup); - this.leftPanel.Dock = System.Windows.Forms.DockStyle.Left; - this.leftPanel.Location = new System.Drawing.Point(0, 0); - this.leftPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.leftPanel.Name = "leftPanel"; - this.leftPanel.Size = new System.Drawing.Size(233, 714); - this.leftPanel.TabIndex = 35; + leftPanel.Controls.Add(connectedClientsGroup); + leftPanel.Controls.Add(settingsGroup); + leftPanel.Dock = System.Windows.Forms.DockStyle.Left; + leftPanel.Location = new System.Drawing.Point(0, 0); + leftPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + leftPanel.Name = "leftPanel"; + leftPanel.Size = new System.Drawing.Size(233, 714); + leftPanel.TabIndex = 35; // // Timestamp // - this.Timestamp.DataPropertyName = "Timestamp"; + Timestamp.DataPropertyName = "Timestamp"; dataGridViewCellStyle1.Format = "g"; - this.Timestamp.DefaultCellStyle = dataGridViewCellStyle1; - this.Timestamp.HeaderText = "Timestamp"; - this.Timestamp.MinimumWidth = 22; - this.Timestamp.Name = "Timestamp"; - this.Timestamp.ReadOnly = true; - this.Timestamp.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + Timestamp.DefaultCellStyle = dataGridViewCellStyle1; + Timestamp.HeaderText = "Timestamp"; + Timestamp.MinimumWidth = 24; + Timestamp.Name = "Timestamp"; + Timestamp.ReadOnly = true; + Timestamp.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; // // PacketSize // - this.PacketSize.DataPropertyName = "Size"; - this.PacketSize.HeaderText = "Size"; - this.PacketSize.MinimumWidth = 22; - this.PacketSize.Name = "PacketSize"; - this.PacketSize.ReadOnly = true; - this.PacketSize.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; - this.PacketSize.Width = 55; + PacketSize.DataPropertyName = "Size"; + PacketSize.HeaderText = "Size"; + PacketSize.MinimumWidth = 24; + PacketSize.Name = "PacketSize"; + PacketSize.ReadOnly = true; + PacketSize.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + PacketSize.Width = 55; // // Type // - this.Type.DataPropertyName = "Type"; + Type.DataPropertyName = "Type"; dataGridViewCellStyle2.Format = "X2"; - this.Type.DefaultCellStyle = dataGridViewCellStyle2; - this.Type.HeaderText = "Type"; - this.Type.MinimumWidth = 22; - this.Type.Name = "Type"; - this.Type.ReadOnly = true; - this.Type.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; - this.Type.Width = 55; + Type.DefaultCellStyle = dataGridViewCellStyle2; + Type.HeaderText = "Type"; + Type.MinimumWidth = 24; + Type.Name = "Type"; + Type.ReadOnly = true; + Type.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + Type.Width = 55; // // Code // - this.Code.DataPropertyName = "Code"; + Code.DataPropertyName = "DisplayCode"; dataGridViewCellStyle3.Format = "X2"; - this.Code.DefaultCellStyle = dataGridViewCellStyle3; - this.Code.HeaderText = "Code"; - this.Code.MinimumWidth = 22; - this.Code.Name = "Code"; - this.Code.ReadOnly = true; - this.Code.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; - this.Code.Width = 55; + dataGridViewCellStyle3.NullValue = null; + Code.DefaultCellStyle = dataGridViewCellStyle3; + Code.HeaderText = "Code"; + Code.MinimumWidth = 24; + Code.Name = "Code"; + Code.ReadOnly = true; + Code.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + Code.Width = 55; // // Direction // - this.Direction.DataPropertyName = "Direction"; - this.Direction.HeaderText = "Direction"; - this.Direction.MinimumWidth = 22; - this.Direction.Name = "Direction"; - this.Direction.ReadOnly = true; - this.Direction.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; - this.Direction.Width = 75; + Direction.DataPropertyName = "Direction"; + Direction.HeaderText = "Direction"; + Direction.MinimumWidth = 24; + Direction.Name = "Direction"; + Direction.ReadOnly = true; + Direction.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + Direction.Width = 75; + // + // Message + // + Message.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + Message.DataPropertyName = "Message"; + Message.HeaderText = "Message"; + Message.MinimumWidth = 24; + Message.Name = "Message"; + Message.ReadOnly = true; + Message.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; // // PacketData // - this.PacketData.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.PacketData.DataPropertyName = "PacketData"; - this.PacketData.HeaderText = "Data"; - this.PacketData.MinimumWidth = 22; - this.PacketData.Name = "PacketData"; - this.PacketData.ReadOnly = true; - this.PacketData.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + PacketData.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + PacketData.DataPropertyName = "PacketData"; + PacketData.HeaderText = "Data"; + PacketData.MinimumWidth = 24; + PacketData.Name = "PacketData"; + PacketData.ReadOnly = true; + PacketData.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; + PacketData.Visible = false; // // MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1272, 714); - this.Controls.Add(this.trafficGroup); - this.Controls.Add(this.leftPanel); - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.Name = "MainForm"; - this.Text = "MUnique OpenMU Network Analyzer"; - ((System.ComponentModel.ISupportInitialize)(this.packetGridView)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.packetBindingSource)).EndInit(); - this.packetInfoGroup.ResumeLayout(false); - this.packetInfoGroup.PerformLayout(); - this.settingsGroup.ResumeLayout(false); - this.settingsGroup.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.targetPortNumericUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.listenerPortNumericUpDown)).EndInit(); - this.connectedClientsGroup.ResumeLayout(false); - this.connectionContextMenu.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.clientBindingSource)).EndInit(); - this.trafficGroup.ResumeLayout(false); - this.leftPanel.ResumeLayout(false); - this.ResumeLayout(false); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(1272, 714); + Controls.Add(trafficGroup); + Controls.Add(leftPanel); + Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon"); + Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + Name = "MainForm"; + Text = "MUnique OpenMU Network Analyzer"; + ((System.ComponentModel.ISupportInitialize)packetGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)packetBindingSource).EndInit(); + packetInfoGroup.ResumeLayout(false); + packetInfoGroup.PerformLayout(); + settingsGroup.ResumeLayout(false); + settingsGroup.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)targetPortNumericUpDown).EndInit(); + ((System.ComponentModel.ISupportInitialize)listenerPortNumericUpDown).EndInit(); + connectedClientsGroup.ResumeLayout(false); + connectionContextMenu.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)clientBindingSource).EndInit(); + trafficGroup.ResumeLayout(false); + leftPanel.ResumeLayout(false); + ResumeLayout(false); } #endregion @@ -536,6 +512,7 @@ private void InitializeComponent() private System.Windows.Forms.DataGridViewTextBoxColumn Type; private System.Windows.Forms.DataGridViewTextBoxColumn Code; private System.Windows.Forms.DataGridViewTextBoxColumn Direction; + private System.Windows.Forms.DataGridViewTextBoxColumn Message; private System.Windows.Forms.DataGridViewTextBoxColumn PacketData; } } diff --git a/src/Network/Analyzer/MainForm.cs b/src/Network/Analyzer/MainForm.cs index 7673b0f0b..b4d4bb5f4 100644 --- a/src/Network/Analyzer/MainForm.cs +++ b/src/Network/Analyzer/MainForm.cs @@ -25,7 +25,7 @@ public partial class MainForm : Form private readonly Dictionary _clientVersions = new () { - { new ClientVersion(106, 3, ClientLanguage.English), "Extended Open Source (2.04d)" }, + { new ClientVersion(106, 3, ClientLanguage.English), "Extended S6E3 (2.04d)" }, { new ClientVersion(6, 3, ClientLanguage.English), "S6E3 (1.04d)" }, { new ClientVersion(1, 0, ClientLanguage.Invariant), "Season 1 - 6" }, { new ClientVersion(0, 97, ClientLanguage.Invariant), "0.97" }, @@ -59,15 +59,7 @@ public MainForm() this._analyzer = new PacketAnalyzer(); this.Disposed += (_, _) => this._analyzer.Dispose(); - this.clientVersionComboBox.SelectedIndexChanged += (_, _) => - { - if (this._clientListener is { } listener) - { - listener.ClientVersion = this.SelectedClientVersion; - } - - this._analyzer.ClientVersion = this.SelectedClientVersion; - }; + this.clientVersionComboBox.SelectedIndexChanged += OnSelectedClientVersionChanged; this.clientVersionComboBox.DataSource = new BindingSource(this._clientVersions, null); this.clientVersionComboBox.DisplayMember = "Value"; this.clientVersionComboBox.ValueMember = "Key"; @@ -206,6 +198,10 @@ private void SetPacketDataSource() if (this._unfilteredList is { } oldList) { oldList.ListChanged -= this.OnUnfilteredListChanged; + foreach (var packet in oldList) + { + packet.AnalyzingRequested -= this.OnPacketAnalyzingRequested; + } } this._unfilteredList = this.SelectedConnection?.PacketList; @@ -215,6 +211,17 @@ private void SetPacketDataSource() return; } + foreach (var packet in this._unfilteredList) + { + packet.AnalyzingRequested += this.OnPacketAnalyzingRequested; + if (packet.AnalyzedByVersion != this.SelectedClientVersion) + { + packet.ClearMessage(); + } + } + + this._unfilteredList.ListChanged += this.OnUnfilteredListChanged; + if (this._filterExpression is null) { this.packetBindingSource.DataSource = this.SelectedConnection?.PacketList; @@ -222,14 +229,18 @@ private void SetPacketDataSource() else { this.packetBindingSource.DataSource = this._unfilteredList.AsQueryable().Where(this._filterExpression).ToList(); - this._unfilteredList.ListChanged += this.OnUnfilteredListChanged; } } + private void OnPacketAnalyzingRequested(object? sender, Packet.AnalyzingRequestedEventArgs e) + { + e.ClientVersion = this._analyzer.ClientVersion; + (e.Message, e.Definition) = this._analyzer.ExtractShortInformation(e.Packet); + } + private void OnUnfilteredListChanged(object? sender, ListChangedEventArgs e) { if (e.ListChangedType != ListChangedType.ItemAdded - || this._filterMethod is not { } filter || this._unfilteredList is not { } sourceList || this._unfilteredList?.Count < e.NewIndex || e.NewIndex < 0) @@ -238,13 +249,31 @@ private void OnUnfilteredListChanged(object? sender, ListChangedEventArgs e) } var newPacket = sourceList[e.NewIndex]; - - if (filter.DynamicInvoke(newPacket) is true) + newPacket.AnalyzingRequested += this.OnPacketAnalyzingRequested; + + if (this._filterMethod is { } filter + && filter.DynamicInvoke(newPacket) is true) { this.packetBindingSource.Add(newPacket); } } + private void OnSelectedClientVersionChanged(object? o, EventArgs eventArgs) + { + if (this._clientListener is { } listener) + { + listener.ClientVersion = this.SelectedClientVersion; + } + + this._analyzer.ClientVersion = this.SelectedClientVersion; + if (this._unfilteredList is { } unfilteredList) + { + foreach (var packet in unfilteredList) + { + packet.ClearMessage(); + } + } + } private void OnPacketFilterStringChanged(object? sender, AdvancedDataGridView.FilterEventArgs e) { try @@ -265,6 +294,10 @@ private void StartProxy(object sender, System.EventArgs e) this._clientListener.Stop(); this._clientListener = null; this.btnStartProxy.Text = "Start Proxy"; + this.listenerPortNumericUpDown.Enabled = true; + this.targetPortNumericUpDown.Enabled = true; + this.targetHostTextBox.Enabled = true; + this.clientVersionComboBox.Enabled = true; return; } @@ -283,6 +316,10 @@ private void StartProxy(object sender, System.EventArgs e) this._clientListener.ClientConnected += this.ClientListenerOnClientConnected; this._clientListener.Start(); this.btnStartProxy.Text = "Stop Proxy"; + this.listenerPortNumericUpDown.Enabled = false; + this.targetPortNumericUpDown.Enabled = false; + this.targetHostTextBox.Enabled = false; + this.clientVersionComboBox.Enabled = false; } private void ClientListenerOnClientConnected(object? sender, ClientConnectedEventArgs e) diff --git a/src/Network/Analyzer/MainForm.resx b/src/Network/Analyzer/MainForm.resx index 82be5c0dd..4e0a41d42 100644 --- a/src/Network/Analyzer/MainForm.resx +++ b/src/Network/Analyzer/MainForm.resx @@ -1,4 +1,64 @@ - + + + @@ -72,6 +132,9 @@ True + + True + True diff --git a/src/Network/Analyzer/Packet.cs b/src/Network/Analyzer/Packet.cs index 8cd4dff21..528c4b75f 100644 --- a/src/Network/Analyzer/Packet.cs +++ b/src/Network/Analyzer/Packet.cs @@ -4,17 +4,26 @@ namespace MUnique.OpenMU.Network.Analyzer; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using MUnique.OpenMU.Network.Packets; +using MUnique.OpenMU.Network.PlugIns; + /// /// A captured data packet. /// -public class Packet +public sealed class Packet : INotifyPropertyChanged { private readonly byte[] _innerData; private string? _dataAsString; + private ushort? _displayCode; + private string? _message; + private ClientVersion _analyzedByVersion; + private PacketDefinition? _definition; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The timestamp. /// The data. @@ -27,6 +36,14 @@ public Packet(TimeSpan timestamp, byte[] data, bool toServer) this.Direction = this.ToServer ? "C->S" : "S->C"; } + /// + /// Occurs when analyzing the packet requested, e.g. when the description is needed. + /// + public event EventHandler? AnalyzingRequested; + + /// + public event PropertyChangedEventHandler? PropertyChanged; + /// /// Gets the timestamp. /// @@ -52,11 +69,61 @@ public Packet(TimeSpan timestamp, byte[] data, bool toServer) /// public byte? SubCode => this._innerData.AsSpan().GetPacketSubType(); + /// + /// Gets the display code of the packet, which specifies the kind of the message. + /// + public ushort DisplayCode + { + get + { + if (this._displayCode is not null) + { + return this._displayCode.Value; + } + + if (this._definition?.SubCodeSpecified is not true) + { + return this.Code; + } + + ushort result = this.Code; + if (this.SubCode is { } subCode) + { + result <<= 8; + result |= subCode; + } + + this._displayCode = result; + return result; + } + } + /// /// Gets the direction as string. /// public string Direction { get; } + /// + /// Gets the packet as text in a one-line string. + /// + public string Message + { + get + { + if (this._message is null && this.AnalyzingRequested is not null) + { + var request = new AnalyzingRequestedEventArgs(this); + this.AnalyzingRequested?.Invoke(this, request); + this._message = request.Message; + this._analyzedByVersion = request.ClientVersion; + this._definition = request.Definition; + this.RaisePropertyChanged(nameof(DisplayCode)); + } + + return this._message ?? string.Empty; + } + } + /// /// Gets a value indicating whether the packet was sent to the server; Otherwise it was sent to the client. /// @@ -72,9 +139,66 @@ public Packet(TimeSpan timestamp, byte[] data, bool toServer) /// public string PacketData => this._dataAsString ??= this._innerData.AsString(); + /// + /// Gets the protocol version which was applied when analyzing. + /// + public ClientVersion AnalyzedByVersion => _analyzedByVersion; + /// public override string ToString() { return $"{this.Direction}: {this.PacketData}"; } + + /// + /// Clears the message which was generated by the packet analyzer based on a selected version. + /// + public void ClearMessage() + { + this._analyzedByVersion = default; + this._definition = null; + this._displayCode = null; + this._message = null; + this.RaisePropertyChanged(nameof(Message)); + } + + private void RaisePropertyChanged([CallerMemberName] string? propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + /// + /// Event args for . + /// + public class AnalyzingRequestedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The data. + public AnalyzingRequestedEventArgs(Packet data) + { + Packet = data; + } + + /// + /// Gets the packet which should be analyzed. + /// + public Packet Packet { get; } + + /// + /// Gets or sets the definition which was found during the analyzing. + /// + public PacketDefinition? Definition { get; set; } + + /// + /// Gets or sets the client version which was set during analyzing. + /// + public ClientVersion ClientVersion { get; set; } + + /// + /// Gets or sets the message which describes the packet in a one-line string. + /// + public string Message { get; set; } = string.Empty; + } } \ No newline at end of file diff --git a/src/Network/Analyzer/PacketAnalyzer.cs b/src/Network/Analyzer/PacketAnalyzer.cs index 365ef2f94..d554cf38d 100644 --- a/src/Network/Analyzer/PacketAnalyzer.cs +++ b/src/Network/Analyzer/PacketAnalyzer.cs @@ -19,7 +19,8 @@ public sealed class PacketAnalyzer : IDisposable private const string ClientToServerPacketsFile = "ClientToServerPackets.xml"; private const string ServerToClientPacketsFile = "ServerToClientPackets.xml"; private const string CommonFile = "CommonEnums.xml"; - private const int DefaultVersionValue = 090; + private const int DefaultVersionValue = 100; + private const int ExtendedVersionValue = 106 * 100 + 3; private readonly IList _watchers = new List(); private PacketDefinitions? _clientPacketDefinitions; @@ -77,6 +78,49 @@ public string ExtractInformation(Packet packet) return string.Empty; } + /// + /// Extracts the information of the packet and returns it as a short, formatted string. + /// + /// The packet. + /// The formatted string with the extracted information. + public (string, PacketDefinition?) ExtractShortInformation(Packet packet) + { + var definitions = packet.ToServer ? this._clientPacketDefinitions : this._serverPacketDefinitions; + var definition = this.DeterminePacketDefinition(packet); + if (definition is null) + { + return (packet.PacketData, null); + } + + var stringBuilder = new StringBuilder(definition.Caption ?? definition.Name ?? string.Empty); + var relevantFields = definition.Fields? + .Where(f => f.Type != FieldType.Binary && f.Type != FieldType.StructureArray) + .Where(f => f.Name != "HeaderCode") + ?? []; + if (relevantFields.Any()) + { + stringBuilder.Append(" ("); + var isFirst = true; + foreach (var field in relevantFields) + { + if (!isFirst) + { + stringBuilder.Append("; "); + } + + isFirst = false; + + stringBuilder.Append(field.Name) + .Append(": ") + .Append(this.ExtractFieldValueOrGetError(packet.Data.AsSpan(), field, definition, definitions!)); + } + + stringBuilder.Append(")"); + } + + return (stringBuilder.ToString(), definition); + } + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// @@ -100,6 +144,11 @@ public void Dispose() int GetVersion(string name) { + if (name.EndsWith("Extended", StringComparison.InvariantCulture)) + { + return ExtendedVersionValue; + } + var match = Regex.Match(name, "^[A-Za-z]+?([0-9]{3})$"); if (match.Success) { @@ -284,39 +333,45 @@ private string ExtractFieldValue(Span data, Field field, PacketDefinition }; } - private string ExtractStructureArrayValues(Span data, Field field, PacketDefinition packet, PacketDefinitions definitions) + private string ExtractStructureArrayValues(Span data, Field arrayField, PacketDefinition packet, PacketDefinitions definitions) { - var type = packet.Structures?.FirstOrDefault(s => s.Name == field.TypeName) - ?? definitions.Structures?.FirstOrDefault(s => s.Name == field.TypeName) - ?? this._commonDefinitions?.Structures?.FirstOrDefault(s => s.Name == field.TypeName); - if (type is null) + var elementType = packet.Structures?.FirstOrDefault(s => s.Name == arrayField.TypeName) + ?? definitions.Structures?.FirstOrDefault(s => s.Name == arrayField.TypeName) + ?? this._commonDefinitions?.Structures?.FirstOrDefault(s => s.Name == arrayField.TypeName); + if (elementType is null) { - return data[field.Index..].AsString(); + return data[arrayField.Index..].AsString(); } - var countField = packet.Fields?.FirstOrDefault(f => f.Name == field.ItemCountField) - ?? packet.Structures?.SelectMany(s => s.Fields ?? Enumerable.Empty()).FirstOrDefault(f => f.Name == field.ItemCountField); + var countField = packet.Fields?.FirstOrDefault(f => f.Name == arrayField.ItemCountField) + ?? packet.Structures?.SelectMany(s => s.Fields ?? Enumerable.Empty()).FirstOrDefault(f => f.Name == arrayField.ItemCountField); int count = countField is null ? 0 : int.Parse(this.ExtractFieldValue(data, countField, packet, definitions), CultureInfo.InvariantCulture); if (count == 0) { return string.Empty; } - var typeLength = type.Length > 0 ? type.Length : this.DetermineFixedStructLength(data, field, type, count); + var typeLength = elementType.Length > 0 ? elementType.Length : this.DetermineFixedStructLength(data, arrayField, elementType, count); + var fixedLengthByCount = CalcFixStructLengthBySizeAndCount(data, arrayField, elementType, count); var stringBuilder = new StringBuilder(); - var restData = data[field.Index..]; + var restData = data[arrayField.Index..]; for (int i = 0; i < count; i++) { - var currentLength = typeLength ?? this.DetermineDynamicStructLength(restData, type, packet); - var elementData = restData[..currentLength]; - restData = restData[currentLength..]; + var currentLength = typeLength ?? this.DetermineDynamicStructLength(restData, elementType, packet) ?? fixedLengthByCount; + if (currentLength is null) + { + break; + } + + var elementData = restData[..currentLength.Value]; + restData = restData[currentLength.Value..]; stringBuilder.Append(Environment.NewLine) - .Append(field.Name + $"[{i}]:"); + .Append(arrayField.Name + $"[{i}]:"); stringBuilder.Append(Environment.NewLine) .Append(" Raw: ").Append(elementData.AsString()); - foreach (var structField in type.Fields ?? Enumerable.Empty()) + foreach (var structField in elementType.Fields ?? Enumerable.Empty()) { stringBuilder.Append(Environment.NewLine) .Append(" ").Append(structField.Name).Append(": ").Append(this.ExtractFieldValue(elementData, structField, packet, definitions)); @@ -342,7 +397,11 @@ private string ExtractEnumValue(Span data, Field field, PacketDefinition p { return type.Length; } + return null; + } + private int? CalcFixStructLengthBySizeAndCount(Span data, Field field, Structure type, int count) + { if (type.Fields?.All(f => f.Type != FieldType.StructureArray) ?? false) { return (data.Length - field.Index) / count; @@ -359,17 +418,90 @@ private string ExtractEnumValue(Span data, Field field, PacketDefinition p /// The type. /// Type of the packet. /// The dynamic length of a struct with a nested structure array. - private int DetermineDynamicStructLength(Span restData, Structure type, PacketDefinition packetType) + private int? DetermineDynamicStructLength(Span restData, Structure type, PacketDefinition packetType) { - if (type.Fields is null || packetType.Structures is null) + if (type.Fields is null) { - return 0; + return null; } - var nestedStructField = type.Fields.First(f => f.Type == FieldType.StructureArray); - var countField = type.Fields.First(f => f.Name == nestedStructField.ItemCountField); - var count = restData[countField.Index]; - var nestedStructType = packetType.Structures.First(s => s.Name == nestedStructField.TypeName); - return nestedStructField.Index + (count * nestedStructType.Length); + if (packetType.Structures is not null + && type.Fields.FirstOrDefault(f => f.Type == FieldType.StructureArray) is { } nestedStructField) + { + + var countField = type.Fields.First(f => f.Name == nestedStructField.ItemCountField); + var count = restData[countField.Index]; + var nestedStructType = packetType.Structures.First(s => s.Name == nestedStructField.TypeName); + return nestedStructField.Index + (count * nestedStructType.Length); + + } + if (this._clientVersionValue == ExtendedVersionValue + && type.Fields.FirstOrDefault(f => f.Type == FieldType.Binary) is { } binaryField + && binaryField.Name?.EndsWith("ItemData") is true) + { + return binaryField.Index + DetermineItemSize(restData, binaryField); + } + + if (type.Fields.MaxBy(f => f.Index) is { Type: not (FieldType.Binary or FieldType.StructureArray)} lastField) + { + return lastField.Index + FieldSize(lastField.Type); + } + + return null; + } + + private int DetermineItemSize(Span restData, Field binaryField) + { + var itemData = restData.Slice(binaryField.Index); + var size = 5; + var options = itemData[4]; + if ((options & 1) == 1) // Option + { + size++; + } + + if ((options & 8) == 8) // Excellent + { + size++; + } + + if ((options & 0x10) == 0x10) // Ancient + { + size++; + } + + if ((options & 0x20) == 0x20) // Harmony + { + size++; + } + + if ((options & 0x80) == 0x80) // Sockets + { + size++; + var socketCount = itemData[size] & 0xF; + size += socketCount; + } + + return size; + } + + private int FieldSize(FieldType fieldType) + { + return fieldType switch + { + FieldType.Byte => 1, + FieldType.Boolean => 1, + FieldType.IntegerLittleEndian => 4, + FieldType.IntegerBigEndian => 4, + FieldType.ShortLittleEndian => 2, + FieldType.ShortBigEndian => 2, + FieldType.LongLittleEndian => 8, + FieldType.LongBigEndian => 8, + FieldType.Enum => 1, + FieldType.StructureArray => 1, + FieldType.Float => 4, + FieldType.Double => 8, + _ => 1, + }; } } \ No newline at end of file diff --git a/src/Network/Analyzer/Program.cs b/src/Network/Analyzer/Program.cs index 93471ce8e..c37bcd477 100644 --- a/src/Network/Analyzer/Program.cs +++ b/src/Network/Analyzer/Program.cs @@ -17,8 +17,14 @@ internal static class Program [STAThread] internal static void Main() { + AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } + + private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) + { + // todo + } } \ No newline at end of file diff --git a/src/Network/Packets/EnumValue.cs b/src/Network/Packets/EnumValue.cs index 963f22284..233f6b570 100644 --- a/src/Network/Packets/EnumValue.cs +++ b/src/Network/Packets/EnumValue.cs @@ -27,5 +27,5 @@ public class EnumValue /// /// Gets or sets the numerical value of this enum value. /// - public byte Value { get; set; } + public int Value { get; set; } } \ No newline at end of file