Skip to content

Commit f14b7d0

Browse files
committed
Removed MemoryBuffer.Process to reduce coupling.
1 parent dbe005c commit f14b7d0

36 files changed

+111
-114
lines changed

ReClass.NET/Forms/MainForm.Functions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public void ReplaceSelectedNodesWithType(Type type)
310310

311311
node.IsSelected = true;
312312

313-
var info = new MemoryViewControl.SelectedNodeInfo(node, selected.Memory, selected.Address, selected.Level);
313+
var info = new MemoryViewControl.SelectedNodeInfo(node, selected.Process, selected.Memory, selected.Address, selected.Level);
314314

315315
newSelected.Add(info);
316316

@@ -319,7 +319,7 @@ public void ReplaceSelectedNodesWithType(Type type)
319319
{
320320
foreach (var createdNode in createdNodes)
321321
{
322-
hotSpotsToReplace.Enqueue(new MemoryViewControl.SelectedNodeInfo(createdNode, selected.Memory, selected.Address + createdNode.Offset - node.Offset, selected.Level));
322+
hotSpotsToReplace.Enqueue(new MemoryViewControl.SelectedNodeInfo(createdNode, selected.Process, selected.Memory, selected.Address + createdNode.Offset - node.Offset, selected.Level));
323323
}
324324
}
325325
}

ReClass.NET/Forms/MainForm.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ public MainForm()
6262
processInfoToolStripStatusLabel.Text = "No process selected";
6363
};
6464

65-
memoryViewControl.Memory = new MemoryBuffer
66-
{
67-
Process = Program.RemoteProcess
68-
};
65+
memoryViewControl.Process = Program.RemoteProcess;
66+
memoryViewControl.Memory = new MemoryBuffer();
6967

7068
pluginManager = new PluginManager(new DefaultPluginHost(this, Program.RemoteProcess, Program.Logger));
7169
}
@@ -555,7 +553,7 @@ private void dissectNodesToolStripMenuItem_Click(object sender, EventArgs e)
555553

556554
foreach (var g in hexNodes.GroupBy(n => n.Node.GetParentContainer()))
557555
{
558-
NodeDissector.DissectNodes(g.Select(h => (BaseHexNode)h.Node), g.First().Memory);
556+
NodeDissector.DissectNodes(g.Select(h => (BaseHexNode)h.Node), Program.RemoteProcess, g.First().Memory);
559557
}
560558

561559
ClearSelection();

ReClass.NET/Memory/MemoryBuffer.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public class MemoryBuffer
1313

1414
private bool hasHistory;
1515

16-
public RemoteProcess Process { get; set; }
17-
1816
public byte[] RawData => data;
1917

2018
public int Size
@@ -81,19 +79,13 @@ public MemoryBuffer Clone()
8179

8280
return new MemoryBuffer(this)
8381
{
84-
Offset = Offset,
85-
Process = Process
82+
Offset = Offset
8683
};
8784
}
8885

