diff options
| author | jakob <jakob@memeware.net> | 2017-08-28 15:15:01 -0400 |
|---|---|---|
| committer | jakob <jakob@memeware.net> | 2017-08-28 15:15:01 -0400 |
| commit | e687f96e883af18ef293b6844ef28f0c829d6e3c (patch) | |
| tree | dc34dc46e384071e962694f5a5ac5f01cec8f08e /wrapper/ptrace.c | |
| parent | a4365445d4d32001362f6e8bfae93a3b8f152fde (diff) | |
Updated ptrace wrapper to allow creation of new processes.
Diffstat (limited to 'wrapper/ptrace.c')
| -rw-r--r-- | wrapper/ptrace.c | 33 |
1 files changed, 33 insertions, 0 deletions
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) { |