Skip to content

Commit 64cffb9

Browse files
committed
Improved instruction rendering.
1 parent 797f855 commit 64cffb9

File tree

4 files changed

+85
-41
lines changed

4 files changed

+85
-41
lines changed

Nodes/BaseFunctionNode.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.Contracts;
4+
using System.Drawing;
5+
using System.Linq;
6+
using ReClassNET.Memory;
7+
using ReClassNET.UI;
8+
using ReClassNET.Util;
9+
10+
namespace ReClassNET.Nodes
11+
{
12+
public abstract class BaseFunctionNode : BaseNode
13+
{
14+
protected class FunctionNodeInstruction
15+
{
16+
public string Address;
17+
public string Data;
18+
public string Instruction;
19+
}
20+
21+
protected IntPtr address = IntPtr.Zero;
22+
protected readonly List<FunctionNodeInstruction> instructions = new List<FunctionNodeInstruction>();
23+
24+
protected int DrawInstructions(ViewInfo view, int tx, int y)
25+
{
26+
Contract.Requires(view != null);
27+
28+
var minWidth = 26 * view.Font.Width;
29+
30+
foreach (var instruction in instructions)
31+
{
32+
y += view.Font.Height;
33+
34+
using (var brush = new SolidBrush(view.Settings.HiddenColor))
35+
{
36+
var x = AddText(view, tx, y, view.Settings.AddressColor, HotSpot.ReadOnlyId, instruction.Address) + 6;
37+
38+
view.Context.FillRectangle(brush, x, y, 1, view.Font.Height);
39+
x += 6;
40+
41+
x = Math.Max(AddText(view, x, y, view.Settings.HexColor, HotSpot.ReadOnlyId, instruction.Data) + 6, x + minWidth);
42+
43+
view.Context.FillRectangle(brush, x, y, 1, view.Font.Height);
44+
x += 6;
45+
46+
AddText(view, x, y, view.Settings.ValueColor, HotSpot.ReadOnlyId, instruction.Instruction);
47+
}
48+
}
49+
50+
return y;
51+
}
52+
53+
protected void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address, out int memorySize)
54+
{
55+
Contract.Requires(memory != null);
56+
57+
memorySize = 0;
58+
59+
var disassembler = new Disassembler(memory.Process.CoreFunctions);
60+
foreach (var instruction in disassembler.RemoteDisassembleFunction(memory.Process, address, 8192))
61+
{
62+
memorySize += instruction.Length;
63+
64+
instructions.Add(new FunctionNodeInstruction
65+
{
66+
Address = instruction.Address.ToString(Constants.StringHexFormat),
67+
Data = string.Join(" ", instruction.Data.Take(instruction.Length).Select(b => $"{b:X2}")),
68+
Instruction = instruction.Instruction
69+
});
70+
}
71+
}
72+
}
73+
}

Nodes/BaseFunctionPtrNode.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics.Contracts;
43
using System.Linq;
54
using ReClassNET.Memory;
@@ -8,11 +7,8 @@
87

98
namespace ReClassNET.Nodes
109
{
11-
public abstract class BaseFunctionPtrNode : BaseNode
10+
public abstract class BaseFunctionPtrNode : BaseFunctionNode
1211
{
13-
private IntPtr address = IntPtr.Zero;
14-
private readonly List<string> instructions = new List<string>();
15-
1612
/// <summary>Size of the node in bytes.</summary>
1713
public override int MemorySize => IntPtr.Size;
1814

@@ -22,7 +18,7 @@ public override string GetToolTipText(HotSpot spot, MemoryBuffer memory)
2218

2319
DisassembleRemoteCode(memory, ptr);
2420

25-
return string.Join("\n", instructions);
21+
return string.Join("\n", instructions.Select(i => i.Instruction));
2622
}
2723

2824
protected int Draw(ViewInfo view, int x, int y, string type, string name)
@@ -80,12 +76,7 @@ protected int Draw(ViewInfo view, int x, int y, string type, string name)
8076

8177
DisassembleRemoteCode(view.Memory, ptr);
8278

83-
foreach (var line in instructions)
84-
{
85-
y += view.Font.Height;
86-
87-
AddText(view, tx, y, view.Settings.NameColor, HotSpot.ReadOnlyId, line);
88-
}
79+
y = DrawInstructions(view, tx, y);
8980
}
9081

