about summary refs log tree commit diff
path: root/src/afl-performance.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2024-06-09 19:09:17 +0200
committerGitHub <noreply@github.com>2024-06-09 19:09:17 +0200
commit9f6b012fbfc8b79dda83e73a208e429aaf25e7ee (patch)
tree7f729cd9133553252979386a910c4072e59293d9 /src/afl-performance.c
parentfd713413e85a45a18c51712f55d5742356f00730 (diff)
parentec0b83f127702fe23da72f4d424bc13a5bacfae9 (diff)
downloadafl++-9f6b012fbfc8b79dda83e73a208e429aaf25e7ee.tar.gz
Merge pull request #2117 from AFLplusplus/dev v4.21c
push to stable
Diffstat (limited to 'src/afl-performance.c')
-rw-r--r--src/afl-performance.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/afl-performance.c b/src/afl-performance.c
index 6c6e3c8b..e8ece6b5 100644
--- a/src/afl-performance.c
+++ b/src/afl-performance.c
@@ -95,6 +95,24 @@ inline u64 hash64(u8 *key, u32 len, u64 seed) {
 
 }
 
+/* Hash a file */
+
+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;
+
+}
+
 // Public domain SHA1 implementation copied from:
 // https://github.com/x42/liboauth/blob/7001b8256cd654952ec2515b055d2c5b243be600/src/sha1.c