Skip to content

Commit

Permalink
U/sgriffin/nodes (#71)
Browse files Browse the repository at this point in the history
* Rebuild MAPIString on AnnotatedData and strip special handling from AddNodesForTree

Add nodeName to AddNodesForTree to ease debugging

* Rebuild MAPIString on AnnotatedData and strip special handling from AddNodesForTree

Add nodeName to AddNodesForTree to ease debugging

* Remove special casing for AnnotatedBytes, which is now subclassed from AnnotatedData

* Rebuild AnnotatedData to support multiple parsings

* hide obj types from output

* remove trailing \0 from tree copy

* Add meta tags to tag parsing

* parse named props in fx transfer data

* Parse times in fx buffers

* better time handling
  • Loading branch information
stephenegriffin authored Aug 25, 2023
1 parent 8ce5a09 commit ed9ac96
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 136 deletions.
16 changes: 14 additions & 2 deletions MAPIInspector/Source/MAPIControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MAPIInspector/Source/MAPIInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,7 @@ public void DisplayObject(object obj, byte[] bytesForHexview)
try
{
int result;
TreeNode topNode = BaseStructure.AddNodesForTree(obj, 0, out result);
TreeNode topNode = BaseStructure.AddNodesForTree("DisplayObjectRoot", obj, 0, out result);
this.MAPIViewControl.Nodes.Add(topNode);
topNode.ExpandAll();
this.MAPIControl.MAPIHexBox.ByteProvider = new StaticByteProvider(bytesForHexview);
Expand Down
82 changes: 10 additions & 72 deletions MAPIInspector/Source/Parsers/BaseStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ public enum DataType
/// <summary>
/// Add the object to TreeNode and calculate the byte number it consumed
/// </summary>
/// <param name="nodeName">Best guess at current node name for debugging - not currently used for display</param>
/// <param name="obj">The object need to display in TreeView</param>
/// <param name="startIndex">The start position of the object in HexView</param>
/// <param name="offset">The byte number consumed by the object</param>
/// <returns>The TreeNode with object value information</returns>
public static TreeNode AddNodesForTree(object obj, int startIndex, out int offset)
public static TreeNode AddNodesForTree(string nodeName, object obj, int startIndex, out int offset)
{
Type t = obj.GetType();
int current = startIndex;
Expand All @@ -151,61 +152,14 @@ public static TreeNode AddNodesForTree(object obj, int startIndex, out int offse
if (obj is AnnotatedData ad)
{
offset = ad.Size;
return res;
}
else if (t.Name == "MAPIString")
{
int os = 0;
FieldInfo[] infoString = t.GetFields();
string terminator = (string)infoString[2].GetValue(obj);
TreeNode node = new TreeNode(string.Format("{0}:{1}", infoString[0].Name, infoString[0].GetValue(obj)));

// If the Encoding is Unicode.
if (infoString[1].GetValue(obj).ToString() == "System.Text.UnicodeEncoding")
res.Text = ad.ToString();
foreach(var parsedValue in ad.parsedValues)
{
// If the StringLength is not equal 0, the StringLength will be os value.
if (infoString[3].GetValue(obj).ToString() != "0")
{
os = ((int)infoString[3].GetValue(obj)) * 2;
}
else
{
if (infoString[0].GetValue(obj) != null)
{
os = ((string)infoString[0].GetValue(obj)).Length * 2;
}

if (infoString[4].GetValue(obj).ToString() != "False")
{
os -= 1;
}

os += terminator.Length * 2;
}
var alternateParsingNode = new TreeNode($"{parsedValue.Key}:{parsedValue.Value}");
alternateParsingNode.Tag = new Position(current, offset);
res.Nodes.Add(alternateParsingNode);
}
else
{
// If the Encoding is ASCII.
if (infoString[3].GetValue(obj).ToString() != "0")
{
// If the StringLength is not equal 0, the StringLength will be os value
os = (int)infoString[3].GetValue(obj);
}
else
{
if (infoString[0].GetValue(obj) != null)
{
os = ((string)infoString[0].GetValue(obj)).Length;
}

os += terminator.Length;
}
}

offset = os;
Position positionString = new Position(current, os);
node.Tag = positionString;
res.Nodes.Add(node);
return res;
}
else if (t.Name == "MAPIStringAddressBook")
Expand Down Expand Up @@ -284,22 +238,6 @@ public static TreeNode AddNodesForTree(object obj, int startIndex, out int offse

return res;
}
else if (t.Name == "AnnotatedBytes")
{
var infoString = t.GetFields();
var bytes = (byte[])infoString[0].GetValue(obj);
var bytesString = Utilities.ConvertArrayToHexString(bytes);
var annotation = (string)infoString[1].GetValue(obj);
var node = new TreeNode($"{infoString[0].Name}:{bytesString}");

offset = bytes.Length;
node.Tag = new Position(current, offset);
res.Nodes.Add(node);
var annotationNode = new TreeNode($"annotation:{annotation}");
annotationNode.Tag = new Position(current, offset);
res.Nodes.Add(annotationNode);
return res;
}

// Check whether the data type is simple type
if (Enum.IsDefined(typeof(DataType), t.Name))
Expand Down Expand Up @@ -569,7 +507,7 @@ public static TreeNode AddNodesForTree(object obj, int startIndex, out int offse
compressBufferindex += 1;
}

tn = AddNodesForTree(a[k], current, out os);
tn = AddNodesForTree(fieldNameForAut, a[k], current, out os);
treeNodeArray.Nodes.Add(tn);
Position ps = new Position(current, os);
tn.Tag = ps;
Expand Down Expand Up @@ -612,7 +550,7 @@ public static TreeNode AddNodesForTree(object obj, int startIndex, out int offse
if (fieldName == "Payload" && IsCompressedXOR)
{
RPC_HEADER_EXT header = (RPC_HEADER_EXT)info[0].GetValue(obj);
node = AddNodesForTree(info[i].GetValue(obj), current, out os);
node = AddNodesForTree(fieldName, info[i].GetValue(obj), current, out os);
Position nodePosition = (Position)node.Tag;
nodePosition.Offset = header.Size;
os = nodePosition.Offset;
Expand All @@ -629,7 +567,7 @@ public static TreeNode AddNodesForTree(object obj, int startIndex, out int offse
compressBufferindex -= 1;
}

node = AddNodesForTree(info[i].GetValue(obj), current, out os);
node = AddNodesForTree(fieldName, info[i].GetValue(obj), current, out os);
Position nodePosition = new Position(current, os);
node.Tag = nodePosition;
}
Expand Down
Loading

0 comments on commit ed9ac96

Please sign in to comment.