|
|
@@ -0,0 +1,56 @@
|
|
|
+
|
|
|
+#include <sys/ptrace.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#include <sys/user.h>
|
|
|
+#include <sys/wait.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include "sandbox.h"
|
|
|
+
|
|
|
+
|
|
|
+/* DEBUG HEADER */
|
|
|
+#include <stdio.h>
|
|
|
+
|
|
|
+void doExec(int pid_parent, const t_param *params)
|
|
|
+{
|
|
|
+ char **argv = (char **)params->cmd;
|
|
|
+
|
|
|
+ ptrace(PTRACE_TRACEME, 0, 0, 0);
|
|
|
+ kill(getpid(), SIGINT);
|
|
|
+ execvp(argv[0], argv);
|
|
|
+}
|
|
|
+
|
|
|
+void doTrace(int pid, const t_param *params)
|
|
|
+{
|
|
|
+ int status;
|
|
|
+ struct user_regs_struct registers;
|
|
|
+
|
|
|
+ waitpid(pid, &status, 0);
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ ptrace(PTRACE_SYSCALL, pid, NULL, 0);
|
|
|
+ if (waitpid(pid, &status, 0) == -1)
|
|
|
+ break;
|
|
|
+ ptrace(PTRACE_GETREGS, pid, 0, ®isters);
|
|
|
+ printf("CALL %llu\n", (int) registers.orig_rax);
|
|
|
+ fflush(stdout);
|
|
|
+
|
|
|
+ /* syscall return */
|
|
|
+ ptrace(PTRACE_SYSCALL, pid, NULL, 0);
|
|
|
+ if (waitpid(pid, &status, 0) == -1)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int launch_program(const t_param *params)
|
|
|
+{
|
|
|
+ int child = fork();
|
|
|
+
|
|
|
+ if (child == -1)
|
|
|
+ return -1;
|
|
|
+ else if (child == 0)
|
|
|
+ doExec(getpid(), params);
|
|
|
+ else
|
|
|
+ doTrace(child, params);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|