@@ -231,6 +231,7 @@ def _setup_prototype(lib, fname, restype, *argtypes):
231231 ctypes .c_int , ctypes .c_void_p )
232232UC_HOOK_INSN_OUT_CB = ctypes .CFUNCTYPE (None , ctypes .c_size_t , ctypes .c_uint32 , \
233233 ctypes .c_int , ctypes .c_uint32 , ctypes .c_void_p )
234+ UC_HOOK_INSN_SYSCALL_CB = ctypes .CFUNCTYPE (None , ctypes .c_size_t , ctypes .c_void_p )
234235
235236
236237# access to error code via @errno of UcError
@@ -383,6 +384,12 @@ def _hook_insn_out_cb(self, handle, port, size, value, user_data):
383384 cb (self , port , size , value , data )
384385
385386
387+ def _hook_insn_syscall_cb (self , handle , user_data ):
388+ # call user's callback with self object
389+ (cb , data ) = self ._callbacks [user_data ]
390+ cb (self , data )
391+
392+
386393 # add a hook
387394 def hook_add (self , htype , callback , user_data = None , arg1 = 1 , arg2 = 0 ):
388395 _h2 = ctypes .c_size_t ()
@@ -413,6 +420,8 @@ def hook_add(self, htype, callback, user_data=None, arg1=1, arg2=0):
413420 cb = ctypes .cast (UC_HOOK_INSN_IN_CB (self ._hook_insn_in_cb ), UC_HOOK_INSN_IN_CB )
414421 if arg1 == x86_const .X86_INS_OUT : # OUT instruction
415422 cb = ctypes .cast (UC_HOOK_INSN_OUT_CB (self ._hook_insn_out_cb ), UC_HOOK_INSN_OUT_CB )
423+ if arg1 in (x86_const .X86_INS_SYSCALL , x86_const .X86_INS_SYSENTER ): # SYSCALL/SYSENTER instruction
424+ cb = ctypes .cast (UC_HOOK_INSN_SYSCALL_CB (self ._hook_insn_syscall_cb ), UC_HOOK_INSN_SYSCALL_CB )
416425 status = _uc .uc_hook_add (self ._uch , ctypes .byref (_h2 ), htype , \
417426 cb , ctypes .cast (self ._callback_count , ctypes .c_void_p ), insn )
418427 elif htype == UC_HOOK_INTR :
0 commit comments