mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-21 05:42:12 +00:00
move function
This commit is contained in:
@ -51,8 +51,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
u8 be_quiet = 0;
|
||||
u8 *doc_path = "";
|
||||
u8 last_intr = 0;
|
||||
@ -169,22 +167,6 @@ 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);
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user