about summary refs log tree commit diff
path: root/instrumentation
diff options
context:
space:
mode:
authorDavide Quarta <quarta@qti.qualcomm.com>2024-01-23 19:36:49 +0100
committerDavide Quarta <quarta@qti.qualcomm.com>2024-01-23 19:36:49 +0100
commit8fedf4998449d5b6b909a1118fc2e152e4d2e6e7 (patch)
tree71c8d03f94c006f952be8522f8403fe0fca273c7 /instrumentation
parentb99bbf671b7469a5aad29898fe28489004c4cbe7 (diff)
downloadafl++-8fedf4998449d5b6b909a1118fc2e152e4d2e6e7.tar.gz
replay mode support
Diffstat (limited to 'instrumentation')
-rw-r--r--instrumentation/afl-compiler-rt.o.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index 39a762b6..0fa22aee 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -83,6 +83,10 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 
+#ifdef AFL_PERSISTENT_REPLAY
+#include "persistent_replay.h"
+#endif
+
 /* Globals needed by the injected instrumentation. The __afl_area_initial region
    is used for instrumentation output before __afl_map_shm() has a chance to
    run. It will end up as .comm, so it shouldn't be too wasteful. */
@@ -1338,6 +1342,38 @@ int __afl_persistent_loop(unsigned int max_cnt) {
   static u8  first_pass = 1;
   static u32 cycle_cnt;
 
+#ifdef AFL_PERSISTENT_REPLAY
+
+#ifndef PATH_MAX
+  #define PATH_MAX 4096
+#endif
+
+  static u8  inited = 0;
+  char tcase[PATH_MAX];
+
+  if( unlikely(is_replay_record) ){
+
+      if (!inited){
+        cycle_cnt = replay_record_cnt;
+        inited = 1;
+      }
+
+      snprintf(tcase, PATH_MAX, "%s/%s",
+                  replay_record_dir ? replay_record_dir : "./",
+                  record_list[replay_record_cnt-cycle_cnt]->d_name);
+
+      if (record_arg) {
+        *record_arg = tcase;
+      } else {
+        int fd = open(tcase, O_RDONLY);
+        dup2(fd, 0);
+        close(fd);
+      }
+    return cycle_cnt--;
+  } else
+
+#endif  
+
   if (first_pass) {
 
     /* Make sure that every iteration of __AFL_LOOP() starts with a clean slate.