Skip to content

Commit d07a431

Browse files
committed
Fixed issue #6.
1 parent 917e7f4 commit d07a431

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

UI/MemoryViewControl.cs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,12 @@ protected override void OnMouseClick(MouseEventArgs e)
276276
foreach (var spot in containerNode.Nodes
277277
.SkipWhile(n => n != first.Node)
278278
.TakeUntil(n => n == last.Node)
279-
.Select(n => new HotSpot { Address = containerNode.Offset.Add(n.Offset), Node = n }))
279+
.Select(n => new HotSpot
280+
{
281+
Address = containerNode.Offset.Add(n.Offset),
282+
Node = n,
283+
Memory = first.Memory
284+
}))
280285
{
281286
spot.Node.IsSelected = true;
282287
selectedNodes.Add(spot);
@@ -404,7 +409,7 @@ protected override void OnMouseHover(EventArgs e)
404409
{
405410
if (spot.Rect.Contains(toolTipPosition))
406411
{
407-
var text = spot.Node.GetToolTipText(spot, Memory);
412+
var text = spot.Node.GetToolTipText(spot, spot.Memory);
408413
if (!string.IsNullOrEmpty(text))
409414
{
410415
toolTip.Show(text, this, toolTipPosition.OffsetEx(16, 16));
@@ -511,7 +516,12 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
511516
foreach (var spot in containerNode.Nodes
512517
.SkipWhile(n => n != first.Node)
513518
.TakeUntil(n => n == last.Node)
514-
.Select(n => new HotSpot { Address = containerNode.Offset.Add(n.Offset), Node = n }))
519+
.Select(n => new HotSpot
520+
{
521+
Address = containerNode.Offset.Add(n.Offset),
522+
Node = n,
523+
Memory = toSelect.Memory
524+
}))
515525
{
516526
spot.Node.IsSelected = true;
517527
selectedNodes.Add(spot);
@@ -692,7 +702,10 @@ private void dissectNodesToolStripMenuItem_Click(object sender, EventArgs e)
692702
var hexNodes = selectedNodes.Where(h => h.Node is BaseHexNode);
693703
if (hexNodes.Any())
694704
{
695-
NodeDissector.DissectNodes(hexNodes.Select(h => (BaseHexNode)h.Node), Memory);
705+
foreach (var g in hexNodes.GroupBy(n => n.Node.ParentNode))
706+
{
707+
NodeDissector.DissectNodes(g.Select(h => (BaseHexNode)h.Node), g.First().Memory);
708+
}
696709

697710
ClearSelection();
698711
}
@@ -764,11 +777,17 @@ private static IEnumerable<List<HotSpot>> PartitionSelectedNodes(IEnumerable<Hot
764777
}
765778
}
766779

767-
private static IEnumerable<HotSpot> RecursiveReplaceNodes(BaseContainerNode parentNode, Type type, IEnumerable<BaseNode> nodesToReplace)
780+
/// <summary>Recursive replace all splitted nodes.</summary>
781+
/// <param name="parentNode">The parent node.</param>
782+
/// <param name="type">The node type.</param>
783+
/// <param name="nodesToReplace">The nodes to replace.</param>
784+
/// <returns>The new nodes.</returns>
785+
private static IEnumerable<BaseNode> RecursiveReplaceNodes(BaseContainerNode parentNode, Type type, IEnumerable<BaseNode> nodesToReplace)
768786
{
769787
Contract.Requires(parentNode != null);
770788
Contract.Requires(type != null);
771789
Contract.Requires(nodesToReplace != null);
790+
Contract.Ensures(Contract.Result<IEnumerable<HotSpot>>() != null);
772791

773792
foreach (var nodeToReplace in nodesToReplace)
774793
{
@@ -779,17 +798,13 @@ private static IEnumerable<HotSpot> RecursiveReplaceNodes(BaseContainerNode pare
779798

780799
node.IsSelected = true;
781800

782-
yield return new HotSpot
783-
{
784-
Address = node.ParentNode.Offset.Add(node.Offset),
785-
Node = node
786-
};
801+
yield return node;
787802

788803
if (temp.Count > 1)
789804
{
790-
foreach (var hs in RecursiveReplaceNodes(parentNode, type, temp))
805+
foreach (var n in RecursiveReplaceNodes(parentNode, type, temp.Skip(1)))
791806
{
792-
yield return hs;
807+
yield return n;
793808
}
794809
}
795810
}
@@ -817,6 +832,7 @@ public void ReplaceSelectedNodesWithType(Type type)
817832

818833
var hotspot = new HotSpot
819834
{
835+
Memory = selected.Memory,
820836
Address = node.ParentNode.Offset.Add(node.Offset),
821837
Node = node
822838
};
@@ -835,7 +851,15 @@ public void ReplaceSelectedNodesWithType(Type type)
835851
// If the block contains more than one node and the replaced node decomposed to more than one node replace the new nodes to.
836852
if (selectedPartition.Count > 1 && createdNodes.Count > 1)
837853
{
838-
newSelected.AddRange(RecursiveReplaceNodes(selected.Node.ParentNode, type, createdNodes.Skip(1)));
854+
newSelected.AddRange(
855+
RecursiveReplaceNodes(selected.Node.ParentNode, type, createdNodes.Skip(1))
856+
.Select(n => new HotSpot
857+
{
858+
Memory = selected.Memory,
859+
Address = n.ParentNode.Offset.Add(n.Offset),
860+
Node = n
861+
})
862+
);
839863
}
840864
}
841865
}

0 commit comments

Comments
 (0)