From 294a7f5e81e5630510c9a4003d04d5dc846aed24 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 10 Oct 2021 14:32:41 +0300 Subject: [PATCH 1/3] Simplify info in nethook analyzer --- .../NetHookAnalyzer2/NetHookItemTreeBuilder.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs index d11f65c4c..013a2a031 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs @@ -61,7 +61,7 @@ TreeNode CreateTreeNodeCore(bool displayUnsetFields) { var rawEMsg = PeekUInt(stream); - node.Nodes.Add(BuildInfoNode(rawEMsg, configuration)); + node.Nodes.Add(BuildInfoNode(rawEMsg)); var header = ReadHeader(rawEMsg, stream); node.Nodes.Add(new TreeNodeObjectExplorer("Header", header, configuration).TreeNode); @@ -102,17 +102,17 @@ TreeNode CreateTreeNodeCore(bool displayUnsetFields) return node; } - static TreeNode BuildInfoNode(uint rawEMsg, TreeNodeObjectExplorerConfiguration configuration) + static TreeNode BuildInfoNode(uint rawEMsg) { - var eMsg = MsgUtil.GetMsg(rawEMsg); + var eMsg = MsgUtil.GetMsg( rawEMsg ); + var eMsgName = $"EMsg {eMsg} ({(int)eMsg})"; - var eMsgExplorer = new TreeNodeObjectExplorer("EMsg", eMsg, configuration); - - return new TreeNode("Info", new[] + if( MsgUtil.IsProtoBuf( rawEMsg ) ) { - eMsgExplorer.TreeNode, - new TreeNodeObjectExplorer("Is Protobuf", MsgUtil.IsProtoBuf(rawEMsg), configuration).TreeNode - }); + return new TreeNode( eMsgName ); + } + + return new TreeNode( $"{eMsgName} (Non ProtoBuf)" ); } } } From 1b0437d86a98b2a8143bb75651d30ece01cc7eeb Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 18 Oct 2021 12:36:55 +0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Yaakov --- .../NetHookAnalyzer2/NetHookItemTreeBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs index 013a2a031..479ae6f62 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs @@ -105,14 +105,14 @@ TreeNode CreateTreeNodeCore(bool displayUnsetFields) static TreeNode BuildInfoNode(uint rawEMsg) { var eMsg = MsgUtil.GetMsg( rawEMsg ); - var eMsgName = $"EMsg {eMsg} ({(int)eMsg})"; + var eMsgName = $"EMsg {eMsg:G} ({eMsg:D})"; if( MsgUtil.IsProtoBuf( rawEMsg ) ) { return new TreeNode( eMsgName ); } - return new TreeNode( $"{eMsgName} (Non ProtoBuf)" ); + return new TreeNode( $"{eMsgName} (Non-Protobuf)" ); } } } From 2905b4040ea2c915549ef34c9f2713f09ec4dccf Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 18 Oct 2021 13:41:42 +0300 Subject: [PATCH 3/3] Make info a root node --- .../NetHookAnalyzer2/MainForm.Designer.cs | 1 + .../NetHookAnalyzer2/MainForm.cs | 2 +- .../NetHookItemTreeBuilder.cs | 57 +++++++++---------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.Designer.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.Designer.cs index ff90a568f..763651a02 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.Designer.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.Designer.cs @@ -300,6 +300,7 @@ private void InitializeComponent() this.itemExplorerTreeView.Name = "itemExplorerTreeView"; this.itemExplorerTreeView.Size = new System.Drawing.Size(455, 426); this.itemExplorerTreeView.TabIndex = 0; + this.itemExplorerTreeView.ShowRootLines = false; // // timestampColumnHeader // diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs index ca7c14824..4dbf906fb 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/MainForm.cs @@ -388,7 +388,7 @@ void RepopulateTreeView() } itemExplorerTreeView.Nodes.Clear(); - itemExplorerTreeView.Nodes.AddRange(BuildTree(item).Nodes.Cast().ToArray()); + itemExplorerTreeView.Nodes.Add(BuildTree(item)); itemExplorerTreeView.Nodes[0].EnsureVisible(); // Scroll to top } diff --git a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs index 479ae6f62..dd9517a88 100644 --- a/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs +++ b/Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItemTreeBuilder.cs @@ -55,47 +55,44 @@ TreeNode CreateTreeNodeCore(bool displayUnsetFields) { var configuration = new TreeNodeObjectExplorerConfiguration { ShowUnsetFields = displayUnsetFields }; - var node = new TreeNode(); + using var stream = item.OpenStream(); - using (var stream = item.OpenStream()) - { - var rawEMsg = PeekUInt(stream); + var rawEMsg = PeekUInt(stream); + var node = BuildInfoNode(rawEMsg); + node.Expand(); - node.Nodes.Add(BuildInfoNode(rawEMsg)); + var header = ReadHeader(rawEMsg, stream); + node.Nodes.Add(new TreeNodeObjectExplorer("Header", header, configuration).TreeNode); - var header = ReadHeader(rawEMsg, stream); - node.Nodes.Add(new TreeNodeObjectExplorer("Header", header, configuration).TreeNode); + var body = ReadBody(rawEMsg, stream, header); + var bodyNode = new TreeNodeObjectExplorer("Body", body, configuration).TreeNode; + node.Nodes.Add(bodyNode); - var body = ReadBody(rawEMsg, stream, header); - var bodyNode = new TreeNodeObjectExplorer("Body", body, configuration).TreeNode; - node.Nodes.Add(bodyNode); + var payload = ReadPayload(stream); + if (payload != null && payload.Length > 0) + { + node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload, configuration).TreeNode); + } - var payload = ReadPayload(stream); - if (payload != null && payload.Length > 0) + if (Specializations != null) + { + var objectsToSpecialize = new[] { body }; + while (objectsToSpecialize.Any()) { - node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload, configuration).TreeNode); - } + var specializations = objectsToSpecialize.SelectMany(o => Specializations.SelectMany(x => x.ReadExtraObjects(o))); - if (Specializations != null) - { - var objectsToSpecialize = new[] { body }; - while (objectsToSpecialize.Any()) + if (!specializations.Any()) { - var specializations = objectsToSpecialize.SelectMany(o => Specializations.SelectMany(x => x.ReadExtraObjects(o))); - - if (!specializations.Any()) - { - break; - } + break; + } - bodyNode.Collapse(ignoreChildren: true); + bodyNode.Collapse(ignoreChildren: true); - var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value, configuration).TreeNode).ToArray(); - node.Nodes.AddRange(extraNodes); + var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value, configuration).TreeNode).ToArray(); + node.Nodes.AddRange(extraNodes); - // Let the specializers examine any new message objects. - objectsToSpecialize = specializations.Select(x => x.Value).ToArray(); - } + // Let the specializers examine any new message objects. + objectsToSpecialize = specializations.Select(x => x.Value).ToArray(); } }