pull/160/head
Kye 2 years ago
parent e9ea31c615
commit baceee5e61

@ -241,110 +241,110 @@ class ToolsFactory:
##########################################+> SYS ##########################################+> SYS
# import signal import signal
# from typing import Optional, Tuple from typing import Optional, Tuple
# from ptrace.debugger import ( from ptrace.debugger import (
# NewProcessEvent, NewProcessEvent,
# ProcessExecution, ProcessExecution,
# ProcessExit, ProcessExit,
# ProcessSignal, ProcessSignal,
# PtraceDebugger, PtraceDebugger,
# PtraceProcess, PtraceProcess,
# ) )
# from ptrace.func_call import FunctionCallOptions from ptrace.func_call import FunctionCallOptions
# from ptrace.syscall import PtraceSyscall from ptrace.syscall import PtraceSyscall
# from ptrace.tools import signal_to_exitcode from ptrace.tools import signal_to_exitcode
# class SyscallTimeoutException(Exception): class SyscallTimeoutException(Exception):
# def __init__(self, pid: int, *args) -> None: def __init__(self, pid: int, *args) -> None:
# super().__init__(f"deadline exceeded while waiting syscall for {pid}", *args) super().__init__(f"deadline exceeded while waiting syscall for {pid}", *args)
# class SyscallTracer: class SyscallTracer:
# def __init__(self, pid: int): def __init__(self, pid: int):
# self.debugger: PtraceDebugger = PtraceDebugger() self.debugger: PtraceDebugger = PtraceDebugger()
# self.pid: int = pid self.pid: int = pid
# self.process: PtraceProcess = None self.process: PtraceProcess = None
# def is_waiting(self, syscall: PtraceSyscall) -> bool: def is_waiting(self, syscall: PtraceSyscall) -> bool:
# if syscall.name.startswith("wait"): if syscall.name.startswith("wait"):
# return True return True
# return False return False
# def attach(self): def attach(self):
# self.process = self.debugger.addProcess(self.pid, False) self.process = self.debugger.addProcess(self.pid, False)
# def detach(self): def detach(self):
# self.process.detach() self.process.detach()
# self.debugger.quit() self.debugger.quit()
# def set_timer(self, timeout: int): def set_timer(self, timeout: int):
# def handler(signum, frame): def handler(signum, frame):
# raise SyscallTimeoutException(self.process.pid) raise SyscallTimeoutException(self.process.pid)
# signal.signal(signal.SIGALRM, handler) signal.signal(signal.SIGALRM, handler)
# signal.alarm(timeout) signal.alarm(timeout)
# def reset_timer(self): def reset_timer(self):
# signal.alarm(0) signal.alarm(0)
# def wait_syscall_with_timeout(self, timeout: int): def wait_syscall_with_timeout(self, timeout: int):
# self.set_timer(timeout) self.set_timer(timeout)
# self.process.waitSyscall() self.process.waitSyscall()
# self.reset_timer() self.reset_timer()
# def wait_until_stop_or_exit(self) -> Tuple[Optional[int], str]: def wait_until_stop_or_exit(self) -> Tuple[Optional[int], str]:
# self.process.syscall() self.process.syscall()
# exitcode = None exitcode = None
# reason = "" reason = ""
# while True: while True:
# if not self.debugger: if not self.debugger:
# break break
# try: try:
# self.wait_syscall_with_timeout(30) self.wait_syscall_with_timeout(30)
# except ProcessExit as event: except ProcessExit as event:
# if event.exitcode is not None: if event.exitcode is not None:
# exitcode = event.exitcode exitcode = event.exitcode
# continue continue
# except ProcessSignal as event: except ProcessSignal as event:
# event.process.syscall(event.signum) event.process.syscall(event.signum)
# exitcode = signal_to_exitcode(event.signum) exitcode = signal_to_exitcode(event.signum)
# reason = event.reason reason = event.reason
# continue continue
# except NewProcessEvent as event: except NewProcessEvent as event:
# continue continue
# except ProcessExecution as event: except ProcessExecution as event:
# continue continue
# except Exception as e: except Exception as e:
# reason = str(e) reason = str(e)
# break break
# syscall = self.process.syscall_state.event(
# FunctionCallOptions(
# write_types=False,
# write_argname=False,
# string_max_length=300,
# replace_socketcall=True,
# write_address=False,
# max_array_count=20,
# )
# )
# self.process.syscall() syscall = self.process.syscall_state.event(
FunctionCallOptions(
write_types=False,
write_argname=False,
string_max_length=300,
replace_socketcall=True,
write_address=False,
max_array_count=20,
)
)
# if syscall is None: self.process.syscall()
# continue
# if syscall.result: if syscall is None:
# continue continue
if syscall.result:
continue
# self.reset_timer() self.reset_timer()
# return exitcode, reason return exitcode, reason
# ##########################################+> SYS CALL END ##########################################+> SYS CALL END

Loading…
Cancel
Save