9182
return y + view.Font.Height;
@@ -118,11 +109,8 @@ private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
118109

119110
if (!address.IsNull() && memory.Process.IsValid)
120111
{
121-
var disassembler = new Disassembler(memory.Process.CoreFunctions);
122-
instructions.AddRange(
123-
disassembler.RemoteDisassembleFunction(memory.Process, address, 200)
124-
.Select(i => $"{i.Address.ToString(Constants.StringHexFormat)} {i.Instruction}")
125-
);
112+
int unused;
113+
DisassembleRemoteCode(memory, address, out unused);
126114
}
127115
}
128116
}

Nodes/FunctionNode.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics.Contracts;
43
using System.Linq;
54
using ReClassNET.Memory;
@@ -8,11 +7,8 @@
87

98
namespace ReClassNET.Nodes
109
{
11-
public class FunctionNode : BaseNode
10+
public class FunctionNode : BaseFunctionNode
1211
{
13-
private IntPtr address = IntPtr.Zero;
14-
private readonly List<string> instructions = new List<string>();
15-
1612
public string Signature { get; set; } = "void function()";
1713

1814
public ClassNode BelongsToClass { get; set; }
@@ -25,7 +21,7 @@ public override string GetToolTipText(HotSpot spot, MemoryBuffer memory)
2521
{
2622
DisassembleRemoteCode(memory, spot.Address);
2723

28-
return string.Join("\n", instructions);
24+
return string.Join("\n", instructions.Select(i => i.Instruction));
2925
}
3026

3127
public override int Draw(ViewInfo view, int x, int y)
@@ -71,13 +67,7 @@ public override int Draw(ViewInfo view, int x, int y)
7167
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, BelongsToClass == null ? "<None>" : $"<{BelongsToClass.Name}>");
7268
x = AddIcon(view, x, y, Icons.Change, 1, HotSpotType.ChangeType);
7369

74-
y += view.Font.Height;
75-
foreach (var line in instructions)
76-
{
77-
y += view.Font.Height;
78-
79-
AddText(view, tx, y, view.Settings.NameColor, HotSpot.ReadOnlyId, line);
80-
}
70+
y = DrawInstructions(view, tx, y + 4) + 4;
8171
}
8272

8373
return y + view.Font.Height;
@@ -120,18 +110,10 @@ private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address)
120110

121111
if (!address.IsNull() && memory.Process.IsValid)
122112
{
123-
memorySize = 0;
124-
125-
var disassembler = new Disassembler(memory.Process.CoreFunctions);
126-
foreach (var instruction in disassembler.RemoteDisassembleFunction(memory.Process, address, 8192))
127-
{
128-
memorySize += instruction.Length;
129-
130-
instructions.Add($"{instruction.Address.ToString(Constants.StringHexFormat)} {instruction.Instruction}");
131-
}
132-
133-
ParentNode?.ChildHasChanged(this);
113+
DisassembleRemoteCode(memory, address, out memorySize);
134114
}
115+
116+
ParentNode?.ChildHasChanged(this);
135117
}
136118
}
137119
}

ReClass.NET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<Compile Include="Native\INativeMethods.cs" />
182182
<Compile Include="Native\NativeMethods.Unix.cs" />
183183
<Compile Include="Native\NativeMethods.Windows.cs" />
184+
<Compile Include="Nodes\BaseFunctionNode.cs" />
184185
<Compile Include="Nodes\BoolNode.cs" />
185186
<Compile Include="Nodes\ClassUtil.cs" />
186187
<Compile Include="Nodes\FunctionNode.cs" />

0 commit comments

Comments
 (0)