summary refs log tree commit diff
path: root/libAflDyninst.cpp
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2018-03-16 03:28:38 +0100
committervan Hauser <vh@thc.org>2018-03-16 03:28:38 +0100
commitec63e8c3dbea7e18bf3c2dd18d1216c5906f704e (patch)
tree0559a7330f663e161c8ffcd178872062d047b97f /libAflDyninst.cpp
parent682b4f6b8a0d3244775e1c32563031cbd9277e24 (diff)
downloadafl-dyninst-ec63e8c3dbea7e18bf3c2dd18d1216c5906f704e.tar.gz
finished dynamorio changes
Diffstat (limited to 'libAflDyninst.cpp')
-rw-r--r--libAflDyninst.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/libAflDyninst.cpp b/libAflDyninst.cpp
index 43d5d78..9b48102 100644
--- a/libAflDyninst.cpp
+++ b/libAflDyninst.cpp
@@ -93,3 +93,41 @@ void save_rdi() {
 void restore_rdi() {
   rdi = saved_di;
 }
+
+
+void initOnlyAflForkServer() {
+  // enter fork() server thyme!
+  int n = write(FORKSRV_FD + 1, &__afl_temp_data, 4);
+
+  if (n != 4) {
+    PRINT_ERROR("Error writting fork server\n");
+    return;
+  }
+  while (1) {
+    n = read(FORKSRV_FD, &__afl_temp_data, 4);
+    if (n != 4) {
+      PRINT_ERROR("Error reading fork server\n");
+      return;
+    }
+
+    __afl_fork_pid = fork();
+    if (__afl_fork_pid < 0) {
+      PRINT_ERROR("Error on fork()\n");
+      return;
+    }
+    if (__afl_fork_pid == 0) {
+      close(FORKSRV_FD);
+      close(FORKSRV_FD + 1);
+      break;
+    } else {
+      // parrent stuff
+      n = write(FORKSRV_FD + 1, &__afl_fork_pid, 4);
+      pid_t temp_pid = waitpid(__afl_fork_pid, &__afl_temp_data, 2);
+
+      if (temp_pid == 0) {
+        return;
+      }
+      n = write(FORKSRV_FD + 1, &__afl_temp_data, 4);
+    }
+  }
+}