This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements a basic PTRACE_TRACEME support
- Loading branch information
Showing
2 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
import simuvex | ||
import logging | ||
|
||
###################################### | ||
# ptrace | ||
###################################### | ||
|
||
l = logging.getLogger("simuvex.procedures.syscall") | ||
|
||
class ptrace(simuvex.SimProcedure): | ||
#pylint:disable=arguments-differ | ||
#pylint:disable=arguments-differ,unused-argument | ||
|
||
IS_SYSCALL = True | ||
|
||
selftraced = False | ||
|
||
def run(self, request, pid, addr, data): | ||
request = self.state.se.any_int(request) | ||
|
||
# if request == PTRACE_TRACEME | ||
if request == 0: | ||
# returns an error if process is already traced | ||
if ptrace.selftraced: | ||
res=self.state.se.BVV(-1, self.state.arch.bits) | ||
|
||
else: | ||
ptrace.selftraced = True | ||
res=self.state.se.BVV(0, self.state.arch.bits) | ||
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: | ||
raise simuvex.SimProcedureError("Unimplemented PTRACE_* request(#"+str(request)+")") | ||
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 |