From bd72549aa7521b0a7df05e22c9721ca5adcf9f96 Mon Sep 17 00:00:00 2001 From: Stephen Griffin Date: Mon, 12 Feb 2024 15:37:28 -0500 Subject: [PATCH 1/3] Clean up handling of MAPIStringAddressBook --- MAPIInspector/Source/Parsers/BaseStructure.cs | 36 +++++++++---------- MAPIInspector/Source/Parsers/MSOXCDATA.cs | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/MAPIInspector/Source/Parsers/BaseStructure.cs b/MAPIInspector/Source/Parsers/BaseStructure.cs index 3ec0b58..e7c2e64 100644 --- a/MAPIInspector/Source/Parsers/BaseStructure.cs +++ b/MAPIInspector/Source/Parsers/BaseStructure.cs @@ -153,7 +153,7 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd { offset = ad.Size; res.Text = ad.ToString(); - foreach(var parsedValue in ad.parsedValues) + foreach (var parsedValue in ad.parsedValues) { var alternateParsingNode = new TreeNode($"{parsedValue.Key}:{parsedValue.Value}"); alternateParsingNode.Tag = new Position(current, offset); @@ -162,14 +162,12 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd return res; } - else if (t.Name == "MAPIStringAddressBook") + else if (obj is MAPIStringAddressBook stringAddressBook) { - FieldInfo[] infoString = t.GetFields(); - // MagicByte node - if (infoString[1].GetValue(obj) != null) + if (stringAddressBook.HasValue != null) { - TreeNode nodeMagic = new TreeNode(string.Format("{0}:{1}", infoString[1].Name, infoString[1].GetValue(obj))); + TreeNode nodeMagic = new TreeNode($"HasValue:{stringAddressBook.HasValue}"); Position positionStringMagic = new Position(current, 1); nodeMagic.Tag = positionStringMagic; res.Nodes.Add(nodeMagic); @@ -177,26 +175,26 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd } // value node - string terminator = (string)infoString[3].GetValue(obj); + string terminator = stringAddressBook.Terminator; int os = 0; - TreeNode node = new TreeNode(string.Format("{0}:{1}", infoString[0].Name, infoString[0].GetValue(obj))); + TreeNode node = new TreeNode($"Value:{stringAddressBook.Value}"); // If the Encoding is Unicode. - if (infoString[2].GetValue(obj).ToString() == "System.Text.UnicodeEncoding") + if (stringAddressBook.Encode == Encoding.Unicode) { // If the StringLength is not equal 0, the StringLength will be OS value. - if (infoString[4].GetValue(obj).ToString() != "0") + if (stringAddressBook.StringLength != 0) { - os = ((int)infoString[4].GetValue(obj)) * 2; + os = stringAddressBook.StringLength * 2; } else { - if (infoString[0].GetValue(obj) != null) + if (stringAddressBook.Value != null) { - os = ((string)infoString[0].GetValue(obj)).Length * 2; + os = stringAddressBook.Value.Length * 2; } - if (infoString[5].GetValue(obj).ToString() != "False") + if (stringAddressBook.ReducedUnicode != false) { os -= 1; } @@ -207,16 +205,16 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd else { // If the Encoding is ASCII. - if (infoString[4].GetValue(obj).ToString() != "0") + if (stringAddressBook.StringLength != 0) { // If the StringLength is not equal 0, the StringLength will be OS value. - os = (int)infoString[4].GetValue(obj); + os = stringAddressBook.StringLength; } else { - if (infoString[0].GetValue(obj) != null) + if (stringAddressBook.Value != null) { - os = ((string)infoString[0].GetValue(obj)).Length; + os = stringAddressBook.Value.Length; } os += terminator.Length; @@ -227,7 +225,7 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd node.Tag = positionString; res.Nodes.Add(node); - if (infoString[1].GetValue(obj) != null) + if (stringAddressBook.HasValue != null) { offset = os + 1; } diff --git a/MAPIInspector/Source/Parsers/MSOXCDATA.cs b/MAPIInspector/Source/Parsers/MSOXCDATA.cs index 4b4d4dd..0ed44f3 100644 --- a/MAPIInspector/Source/Parsers/MSOXCDATA.cs +++ b/MAPIInspector/Source/Parsers/MSOXCDATA.cs @@ -4113,7 +4113,7 @@ public class MAPIStringAddressBook : BaseStructure /// /// The string Encoding : ASCII or Unicode /// - private Encoding Encode; + public Encoding Encode; /// /// The string Terminator. Default is "\0". From b2d9a8cc8405682f932effa5cc4c0121cd99770d Mon Sep 17 00:00:00 2001 From: Stephen Griffin Date: Mon, 12 Feb 2024 15:58:38 -0500 Subject: [PATCH 2/3] Use annotaed data and remove special case --- MAPIInspector/Source/Parsers/BaseStructure.cs | 74 ------------------- MAPIInspector/Source/Parsers/MSOXCDATA.cs | 67 ++++++++++++++--- 2 files changed, 58 insertions(+), 83 deletions(-) diff --git a/MAPIInspector/Source/Parsers/BaseStructure.cs b/MAPIInspector/Source/Parsers/BaseStructure.cs index e7c2e64..e703971 100644 --- a/MAPIInspector/Source/Parsers/BaseStructure.cs +++ b/MAPIInspector/Source/Parsers/BaseStructure.cs @@ -162,80 +162,6 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd return res; } - else if (obj is MAPIStringAddressBook stringAddressBook) - { - // MagicByte node - if (stringAddressBook.HasValue != null) - { - TreeNode nodeMagic = new TreeNode($"HasValue:{stringAddressBook.HasValue}"); - Position positionStringMagic = new Position(current, 1); - nodeMagic.Tag = positionStringMagic; - res.Nodes.Add(nodeMagic); - current += 1; - } - - // value node - string terminator = stringAddressBook.Terminator; - int os = 0; - TreeNode node = new TreeNode($"Value:{stringAddressBook.Value}"); - - // If the Encoding is Unicode. - if (stringAddressBook.Encode == Encoding.Unicode) - { - // If the StringLength is not equal 0, the StringLength will be OS value. - if (stringAddressBook.StringLength != 0) - { - os = stringAddressBook.StringLength * 2; - } - else - { - if (stringAddressBook.Value != null) - { - os = stringAddressBook.Value.Length * 2; - } - - if (stringAddressBook.ReducedUnicode != false) - { - os -= 1; - } - - os += terminator.Length * 2; - } - } - else - { - // If the Encoding is ASCII. - if (stringAddressBook.StringLength != 0) - { - // If the StringLength is not equal 0, the StringLength will be OS value. - os = stringAddressBook.StringLength; - } - else - { - if (stringAddressBook.Value != null) - { - os = stringAddressBook.Value.Length; - } - - os += terminator.Length; - } - } - - Position positionString = new Position(current, os); - node.Tag = positionString; - res.Nodes.Add(node); - - if (stringAddressBook.HasValue != null) - { - offset = os + 1; - } - else - { - offset = os; - } - - return res; - } // Check whether the data type is simple type if (Enum.IsDefined(typeof(DataType), t.Name)) diff --git a/MAPIInspector/Source/Parsers/MSOXCDATA.cs b/MAPIInspector/Source/Parsers/MSOXCDATA.cs index 0ed44f3..252d006 100644 --- a/MAPIInspector/Source/Parsers/MSOXCDATA.cs +++ b/MAPIInspector/Source/Parsers/MSOXCDATA.cs @@ -4098,7 +4098,7 @@ public override int Size /// /// The MAPIString class to record the related attributes of string. /// - public class MAPIStringAddressBook : BaseStructure + public class MAPIStringAddressBook : AnnotatedData { /// /// The string value @@ -4130,20 +4130,13 @@ public class MAPIStringAddressBook : BaseStructure /// public bool ReducedUnicode; - /// - /// Initializes a new instance of the MAPIStringAddressBook class without parameters. - /// - public MAPIStringAddressBook() - { - } - /// /// Initializes a new instance of the MAPIStringAddressBook class with parameters. /// /// The encoding type /// The string terminator /// The string length - /// INdicate whether the terminator is reduced + /// Indicate whether the terminator is reduced public MAPIStringAddressBook(Encoding encode, string terminator = "\0", int stringLength = 0, bool reducedUnicode = false) { this.Encode = encode; @@ -4170,6 +4163,62 @@ public override void Parse(Stream s) this.Value = this.ReadString(this.Encode, this.Terminator, this.StringLength, this.ReducedUnicode); } + public override string ToString() => Value; + public override int Size + { + get + { + var len = 0; + + if (Encode == Encoding.Unicode) + { + // If the StringLength is not equal 0, the StringLength will be basis for size + if (StringLength != 0) + { + len = StringLength * 2; + } + else + { + if (Value != null) + { + len = Value.Length * 2; + } + + if (ReducedUnicode) + { + len -= 1; + } + + len += Terminator.Length * 2; + } + } + else + { + // If the Encoding is ASCII. + if (StringLength != 0) + { + // If the StringLength is not equal 0, the StringLength will be basis for size + len = StringLength; + } + else + { + if (Value != null) + { + len = Value.Length; + } + + len += Terminator.Length; + } + } + + if (HasValue != null) + { + len += 1; + } + + return len; + } + } } #region 2.1 AddressList Structures From 47136753fa824c2b898639d291e9060f370c70b8 Mon Sep 17 00:00:00 2001 From: Stephen Griffin Date: Mon, 12 Feb 2024 16:37:52 -0500 Subject: [PATCH 3/3] parse address book prop tag names --- MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs b/MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs index 604cd77..e95af2b 100644 --- a/MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs +++ b/MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs @@ -1,5 +1,6 @@ namespace MAPIInspector.Parsers { + using MapiInspector; using System; using System.Collections.Generic; using System.IO; @@ -4307,6 +4308,11 @@ public class AddressBookPropertyValue : BaseStructure /// private CountWideEnum countWide; + /// + /// Source property tag information + /// + public AnnotatedComment PropertyTag; + /// /// Initializes a new instance of the AddressBookPropertyValue class. /// @@ -4367,13 +4373,18 @@ public class AddressBookTaggedPropertyValue : BaseStructure /// /// An unsigned integer that identifies the property. /// - public ushort PropertyId; + public PidTagPropertyEnum PropertyId; /// /// An AddressBookPropertyValue structure /// public AddressBookPropertyValue PropertyValue; + /// + /// Source property tag information + /// + public AnnotatedComment PropertyTag; + /// /// Parse the AddressBookTaggedPropertyValue structure. /// @@ -4382,10 +4393,11 @@ public override void Parse(Stream s) { base.Parse(s); this.PropertyType = (PropertyDataType)this.ReadUshort(); - this.PropertyId = this.ReadUshort(); + this.PropertyId = (PidTagPropertyEnum)this.ReadUshort(); AddressBookPropertyValue addressBookValue = new AddressBookPropertyValue(this.PropertyType); addressBookValue.Parse(s); this.PropertyValue = addressBookValue; + this.PropertyTag = $"{PropertyType}:{Utilities.EnumToString(PropertyId)}"; } } #endregion @@ -4445,6 +4457,11 @@ public class AddressBookTypedPropertyValue : BaseStructure /// public AddressBookPropertyValue PropertyValue; + /// + /// Source property tag information + /// + public AnnotatedComment PropertyTag; + /// /// Parse the AddressBookTypedPropertyValue structure. /// @@ -4481,6 +4498,11 @@ public class AddressBookFlaggedPropertyValue : BaseStructure /// private PropertyDataType propertyDataType; + /// + /// Source property tag information + /// + public AnnotatedComment PropertyTag; + /// /// Initializes a new instance of the AddressBookFlaggedPropertyValue class. /// @@ -4540,6 +4562,11 @@ public class AddressBookFlaggedPropertyValueWithType : BaseStructure /// public AddressBookPropertyValue PropertyValue; + /// + /// Source property tag information + /// + public AnnotatedComment PropertyTag; + /// /// Parse the AddressBookFlaggedPropertyValueWithType structure. /// @@ -4628,12 +4655,14 @@ public override void Parse(Stream s) { AddressBookPropertyValue propValue = new AddressBookPropertyValue(propTag.PropertyType, this.ptypMultiCountSize); propValue.Parse(s); + propValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}"; addrRowValue = propValue; } else { AddressBookTypedPropertyValue typePropValue = new AddressBookTypedPropertyValue(); typePropValue.Parse(s); + typePropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}"; addrRowValue = typePropValue; } } @@ -4643,12 +4672,14 @@ public override void Parse(Stream s) { AddressBookFlaggedPropertyValue flagPropValue = new AddressBookFlaggedPropertyValue(propTag.PropertyType); flagPropValue.Parse(s); + flagPropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}"; addrRowValue = flagPropValue; } else { AddressBookFlaggedPropertyValueWithType flagPropValue = new AddressBookFlaggedPropertyValueWithType(); flagPropValue.Parse(s); + flagPropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}"; addrRowValue = flagPropValue; } }