-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashLookupPluginExt.cs
More file actions
381 lines (320 loc) · 13.5 KB
/
HashLookupPluginExt.cs
File metadata and controls
381 lines (320 loc) · 13.5 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
using ReClassNET.Plugins;
using ReClassNET.Logger;
using ReClassNET.Nodes;
using ReClassNET.Memory;
using System;
using HashLookupPlugin;
using System.Diagnostics.Contracts;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
using ReClassNET.Controls;
using ReClassNET.UI;
using ReClassNET.Extensions;
using System.Xml.Linq;
using System.Diagnostics;
using ReClassNET.DataExchange.ReClass;
using System.Runtime.Remoting.Contexts;
using System.Linq;
using System.Security.Policy;
using System.Data.OleDb;
using System.Threading;
using ReClassNET.Forms;
using ReClassNET;
namespace HashLookupPlugin
{
public class HashLookupPluginExt : Plugin
{
private IPluginHost host;
public static Dictionary<ulong, string> Hashes;
public static bool useComments = true;
static HashLookupPluginExt()
{
Hashes = HashDictionary.Hashes;
System.Diagnostics.Debug.WriteLine("Loaded plugin.");
}
public override bool Initialize(IPluginHost host)
{
this.host = host;
// Notfiy the plugin if a window is shown.
GlobalWindowManager.WindowAdded += OnWindowAdded;
return true;
}
public override void Terminate()
{
GlobalWindowManager.WindowAdded -= OnWindowAdded;
host = null;
}
// <ParentNode, <oldNode, newNode>>
public override Image Icon => Properties.Resources.logo_hash1;
public override CustomNodeTypes GetCustomNodeTypes()
{
return new CustomNodeTypes
{
CodeGenerator = new StringHashCodeGenerator(),
Serializer = new StringHashNodeConverter(),
NodeTypes = new[] { typeof(StringHashNode) }
};
}
public override IReadOnlyList<INodeInfoReader> GetNodeInfoReaders()
{
return new[] { new NodeInfoReader() };
}
private void OnWindowAdded(object sender, GlobalWindowManagerEventArgs e)
{
if (e.Form is SettingsForm settingsForm)
{
settingsForm.Shown += delegate (object sender2, EventArgs e2)
{
try
{
var settingsTabControl = settingsForm.Controls.Find("settingsTabControl", true).FirstOrDefault() as TabControl;
if (settingsTabControl != null)
{
var newTab = new TabPage("Symbol parser")
{
UseVisualStyleBackColor = true
};
var checkBox = new CheckBox
{
AutoSize = true,
Text = "Use comments",
AutoCheck = true,
Checked = useComments
};
checkBox.CheckedChanged += delegate { useComments = checkBox.Checked; };
newTab.Controls.Add(checkBox);
settingsTabControl.TabPages.Add(newTab);
}
}
catch
{
}
};
}
}
}
public class NodeInfoReader : INodeInfoReader
{
private Dictionary<BaseContainerNode, Dictionary<BaseNode, BaseNode>> toReplace = new Dictionary<BaseContainerNode, Dictionary<BaseNode, BaseNode>>();
private BaseContainerNode lastParent;
public void addToReplace(BaseNode oldNode, BaseNode newNode, BaseContainerNode parentNode)
{
//newNode.CopyFromNode(oldNode);
if (toReplace.TryGetValue(parentNode, out Dictionary<BaseNode, BaseNode> nodesToReplace))
{
if (nodesToReplace.ContainsKey(oldNode))
return;
nodesToReplace.Add(oldNode, newNode);
}
else
{
Debug.WriteLine($"Creating new parent dictionary under {parentNode.Name}");
Dictionary<BaseNode, BaseNode> nodesToReplace2 = new Dictionary<BaseNode, BaseNode>();
nodesToReplace2.Add(oldNode, newNode);
toReplace.Add(parentNode, nodesToReplace2);
}
Debug.WriteLine($"{oldNode.Offset} | Buffered node {oldNode.Name}({oldNode.GetType().ToString()}) to be swapped with node {newNode.Name}({newNode.GetType().ToString()}) under {parentNode.Name}");
}
public bool swapNode(BaseNode oldNode, BaseNode newNode, BaseContainerNode parentNode)
{
if (!parentNode.Nodes.Contains(oldNode))
{
Debug.WriteLine($"Node {oldNode.Name} not found in {parentNode.Name}");
return false;
}
Debug.WriteLine($"{oldNode.Offset} | Swapping {newNode.Name} with {oldNode.Name} in {parentNode.Name}");
parentNode.InsertNode(oldNode, newNode);
if (!parentNode.RemoveNode(oldNode))
{
Debug.WriteLine($"{oldNode.Offset} | Failed to remove node {oldNode.Name}");
return false;
}
//parentNode.UpdateOffsets();
return true;
}
public string ReadNodeInfo(BaseHexCommentNode node, IRemoteMemoryReader reader, MemoryBuffer memory, IntPtr nodeAddress, IntPtr nodeValue)
{
var parNode = node.GetParentContainer();
if (parNode == null || lastParent == parNode)
return "";
//Debug.WriteLine($"Parent class: {parNode.Name} | Parent container: {node.GetParentContainer().Name}");
if (toReplace.Count > 0)
{
for (int i = 0; i < toReplace.Count; i++)
{
var item = toReplace.ElementAt(i);
if (item.Key != parNode)
{
foreach (var item1 in item.Value)
{
//if (parNode.Nodes[parNode.FindNodeIndex(item1.Key)].IsHidden)
if (item.Key.Nodes.Contains(item1.Key))
{
if (swapNode(item1.Key, item1.Value, item.Key))
Debug.WriteLine($"Node {item1.Key.Name} swapped successfully");
else
Debug.WriteLine($"Failed to swap node {item1.Key.Name}");
}
else
{
item.Value.Remove(item1.Key);
break;
}
}
if (item.Value.Count == 0)
if (!toReplace.Remove(item.Key))
Debug.WriteLine($"Failed to remove parent node \"{item.Key.Name}\" with {item.Value.Count} children");
else
Debug.WriteLine($"Successfully removed parent node \"{item.Key.Name}\"");
}
}
}
for (int i = 0; i < parNode.Nodes.Count; i++)
{
var item = parNode.Nodes[i];
var typee = item.GetType();
//if (typee != typeof(Hex64Node) || typee != typeof(StringHashNode))
//continue;
bool isHash = HashLookupPluginExt.Hashes.TryGetValue(memory.ReadUInt64(item.Offset), out string str);
bool isStringHashNode = typee == typeof(StringHashNode);
StringHashNode itemAsStringHashNode = new StringHashNode();
if (isStringHashNode)
{
itemAsStringHashNode = (StringHashNode)item;
string oldStringHash = itemAsStringHashNode.hashedString;
if (oldStringHash != str)
{
Debug.WriteLine($"HashString \"{oldStringHash}\" changed to \"{str}\"");
var newNode = new StringHashNode();
newNode.hashedString = str;
newNode.CopyFromNode(item);
newNode.autoCreated = true;
addToReplace(item, newNode, parNode);
continue;
}
}
if (isHash && !isStringHashNode)
{
if (typee != typeof(Hex64Node) || HashLookupPluginExt.useComments)
{
item.Comment = str;
continue;
}
item.Comment = "";
var newNode = new StringHashNode();
newNode.hashedString = str;
newNode.CopyFromNode(item);
newNode.autoCreated = true;
addToReplace(item, newNode, parNode);
//Debug.WriteLine($"1 Type: {pnewNode.ToString()} Name: {pnewNode.Name} Offset: {pnewNode.Offset}");
//Debug.WriteLine($"2 Type: {parNode.ToString()} Name: {parNode.Name} Offset: {parNode.Offset}\n");
//parNode.AddNode(newNode);
//newNode.Offset = item.Offset;
//item.Comment = $" <SYMBOL> {str}";
//parNode.InsertNode(item, newNode);
//parNode.ReplaceChildNode(item, newNode);
}
else if (!isHash && (isStringHashNode || HashLookupPluginExt.useComments))
{
if (isStringHashNode)
{
var newNode = new Hex64Node();
newNode.CopyFromNode(item);
addToReplace(item, newNode, parNode);
}
if (item.Comment != "")
{
item.Comment = "";
}
}
else if (isStringHashNode)
{
if (HashLookupPluginExt.useComments && itemAsStringHashNode.autoCreated)
{
var newNode = new Hex64Node();
newNode.CopyFromNode(item);
newNode.Comment = str;
addToReplace(item, newNode, parNode);
continue;
}
item.Comment = "";
}
/*
if (HashLookupPluginExt.Hashes.TryGetValue(memory.ReadUInt64(item.Offset), out string str))
{
item.Comment = $" <SYMBOL> {str}";
}
else if(item.Comment != null)
{
item.Comment = "";
}
*/
}
lastParent = parNode;
return "";
}
}
public class StringHashNode : BaseHexNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
public bool autoCreated;
public override int MemorySize => sizeof(ulong);
public string hashedString;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "Hashed String";
icon = Properties.Resources.logo_hash1; // Add an icon if needed
}
public StringHashNode()
{
}
public override void Initialize()
{
}
public override Size Draw(DrawContext context, int x, int y)
{
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
var val = context.Memory.ReadUInt64(Offset);
if (HashLookupPluginExt.Hashes.TryGetValue(val, out string str))
{
hashedString = str;
}
else
{
hashedString = $"Not a symbol";
}
var origX = x;
var origY = y;
AddSelection(context, x, y, context.Font.Height);
/*
x = AddIconPadding(context, x);
x = AddIconPadding(context, x);
var tx = x;
x = AddAddressOffset(context, x, y);
*/
var newsize = base.Draw(context, x, y, context.Settings.ShowNodeText ? context.Memory.ReadString(context.Settings.RawDataEncoding, Offset, 8) + " " : null, 8);
x += newsize.Width;
origY -= newsize.Height;
x = AddText(context, x, y, context.Settings.PluginColor, HotSpot.NoneId, $"<SYMBOL> {hashedString}");
x += context.Font.Width;
//AddComment(context, x, y);
AddDeleteIcon(context, y);
//y += context.Font.Height;
var size = new Size(x - origX, y - origY);
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var h = context.Font.Height;
return h;
}
}
}