From e687f96e883af18ef293b6844ef28f0c829d6e3c Mon Sep 17 00:00:00 2001 From: jakob Date: Mon, 28 Aug 2017 15:15:01 -0400 Subject: Updated ptrace wrapper to allow creation of new processes. --- wrapper/Makefile | 2 +- wrapper/ptrace.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'wrapper') diff --git a/wrapper/Makefile b/wrapper/Makefile index 1019833..026f4ba 100644 --- a/wrapper/Makefile +++ b/wrapper/Makefile @@ -8,5 +8,5 @@ LDFLAGS += $(USER_LDFLAGS) all: libptracew.so -libtestw.so: ptrace.c +libptracew.so: ptrace.c $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) diff --git a/wrapper/ptrace.c b/wrapper/ptrace.c index 3ce42a1..caf510f 100644 --- a/wrapper/ptrace.c +++ b/wrapper/ptrace.c @@ -16,9 +16,42 @@ along with Hypodermic. If not, see . */ #include +#include #include #include +#include + + +static void run_target(const char *path) { + if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) < 0) { + return; + } + + execl(path, path, 0); +} + + +int new_proc(const char *path) { + int wait_stat; + pid_t pid; + + if (path == NULL) { + return -1; + } + + pid = fork(); + + if (pid == 0) { + run_target(path); + } else if (pid > 0) { + wait(&wait_stat); + } else { + return -1; + } + + return pid; +} int attach(int pid) { -- cgit v1.3