about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--TODO.md1
-rw-r--r--include/afl-fuzz.h1
-rw-r--r--src/afl-common.c18
3 files changed, 20 insertions, 0 deletions
diff --git a/TODO.md b/TODO.md
index ace07434..aba3cf81 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,6 +2,7 @@
 
 ## Must
 
+ - fast restart of afl-fuzz if cmdline + target hash is the same
  - hardened_usercopy=0 page_alloc.shuffle=0
  - add value_profile but only enable after 15 minutes without finds
  - cmplog max items env?
diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h
index d3501e8d..e3e4e246 100644
--- a/include/afl-fuzz.h
+++ b/include/afl-fuzz.h
@@ -1278,6 +1278,7 @@ void   get_core_count(afl_state_t *);
 void   fix_up_sync(afl_state_t *);
 void   check_asan_opts(afl_state_t *);
 void   check_binary(afl_state_t *, u8 *);
+u64    get_binary_hash(u8 *fn);
 void   check_if_tty(afl_state_t *);
 void   save_cmdline(afl_state_t *, u32, char **);
 void   read_foreign_testcases(afl_state_t *, int);
diff --git a/src/afl-common.c b/src/afl-common.c
index efdb5d60..4250fb36 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -51,6 +51,8 @@
 #include <fcntl.h>
 #include <signal.h>
 
+#include "hash.h"
+
 u8  be_quiet = 0;
 u8 *doc_path = "";
 u8  last_intr = 0;
@@ -167,6 +169,22 @@ void set_sanitizer_defaults() {
 
 }
 
+u64 get_binary_hash(u8 *fn) {
+
+  int fd = open(fn, O_RDONLY);
+  if (fd < 0) { PFATAL("Unable to open '%s'", fn); }
+  struct stat st;
+  if (fstat(fd, &st) < 0) { PFATAL("Unable to fstat '%s'", fn); }
+  u32 f_len = st.st_size;
+  u8 *f_data = mmap(0, f_len, PROT_READ, MAP_PRIVATE, fd, 0);
+  if (f_data == MAP_FAILED) { PFATAL("Unable to mmap file '%s'", fn); }
+  close(fd);
+  u64 hash = hash64(f_data, f_len, 0);
+  if (munmap(f_data, f_len)) { PFATAL("unmap() failed"); }
+  return hash;
+
+}
+
 u32 check_binary_signatures(u8 *fn) {
 
   int ret = 0, fd = open(fn, O_RDONLY);