-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPS2PtrNode.cs
More file actions
726 lines (598 loc) · 24.2 KB
/
PS2PtrNode.cs
File metadata and controls
726 lines (598 loc) · 24.2 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
using System;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.Nodes;
using ReClassNET.UI;
namespace PCSX2Plugin
{
public class EEMemNode : BaseClassWrapperNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
public override int MemorySize => 0x4;
protected override bool PerformCycleCheck => false;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "Get EEMem Address";
icon = Properties.Resources.logo_pcsx2;
}
public override void Initialize()
{
var node = ClassNode.Create();
node.Initialize();
node.AddBytes(64);
ChangeInnerNode(node);
}
public override Size Draw(DrawContext context, int x, int y)
{
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
Name = "int EEMem"; // auto generate struct name to fix any padding issues
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.Pointer, -1, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
/* RENDER ROW ITEM */
long ptr = 0;
PS2Helpers.GetEEMem(context, ref ptr);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "EEMem") + context.Font.Width;
x = AddText(context, x, y, Color.Red, HotSpot.NoneId, " -> ");
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.AddressId, String.Format("0x{0:X}", ptr));
x += context.Font.Width;
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])
{
IntPtr addr = (IntPtr)(ptr + Offset);
memory.Size = InnerNode.MemorySize;
memory.UpdateFrom(context.Process, addr);
DrawContext v = context.Clone();
v.Address = addr;
v.Memory = memory;
var innerSize = InnerNode.Draw(v, tx, y);
size.Width = Math.Max(size.Width, innerSize.Width + tx - origX);
size.Height += innerSize.Height;
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var h = context.Font.Height;
if (LevelsOpen[context.Level])
{
h += InnerNode.CalculateDrawnHeight(context);
}
return h;
}
}
public class ScratchpadNode : BaseClassWrapperNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
public override int MemorySize => 0x4;
protected override bool PerformCycleCheck => false;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "Get Scratchpad Address";
icon = Properties.Resources.logo_pcsx2;
}
public override void Initialize()
{
var node = ClassNode.Create();
node.Initialize();
node.AddBytes(64);
ChangeInnerNode(node);
}
public override Size Draw(DrawContext context, int x, int y)
{
if (IsHidden && !IsWrapped)
{
return DrawHidden(context, x, y);
}
Name = "int Scratchpad"; // auto generate struct name to fix any padding issues
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.Pointer, -1, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
/* RENDER ROW ITEM */
long ptr = 0;
PS2Helpers.GetScratchpad(context, ref ptr);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "Scratchpad") + context.Font.Width;
x = AddText(context, x, y, Color.Red, HotSpot.NoneId, " -> ");
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.AddressId, String.Format("0x{0:X}", ptr));
x += context.Font.Width;
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])
{
IntPtr addr = (IntPtr)(ptr + Offset);
memory.Size = InnerNode.MemorySize;
memory.UpdateFrom(context.Process, addr);
DrawContext v = context.Clone();
v.Address = addr;
v.Memory = memory;
var innerSize = InnerNode.Draw(v, tx, y);
size.Width = Math.Max(size.Width, innerSize.Width + tx - origX);
size.Height += innerSize.Height;
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var h = context.Font.Height;
if (LevelsOpen[context.Level])
{
h += InnerNode.CalculateDrawnHeight(context);
}
return h;
}
}
public class PS2PtrNode : BaseClassWrapperNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
public override int MemorySize => 0x4;
protected override bool PerformCycleCheck => false;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "PS2 Pointer";
icon = Properties.Resources.logo_pcsx2;
}
public override void Initialize()
{
var node = ClassNode.Create();
node.Initialize();
node.AddBytes(64);
ChangeInnerNode(node);
}
public override Size Draw(DrawContext context, int x, int y)
{
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.Pointer, -1, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
/* RENDER ROW ITEM */
var ptr = context.Memory.ReadUInt32(Offset);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "PS2Ptr") + context.Font.Width;
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
x = AddIcon(context, x, y, context.IconProvider.Change, 4, HotSpotType.ChangeClassType);
x = AddText(context, x, y, Color.Red, HotSpot.NoneId, " -> ");
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.AddressId, String.Format("0x{0:X}", ptr));
x += context.Font.Width;
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])
{
IntPtr addr = context.Address + Offset;
if (!addr.IsNull())
{
long address = 0;
var _uint = context.Process.ReadRemoteUInt32(addr);
if (!addr.IsNull() && PS2Helpers.GetEEMem(context, ref address))
addr = (IntPtr)(address + _uint);
}
memory.Size = InnerNode.MemorySize;
memory.UpdateFrom(context.Process, addr);
DrawContext v = context.Clone();
v.Address = addr;
v.Memory = memory;
var innerSize = InnerNode.Draw(v, tx, y);
size.Width = Math.Max(size.Width, innerSize.Width + tx - origX);
size.Height += innerSize.Height;
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var h = context.Font.Height;
if (LevelsOpen[context.Level])
{
h += InnerNode.CalculateDrawnHeight(context);
}
return h;
}
}
public class PS2ScratchPtrNode : BaseClassWrapperNode
{
private readonly MemoryBuffer memory = new MemoryBuffer();
public override int MemorySize => 0x2;
protected override bool PerformCycleCheck => false;
public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "PS2 Scratchpad Pointer";
icon = Properties.Resources.logo_pcsx2;
}
public override void Initialize()
{
var node = ClassNode.Create();
node.Initialize();
node.AddBytes(64);
ChangeInnerNode(node);
}
public override Size Draw(DrawContext context, int x, int y)
{
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.Pointer, -1, HotSpotType.None);
var tx = x;
x = AddAddressOffset(context, x, y);
/* RENDER ROW ITEM */
var ptr = context.Memory.ReadUInt16(Offset);
x = AddText(context, x, y, context.Settings.TypeColor, HotSpot.NoneId, "PS2ScratchpadPtr") + context.Font.Width;
x = AddText(context, x, y, context.Settings.NameColor, HotSpot.NameId, Name) + context.Font.Width;
x = AddIcon(context, x, y, context.IconProvider.Change, 4, HotSpotType.ChangeClassType);
x = AddText(context, x, y, Color.Red, HotSpot.NoneId, " -> ");
x = AddText(context, x, y, context.Settings.ValueColor, HotSpot.AddressId, String.Format("0x{0:X}", ptr));
x += context.Font.Width;
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])
{
IntPtr addr = context.Address + Offset;
if (!addr.IsNull())
{
long address = 0;
var _uint = context.Process.ReadRemoteUInt16(addr);
if (!addr.IsNull() && PS2Helpers.GetScratchpad(context, ref address))
addr = (IntPtr)(address + _uint);
}
memory.Size = InnerNode.MemorySize;
memory.UpdateFrom(context.Process, addr);
DrawContext v = context.Clone();
v.Address = addr;
v.Memory = memory;
var innerSize = InnerNode.Draw(v, tx, y);
size.Width = Math.Max(size.Width, innerSize.Width + tx - origX);
size.Height += innerSize.Height;
}
return size;
}
public override int CalculateDrawnHeight(DrawContext context)
{
if (IsHidden && !IsWrapped)
{
return HiddenHeight;
}
var h = context.Font.Height;
if (LevelsOpen[context.Level])
{
h += InnerNode.CalculateDrawnHeight(context);
}
return h;
}
}
public class PS2Helpers
{
/// IMPORTS
[Flags]
public enum MemoryProtectionFlags : uint
{
PAGE_NOACCESS = 0x01,
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_WRITECOPY = 0x08,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE = 0x40,
PAGE_EXECUTE_WRITECOPY = 0x80
}
[StructLayout(LayoutKind.Sequential)]
struct IMAGE_DOS_HEADER
{
public short e_magic;
public short e_cblp;
public short e_cp;
public short e_crlc;
public short e_cparhdr;
public short e_minalloc;
public short e_maxalloc;
public short e_ss;
public short e_sp;
public short e_csum;
public short e_ip;
public short e_cs;
public short e_lfarlc;
public short e_ovno;
public short e_res_0;
public short e_res_1;
public short e_res_2;
public short e_res_3;
public short e_oemid;
public short e_oeminfo;
public short e_res2_0;
public short e_res2_1;
public short e_res2_2;
public short e_res2_3;
public short e_res2_4;
public short e_res2_5;
public short e_res2_6;
public short e_res2_7;
public short e_res2_8;
public short e_res2_9;
public int e_lfanew;
}
[StructLayout(LayoutKind.Sequential)]
struct IMAGE_DATA_DIRECTORY
{
public uint VirtualAddress;
public uint Size;
}
[StructLayout(LayoutKind.Sequential)]
struct IMAGE_NT_HEADERS
{
public uint Signature;
public IMAGE_FILE_HEADER FileHeader;
public IMAGE_OPTIONAL_HEADER OptionalHeader;
}
[StructLayout(LayoutKind.Sequential)]
struct IMAGE_FILE_HEADER
{
public ushort Machine;
public ushort NumberOfSections;
public uint TimeDateStamp;
public uint PointerToSymbolTable;
public uint NumberOfSymbols;
public ushort SizeOfOptionalHeader;
public ushort Characteristics;
}
[StructLayout(LayoutKind.Sequential)]
struct IMAGE_OPTIONAL_HEADER
{
public ushort Magic;
public byte MajorLinkerVersion;
public byte MinorLinkerVersion;
public uint SizeOfCode;
public uint SizeOfInitializedData;
public uint SizeOfUninitializedData;
public uint AddressOfEntryPoint;
public uint BaseOfCode;
public uint BaseOfData;
public uint ImageBase;
public uint SectionAlignment;
public uint FileAlignment;
public ushort MajorOperatingSystemVersion;
public ushort MinorOperatingSystemVersion;
public ushort MajorImageVersion;
public ushort MinorImageVersion;
public ushort MajorSubsystemVersion;
public ushort MinorSubsystemVersion;
public uint Win32VersionValue;
public uint SizeOfImage;
public uint SizeOfHeaders;
public uint CheckSum;
public ushort Subsystem;
public ushort DllCharacteristics;
public uint SizeOfStackReserve;
public uint SizeOfStackCommit;
public uint SizeOfHeapReserve;
public uint SizeOfHeapCommit;
public uint LoaderFlags;
public uint NumberOfRvaAndSizes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public IMAGE_DATA_DIRECTORY[] DataDirectory;
}
[StructLayout(LayoutKind.Sequential)]
struct ExportDirectory
{
public uint Characteristics;
public uint TimeDateStamp;
public ushort MajorVersion;
public ushort MinorVersion;
public uint Name;
public uint Base;
public uint NumberOfFunctions;
public uint NumberOfNames;
public uint AddressOfFunctions;
public uint AddressOfNames;
public uint AddressOfNameOrdinals;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public ExportEntry[] Exports;
}
[StructLayout(LayoutKind.Sequential)]
struct ExportEntry
{
public uint NameRVA;
public uint Ordinal;
public uint AddressOfData;
public uint ForwarderRVA;
}
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_BASIC_INFORMATION
{
public IntPtr BaseAddress;
public IntPtr AllocationBase;
public MemoryProtectionFlags AllocationProtect;
public IntPtr RegionSize;
public uint State;
public uint Protect;
public uint Type;
}
/* */
public static class PS2MemSize
{
/* inaccessible */
private const int MainRam = (1024 * 1024) * 32; // 32MB
private const int ExtraRam = (1024 * 1024) * 96; // 96MB
private const int Rom = (1024 * 1024) * 4; // 4MB
private const int Rom1 = (1024 * 1024) * 4; // 4MB
private const int Rom2 = (1024 * 1024) * 4; // 4MB
private const int IopRam = (1024 * 1024) * 2; // 2MB
private const int IopHardware = 1 * 64; // 64KB
private const int Scratch = 1 * 16; // 16KB
private const int Zero = (1024 * 1) * 1; // 1MB
/* accessible */
public const int MainOffset = 0;
public const int ExtraOffset = MainOffset + MainRam;
public const int ScratchOffset = ExtraOffset + ExtraRam;
public const int RomOffset = ScratchOffset + Scratch;
public const int Rom1Offset = RomOffset + Rom;
public const int Rom2Offset = Rom1Offset + Rom1;
public const int ZeroReadOffset = Rom2Offset + Rom2;
public const int ZeroWriteOffset = ZeroReadOffset + Zero;
}
private static Int64 EEMem = 0;
public static bool GetEEMem(DrawContext ctx, ref Int64 outBaseAddr)
{
Int64 result = EEMem;
if (result > 0)
{
outBaseAddr = result;
return true;
}
if (ctx.Process == null || ctx.Process.IsValid == false)
return false;
var procId = ctx.Process.UnderlayingProcess.Id;
var procName = ctx.Process.UnderlayingProcess.Name;
if (procName.Count() <= 0)
return false;
IntPtr baseAddress = IntPtr.Zero;
foreach (var proc in ctx.Process.Modules)
{
if (proc.Name != procName)
continue;
baseAddress = proc.Start;
break;
}
if (baseAddress.IsNull())
return false;
/* Read DOS header */
//
IMAGE_DOS_HEADER dosHeader = ReadStruct<IMAGE_DOS_HEADER>(ctx.Process, baseAddress);
if (dosHeader.e_magic != 0x5A4D) // 'MZ'
return false;
/* Read PE header */
IMAGE_NT_HEADERS ntHeader = ReadStruct<IMAGE_NT_HEADERS>(ctx.Process, baseAddress + dosHeader.e_lfanew);
if (ntHeader.Signature != 0x00004550) // 'PE'
return false;
/* Enumerate Directories */
IntPtr EEMemAddr = IntPtr.Zero;
foreach (IMAGE_DATA_DIRECTORY dir in ntHeader.OptionalHeader.DataDirectory)
{
// Get the address of the export table
var exportsRva = (IntPtr)(baseAddress.ToInt64() + dir.VirtualAddress);
if (exportsRva == IntPtr.Zero)
continue;
// Read the export table
ExportDirectory exports = ReadStruct<ExportDirectory>(ctx.Process, exportsRva);
if (exports.NumberOfNames != exports.NumberOfFunctions || exports.AddressOfNames == 0 || exports.AddressOfFunctions == 0 || exports.AddressOfNameOrdinals == 0)
continue;
// Read address offsets into an array
uint[] namesRvaArray = ReadArray<uint>(ctx.Process, (IntPtr)(baseAddress.ToInt64() + exports.AddressOfNames), (int)exports.NumberOfNames);
uint[] functionsRvaArray = ReadArray<uint>(ctx.Process, (IntPtr)(baseAddress.ToInt64() + exports.AddressOfFunctions), (int)exports.NumberOfFunctions);
ushort[] nameOrdinalsArray = ReadArray<ushort>(ctx.Process, (IntPtr)(baseAddress.ToInt64() + exports.AddressOfNameOrdinals), (int)exports.NumberOfNames);
// Iterate names in names array
uint rva = 0;
int index = -1;
foreach (uint nameRva in namesRvaArray)
{
index++;
string currentFunctionName = ctx.Process.ReadRemoteStringUntilFirstNullCharacter((IntPtr)(baseAddress.ToInt64() + nameRva), System.Text.Encoding.ASCII, 64); // ReadString((IntPtr)(baseAddress.ToInt64() + nameRva));
if (currentFunctionName.ToLower() == "eemem") // compare exported name with input
{
rva = nameRva;
break;
}
}
if (rva == 0)
continue;
// get function address
int ordinal_index = nameOrdinalsArray[index];// get ordinal at the current index
uint functionRva = functionsRvaArray[ordinal_index]; // get function va from the ordinal index of the functions array
if (functionRva <= 0)
continue;
long functionAddress = (long)(baseAddress.ToInt64() + functionRva);
if (functionAddress <= 0)
continue;
EEMemAddr = (IntPtr)functionAddress;
}
if (EEMemAddr == IntPtr.Zero)
return false;
result = ctx.Process.ReadRemoteInt64(EEMemAddr); // read the address of the EEMem function
outBaseAddr = EEMem;
EEMem = result;
return EEMem != 0;
}
public static bool GetScratchpad(DrawContext ctx, ref Int64 outBaseAddr)
{
if (EEMem <= 0 && GetEEMem(ctx, ref EEMem) == false)
return false;
outBaseAddr = EEMem + PS2MemSize.ScratchOffset;
return outBaseAddr > EEMem;
}
// Reads an array of members at the specified address in memory
private static T[] ReadArray<T>(RemoteProcess proc, IntPtr addr, int size) where T : struct
{
int structSize = Marshal.SizeOf(typeof(T)) * size;
byte[] buffer = proc.ReadRemoteMemory(addr, structSize);
T[] result = new T[size];
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)));
for (int i = 0; i < size; i++)
{
Marshal.Copy(buffer, i * Marshal.SizeOf(typeof(T)), ptr, Marshal.SizeOf(typeof(T)));
result[i] = Marshal.PtrToStructure<T>(ptr);
}
return result;
}
// Reads memory at the specified address and transforms the result into the input structure
private static T ReadStruct<T>(RemoteProcess proc, IntPtr addr) where T : struct
{
int structSize = Marshal.SizeOf(typeof(T));
byte[] buffer = proc.ReadRemoteMemory(addr, structSize);
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
return (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
}
finally
{
handle.Free();
}
}
}
}