@@ -161,35 +161,32 @@ def getNameFromErrorCode(ret: int) -> str:
161161 def load_syscall (self ):
162162 # import syscall mapping function
163163 map_syscall = ql_syscall_mapping_function (self .ql .ostype )
164- syscall = self .syscall
165- syscall_name = map_syscall (self .ql , syscall )
164+ syscall_id = self .syscall
165+ syscall_name = map_syscall (self .ql , syscall_id )
166166
167167 # get syscall on-enter hook (if any)
168168 hooks_dict = self .posix_syscall_hooks [QL_INTERCEPT .ENTER ]
169- onenter_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall )
169+ onenter_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall_id )
170170
171171 # get syscall on-exit hook (if any)
172172 hooks_dict = self .posix_syscall_hooks [QL_INTERCEPT .EXIT ]
173- onexit_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall )
173+ onexit_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall_id )
174174
175175 # get syscall replacement hook (if any)
176176 hooks_dict = self .posix_syscall_hooks [QL_INTERCEPT .CALL ]
177- syscall_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall )
177+ syscall_hook = hooks_dict .get (syscall_name ) or hooks_dict .get (syscall_id )
178178
179- if syscall_hook :
180- syscall_name = syscall_hook .__name__
181- else :
182- _ostype_str = ostype_convert_str (self .ql .ostype )
183- _posix_syscall = ql_get_module_function (f"qiling.os.posix" , "syscall" )
184- _os_syscall = ql_get_module_function (f"qiling.os.{ _ostype_str .lower ()} " , "syscall" )
179+ if not syscall_hook :
180+ osname = ostype_convert_str (self .ql .ostype )
181+ os_syscalls = ql_get_module_function (f"qiling.os.{ osname .lower ()} " , "syscall" )
182+ posix_syscalls = ql_get_module_function (f"qiling.os.posix" , "syscall" )
185183
186- if syscall_name in dir (_posix_syscall ) or syscall_name in dir (_os_syscall ):
187- syscall_hook = eval (syscall_name )
188- syscall_name = syscall_hook .__name__
189- else :
190- syscall_hook = None
184+ # look in os-specific and posix syscall hooks
185+ syscall_hook = getattr (os_syscalls , syscall_name , None ) or getattr (posix_syscalls , syscall_name , None )
191186
192187 if syscall_hook :
188+ syscall_name = syscall_hook .__name__
189+
193190 # extract the parameters list from hook signature
194191 param_names = tuple (signature (syscall_hook ).parameters .values ())
195192
@@ -225,12 +222,11 @@ def load_syscall(self):
225222 raise
226223
227224 except Exception as e :
228- self .ql .log .exception ("" )
229- self .ql .log .info (f'Syscall ERROR: { syscall_name } DEBUG: { e } ' )
225+ self .ql .log .exception (f'Syscall ERROR: { syscall_name } DEBUG: { e } ' )
230226 raise e
231227
232228 # print out log entry
233- syscall_basename = syscall_hook . __name__ [len (SYSCALL_PREF ):]
229+ syscall_basename = syscall_name [len (SYSCALL_PREF ):]
234230 args = []
235231
236232 for name , value in zip (param_names , params ):
@@ -254,10 +250,10 @@ def load_syscall(self):
254250
255251 self .utils .syscalls_counter += 1
256252 else :
257- self .ql .log .warning (f'{ self .ql .reg .arch_pc :#x} : syscall { syscall_name } number = { syscall :#x} ({ syscall :d} ) not implemented' )
253+ self .ql .log .warning (f'{ self .ql .reg .arch_pc :#x} : syscall { syscall_name } number = { syscall_id :#x} ({ syscall_id :d} ) not implemented' )
258254
259255 if self .ql .debug_stop :
260- raise QlErrorSyscallNotFound (" Syscall Not Found" )
256+ raise QlErrorSyscallNotFound (f' Syscall not found: { syscall_name } ' )
261257
262258 def get_syscall (self ) -> int :
263259 if self .ql .archtype == QL_ARCH .ARM :
0 commit comments