Skip to content

Commit 048c136

Browse files
committed
Simplify catch_KeyboardInterrupt
1 parent 46020d6 commit 048c136

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

qiling/core_hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ def _hook_addr_cb(self, uc: Uc, addr: int, size: int, pack_data):
149149
# Class Hooks #
150150
###############
151151
def _ql_hook_internal(self, hook_type, callback, user_data=None, *args) -> int:
152-
_callback = (catch_KeyboardInterrupt(self))(callback)
152+
_callback = catch_KeyboardInterrupt(self, callback)
153153
# pack user_data & callback for wrapper _callback
154154
return self._h_uc.hook_add(hook_type, _callback, (self, user_data), 1, 0, *args)
155155

156156

157157
def _ql_hook_addr_internal(self, callback: Callable, address: int) -> int:
158-
_callback = (catch_KeyboardInterrupt(self))(callback)
159-
# pack user_data & callback for wrapper _callback
158+
_callback = catch_KeyboardInterrupt(self, callback)
159+
160160
return self._h_uc.hook_add(UC_HOOK_CODE, _callback, self, address, address)
161161

162162

qiling/utils.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
from qiling.const import QL_ARCH, QL_ENDIAN, QL_OS, QL_DEBUGGER
2222
from qiling.const import debugger_map, arch_map, os_map, arch_os_map
2323

24-
def catch_KeyboardInterrupt(ql):
25-
def decorator(func):
26-
def wrapper(*args, **kw):
27-
try:
28-
return func(*args, **kw)
29-
except BaseException as e:
30-
ql.stop()
31-
ql._internal_exception = e
32-
33-
return wrapper
34-
35-
return decorator
24+
def catch_KeyboardInterrupt(ql, func):
25+
def wrapper(*args, **kw):
26+
try:
27+
return func(*args, **kw)
28+
except BaseException as e:
29+
ql.stop()
30+
ql._internal_exception = e
31+
32+
return wrapper
3633

3734
def enum_values(e: Type[Enum]) -> Container:
3835
return e.__members__.values()

0 commit comments

Comments
 (0)