89-
public void Update(IntPtr address)
90-
{
91-
Update(address, true);
92-
}
93-
94-
public void Update(IntPtr address, bool setHistory)
86+
public void UpdateFrom(IRemoteMemoryReader reader, IntPtr address)
9587
{
96-
if (Process == null)
88+
if (reader == null)
9789
{
9890
data.FillWithZero();
9991

@@ -102,14 +94,11 @@ public void Update(IntPtr address, bool setHistory)
10294
return;
10395
}
10496

105-
if (setHistory)
106-
{
107-
Array.Copy(data, historyData, data.Length);
97+
Array.Copy(data, historyData, data.Length);
10898

109-
hasHistory = ContainsValidData;
110-
}
99+
hasHistory = ContainsValidData;
111100

112-
ContainsValidData = Process.ReadRemoteMemoryIntoBuffer(address, ref data);
101+
ContainsValidData = reader.ReadRemoteMemoryIntoBuffer(address, ref data);
113102
if (!ContainsValidData)
114103
{
115104
data.FillWithZero();

ReClass.NET/Memory/NodeDissector.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ namespace ReClassNET.Memory
99
{
1010
public class NodeDissector
1111
{
12-
public static void DissectNodes(IEnumerable<BaseHexNode> nodes, MemoryBuffer memory)
12+
public static void DissectNodes(IEnumerable<BaseHexNode> nodes, IProcessReader reader, MemoryBuffer memory)
1313
{
1414
Contract.Requires(nodes != null);
1515
Contract.Requires(Contract.ForAll(nodes, n => n != null));
1616
Contract.Requires(memory != null);
1717

1818
foreach (var node in nodes)
1919
{
20-
if (GuessNode(node, memory, out var guessedNode))
20+
if (GuessNode(node, reader, memory, out var guessedNode))
2121
{
2222
node.GetParentContainer()?.ReplaceChildNode(node, guessedNode);
2323
}
2424
}
2525
}
2626

27-
public static bool GuessNode(BaseHexNode node, MemoryBuffer memory, out BaseNode guessedNode)
27+
public static bool GuessNode(BaseHexNode node, IProcessReader reader, MemoryBuffer memory, out BaseNode guessedNode)
2828
{
2929
Contract.Requires(node != null);
3030
Contract.Requires(memory != null);
@@ -61,13 +61,13 @@ public static bool GuessNode(BaseHexNode node, MemoryBuffer memory, out BaseNode
6161
#if RECLASSNET64
6262
if (is8ByteAligned)
6363
{
64-
if (GuessPointerNode(data64.IntPtr, memory.Process, out guessedNode))
64+
if (GuessPointerNode(data64.IntPtr, reader, out guessedNode))
6565
{
6666
return true;
6767
}
6868
}
6969
#else
70-
if (GuessPointerNode(data32.IntPtr, memory.Process, out guessedNode))
70+
if (GuessPointerNode(data32.IntPtr, reader, out guessedNode))
7171
{
7272
return true;
7373
}

ReClass.NET/Nodes/BaseFunctionNode.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ protected Size DrawInstructions(ViewInfo view, int tx, int y)
5454
return new Size(maxWidth, y - origY);
5555
}
5656

57-
protected void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address, out int memorySize)
57+
protected void DisassembleRemoteCode(RemoteProcess process, IntPtr address, out int memorySize)
5858
{
59-
Contract.Requires(memory != null);
59+
Contract.Requires(process != null);
6060

6161
memorySize = 0;
6262

63-
var disassembler = new Disassembler(memory.Process.CoreFunctions);
64-
foreach (var instruction in disassembler.RemoteDisassembleFunction(memory.Process, address, 8192))
63+
var disassembler = new Disassembler(process.CoreFunctions);
64+
foreach (var instruction in disassembler.RemoteDisassembleFunction(process, address, 8192))
6565
{
6666
memorySize += instruction.Length;
6767

ReClass.NET/Nodes/BaseFunctionPtrNode.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public abstract class BaseFunctionPtrNode : BaseFunctionNode
1313
{
1414
public override int MemorySize => IntPtr.Size;
1515

16-
public override string GetToolTipText(HotSpot spot, MemoryBuffer memory)
16+
public override string GetToolTipText(HotSpot spot)
1717
{
18-
var ptr = memory.ReadIntPtr(Offset);
18+
var ptr = spot.Memory.ReadIntPtr(Offset);
1919

20-
DisassembleRemoteCode(memory, ptr);
20+
DisassembleRemoteCode(spot.Process, ptr);
2121

2222
return string.Join("\n", instructions.Select(i => i.Instruction));
2323
}
@@ -59,10 +59,10 @@ protected Size Draw(ViewInfo view, int x, int y, string type, string name)
5959
{
6060
var value = view.Memory.ReadIntPtr(Offset);
6161

62-
var module = view.Memory.Process.GetModuleToPointer(value);
62+
var module = view.Process.GetModuleToPointer(value);
6363
if (module != null)
6464
{
65-
var symbols = view.Memory.Process.Symbols.GetSymbolsForModule(module);
65+
var symbols = view.Process.Symbols.GetSymbolsForModule(module);
6666
var symbol = symbols?.GetSymbolString(value, module);
6767
if (!string.IsNullOrEmpty(symbol))
6868
{
@@ -81,7 +81,7 @@ protected Size Draw(ViewInfo view, int x, int y, string type, string name)
8181
{
8282
var ptr = view.Memory.ReadIntPtr(Offset);
8383

84-
DisassembleRemoteCode(view.Memory, ptr);
84+
DisassembleRemoteCode(view.Process, ptr);
8585

8686
var instructionSize = DrawInstructions(view, tx, y);
8787

@@ -107,19 +107,19 @@ public override int CalculateDrawnHeight(ViewInfo view)
107107
return height;
108108
}
109109

110-
private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
110+
private void DisassembleRemoteCode(RemoteProcess process, IntPtr address)
111111
{
112-
Contract.Requires(memory != null);
112+
Contract.Requires(process != null);
113113

114114
if (this.address != address)
115115
{
116116
instructions.Clear();
117117

118118
this.address = address;
119119

120-
if (!address.IsNull() && memory.Process.IsValid)
120+
if (!address.IsNull() && process.IsValid)
121121
{
122-
DisassembleRemoteCode(memory, address, out _);
122+
DisassembleRemoteCode(process, address, out _);
123123
}
124124
}
125125
}

ReClass.NET/Nodes/BaseHexCommentNode.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected int AddComment(ViewInfo view, int x, int y, float fvalue, IntPtr ivalu
3030
}
3131
}
3232

33-
var namedAddress = view.Memory.Process.GetNamedAddress(ivalue);
33+
var namedAddress = view.Process.GetNamedAddress(ivalue);
3434
if (!string.IsNullOrEmpty(namedAddress))
3535
{
3636
if (view.Settings.ShowCommentPointer)
@@ -41,7 +41,7 @@ protected int AddComment(ViewInfo view, int x, int y, float fvalue, IntPtr ivalu
4141

4242
if (view.Settings.ShowCommentRtti)
4343
{
44-
var rtti = view.Memory.Process.ReadRemoteRuntimeTypeInformation(ivalue);
44+
var rtti = view.Process.ReadRemoteRuntimeTypeInformation(ivalue);
4545
if (!string.IsNullOrEmpty(rtti))
4646
{
4747
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, rtti) + view.Font.Width;
@@ -50,10 +50,10 @@ protected int AddComment(ViewInfo view, int x, int y, float fvalue, IntPtr ivalu
5050

5151
if (view.Settings.ShowCommentSymbol)
5252
{
53-
var module = view.Memory.Process.GetModuleToPointer(ivalue);
53+
var module = view.Process.GetModuleToPointer(ivalue);
5454
if (module != null)
5555
{
56-
var symbols = view.Memory.Process.Symbols.GetSymbolsForModule(module);
56+
var symbols = view.Process.Symbols.GetSymbolsForModule(module);
5757
var symbol = symbols?.GetSymbolString(ivalue, module);
5858
if (!string.IsNullOrEmpty(symbol))
5959
{
@@ -64,7 +64,7 @@ protected int AddComment(ViewInfo view, int x, int y, float fvalue, IntPtr ivalu
6464

6565
if (view.Settings.ShowCommentString)
6666
{
67-
var data = view.Memory.Process.ReadRemoteMemory(ivalue, 64);
67+
var data = view.Process.ReadRemoteMemory(ivalue, 64);
6868

6969
// First check if it could be an UTF8 string and if not try UTF16.
7070
if (data.Take(IntPtr.Size).InterpretAsSingleByteCharacter().IsPrintableData())

ReClass.NET/Nodes/BaseHexNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void Update(HotSpot spot, int maxId)
113113
{
114114
if (byte.TryParse(spot.Text, NumberStyles.HexNumber, null, out var val))
115115
{
116-
spot.Memory.Process.WriteRemoteMemory(spot.Address + spot.Id, val);
116+
spot.Process.WriteRemoteMemory(spot.Address + spot.Id, val);
117117
}
118118
}
119119
}

ReClass.NET/Nodes/BaseMatrixNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void Update(HotSpot spot, int max)
136136
{
137137
if (float.TryParse(spot.Text, out var val))
138138
{
139-
spot.Memory.Process.WriteRemoteMemory(spot.Address + spot.Id * ValueTypeSize, val);
139+
spot.Process.WriteRemoteMemory(spot.Address + spot.Id * ValueTypeSize, val);
140140
}
141141
}
142142
}

ReClass.NET/Nodes/BaseNode.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ protected BaseNode()
106106

107107
public abstract void GetUserInterfaceInfo(out string name, out Image icon);
108108

109-
public virtual bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, out IntPtr address)
109+
public virtual bool UseMemoryPreviewToolTip(HotSpot spot, out IntPtr address)
110110
{
111111
Contract.Requires(spot != null);
112-
Contract.Requires(memory != null);
113112

114113
address = IntPtr.Zero;
115114

@@ -118,12 +117,10 @@ public virtual bool UseMemoryPreviewToolTip(HotSpot spot, MemoryBuffer memory, o
118117

119118
/// <summary>Gets informations about this node to show in a tool tip.</summary>
120119
/// <param name="spot">The spot.</param>
121-
/// <param name="memory">The process memory.</param>
122120
/// <returns>The information to show in a tool tip or null if no information should be shown.</returns>
123-
public virtual string GetToolTipText(HotSpot spot, MemoryBuffer memory)
121+
public virtual string GetToolTipText(HotSpot spot)
124122
{
125123
Contract.Requires(spot != null);
126-
Contract.Requires(memory != null);
127124

128125
return null;
129126
}
@@ -297,6 +294,7 @@ protected void AddHotSpot(ViewInfo view, Rectangle spot, string text, int id, Ho
297294
Type = type,
298295
Node = this,
299296
Level = view.Level,
297+
Process = view.Process,
300298
Memory = view.Memory
301299
});
302300
}

0 commit comments

Comments
 (0)