diff options
Diffstat (limited to 'wrapper')
| -rw-r--r-- | wrapper/Makefile | 2 | ||||
| -rw-r--r-- | wrapper/ptrace.c | 33 |
2 files changed, 34 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. */ #include <sys/ptrace.h> +#include <sys/types.h> #include <sys/wait.h> #include <stddef.h> +#include <unistd.h> + + +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) { |