Skip to content

Commit eab8099

Browse files
authored
Merge pull request #984 from commial/feature/remove_bp_by_addr
Add a "remove_breakpoints_by_address" capability to jitter
2 parents 016eed4 + a9a20dd commit eab8099

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

miasm2/jitter/jitload.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ class CallbackHandler(object):
6767
def __init__(self):
6868
self.callbacks = {} # Key -> [callback list]
6969

70-
def add_callback(self, name, callback):
71-
"""Add a callback to the key @name, iff the @callback isn't already
70+
def add_callback(self, key, callback):
71+
"""Add a callback to the key @key, iff the @callback isn't already
7272
assigned to it"""
73-
if callback not in self.callbacks.get(name, []):
74-
self.callbacks[name] = self.callbacks.get(name, []) + [callback]
73+
if callback not in self.callbacks.get(key, []):
74+
self.callbacks[key] = self.callbacks.get(key, []) + [callback]
7575

76-
def set_callback(self, name, *args):
77-
"Set the list of callback for key 'name'"
78-
self.callbacks[name] = list(args)
76+
def set_callback(self, key, *args):
77+
"Set the list of callback for key 'key'"
78+
self.callbacks[key] = list(args)
7979

80-
def get_callbacks(self, name):
81-
"Return the list of callbacks associated to key 'name'"
82-
return self.callbacks.get(name, [])
80+
def get_callbacks(self, key):
81+
"Return the list of callbacks associated to key 'key'"
82+
return self.callbacks.get(key, [])
8383

8484
def remove_callback(self, callback):
8585
"""Remove the callback from the list.
@@ -101,24 +101,30 @@ def remove_callback(self, callback):
101101

102102
return empty_keys
103103

104-
def has_callbacks(self, name):
105-
return name in self.callbacks
104+
def has_callbacks(self, key):
105+
return key in self.callbacks
106106

107-
def call_callbacks(self, name, *args):
108-
"""Call callbacks associated to key 'name' with arguments args. While
107+
def remove_key(self, key):
108+
"""Remove and return all callbacks associated to @key"""
109+
callbacks = self.callbacks.get(key, [])
110+
del self.callbacks[key]
111+
return callbacks
112+
113+
def call_callbacks(self, key, *args):
114+
"""Call callbacks associated to key 'key' with arguments args. While
109115
callbacks return True, continue with next callback.
110116
Iterator on other results."""
111117

112118
res = True
113119

114-
for c in self.get_callbacks(name):
120+
for c in self.get_callbacks(key):
115121
res = c(*args)
116122
if res is not True:
117123
yield res
118124

119-
def __call__(self, name, *args):
125+
def __call__(self, key, *args):
120126
"Wrapper for call_callbacks"
121-
return self.call_callbacks(name, *args)
127+
return self.call_callbacks(key, *args)
122128

123129

124130
class CallbackHandlerBitflag(CallbackHandler):
@@ -299,6 +305,14 @@ def remove_breakpoints_by_callback(self, callback):
299305
for key in empty_keys:
300306
self.jit.remove_disassembly_splits(key)
301307

308+
def remove_breakpoints_by_address(self, address):
309+
"""Remove all breakpoints associated with @address.
310+
@address: address of breakpoints to remove
311+
"""
312+
callbacks = self.breakpoints_handler.remove_key(address)
313+
if callbacks:
314+
self.jit.remove_disassembly_splits(address)
315+
302316
def add_exception_handler(self, flag, callback):
303317
"""Add a callback associated with an exception flag.
304318
@flag: bitflag

0 commit comments

Comments
 (0)