Debian Codegraph @

ptrace/debugger/syscall_state.py

raw
1 from ptrace.syscall import PtraceSyscall
2 from signal import SIGTRAP
3
4
5 class SyscallState(object):
6
7 def __init__(self, process):
8 self.process = process
9 self.ignore_exec_trap = True
10 self.ignore_callback = None
11 self.clear()
12
13 def event(self, options):
14 if self.next_event == "exit":
15 return self.exit()
16 else:
17 return self.enter(options)
18
19 def enter(self, options):
20 # syscall enter
21 regs = self.process.getregs()
22 self.syscall = PtraceSyscall(self.process, options, regs)
23 self.name = self.syscall.name
24 if (not self.ignore_callback) \
25 or (not self.ignore_callback(self.syscall)):
26 self.syscall.enter(regs)
27 else:
28 self.syscall = None
29 self.next_event = "exit"
30 return self.syscall
31
32 def exit(self):
33 if self.syscall:
34 self.syscall.exit()
35 if self.ignore_exec_trap \
36 and self.name == "execve" \
37 and not self.process.debugger.trace_exec:
38 # Ignore the SIGTRAP after exec() syscall exit
39 self.process.syscall()
40 self.process.waitSignals(SIGTRAP, SIGTRAP | 0x80)
41 syscall = self.syscall
42 self.clear()
43 return syscall
44
45 def clear(self):
46 self.syscall = None
47 self.name = None
48 self.next_event = "enter"