forked from PeaceBeUponYou/ReClass.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualMethodTableNode.cs
More file actions
150 lines (126 loc) · 3.69 KB
/
Copy pathVirtualMethodTableNode.cs
File metadata and controls
150 lines (126 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public class VirtualMethodTableNode : BaseContainerNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
private bool bAutoGuess = false;
private const int MaxVTableSize = 2000;
public override int MemorySize => IntPtr.Size;
protected override bool ShouldCompensateSizeChanges => false;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "VTable Pointer";
icon = Properties.Resources.B16x16_Button_VTable;
}
public override bool CanHandleChildNode(BaseNode node)
{
return node is VirtualMethodNode && bChildNodeChangeAllowed;
}
public override void Initialize()
{
for (var i = 0; i < 10; ++i)
{
AddNode(CreateDefaultNodeForSize(IntPtr.Size));
}
}
private void AutoGuessVTableSize(DrawContext context)
{
if (!Program.RemoteProcess.IsValid)
return;
bAutoGuess = true;
var reader = Program.RemoteProcess;
var mainvt = reader.ReadRemoteIntPtr(context.Address);
var p = reader.ReadRemoteIntPtr(mainvt);
if (p == IntPtr.Zero) return;
var module = reader.GetModuleToPointer(p); //Only applicable for precompiled binaries
int tableSize = 0;
if (module != null)
{
for (tableSize = 0; tableSize < MaxVTableSize; ++tableSize)
{
p = reader.ReadRemoteIntPtr(mainvt.Add(new IntPtr( tableSize * IntPtr.Size )));
if (reader.GetModuleToPointer(p) != module)
break;
}
}
if (tableSize > Nodes.Count)
{
ClearNodes();
for (var i = 0; i < tableSize; ++i)
{
AddNode(CreateDefaultNodeForSize(IntPtr.Size));
}
}
}
public override Size Draw(DrawContext context, int x, int y)
{
if (!bAutoGuess)
AutoGuessVTableSize(context);
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var origX = x;
var origY = y;
AddSelection(context, x, y, context.Font.Height);
x = AddOpenCloseIcon(context, x, y);
x = AddIcon(context, x, y, context.IconProvider.VirtualTable, HotSpot.NoneId, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
x = AddText(context, x, y, context.Settings.VTableColor, HotSpot.NoneId, $"VTable[{Nodes.Count}]") + context.Font.Width;
if (!IsWrapped)
{
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
}
x = AddComment(context, x, y);
DrawInvalidMemoryIndicatorIcon(context, y);
AddContextDropDownIcon(context, y);
AddDeleteIcon(context, y);
y += context.Font.Height;
var size = new Size(x - origX, y - origY);
if (LevelsOpen[context.Level])
{
var ptr = context.Memory.ReadIntPtr(Offset);
memory.Size = Nodes.Count * IntPtr.Size;
memory.UpdateFrom(context.Process, ptr);
var innerContext = context.Clone();
innerContext.Address = ptr;
innerContext.Memory = memory;
foreach (var node in Nodes)
{
var innerSize = node.Draw(innerContext, tx, y);
size.Width = Math.Max(size.Width, innerSize.Width + tx - origX);
size.Height += innerSize.Height;
y += innerSize.Height;
}
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var height = context.Font.Height;
if (LevelsOpen[context.Level])
{
height += Nodes.Sum(n => n.CalculateDrawnHeight(context));
}
return height;
}
protected override BaseNode CreateDefaultNodeForSize(int size)
{
// ignore the size parameter
return new VirtualMethodNode();
}
}
}