Skip to content

Commit 084ee73

Browse files
committed
Added breakpoint handler.
1 parent 2a698d5 commit 084ee73

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

Debugger/HardwareBreakpoint.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using ReClassNET.Memory;
3+
using ReClassNET.Native;
4+
using System.Diagnostics.Contracts;
35

46
namespace ReClassNET.Debugger
57
{
@@ -13,39 +15,45 @@ public enum HardwareBreakpointRegister
1315
Dr3
1416
}
1517

16-
public enum HardwareBreakpointType
18+
public enum HardwareBreakpointTrigger
1719
{
20+
Execute,
1821
Access,
19-
ReadWrite,
2022
Write,
2123
}
2224

2325
public enum HardwareBreakpointSize
2426
{
25-
Size1,
26-
Size2,
27-
Size4,
28-
Size8
27+
Size1 = 1,
28+
Size2 = 2,
29+
Size4 = 4,
30+
Size8 = 8
2931
}
3032

3133
public sealed class HardwareBreakpoint : IBreakpoint
3234
{
3335
public IntPtr Address { get; }
3436
public HardwareBreakpointRegister Register { get; }
35-
public HardwareBreakpointType Type { get; }
37+
public HardwareBreakpointTrigger Trigger { get; }
3638
public HardwareBreakpointSize Size { get; }
3739

38-
public HardwareBreakpoint(IntPtr address, HardwareBreakpointRegister register, HardwareBreakpointType type, HardwareBreakpointSize size)
40+
private readonly BreakpointHandler handler;
41+
42+
public HardwareBreakpoint(IntPtr address, HardwareBreakpointRegister register, HardwareBreakpointTrigger trigger, HardwareBreakpointSize size, BreakpointHandler handler)
3943
{
44+
Contract.Requires(handler != null);
45+
4046
if (register == HardwareBreakpointRegister.InvalidRegister)
4147
{
4248
throw new InvalidOperationException();
4349
}
4450

4551
Address = address;
4652
Register = register;
47-
Type = type;
53+
Trigger = trigger;
4854
Size = size;
55+
56+
this.handler = handler;
4957
}
5058

5159
public bool Set(RemoteProcess process)
@@ -58,6 +66,11 @@ public void Remove(RemoteProcess process)
5866
process.NativeHelper.DebuggerSetHardwareBreakpoint(process.UnderlayingProcess.Id, this, false);
5967
}
6068

69+
public void Handler(ref DebugEvent evt)
70+
{
71+
handler?.Invoke(this, ref evt);
72+
}
73+
6174
public override bool Equals(object obj)
6275
{
6376
var hwbp = obj as HardwareBreakpoint;
@@ -66,13 +79,13 @@ public override bool Equals(object obj)
6679
return false;
6780
}
6881

69-
// Two hardware breakpoints are equal if the address and type are equal.
70-
return Address == hwbp.Address && Type == hwbp.Type;
82+
// Two hardware breakpoints are equal if they use the same register.
83+
return Register == hwbp.Register;
7184
}
7285

7386
public override int GetHashCode()
7487
{
75-
return (Address.GetHashCode() * 17) ^ Type.GetHashCode();
88+
return Register.GetHashCode();
7689
}
7790
}
7891
}

Debugger/IBreakpoint.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
using System;
22
using System.Diagnostics.Contracts;
33
using ReClassNET.Memory;
4+
using ReClassNET.Native;
45

56
namespace ReClassNET.Debugger
67
{
8+
public delegate void BreakpointHandler(IBreakpoint breakpoint, ref DebugEvent evt);
9+
710
public interface IBreakpoint
811
{
912
IntPtr Address { get; }
1013

1114
bool Set(RemoteProcess process);
1215
void Remove(RemoteProcess process);
16+
17+
void Handler(ref DebugEvent evt);
1318
}
1419

1520
[ContractClassFor(typeof(IBreakpoint))]
@@ -23,6 +28,11 @@ public IntPtr Address
2328
}
2429
}
2530

31+
public void Handler(ref DebugEvent evt)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
2636
public void Remove(RemoteProcess process)
2737
{
2838
Contract.Requires(process != null);

Debugger/SoftwareBreakpoint.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using ReClassNET.Memory;
3+
using ReClassNET.Native;
4+
using System.Diagnostics.Contracts;
35

46
namespace ReClassNET.Debugger
57
{
@@ -9,9 +11,15 @@ public sealed class SoftwareBreakpoint : IBreakpoint
911

1012
private byte orig;
1113

12-
public SoftwareBreakpoint(IntPtr address)
14+
private readonly BreakpointHandler handler;
15+
16+
public SoftwareBreakpoint(IntPtr address, BreakpointHandler handler)
1317
{
18+
Contract.Requires(handler != null);
19+
1420
Address = address;
21+
22+
this.handler = handler;
1523
}
1624

1725
public bool Set(RemoteProcess process)
@@ -31,6 +39,11 @@ public void Remove(RemoteProcess process)
3139
process.WriteRemoteMemory(Address, new byte[] { orig });
3240
}
3341

42+
public void Handler(ref DebugEvent evt)
43+
{
44+
handler?.Invoke(this, ref evt);
45+
}
46+
3447
public override bool Equals(object obj)
3548
{
3649
var bp = obj as SoftwareBreakpoint;

0 commit comments

Comments
 (0)