From 90af0227e0c5d61a0756625a5d0e6c638363652e Mon Sep 17 00:00:00 2001 From: Maxime Meignan Date: Wed, 22 Feb 2017 04:31:04 -0500 Subject: [PATCH] implements a basic ptrace support now handles PTRACE_TRACEME requests --- simuvex/procedures/libc___so___6/ptrace.py | 11 +++++++ simuvex/procedures/syscalls/ptrace.py | 35 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 simuvex/procedures/libc___so___6/ptrace.py create mode 100644 simuvex/procedures/syscalls/ptrace.py diff --git a/simuvex/procedures/libc___so___6/ptrace.py b/simuvex/procedures/libc___so___6/ptrace.py new file mode 100644 index 00000000..4b12accd --- /dev/null +++ b/simuvex/procedures/libc___so___6/ptrace.py @@ -0,0 +1,11 @@ +import simuvex + +class ptrace(simuvex.SimProcedure): + def run(self, request, pid, addr, data): #pylint:disable=arguments-differ,unused-argument + + return self.inline_call(simuvex.SimProcedures['syscalls']['ptrace'], + request, + pid, + addr, + data + ).ret_expr diff --git a/simuvex/procedures/syscalls/ptrace.py b/simuvex/procedures/syscalls/ptrace.py new file mode 100644 index 00000000..a7698a1e --- /dev/null +++ b/simuvex/procedures/syscalls/ptrace.py @@ -0,0 +1,35 @@ +import simuvex +import logging + +###################################### +# ptrace +###################################### + +l = logging.getLogger("simuvex.procedures.syscall") + +class ptrace(simuvex.SimProcedure): + #pylint:disable=arguments-differ,unused-argument + + IS_SYSCALL = True + + def run(self, request, pid, addr, data): + if self.state.se.symbolic(request): + l.warning("Symbolic PTRACE_* request, returning unconstrained value") + res = self.state.se.BVS('ptrace_return', self.state.arch.bits) + + else: + request_concrete = self.state.se.any_int(request) + # PTRACE_TRACEME + if request_concrete == 0: + # process is already traced + if 'ptrace_istraced' in self.state.procedure_data.global_variables and self.state.procedure_data.global_variables['ptrace_istraced']: + res = self.state.se.BVV(-1, self.state.arch.bits) + + else: + self.state.procedure_data.global_variables['ptrace_istraced'] = True + res = self.state.se.BVV(0, self.state.arch.bits) + + else: + l.error("Unimplemented PTRACE_* request(#%d), returning unconstrained value", request_concrete) + res = self.state.se.BVS('ptrace_return', self.state.arch.bits) + return res