diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-11-11 14:32:50 +0100 |
---|---|---|
committer | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-11-11 14:32:50 +0100 |
commit | cd84339bccc104a51a5da614a9f82cc4ae615cce (patch) | |
tree | 7eba7ed8cdfa670e0e92f3240c17829ebc2445c3 /src/afl-fuzz.c | |
parent | 66791a5dad72e56c60fde4db2e53ff91c491da95 (diff) | |
download | afl++-cd84339bccc104a51a5da614a9f82cc4ae615cce.tar.gz |
libradamsa dlopen
Diffstat (limited to 'src/afl-fuzz.c')
-rw-r--r-- | src/afl-fuzz.c | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 14462fb7..a9a576fe 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -24,7 +24,58 @@ */ #include "afl-fuzz.h" -#include "radamsa.h" + +static u8* get_libradamsa_path(u8* own_loc) { + + u8 *tmp, *cp, *rsl, *own_copy; + + tmp = getenv("AFL_PATH"); + + if (tmp) { + + cp = alloc_printf("%s/libradamsa.so", tmp); + + if (access(cp, X_OK)) FATAL("Unable to find '%s'", cp); + + return cp; + + } + + own_copy = ck_strdup(own_loc); + rsl = strrchr(own_copy, '/'); + + if (rsl) { + + *rsl = 0; + + cp = alloc_printf("%s/libradamsa.so", own_copy); + ck_free(own_copy); + + if (!access(cp, X_OK)) + return cp; + + } else + + ck_free(own_copy); + + if (!access(BIN_PATH "/libradamsa.so", X_OK)) { + + return ck_strdup(BIN_PATH "/libradamsa.so"); + + } + + SAYF("\n" cLRD "[-] " cRST + "Oops, unable to find the 'libradamsa.so' binary. The binary must be " + "built\n" + " separately using 'make radamsa'." + "If you\n" + " already have the binary installed, you may need to specify " + "AFL_PATH in the\n" + " environment.\n"); + + FATAL("Failed to locate 'libradamsa.so'."); + +} /* Display usage hints. */ @@ -545,9 +596,21 @@ int main(int argc, char** argv) { if (use_radamsa) { OKF("Using Radamsa add-on"); - /* randamsa_init installs some signal hadlers, call it firstly so that - AFL++ can then replace those signal handlers */ - radamsa_init(); + + u8* libradamsa_path = get_libradamsa_path(argv[0]); + void* handle = dlopen(libradamsa_path, RTLD_NOW); + ck_free(libradamsa_path); + + if (!handle) FATAL("Failed to dlopen() libradamsa"); + + void (*radamsa_init_ptr)(void) = dlsym(handle, "radamsa_init"); + radamsa_mutate_ptr = dlsym(handle, "radamsa_mutate"); + + if (!radamsa_init_ptr || !radamsa_mutate_ptr) FATAL("Failed to dlsym() libradamsa"); + + /* randamsa_init installs some signal hadlers, call it before setup_signal_handlers + so that AFL++ can then replace those signal handlers */ + radamsa_init_ptr(); } |