Skip to content

Commit 61b5406

Browse files
committed
Renamed hardware breakpoint class to make it clearer it's x86/x64 specific.
1 parent 949ef30 commit 61b5406

2 files changed

Lines changed: 33 additions & 30 deletions

File tree

winappdbg/breakpoint.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# Breakpoint implementations
3939
"CodeBreakpoint",
4040
"PageBreakpoint",
41-
"HardwareBreakpoint",
41+
"HardwareBreakpoint_x86",
4242
# Hooks and watches
4343
"HookFactory",
4444
"ApiHook",
@@ -81,7 +81,7 @@ class Breakpoint:
8181
"""
8282
Base class for breakpoints. Here's the breakpoints state machine.
8383
84-
.. seealso:: :class:`CodeBreakpoint`, :class:`PageBreakpoint`, :class:`HardwareBreakpoint`
84+
.. seealso:: :class:`CodeBreakpoint`, :class:`PageBreakpoint`, :class:`HardwareBreakpoint_x86`
8585
8686
:cvar DISABLED: *Disabled* -> Enabled, OneShot
8787
:type DISABLED: int
@@ -713,13 +713,12 @@ def running(self, aProcess, aThread):
713713

714714

715715
# ==============================================================================
716+
# TODO: Add a new class HardwareBreakpoint_ARM
716717

717718

718-
# TODO: ARM does support hardware breakpoints, but that involves refactoring
719-
# this whole class, or possibly writing a separate class entirely.
720-
class HardwareBreakpoint(Breakpoint):
719+
class HardwareBreakpoint_x86(Breakpoint):
721720
"""
722-
Hardware breakpoint (using debug registers).
721+
Hardware breakpoint (using debug registers) for x86/x64 architectures.
723722
724723
.. seealso:: :meth:`~winappdbg.debug.Debug.watch_variable`
725724
@@ -779,17 +778,20 @@ def __init__(
779778
Hardware breakpoint object.
780779
781780
:param int address: Memory address for breakpoint.
781+
782782
:param int triggerFlag: When to trigger the breakpoint.
783783
Must be one of the following values:
784784
- :attr:`BREAK_ON_EXECUTION`
785785
- :attr:`BREAK_ON_WRITE`
786786
- :attr:`BREAK_ON_ACCESS`
787+
787788
:param int sizeFlag: Size of the data to watch.
788789
Must be one of the following values:
789790
- :attr:`WATCH_BYTE`
790791
- :attr:`WATCH_WORD`
791792
- :attr:`WATCH_DWORD`
792793
- :attr:`WATCH_QWORD`
794+
793795
:param callable condition: Optional condition callback function.
794796
The callback signature is::
795797
@@ -799,6 +801,7 @@ def condition_callback(event):
799801
Where ``event`` is an :class:`~winappdbg.event.Event` object,
800802
and the return value is a boolean (``True`` to dispatch the event,
801803
``False`` otherwise).
804+
802805
:param callable action: Optional action callback function.
803806
If specified, the event is handled by this callback instead of
804807
being dispatched normally.
@@ -1420,8 +1423,8 @@ def hook(self, debug, pid, address):
14201423
debug.define_hardware_breakpoint(
14211424
tid,
14221425
address,
1423-
HardwareBreakpoint.BP_BREAK_ON_EXECUTION,
1424-
HardwareBreakpoint.BP_WATCH_BYTE,
1426+
HardwareBreakpoint_x86.BP_BREAK_ON_EXECUTION,
1427+
HardwareBreakpoint_x86.BP_WATCH_BYTE,
14251428
True,
14261429
self,
14271430
)
@@ -1469,8 +1472,8 @@ def stalk(self, debug, pid, address):
14691472
bp = debug.define_hardware_breakpoint(
14701473
tid,
14711474
address,
1472-
HardwareBreakpoint.BP_BREAK_ON_EXECUTION,
1473-
HardwareBreakpoint.BP_WATCH_BYTE,
1475+
HardwareBreakpoint_x86.BP_BREAK_ON_EXECUTION,
1476+
HardwareBreakpoint_x86.BP_WATCH_BYTE,
14741477
True,
14751478
self,
14761479
)
@@ -2289,20 +2292,20 @@ class _BreakpointContainer:
22892292
BP_STATE_RUNNING = Breakpoint.RUNNING
22902293

22912294
# Memory breakpoint trigger flags
2292-
BP_BREAK_ON_EXECUTION = HardwareBreakpoint.BREAK_ON_EXECUTION
2293-
BP_BREAK_ON_WRITE = HardwareBreakpoint.BREAK_ON_WRITE
2294-
BP_BREAK_ON_ACCESS = HardwareBreakpoint.BREAK_ON_ACCESS
2295+
BP_BREAK_ON_EXECUTION = HardwareBreakpoint_x86.BREAK_ON_EXECUTION
2296+
BP_BREAK_ON_WRITE = HardwareBreakpoint_x86.BREAK_ON_WRITE
2297+
BP_BREAK_ON_ACCESS = HardwareBreakpoint_x86.BREAK_ON_ACCESS
22952298

22962299
# Memory breakpoint size flags
2297-
BP_WATCH_BYTE = HardwareBreakpoint.WATCH_BYTE
2298-
BP_WATCH_WORD = HardwareBreakpoint.WATCH_WORD
2299-
BP_WATCH_QWORD = HardwareBreakpoint.WATCH_QWORD
2300-
BP_WATCH_DWORD = HardwareBreakpoint.WATCH_DWORD
2300+
BP_WATCH_BYTE = HardwareBreakpoint_x86.WATCH_BYTE
2301+
BP_WATCH_WORD = HardwareBreakpoint_x86.WATCH_WORD
2302+
BP_WATCH_QWORD = HardwareBreakpoint_x86.WATCH_QWORD
2303+
BP_WATCH_DWORD = HardwareBreakpoint_x86.WATCH_DWORD
23012304

23022305
def __init__(self):
23032306
self.__codeBP = dict() # (pid, address) -> CodeBreakpoint
23042307
self.__pageBP = dict() # (pid, address) -> PageBreakpoint
2305-
self.__hardwareBP = dict() # tid -> [ HardwareBreakpoint ]
2308+
self.__hardwareBP = dict() # tid -> [ HardwareBreakpoint_x86 ]
23062309
self.__runningBP = dict() # tid -> set( Breakpoint )
23072310
self.__tracing = set() # set( tid )
23082311
self.__deferredBP = dict() # pid -> label -> (action, oneshot)
@@ -2603,10 +2606,10 @@ def action_callback(event):
26032606
and the return value is a boolean
26042607
(``True`` to dispatch the event, ``False`` otherwise).
26052608
2606-
:rtype: :class:`HardwareBreakpoint`
2609+
:rtype: :class:`HardwareBreakpoint_x86`
26072610
:return: The hardware breakpoint object.
26082611
"""
2609-
bp = HardwareBreakpoint(address, triggerFlag, sizeFlag, condition, action)
2612+
bp = HardwareBreakpoint_x86(address, triggerFlag, sizeFlag, condition, action)
26102613
begin = bp.get_address()
26112614
end = begin + bp.get_size()
26122615

@@ -2732,7 +2735,7 @@ def get_hardware_breakpoint(self, dwThreadId, address):
27322735
27332736
:param int dwThreadId: Thread global ID.
27342737
:param int address: Memory address where the breakpoint is defined.
2735-
:rtype: :class:`HardwareBreakpoint`
2738+
:rtype: :class:`HardwareBreakpoint_x86`
27362739
:return: The hardware breakpoint object.
27372740
"""
27382741
if dwThreadId not in self.__hardwareBP:
@@ -3007,7 +3010,7 @@ def get_all_page_breakpoints(self):
30073010

30083011
def get_all_hardware_breakpoints(self):
30093012
"""
3010-
:rtype: list of tuple( int, :class:`HardwareBreakpoint` )
3013+
:rtype: list of tuple( int, :class:`HardwareBreakpoint_x86` )
30113014
:return: All hardware breakpoints as a list of tuples (tid, bp).
30123015
"""
30133016
result = list()
@@ -3082,7 +3085,7 @@ def get_thread_hardware_breakpoints(self, dwThreadId):
30823085
:see: :meth:`get_process_hardware_breakpoints`
30833086
30843087
:param int dwThreadId: Thread global ID.
3085-
:rtype: list of :class:`HardwareBreakpoint`
3088+
:rtype: list of :class:`HardwareBreakpoint_x86`
30863089
:return: All hardware breakpoints for the given thread.
30873090
"""
30883091
result = list()
@@ -3097,7 +3100,7 @@ def get_process_hardware_breakpoints(self, dwProcessId):
30973100
:see: :meth:`get_thread_hardware_breakpoints`
30983101
30993102
:param int dwProcessId: Process global ID.
3100-
:rtype: list of tuple( int, :class:`HardwareBreakpoint` )
3103+
:rtype: list of tuple( int, :class:`HardwareBreakpoint_x86` )
31013104
:return: All hardware breakpoints for each thread in the given process
31023105
as a list of tuples (tid, bp).
31033106
"""
@@ -4137,7 +4140,7 @@ def __set_variable_watch(self, tid, address, size, action):
41374140
byte (1), word (2), dword (4) and qword (8).
41384141
:param callable action: (Optional) Action callback function.
41394142
See :meth:`define_hardware_breakpoint` for more details.
4140-
:rtype: :class:`HardwareBreakpoint`
4143+
:rtype: :class:`HardwareBreakpoint_x86`
41414144
:return: Hardware breakpoint at the requested address.
41424145
"""
41434146

winappdbg/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,17 +702,17 @@ def ExecutableAndWriteableAddressIterator(memory_map):
702702
class IntelDebugRegister(StaticClass):
703703
"""
704704
Class to manipulate x86/x64 debug registers.
705-
Used by :class:`HardwareBreakpoint`.
705+
Used by :class:`HardwareBreakpoint_x86`.
706706
707-
.. rubric:: Trigger flags used by HardwareBreakpoint
707+
.. rubric:: Trigger flags used by HardwareBreakpoint_x86
708708
709709
- ``BREAK_ON_EXECUTION``: Break on execution.
710710
- ``BREAK_ON_WRITE``: Break on write.
711711
- ``BREAK_ON_ACCESS``: Break on read or write.
712712
- ``BREAK_ON_IO_ACCESS``: Break on I/O port access.
713713
Not supported by any hardware.
714714
715-
.. rubric:: Size flags used by HardwareBreakpoint
715+
.. rubric:: Size flags used by HardwareBreakpoint_x86
716716
717717
- ``WATCH_BYTE``: Watch a byte.
718718
- ``WATCH_WORD``: Watch a word.
@@ -1057,11 +1057,11 @@ def set_bp(cls, ctx, register, address, trigger, watch):
10571057
10581058
:type trigger: int
10591059
:param trigger:
1060-
Trigger flag. See ``HardwareBreakpoint.validTriggers``.
1060+
Trigger flag. See ``HardwareBreakpoint_x86.validTriggers``.
10611061
10621062
:type watch: int
10631063
:param watch:
1064-
Watch flag. See ``HardwareBreakpoint.validWatchSizes``.
1064+
Watch flag. See ``HardwareBreakpoint_x86.validWatchSizes``.
10651065
"""
10661066
Dr7 = ctx["Dr7"]
10671067
Dr7 |= cls.enableMask[register]

0 commit comments

Comments
 (0)