Skip to content

Commit 21e0433

Browse files
U/sgriffin/nspi (#82)
* Clean up handling of MAPIStringAddressBook * Use annotaed data and remove special case * parse address book prop tag names
1 parent e0cb1b9 commit 21e0433

File tree

3 files changed

+93
-89
lines changed

3 files changed

+93
-89
lines changed

MAPIInspector/Source/Parsers/BaseStructure.cs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd
153153
{
154154
offset = ad.Size;
155155
res.Text = ad.ToString();
156-
foreach(var parsedValue in ad.parsedValues)
156+
foreach (var parsedValue in ad.parsedValues)
157157
{
158158
var alternateParsingNode = new TreeNode($"{parsedValue.Key}:{parsedValue.Value}");
159159
alternateParsingNode.Tag = new Position(current, offset);
@@ -162,82 +162,6 @@ public static TreeNode AddNodesForTree(string nodeName, object obj, int startInd
162162

163163
return res;
164164
}
165-
else if (t.Name == "MAPIStringAddressBook")
166-
{
167-
FieldInfo[] infoString = t.GetFields();
168-
169-
// MagicByte node
170-
if (infoString[1].GetValue(obj) != null)
171-
{
172-
TreeNode nodeMagic = new TreeNode(string.Format("{0}:{1}", infoString[1].Name, infoString[1].GetValue(obj)));
173-
Position positionStringMagic = new Position(current, 1);
174-
nodeMagic.Tag = positionStringMagic;
175-
res.Nodes.Add(nodeMagic);
176-
current += 1;
177-
}
178-
179-
// value node
180-
string terminator = (string)infoString[3].GetValue(obj);
181-
int os = 0;
182-
TreeNode node = new TreeNode(string.Format("{0}:{1}", infoString[0].Name, infoString[0].GetValue(obj)));
183-
184-
// If the Encoding is Unicode.
185-
if (infoString[2].GetValue(obj).ToString() == "System.Text.UnicodeEncoding")
186-
{
187-
// If the StringLength is not equal 0, the StringLength will be OS value.
188-
if (infoString[4].GetValue(obj).ToString() != "0")
189-
{
190-
os = ((int)infoString[4].GetValue(obj)) * 2;
191-
}
192-
else
193-
{
194-
if (infoString[0].GetValue(obj) != null)
195-
{
196-
os = ((string)infoString[0].GetValue(obj)).Length * 2;
197-
}
198-
199-
if (infoString[5].GetValue(obj).ToString() != "False")
200-
{
201-
os -= 1;
202-
}
203-
204-
os += terminator.Length * 2;
205-
}
206-
}
207-
else
208-
{
209-
// If the Encoding is ASCII.
210-
if (infoString[4].GetValue(obj).ToString() != "0")
211-
{
212-
// If the StringLength is not equal 0, the StringLength will be OS value.
213-
os = (int)infoString[4].GetValue(obj);
214-
}
215-
else
216-
{
217-
if (infoString[0].GetValue(obj) != null)
218-
{
219-
os = ((string)infoString[0].GetValue(obj)).Length;
220-
}
221-
222-
os += terminator.Length;
223-
}
224-
}
225-
226-
Position positionString = new Position(current, os);
227-
node.Tag = positionString;
228-
res.Nodes.Add(node);
229-
230-
if (infoString[1].GetValue(obj) != null)
231-
{
232-
offset = os + 1;
233-
}
234-
else
235-
{
236-
offset = os;
237-
}
238-
239-
return res;
240-
}
241165

242166
// Check whether the data type is simple type
243167
if (Enum.IsDefined(typeof(DataType), t.Name))

MAPIInspector/Source/Parsers/MSOXCDATA.cs

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,7 +4098,7 @@ public override int Size
40984098
/// <summary>
40994099
/// The MAPIString class to record the related attributes of string.
41004100
/// </summary>
4101-
public class MAPIStringAddressBook : BaseStructure
4101+
public class MAPIStringAddressBook : AnnotatedData
41024102
{
41034103
/// <summary>
41044104
/// The string value
@@ -4113,7 +4113,7 @@ public class MAPIStringAddressBook : BaseStructure
41134113
/// <summary>
41144114
/// The string Encoding : ASCII or Unicode
41154115
/// </summary>
4116-
private Encoding Encode;
4116+
public Encoding Encode;
41174117

41184118
/// <summary>
41194119
/// The string Terminator. Default is "\0".
@@ -4130,20 +4130,13 @@ public class MAPIStringAddressBook : BaseStructure
41304130
/// </summary>
41314131
public bool ReducedUnicode;
41324132

4133-
/// <summary>
4134-
/// Initializes a new instance of the MAPIStringAddressBook class without parameters.
4135-
/// </summary>
4136-
public MAPIStringAddressBook()
4137-
{
4138-
}
4139-
41404133
/// <summary>
41414134
/// Initializes a new instance of the MAPIStringAddressBook class with parameters.
41424135
/// </summary>
41434136
/// <param name="encode">The encoding type</param>
41444137
/// <param name="terminator">The string terminator</param>
41454138
/// <param name="stringLength">The string length</param>
4146-
/// <param name="reducedUnicode">INdicate whether the terminator is reduced</param>
4139+
/// <param name="reducedUnicode">Indicate whether the terminator is reduced</param>
41474140
public MAPIStringAddressBook(Encoding encode, string terminator = "\0", int stringLength = 0, bool reducedUnicode = false)
41484141
{
41494142
this.Encode = encode;
@@ -4170,6 +4163,62 @@ public override void Parse(Stream s)
41704163

41714164
this.Value = this.ReadString(this.Encode, this.Terminator, this.StringLength, this.ReducedUnicode);
41724165
}
4166+
public override string ToString() => Value;
4167+
public override int Size
4168+
{
4169+
get
4170+
{
4171+
var len = 0;
4172+
4173+
if (Encode == Encoding.Unicode)
4174+
{
4175+
// If the StringLength is not equal 0, the StringLength will be basis for size
4176+
if (StringLength != 0)
4177+
{
4178+
len = StringLength * 2;
4179+
}
4180+
else
4181+
{
4182+
if (Value != null)
4183+
{
4184+
len = Value.Length * 2;
4185+
}
4186+
4187+
if (ReducedUnicode)
4188+
{
4189+
len -= 1;
4190+
}
4191+
4192+
len += Terminator.Length * 2;
4193+
}
4194+
}
4195+
else
4196+
{
4197+
// If the Encoding is ASCII.
4198+
if (StringLength != 0)
4199+
{
4200+
// If the StringLength is not equal 0, the StringLength will be basis for size
4201+
len = StringLength;
4202+
}
4203+
else
4204+
{
4205+
if (Value != null)
4206+
{
4207+
len = Value.Length;
4208+
}
4209+
4210+
len += Terminator.Length;
4211+
}
4212+
}
4213+
4214+
if (HasValue != null)
4215+
{
4216+
len += 1;
4217+
}
4218+
4219+
return len;
4220+
}
4221+
}
41734222
}
41744223

41754224
#region 2.1 AddressList Structures

MAPIInspector/Source/Parsers/MSOXCMAPIHTTP.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace MAPIInspector.Parsers
22
{
3+
using MapiInspector;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -4307,6 +4308,11 @@ public class AddressBookPropertyValue : BaseStructure
43074308
/// </summary>
43084309
private CountWideEnum countWide;
43094310

4311+
/// <summary>
4312+
/// Source property tag information
4313+
/// </summary>
4314+
public AnnotatedComment PropertyTag;
4315+
43104316
/// <summary>
43114317
/// Initializes a new instance of the AddressBookPropertyValue class.
43124318
/// </summary>
@@ -4367,13 +4373,18 @@ public class AddressBookTaggedPropertyValue : BaseStructure
43674373
/// <summary>
43684374
/// An unsigned integer that identifies the property.
43694375
/// </summary>
4370-
public ushort PropertyId;
4376+
public PidTagPropertyEnum PropertyId;
43714377

43724378
/// <summary>
43734379
/// An AddressBookPropertyValue structure
43744380
/// </summary>
43754381
public AddressBookPropertyValue PropertyValue;
43764382

4383+
/// <summary>
4384+
/// Source property tag information
4385+
/// </summary>
4386+
public AnnotatedComment PropertyTag;
4387+
43774388
/// <summary>
43784389
/// Parse the AddressBookTaggedPropertyValue structure.
43794390
/// </summary>
@@ -4382,10 +4393,11 @@ public override void Parse(Stream s)
43824393
{
43834394
base.Parse(s);
43844395
this.PropertyType = (PropertyDataType)this.ReadUshort();
4385-
this.PropertyId = this.ReadUshort();
4396+
this.PropertyId = (PidTagPropertyEnum)this.ReadUshort();
43864397
AddressBookPropertyValue addressBookValue = new AddressBookPropertyValue(this.PropertyType);
43874398
addressBookValue.Parse(s);
43884399
this.PropertyValue = addressBookValue;
4400+
this.PropertyTag = $"{PropertyType}:{Utilities.EnumToString(PropertyId)}";
43894401
}
43904402
}
43914403
#endregion
@@ -4445,6 +4457,11 @@ public class AddressBookTypedPropertyValue : BaseStructure
44454457
/// </summary>
44464458
public AddressBookPropertyValue PropertyValue;
44474459

4460+
/// <summary>
4461+
/// Source property tag information
4462+
/// </summary>
4463+
public AnnotatedComment PropertyTag;
4464+
44484465
/// <summary>
44494466
/// Parse the AddressBookTypedPropertyValue structure.
44504467
/// </summary>
@@ -4481,6 +4498,11 @@ public class AddressBookFlaggedPropertyValue : BaseStructure
44814498
/// </summary>
44824499
private PropertyDataType propertyDataType;
44834500

4501+
/// <summary>
4502+
/// Source property tag information
4503+
/// </summary>
4504+
public AnnotatedComment PropertyTag;
4505+
44844506
/// <summary>
44854507
/// Initializes a new instance of the AddressBookFlaggedPropertyValue class.
44864508
/// </summary>
@@ -4540,6 +4562,11 @@ public class AddressBookFlaggedPropertyValueWithType : BaseStructure
45404562
/// </summary>
45414563
public AddressBookPropertyValue PropertyValue;
45424564

4565+
/// <summary>
4566+
/// Source property tag information
4567+
/// </summary>
4568+
public AnnotatedComment PropertyTag;
4569+
45434570
/// <summary>
45444571
/// Parse the AddressBookFlaggedPropertyValueWithType structure.
45454572
/// </summary>
@@ -4628,12 +4655,14 @@ public override void Parse(Stream s)
46284655
{
46294656
AddressBookPropertyValue propValue = new AddressBookPropertyValue(propTag.PropertyType, this.ptypMultiCountSize);
46304657
propValue.Parse(s);
4658+
propValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}";
46314659
addrRowValue = propValue;
46324660
}
46334661
else
46344662
{
46354663
AddressBookTypedPropertyValue typePropValue = new AddressBookTypedPropertyValue();
46364664
typePropValue.Parse(s);
4665+
typePropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}";
46374666
addrRowValue = typePropValue;
46384667
}
46394668
}
@@ -4643,12 +4672,14 @@ public override void Parse(Stream s)
46434672
{
46444673
AddressBookFlaggedPropertyValue flagPropValue = new AddressBookFlaggedPropertyValue(propTag.PropertyType);
46454674
flagPropValue.Parse(s);
4675+
flagPropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}";
46464676
addrRowValue = flagPropValue;
46474677
}
46484678
else
46494679
{
46504680
AddressBookFlaggedPropertyValueWithType flagPropValue = new AddressBookFlaggedPropertyValueWithType();
46514681
flagPropValue.Parse(s);
4682+
flagPropValue.PropertyTag = $"{propTag.PropertyType}:{Utilities.EnumToString(propTag.PropertyId)}";
46524683
addrRowValue = flagPropValue;
46534684
}
46544685
}

0 commit comments

Comments
 (0)