Skip to content

Commit ff9b23e

Browse files
U/sgriffin/roptransport (#219)
* Fix roptransportsend parsing * fix junk label * uncommenting fix so it works * better search on root nodes * handle no root node selection better
1 parent 68ea173 commit ff9b23e

File tree

5 files changed

+67
-45
lines changed

5 files changed

+67
-45
lines changed

MAPIInspector/Source/BlockParser/BlockJunk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace BlockParser
55
public class BlockJunk : BlockInteresting
66
{
77
public override Color BackColor => Color.Coral;
8-
public override string InterestingLabel => "Exceptions found in this block";
8+
public override string InterestingLabel => "Extra data found in this block";
99

1010
string Label;
1111
BlockBytes junkData;

MAPIInspector/Source/MAPIControl.Events.cs

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,20 @@ private void PerformSearch(bool searchUp, bool searchFrames)
314314
if (string.IsNullOrEmpty(searchText) || searchText == SearchDefaultText) return;
315315

316316
FiddlerApplication.UI.SetStatusText($"Searching for {searchText}");
317+
var includeRoot = false; // Don't include the currently selected node for a seach
317318
var startNode = mapiTreeView?.SelectedNode;
318319
if (startNode == null && mapiTreeView?.Nodes.Count > 0)
319320
{
320321
startNode = mapiTreeView.Nodes[0];
322+
includeRoot = true; // But if no node was selected, incude whatever node we start from
321323
}
322324

323325
if (startNode != null)
324326
{
325327
var nodes = mapiTreeView.Nodes;
326328
TreeNode foundNode = searchUp
327-
? FindPrevNode(nodes, startNode, searchText, !searchFrames)
328-
: FindNextNode(nodes, startNode, searchText, !searchFrames);
329+
? FindPrevNode(nodes, startNode, searchText, !searchFrames, includeRoot)
330+
: FindNextNode(nodes, startNode, searchText, !searchFrames, includeRoot);
329331

330332
if (foundNode != null)
331333
{
@@ -338,6 +340,7 @@ private void PerformSearch(bool searchUp, bool searchFrames)
338340

339341
if (searchFrames)
340342
{
343+
includeRoot = true; // Now that we're searching new frames, always include the root node in our search
341344
var currentSession = Inspector.session;
342345
while (currentSession != null)
343346
{
@@ -348,8 +351,8 @@ private void PerformSearch(bool searchUp, bool searchFrames)
348351
var node = BaseStructure.AddBlock(parseResult, false);
349352
rootNode.Nodes.Add(node);
350353
var foundMatch = searchUp
351-
? FindPrevNode(rootNode.Nodes, node, searchText, true)
352-
: FindNextNode(rootNode.Nodes, node, searchText, true);
354+
? FindPrevNode(rootNode.Nodes, node, searchText, true, includeRoot)
355+
: FindNextNode(rootNode.Nodes, node, searchText, true, includeRoot);
353356
if (foundMatch != null)
354357
{
355358
FiddlerApplication.UI.SelectSessionsMatchingCriteria(s => s.id == nextSession.id);
@@ -365,63 +368,84 @@ private void PerformSearch(bool searchUp, bool searchFrames)
365368
}
366369

367370
// Find next node (downwards, wraps around)
368-
private TreeNode FindNextNode(TreeNodeCollection nodes, TreeNode startNode, string searchText, bool wrap)
371+
private TreeNode FindNextNode(TreeNodeCollection nodes, TreeNode startNode, string searchText, bool wrap, bool matchStartNode)
369372
{
370-
bool foundStart = false;
371-
TreeNode firstMatch = null;
372-
foreach (var node in FlattenNodes(nodes))
373+
var allNodes = FlattenNodes(nodes);
374+
int startIndex = 0;
375+
for (int i = 0; i < allNodes.Count; i++)
373376
{
374-
if (node == startNode)
377+
if (allNodes[i] == startNode)
375378
{
376-
foundStart = true;
377-
continue;
379+
startIndex = i;
380+
break;
378381
}
379-
380-
if (GetNodeText(node).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
382+
}
383+
// Search from startNode (inclusive/exclusive) to end
384+
int first = matchStartNode ? startIndex : startIndex + 1;
385+
for (int i = first; i < allNodes.Count; i++)
386+
{
387+
if (GetNodeText(allNodes[i]).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
388+
return allNodes[i];
389+
}
390+
// If wrap is enabled, search from beginning up to startNode (exclusive)
391+
if (wrap)
392+
{
393+
for (int i = 0; i < startIndex; i++)
381394
{
382-
if (foundStart)
383-
return node;
384-
if (firstMatch == null)
385-
firstMatch = node;
395+
if (GetNodeText(allNodes[i]).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
396+
return allNodes[i];
386397
}
387398
}
388-
389-
return wrap ? firstMatch : null;
399+
return null;
390400
}
391401

392402
// Find previous node (upwards, wraps around)
393-
private TreeNode FindPrevNode(TreeNodeCollection nodes, TreeNode startNode, string searchText, bool wrap)
403+
private TreeNode FindPrevNode(TreeNodeCollection nodes, TreeNode startNode, string searchText, bool wrap, bool matchStartNode)
394404
{
395-
TreeNode lastMatch = null;
396-
foreach (var node in FlattenNodes(nodes))
405+
var allNodes = FlattenNodes(nodes);
406+
int startIndex = 0;
407+
for (int i = 0; i < allNodes.Count; i++)
397408
{
398-
if (node == startNode)
409+
if (allNodes[i] == startNode)
410+
{
411+
startIndex = i;
399412
break;
400-
if (GetNodeText(node).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
401-
lastMatch = node;
413+
}
402414
}
403-
404-
if (lastMatch == null && wrap)
415+
// Search backwards from startNode (inclusive/exclusive) to beginning
416+
int first = matchStartNode ? startIndex : startIndex - 1;
417+
for (int i = first; i >= 0; i--)
405418
{
406-
foreach (var node in FlattenNodes(nodes))
419+
if (GetNodeText(allNodes[i]).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
420+
return allNodes[i];
421+
}
422+
// If wrap is enabled, search from end down to startNode (exclusive)
423+
if (wrap)
424+
{
425+
for (int i = allNodes.Count - 1; i > startIndex; i--)
407426
{
408-
if (GetNodeText(node).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
409-
lastMatch = node;
427+
if (GetNodeText(allNodes[i]).IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0)
428+
return allNodes[i];
410429
}
411430
}
412-
413-
return lastMatch;
431+
return null;
414432
}
415433

416-
// Helper: flatten all nodes in tree (preorder)
417-
private System.Collections.Generic.IEnumerable<TreeNode> FlattenNodes(TreeNodeCollection nodes)
434+
// Helper: flatten all nodes in tree (preorder) and return as a list
435+
private System.Collections.Generic.List<TreeNode> FlattenNodes(TreeNodeCollection nodes)
418436
{
419-
foreach (TreeNode node in nodes)
437+
var result = new System.Collections.Generic.List<TreeNode>();
438+
var stack = new System.Collections.Generic.Stack<TreeNode>();
439+
for (int i = nodes.Count - 1; i >= 0; i--)
440+
stack.Push(nodes[i]);
441+
while (stack.Count > 0)
420442
{
421-
yield return node;
422-
foreach (var child in FlattenNodes(node.Nodes))
423-
yield return child;
443+
var node = stack.Pop();
444+
result.Add(node);
445+
for (int i = node.Nodes.Count - 1; i >= 0; i--)
446+
stack.Push(node.Nodes[i]);
424447
}
448+
return result;
425449
}
426450

427451
private void AttachHexBoxKeyboardHandler(Be.Windows.Forms.HexBox hexBox)

MAPIInspector/Source/Parsers/MSOXCFOLD/rops/RopCopyFolderResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ protected override void Parse()
4141
RopId = ParseT<RopIdType>();
4242
SourceHandleIndex = ParseT<byte>();
4343
ReturnValue = ParseT<ErrorCodes>();
44-
//ParseT<ErrorCodes>();
4544
if ((AdditionalErrorCodes)ReturnValue.Data == AdditionalErrorCodes.NullDestinationObject)
4645
{
4746
DestHandleIndex = ParseT<uint>();

MAPIInspector/Source/Parsers/MSOXCFOLD/rops/RopCreateFolderResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ protected override void Parse()
6767
RopId = ParseT<RopIdType>();
6868
OutputHandleIndex = ParseT<byte>();
6969
ReturnValue = ParseT<ErrorCodes>();
70-
7170
if (ReturnValue == ErrorCodes.Success)
7271
{
7372
FolderId = Parse<FolderID>();

MAPIInspector/Source/Parsers/MSOXCROPS/rops/RopTransportSendResponse.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
namespace MAPIInspector.Parsers
55
{
66
/// <summary>
7-
/// [MS-OXCROPS] 2.2.7.6 RopTransportSend
8-
/// A class indicates the RopTransportSend ROP Response Buffer.
7+
/// [MS-OXCROPS] 2.2.7.6.2 RopTransportSend ROP Success Response Buffer
8+
/// [MS-OXCROPS] 2.2.7.6.3 RopTransportSend ROP Failure Response Buffer
9+
/// /// A class indicates the RopTransportSend ROP Response Buffer.
910
/// </summary>
1011
public class RopTransportSendResponse : Block
1112
{
@@ -46,8 +47,7 @@ protected override void Parse()
4647
{
4748
RopId = ParseT<RopIdType>();
4849
InputHandleIndex = ParseT<byte>();
49-
this.AddError(ReturnValue, "ReturnValue");
50-
50+
ReturnValue = ParseT<ErrorCodes>();
5151
if (ReturnValue == ErrorCodes.Success)
5252
{
5353
NoPropertiesReturned = ParseT<byte>();

0 commit comments

Comments
 (0)