summaryrefslogtreecommitdiff
path: root/wrapper
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-08-28 15:15:01 -0400
committerjakob <jakob@memeware.net>2017-08-28 15:15:01 -0400
commite687f96e883af18ef293b6844ef28f0c829d6e3c (patch)
treedc34dc46e384071e962694f5a5ac5f01cec8f08e /wrapper
parenta4365445d4d32001362f6e8bfae93a3b8f152fde (diff)
Updated ptrace wrapper to allow creation of new processes.
Diffstat (limited to 'wrapper')
-rw-r--r--wrapper/Makefile2
-rw-r--r--wrapper/ptrace.c33
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) {