-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathFunctionNode.cs
More file actions
141 lines (108 loc) · 3.65 KB
/
FunctionNode.cs
File metadata and controls
141 lines (108 loc) · 3.65 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
using System;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public class FunctionNode : BaseFunctionNode
{
public string Signature { get; set; } = "void function()";
public ClassNode BelongsToClass { get; set; }
private int memorySize = IntPtr.Size;
public override int MemorySize => memorySize;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "Function";
icon = Properties.Resources.B16x16_Button_Function;
}
public override string GetToolTipText(HotSpot spot)
{
DisassembleRemoteCode(spot.Process, spot.Address);
return string.Join("\n", Instructions.Select(i => i.Instruction));
}
public override Size Draw(DrawContext context, int x, int y)
{
Contract.Requires(context != null);
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var origX = x;
AddSelection(context, x, y, context.Font.Height);
x = AddIconPadding(context, x);
x = AddIcon(context, x, y, context.IconProvider.Function, HotSpot.NoneId, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "Function") + context.Font.Width;
if (!IsWrapped)
{
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
}
x = AddOpenCloseIcon(context, x, y) + context.Font.Width;
x = AddComment(context, x, y);
DrawInvalidMemoryIndicatorIcon(context, y);
AddContextDropDownIcon(context, y);
AddDeleteIcon(context, y);
var size = new Size(x - origX, context.Font.Height);
var ptr = context.Address + Offset;
DisassembleRemoteCode(context.Process, ptr);
if (LevelsOpen[context.Level])
{
y += context.Font.Height;
x = AddText(context, tx, y, context.Settings.TypeColor, HotSpot.NoneId, "Signature:") + context.Font.Width;
x = AddText(context, x, y, context.Settings.ValueColor, 0, Signature);
size.Width = Math.Max(size.Width, x - origX);
size.Height += context.Font.Height;
y += context.Font.Height;
x = AddText(context, tx, y, context.Settings.TextColor, HotSpot.NoneId, "Belongs to: ");
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.NoneId, BelongsToClass == null ? "<None>" : $"<{BelongsToClass.Name}>") + context.Font.Width;
x = AddIcon(context, x, y, context.IconProvider.Change, 1, HotSpotType.ChangeClassType);
size.Width = Math.Max(size.Width, x - origX);
size.Height += context.Font.Height;
var instructionSize = DrawInstructions(context, tx, y + 4);
size.Width = Math.Max(size.Width, instructionSize.Width + tx - origX);
size.Height += instructionSize.Height + 4;
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var height = context.Font.Height;
if (LevelsOpen[context.Level])
{
height += Instructions.Count * context.Font.Height;
}
return height;
}
public override void Update(HotSpot spot)
{
base.Update(spot);
if (spot.Id == 0) // Signature
{
Signature = spot.Text;
}
}
private void DisassembleRemoteCode(RemoteProcess process, IntPtr address)
{
Contract.Requires(process != null);
if (this.Address != address)
{
Instructions.Clear();
this.Address = address;
if (!address.IsNull() && process.IsValid)
{
DisassembleRemoteCode(process, address, out memorySize);
}
GetParentContainer()?.ChildHasChanged(this);
}
}
}
}