-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrame4PluginEx.cs
More file actions
785 lines (673 loc) · 29.9 KB
/
Frame4PluginEx.cs
File metadata and controls
785 lines (673 loc) · 29.9 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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
using System;
using System.Drawing;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Reflection;
using System.Text;
using System.Threading;
using ReClassNET.Core;
using ReClassNET.Debugger;
using ReClassNET.Forms;
using ReClassNET.Memory;
using ReClassNET.Plugins;
using ReClassNET.UI;
using ReClassNET.Util;
using libframe4;
using static libframe4.FRAME4;
// The namespace name must equal the plugin name
namespace Frame4Plugin
{
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName;
}
public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}
public Boolean ReadBoolean(string Key, string Section = null)
{
return Read(Key, Section) == "True";
}
public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}
public void Write(string Key, Boolean Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value ? "True" : "False", Path);
}
public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}
public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}
public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
/// <summary>The class name must equal the namespace name + "Ext"</summary>
public class Frame4PluginExt : Plugin, ICoreProcessFunctions
{
private const string SettingsFile = "PS4.ini";
private const string DEFAULT_IP = "192.168.2.1";
private const Boolean DEFAULT_DisableSectionsAndModules = true;
private const Boolean DEFAULT_ShowKernelBaseAddress = false;
private const string iniSection = "PS4";
private const string iniIP = "IP";
private const string iniDisableSectionsAndModules = "DisableSectionsAndModules";
private const string iniShowKernelBaseAddress = "ShowKernelBaseAddress";
private readonly object sync = new object();
private IPluginHost host;
private string IP;
private Boolean DisableSectionsAndModules;
private Boolean ShowKernelBaseAddress;
private Boolean KernelMode;
private static AutoResetEvent areDebugEvent = new AutoResetEvent(false);
private static uint ExceptionCode;
private static regs Registers;
private static dbregs DebugRegisters;
private ulong KernelBase { get; set; }
/// <summary>The icon to display in the plugin manager form.</summary>
public override Image Icon => Properties.Resources.icon;
public FRAME4 ps4 { get; set; }
private void tbIP_KeyUp(object sender, KeyEventArgs e)
{
TextBox textBox = (TextBox)sender;
IP = textBox.Text;
}
private void tsbMemoryModeModeClick(object sender, EventArgs e)
{
ToolStripButton tsbMemoryModeMode = (ToolStripButton)sender;
if (tsbMemoryModeMode.Checked)
tsbMemoryModeMode.Text = "Kernel Mode";
else
tsbMemoryModeMode.Text = "Default Mode";
KernelMode = tsbMemoryModeMode.Checked;
}
private void chkDisableSectionsAndModulesCheckedChanged(object sender, EventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
DisableSectionsAndModules = checkBox.Checked;
}
private void chkShowKernelBaseAddressCheckedChanged(object sender, EventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
ShowKernelBaseAddress = checkBox.Checked;
}
/// <summary>
/// This method gets called when a new windows is opened.
/// You can use this function to add a settings panel into the settings dialog for example.
/// </summary>
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 PS4Tab = settingsTabControl.Controls.Find("tabPS4", true).FirstOrDefault() as TabPage;
if (PS4Tab == null)
{
var newTab = new TabPage("PS4")
{
Name = "tabPS4",
UseVisualStyleBackColor = true
};
// IP
var lblIP = new Label()
{
Name = "lblIP",
Text = "IP:",
AutoSize = true,
Location = new System.Drawing.Point(6, 6),
Size = new System.Drawing.Size(28, 13),
};
newTab.Controls.Add(lblIP);
var tbIP = new TextBox()
{
Name = "tbIP",
Text = IP,
Location = new System.Drawing.Point(28, 3),
Size = new System.Drawing.Size(120, 20)
};
tbIP.KeyUp += tbIP_KeyUp;
newTab.Controls.Add(tbIP);
// DisableSectionsAndModules
var chkDisableSectionsAndModules = new CheckBox()
{
Name = "chkDisableSectionsAndModules",
Text = "Disable Sections and Modules (Reduce Bandwidth)",
Checked = DisableSectionsAndModules,
AutoSize = true,
Location = new System.Drawing.Point(6, 28),
Size = new System.Drawing.Size(28, 13),
};
chkDisableSectionsAndModules.CheckedChanged += chkDisableSectionsAndModulesCheckedChanged;
newTab.Controls.Add(chkDisableSectionsAndModules);
// ShowKernelBaseAddress
var chkShowKernelBaseAddress = new CheckBox()
{
Name = "chkShowKernelBaseAddress",
Text = "Show Kernel BaseAddress [Requires Restart]",
Checked = ShowKernelBaseAddress,
AutoSize = true,
Location = new System.Drawing.Point(6, 48),
Size = new System.Drawing.Size(28, 13),
};
chkShowKernelBaseAddress.CheckedChanged += chkShowKernelBaseAddressCheckedChanged;
newTab.Controls.Add(chkShowKernelBaseAddress);
settingsTabControl.TabPages.Add(newTab);
} else
{
var tbIP = PS4Tab.Controls.Find("tbIP", true).FirstOrDefault() as TextBox;
if (tbIP != null)
tbIP.KeyUp += tbIP_KeyUp;
var chkDisableSectionsAndModules = PS4Tab.Controls.Find("chkDisableSectionsAndModules", true).FirstOrDefault() as CheckBox;
if (chkDisableSectionsAndModules != null)
chkDisableSectionsAndModules.CheckedChanged += chkDisableSectionsAndModulesCheckedChanged;
var chkShowKernelBaseAddress = PS4Tab.Controls.Find("chkShowKernelBaseAddress", true).FirstOrDefault() as CheckBox;
if (chkShowKernelBaseAddress != null)
chkShowKernelBaseAddress.CheckedChanged += chkShowKernelBaseAddressCheckedChanged;
}
}
}
catch
{
}
};
}
}
/// <summary>This method gets called when ReClass.NET loads the plugin.</summary>
public override bool Initialize(IPluginHost host)
{
Contract.Requires(host != null);
this.host = host ?? throw new ArgumentNullException(nameof(host));
// Notfiy the plugin if a window is shown.
GlobalWindowManager.WindowAdded += OnWindowAdded;
try
{
var path = Path.Combine(PathUtil.SettingsFolderPath, SettingsFile);
var ini = new IniFile(path);
IP = ini.Read(iniIP, iniSection);
if (IP == "") { IP = DEFAULT_IP; }
var tmp = ini.Read(iniDisableSectionsAndModules, iniSection);
if (tmp == "")
DisableSectionsAndModules = DEFAULT_DisableSectionsAndModules;
else
DisableSectionsAndModules = (tmp == "True");
tmp = ini.Read(iniShowKernelBaseAddress, iniSection);
if (tmp == "")
ShowKernelBaseAddress = DEFAULT_DisableSectionsAndModules;
else
ShowKernelBaseAddress = (tmp == "True");
}
catch // (Exception ex)
{
IP = DEFAULT_IP;
DisableSectionsAndModules = DEFAULT_DisableSectionsAndModules;
ShowKernelBaseAddress = DEFAULT_ShowKernelBaseAddress;
// host.Logger.Log(ex);
}
KernelMode = false;
KernelBase = 0;
ps4 = null;
host.Process.CoreFunctions.RegisterFunctions("Frame4 Loader", this);
if (ShowKernelBaseAddress)
CreateObjects();
return true;
}
public void CreateObjects()
{
foreach (var Window in GlobalWindowManager.Windows)
{
try
{
var mainMenuStrip = Window.Controls.Find("mainMenuStrip", true).FirstOrDefault() as MenuStrip;
if(mainMenuStrip != null)
{
var tbKernelBaseAddress = mainMenuStrip.Items.Find("tbKernelBaseAddress", true).FirstOrDefault() as ToolStripTextBox;
if (tbKernelBaseAddress == null)
{
tbKernelBaseAddress = new ToolStripTextBox()
{
Name = "tbKernelBaseAddress",
Text = "0x0000000000000000",
// AutoSize = true,
Size = new System.Drawing.Size(114, 13),
};
mainMenuStrip.Items.Add(tbKernelBaseAddress);
}
var tsbMemoryModeMode = mainMenuStrip.Items.Find("tsbMemoryModeMode", true).FirstOrDefault() as ToolStripButton;
if (tsbMemoryModeMode == null)
{
tsbMemoryModeMode = new ToolStripButton()
{
Name = "tsbMemoryModeMode",
Text = "Default Mode",
Size = new System.Drawing.Size(114, 13),
Checked = false,
CheckOnClick = true,
};
tsbMemoryModeMode.Click += tsbMemoryModeModeClick;
mainMenuStrip.Items.Add(tsbMemoryModeMode);
}
/*
var newButton = new ToolStripButton()
{
Name = "GetBaseAddressBtn",
Text = "Get Base"
};
newButton.Click += (object sender, EventArgs args) => {
MemoryEntry mainExecutable;
if (ps4 == null)
{
return;
}
mainExecutable = ps4.GetProcessMaps(ProcessId).entries.ToList().Find(e => e.name == "executable");
if (mainExecutable != null)
{
newMenuTextBox.Text = $"0x{mainExecutable.start.ToString("X")}";
}
};
mainMenuStrip.Items.Add(newButton);
*/
break;
}
}
catch (Exception ex)
{
host.Logger.Log(ex);
}
}
}
/// <summary>This method gets called when ReClass.NET unloads the plugin.</summary>
public override void Terminate()
{
Disconnect();
GlobalWindowManager.WindowAdded -= OnWindowAdded;
// Save
var path = Path.Combine(PathUtil.SettingsFolderPath, SettingsFile);
var ini = new IniFile(path);
ini.Write(iniIP, IP, iniSection);
ini.Write(iniDisableSectionsAndModules, DisableSectionsAndModules, iniSection);
ini.Write(iniShowKernelBaseAddress, ShowKernelBaseAddress, iniSection);
host = null;
}
public void Connect()
{
if (ps4 != null)
{
if (ps4.IsConnected) { return; }
ps4 = null;
}
ps4 = new FRAME4(IP);
ps4.Connect();
/*
try
{
ps4 = new FRAME4(IP);
ps4.Connect();
}
catch (Exception ex)
{
ps4 = null;
host.Logger.Log(ex);
}
*/
KernelBase = ps4.KernelBase();
// Display KernelBase
foreach (var Window in GlobalWindowManager.Windows)
{
var mainMenuStrip = Window.Controls.Find("mainMenuStrip", true).FirstOrDefault() as MenuStrip;
if (mainMenuStrip != null)
{
var tbKernelBaseAddress = mainMenuStrip.Items.Find("tbKernelBaseAddress", true).FirstOrDefault() as ToolStripTextBox;
if (tbKernelBaseAddress != null)
{
tbKernelBaseAddress.Text = $"0x{KernelBase.ToString("X")}";
}
break;
}
}
}
public void Disconnect()
{
lock (sync)
{
KernelBase = 0;
if (ps4 != null)
{
if (ps4.IsDebugging)
ps4.DetachDebugger();
if (ps4.IsConnected)
ps4.Disconnect();
ps4 = null;
}
}
}
public void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
{
if (callbackProcess == null)
{
return;
}
Connect();
if (ps4 == null) { return; }
var ProcessList = ps4.GetProcessList().processes.ToList();
foreach (var Process in ProcessList)
{
EnumerateProcessData ProcessData = new EnumerateProcessData()
{
Id = (IntPtr)Process.pid,
Name = Process.name,
Path = Process.name
};
callbackProcess(ref ProcessData);
}
}
SectionProtection GetProtectionLevel(uint prot)
{
SectionProtection sectionProtection = new SectionProtection();
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_READ) == (uint)VM_PROTECTIONS.VM_PROT_READ)
sectionProtection |= SectionProtection.Read;
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_WRITE) == (uint)VM_PROTECTIONS.VM_PROT_WRITE)
sectionProtection |= SectionProtection.Read | SectionProtection.Write;
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_DEFAULT) == (uint)VM_PROTECTIONS.VM_PROT_DEFAULT)
sectionProtection |= SectionProtection.Read | SectionProtection.Write;
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_EXECUTE) == (uint)VM_PROTECTIONS.VM_PROT_EXECUTE)
sectionProtection |= SectionProtection.Execute;
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_READEXEC) == (uint)VM_PROTECTIONS.VM_PROT_READEXEC)
sectionProtection |= SectionProtection.Read | SectionProtection.Execute;
if ((prot & (uint)VM_PROTECTIONS.VM_PROT_ALL) == (uint)VM_PROTECTIONS.VM_PROT_ALL)
sectionProtection |= SectionProtection.Execute | SectionProtection.Read | SectionProtection.Write;
return sectionProtection;
}
public void EnumerateRemoteSectionsAndModules(IntPtr process, EnumerateRemoteSectionCallback callbackSection, EnumerateRemoteModuleCallback callbackModule)
{
if (DisableSectionsAndModules) { return; }
if (ps4 == null) { return; }
lock (sync)
{
try
{
var ProcessMap = ps4.GetProcessMaps(process.ToInt32()).entries;
foreach (var map in ProcessMap)
{
if (map.name.Length == 0)
continue;
EnumerateRemoteModuleData ModuleData = new EnumerateRemoteModuleData()
{
BaseAddress = (IntPtr)map.start,
Size = (IntPtr)(map.end - map.start),
Path = map.name
};
callbackModule(ref ModuleData);
EnumerateRemoteSectionData SectionData = new EnumerateRemoteSectionData()
{
BaseAddress = (IntPtr)map.start,
ModulePath = map.name,
Size = (IntPtr)(map.end - map.start),
Category = SectionCategory.DATA,
Protection = GetProtectionLevel(map.prot),
Name = map.name,
Type = SectionType.Image
};
callbackSection(ref SectionData);
}
}
catch (Exception ex)
{
host.Logger.Log(ex);
throw new Exception("Failed to enumerate process list:" + ex.ToString());
}
}
}
public IntPtr OpenRemoteProcess(IntPtr pid, ProcessAccess desiredAccess)
{
if (ps4 == null) { return IntPtr.Zero; }
lock (sync)
{
try
{
var ProcessMap = ps4.GetProcessMaps(pid.ToInt32());
if (ProcessMap.entries.Length == 0)
return IntPtr.Zero;
}
catch (Exception ex)
{
host.Logger.Log(ex);
}
}
return (IntPtr)pid;
}
public bool IsProcessValid(IntPtr process)
{
if (ps4 == null) { return false; }
lock (sync)
{
return (process.ToInt32() != -1 && (ps4 != null) && ps4.IsConnected);
}
}
public void CloseRemoteProcess(IntPtr process)
{
if (ps4 == null) { return; }
Disconnect();
}
public bool ReadRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
if (ps4 == null) { return false; }
ulong uaddress = (ulong)(address.ToInt64()+offset);
lock (sync)
{
if (KernelMode) // (uaddress >= KernelBase)
buffer = ps4.KernelReadMemory(uaddress, size);
else
buffer = ps4.ReadMemory(process.ToInt32(), uaddress, size);
return buffer.Length != 0;
}
}
public bool WriteRemoteMemory(IntPtr process, IntPtr address, ref byte[] buffer, int offset, int size)
{
if (ps4 == null) { return false; }
ulong uaddress = (ulong)(address.ToInt64() + offset);
lock (sync)
{
try
{
if (KernelMode) // (uaddress >= KernelBase)
{
return false;
// throw new NotImplementedException();
// ps4.KernelWriteMemory(uaddress, buffer);
}
else
ps4.WriteMemory(process.ToInt32(), uaddress, buffer);
}
catch (Exception ex)
{
host.Logger.Log(ex);
return false;
}
}
return true;
}
public void ControlRemoteProcess(IntPtr process, ControlRemoteProcessAction action)
{
if (ps4 == null) { return; }
if (!ps4.IsDebugging) { return; }
switch (action)
{
case ControlRemoteProcessAction.Suspend:
ps4.ProcessStop();
break;
case ControlRemoteProcessAction.Resume:
ps4.ProcessResume();
break;
case ControlRemoteProcessAction.Terminate:
ps4.ProcessKill();
break;
}
}
public bool AttachDebuggerToProcess(IntPtr id)
{
if (ps4 == null) { return false; }
if (ps4.IsDebugging) { return false; }
lock (sync)
{
ps4.AttachDebugger(id.ToInt32(), new DebuggerInterruptCallback(this.DebuggerInterruptCallback));
ps4.ProcessResume();
}
return true;
}
public void DetachDebuggerFromProcess(IntPtr id)
{
if (ps4 == null) { return; }
// if (ps4.IsDebugging) { return; }
lock (sync)
{
ps4.DetachDebugger();
}
}
private void DebuggerInterruptCallback(uint lwpid, uint status, string tdname, regs regs, fpregs fpregs, dbregs dbregs)
{
ExceptionCode = status;
Registers = regs;
DebugRegisters = dbregs;
areDebugEvent.Set();
}
public bool AwaitDebugEvent(ref DebugEvent evt, int timeoutInMilliseconds)
{
bool isSignaled = areDebugEvent.WaitOne(timeoutInMilliseconds);
if (isSignaled)
{
if ((DebugRegisters.dr6 & 1) == 1)
evt.ExceptionInfo.CausedBy = HardwareBreakpointRegister.Dr0;
else if ((DebugRegisters.dr6 & 2) == 2)
evt.ExceptionInfo.CausedBy = HardwareBreakpointRegister.Dr1;
else if ((DebugRegisters.dr6 & 4) == 4)
evt.ExceptionInfo.CausedBy = HardwareBreakpointRegister.Dr2;
else if ((DebugRegisters.dr6 & 8) == 8)
evt.ExceptionInfo.CausedBy = HardwareBreakpointRegister.Dr3;
else
evt.ExceptionInfo.CausedBy = HardwareBreakpointRegister.InvalidRegister;
evt.ExceptionInfo.ExceptionCode = (IntPtr)ExceptionCode;
// evt.ExceptionInfo.ExceptionFlags = (IntPtr)0x0000000000000000;
evt.ExceptionInfo.ExceptionAddress = (IntPtr)Registers.r_rip;
evt.ExceptionInfo.Registers.Rax = (IntPtr)Registers.r_rax;
evt.ExceptionInfo.Registers.Rbx = (IntPtr)Registers.r_rbx;
evt.ExceptionInfo.Registers.Rcx = (IntPtr)Registers.r_rcx;
evt.ExceptionInfo.Registers.Rdx = (IntPtr)Registers.r_rdx;
evt.ExceptionInfo.Registers.Rdi = (IntPtr)Registers.r_rdi;
evt.ExceptionInfo.Registers.Rsi = (IntPtr)Registers.r_rsi;
evt.ExceptionInfo.Registers.Rsp = (IntPtr)Registers.r_rsp;
evt.ExceptionInfo.Registers.Rbp = (IntPtr)Registers.r_rbp;
evt.ExceptionInfo.Registers.Rip = (IntPtr)Registers.r_rip;
evt.ExceptionInfo.Registers.R8 = (IntPtr)Registers.r_r8;
evt.ExceptionInfo.Registers.R9 = (IntPtr)Registers.r_r9;
evt.ExceptionInfo.Registers.R10 = (IntPtr)Registers.r_r10;
evt.ExceptionInfo.Registers.R11 = (IntPtr)Registers.r_r11;
evt.ExceptionInfo.Registers.R12 = (IntPtr)Registers.r_r12;
evt.ExceptionInfo.Registers.R13 = (IntPtr)Registers.r_r13;
evt.ExceptionInfo.Registers.R14 = (IntPtr)Registers.r_r14;
evt.ExceptionInfo.Registers.R15 = (IntPtr)Registers.r_r15;
}
return isSignaled;
}
public void HandleDebugEvent(ref DebugEvent evt)
{
if (ps4 == null) { return; }
if (!ps4.IsDebugging) { return; }
lock (sync)
{
ps4.ProcessResume();
}
}
public bool SetHardwareBreakpoint(IntPtr id, IntPtr address, HardwareBreakpointRegister register, HardwareBreakpointTrigger trigger, HardwareBreakpointSize size, bool set)
{
if (ps4 == null) { return false; }
if (!ps4.IsDebugging) { return false; }
int index = 0;
switch (register)
{
case HardwareBreakpointRegister.InvalidRegister:
return false;
case HardwareBreakpointRegister.Dr0:
index = 0;
break;
case HardwareBreakpointRegister.Dr1:
index = 1;
break;
case HardwareBreakpointRegister.Dr2:
index = 2;
break;
case HardwareBreakpointRegister.Dr3:
index = 3;
break;
}
WATCHPT_LENGTH len = WATCHPT_LENGTH.DBREG_DR7_LEN_1;
switch (size)
{
case HardwareBreakpointSize.Size1:
len = WATCHPT_LENGTH.DBREG_DR7_LEN_1;
break;
case HardwareBreakpointSize.Size2:
len = WATCHPT_LENGTH.DBREG_DR7_LEN_2;
break;
case HardwareBreakpointSize.Size4:
len = WATCHPT_LENGTH.DBREG_DR7_LEN_4;
break;
case HardwareBreakpointSize.Size8:
len = WATCHPT_LENGTH.DBREG_DR7_LEN_8;
break;
}
WATCHPT_BREAKTYPE type = WATCHPT_BREAKTYPE.DBREG_DR7_EXEC;
switch (trigger)
{
case HardwareBreakpointTrigger.Execute:
type = WATCHPT_BREAKTYPE.DBREG_DR7_EXEC;
break;
case HardwareBreakpointTrigger.Access:
type = WATCHPT_BREAKTYPE.DBREG_DR7_RDWR;
break;
case HardwareBreakpointTrigger.Write:
type = WATCHPT_BREAKTYPE.DBREG_DR7_WRONLY;
break;
}
lock (sync)
{
ps4.ChangeWatchpoint(index, set, len, type, (ulong)address.ToInt64());
}
return true;
}
public int ConnectServer(string ip, short port)
{
return -1;
}
public bool OpenDumpFile(IntPtr dumpFilePath)
{
return false;
}
}
}