From 8927b31b8ef6334a5efd28ea779db5a58ac5d445 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 3 Sep 2017 16:19:33 -0400 Subject: Implemented basic machine code injection. --- wrapper/ptrace.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'wrapper/ptrace.c') diff --git a/wrapper/ptrace.c b/wrapper/ptrace.c index 8517519..706fd4e 100644 --- a/wrapper/ptrace.c +++ b/wrapper/ptrace.c @@ -81,6 +81,18 @@ int cont(int pid) { return -1; } + waitpid(pid, &s, WNOHANG); + return 0; +} + + +int step(int pid) { + int s; + + if ((ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL)) < 0) { + return -1; + } + while (!WIFSTOPPED(s)) { waitpid(pid, &s, WNOHANG); } @@ -108,6 +120,16 @@ unsigned long long getreg(int pid, int idx) { return ((unsigned long long *) ®s)[idx]; } + +void setreg(int pid, int idx, unsigned long long value) { + struct user_regs_struct regs; + + ptrace(PTRACE_GETREGS, pid, NULL, ®s); + + ((unsigned long long *) ®s)[idx] = value; + + ptrace(PTRACE_SETREGS, pid, NULL, ®s); +} #else unsigned long getreg(int pid, int idx) { struct user_regs_struct regs; @@ -116,4 +138,14 @@ unsigned long getreg(int pid, int idx) { return ((unsigned long *) ®s)[idx]; } + +void setreg(int pid, int idx, unsigned long value) { + struct user_regs_struct regs; + + ptrace(PTRACE_GETREGS, pid, NULL, ®s); + + ((unsigned long *) ®s)[idx] = value; + + ptrace(PTRACE_SETREGS, pid, NULL, ®s); +} #endif -- cgit v1.3