-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathBaseHexCommentNode.cs
More file actions
114 lines (101 loc) · 3.58 KB
/
BaseHexCommentNode.cs
File metadata and controls
114 lines (101 loc) · 3.58 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
using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.UI;
namespace ReClassNET.Nodes
{
public abstract class BaseHexCommentNode : BaseHexNode
{
protected int AddComment(DrawContext view, int x, int y, float fvalue, IntPtr ivalue, UIntPtr uvalue)
{
Contract.Requires(view != null);
if (view.Settings.ShowCommentFloat)
{
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.ReadOnlyId, fvalue > -999999.0f && fvalue < 999999.0f ? fvalue.ToString("0.000") : "#####") + view.Font.Width;
}
if (view.Settings.ShowCommentInteger)
{
if (ivalue == IntPtr.Zero)
{
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.ReadOnlyId, "0") + view.Font.Width;
}
else
{
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.ReadOnlyId, ivalue.ToInt64().ToString()) + view.Font.Width;
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.ReadOnlyId, $"0x{uvalue.ToUInt64():X}") + view.Font.Width;
}
}
if (ivalue != IntPtr.Zero)
{
var namedAddress = view.Process.GetNamedAddress(ivalue);
if (!string.IsNullOrEmpty(namedAddress))
{
if (view.Settings.ShowCommentPointer)
{
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.NoneId, "->") + view.Font.Width;
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, namedAddress) + view.Font.Width;
}
if (view.Settings.ShowCommentRtti)
{
var rtti = view.Process.ReadRemoteRuntimeTypeInformation(ivalue);
if (!string.IsNullOrEmpty(rtti))
{
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, rtti) + view.Font.Width;
}
}
if (view.Settings.ShowCommentSymbol)
{
var module = view.Process.GetModuleToPointer(ivalue);
if (module != null)
{
var symbols = view.Process.Symbols.GetSymbolsForModule(module);
var symbol = symbols?.GetSymbolString(ivalue, module);
if (!string.IsNullOrEmpty(symbol))
{
x = AddText(view, x, y, view.Settings.OffsetColor, HotSpot.ReadOnlyId, symbol) + view.Font.Width;
}
}
}
if (view.Settings.ShowCommentString)
{
var data = view.Process.ReadRemoteMemory(ivalue, 64);
var isWideString = false;
string text = null;
// First check if it could be an UTF8 string and if not try UTF16.
if (data.Take(IntPtr.Size).InterpretAsSingleByteCharacter().IsPrintableData())
{
text = new string(Encoding.UTF8.GetChars(data).TakeWhile(c => c != 0).ToArray());
}
else if (data.Take(IntPtr.Size * 2).InterpretAsDoubleByteCharacter().IsPrintableData())
{
isWideString = true;
text = new string(Encoding.Unicode.GetChars(data).TakeWhile(c => c != 0).ToArray());
}
if (text != null)
{
x = AddText(view, x, y, view.Settings.TextColor, HotSpot.NoneId, isWideString ? "L'" : "'");
x = AddText(view, x, y, view.Settings.TextColor, HotSpot.ReadOnlyId, text);
x = AddText(view, x, y, view.Settings.TextColor, HotSpot.NoneId, "'") + view.Font.Width;
}
}
if (view.Settings.ShowCommentPluginInfo)
{
var nodeAddress = view.Address + Offset;
foreach (var reader in NodeInfoReader)
{
var info = reader.ReadNodeInfo(this, view.Process, view.Memory, nodeAddress, ivalue);
if (info != null)
{
x = AddText(view, x, y, view.Settings.PluginColor, HotSpot.ReadOnlyId, info) + view.Font.Width;
}
}
}
}
}
return x;
}
}
}