@@ -315,7 +315,7 @@ def _hook_insn_syscall_cb(self, handle, user_data):
315
315
316
316
317
317
# add a hook
318
- def hook_add (self , htype , callback , user_data = None , arg1 = 1 , arg2 = 0 ):
318
+ def hook_add (self , htype , callback , user_data = None , begin = 1 , end = 0 , arg1 = 0 ):
319
319
_h2 = uc_hook_h ()
320
320
321
321
# save callback & user_data
@@ -332,30 +332,28 @@ def hook_add(self, htype, callback, user_data=None, arg1=1, arg2=0):
332
332
if arg1 in (x86_const .UC_X86_INS_SYSCALL , x86_const .UC_X86_INS_SYSENTER ): # SYSCALL/SYSENTER instruction
333
333
cb = ctypes .cast (UC_HOOK_INSN_SYSCALL_CB (self ._hook_insn_syscall_cb ), UC_HOOK_INSN_SYSCALL_CB )
334
334
status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , \
335
- cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), insn )
335
+ cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), ctypes . c_uint64 ( begin ), ctypes . c_uint64 ( end ), insn )
336
336
elif htype == UC_HOOK_INTR :
337
337
cb = ctypes .cast (UC_HOOK_INTR_CB (self ._hook_intr_cb ), UC_HOOK_INTR_CB )
338
338
status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , \
339
- cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ))
339
+ cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), ctypes . c_uint64 ( begin ), ctypes . c_uint64 ( end ) )
340
340
else :
341
- begin = ctypes .c_uint64 (arg1 )
342
- end = ctypes .c_uint64 (arg2 )
343
341
if htype in (UC_HOOK_BLOCK , UC_HOOK_CODE ):
344
342
# set callback with wrapper, so it can be called
345
343
# with this object as param
346
344
cb = ctypes .cast (UC_HOOK_CODE_CB (self ._hookcode_cb ), UC_HOOK_CODE_CB )
347
345
status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , cb , \
348
- ctypes .cast (self ._callback_count , ctypes .c_void_p ), begin , end )
346
+ ctypes .cast (self ._callback_count , ctypes .c_void_p ), ctypes . c_uint64 ( begin ), ctypes . c_uint64 ( end ) )
349
347
elif htype & UC_HOOK_MEM_READ_UNMAPPED or htype & UC_HOOK_MEM_WRITE_UNMAPPED or \
350
348
htype & UC_HOOK_MEM_FETCH_UNMAPPED or htype & UC_HOOK_MEM_READ_PROT or \
351
349
htype & UC_HOOK_MEM_WRITE_PROT or htype & UC_HOOK_MEM_FETCH_PROT :
352
350
cb = ctypes .cast (UC_HOOK_MEM_INVALID_CB (self ._hook_mem_invalid_cb ), UC_HOOK_MEM_INVALID_CB )
353
351
status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , \
354
- cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ))
352
+ cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), ctypes . c_uint64 ( begin ), ctypes . c_uint64 ( end ) )
355
353
else :
356
354
cb = ctypes .cast (UC_HOOK_MEM_ACCESS_CB (self ._hook_mem_access_cb ), UC_HOOK_MEM_ACCESS_CB )
357
355
status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , \
358
- cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ))
356
+ cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), ctypes . c_uint64 ( begin ), ctypes . c_uint64 ( end ) )
359
357
360
358
# save the ctype function so gc will leave it alone.
361
359
self ._ctype_cbs [self ._callback_count ] = cb
0 commit comments