Skip to content

Commit

Permalink
NHA2: Gracefully handle IO errors when reading items.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaakov-h committed Jun 20, 2015
1 parent 92d6f17 commit fe0ca3f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
14 changes: 13 additions & 1 deletion Resources/NetHookAnalyzer2/NetHookAnalyzer2/NetHookItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ public bool LoadFromFile(FileInfo fileInfo)
return true;
}

public string ReadInnerMessageName()
string ReadInnerMessageName()
{
try
{
return ReadInnerMessageNameCore();
}
catch (IOException)
{
return null;
}
}

string ReadInnerMessageNameCore()
{
switch (EMsg)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,39 @@ public TreeNode BuildTree()
return Node;
}

public void CreateTreeNode()
void CreateTreeNode()
{
Node = new TreeNode();
try
{
Node = CreateTreeNodeCore();
}
catch (Exception ex)
{
Node = new TreeNode(null, new[] { new TreeNode(string.Format("{0} encountered whilst parsing item: {1}", ex.GetType().Name, ex.Message)) });
}
}

TreeNode CreateTreeNodeCore()
{
var node = new TreeNode();

using (var stream = item.OpenStream())
{
var rawEMsg = PeekUInt(stream);

Node.Nodes.Add(BuildInfoNode(rawEMsg));
node.Nodes.Add(BuildInfoNode(rawEMsg));

var header = ReadHeader(rawEMsg, stream);
Node.Nodes.Add(new TreeNodeObjectExplorer("Header", header).TreeNode);
node.Nodes.Add(new TreeNodeObjectExplorer("Header", header).TreeNode);

var body = ReadBody(rawEMsg, stream, header);
var bodyNode = new TreeNodeObjectExplorer("Body", body).TreeNode;
Node.Nodes.Add(bodyNode);
node.Nodes.Add(bodyNode);

var payload = ReadPayload(stream);
if (payload != null && payload.Length > 0)
{
Node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload).TreeNode);
node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload).TreeNode);
}

if (Specializations != null)
Expand All @@ -77,13 +89,15 @@ public void CreateTreeNode()
bodyNode.Collapse(ignoreChildren: true);

var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value).TreeNode).ToArray();
Node.Nodes.AddRange(extraNodes);
node.Nodes.AddRange(extraNodes);

// Let the specializers examine any new message objects.
objectsToSpecialize = specializations.Select(x => x.Value).ToArray();
}
}
}

return node;
}

static TreeNode BuildInfoNode(uint rawEMsg)
Expand Down

0 comments on commit fe0ca3f

Please sign in to comment.