aboutsummaryrefslogtreecommitdiff
path: root/utils/aflpp_driver
diff options
context:
space:
mode:
authorhexcoder <hexcoder-@users.noreply.github.com>2021-05-31 19:18:24 +0200
committerGitHub <noreply@github.com>2021-05-31 19:18:24 +0200
commit97a1f89881878db9bd6b4cd666b3447a63818dcf (patch)
tree46e844356f7cf88c08f9f9907caa11656a24f416 /utils/aflpp_driver
parentb246de789105750558f3d6f884ba61e54cb98441 (diff)
parent1a2da67ed0505c9ac0aa1048ba3d607f3c1aa639 (diff)
downloadafl++-97a1f89881878db9bd6b4cd666b3447a63818dcf.tar.gz
Merge branch 'dev' into going_atomic
Diffstat (limited to 'utils/aflpp_driver')
-rw-r--r--utils/aflpp_driver/GNUmakefile6
-rw-r--r--utils/aflpp_driver/README.md6
-rw-r--r--utils/aflpp_driver/aflpp_driver.c44
-rw-r--r--utils/aflpp_driver/aflpp_qemu_driver_hook.c10
4 files changed, 48 insertions, 18 deletions
diff --git a/utils/aflpp_driver/GNUmakefile b/utils/aflpp_driver/GNUmakefile
index 8ac054a6..ad99b893 100644
--- a/utils/aflpp_driver/GNUmakefile
+++ b/utils/aflpp_driver/GNUmakefile
@@ -7,7 +7,7 @@ ifneq "" "$(LLVM_BINDIR)"
LLVM_BINDIR := $(LLVM_BINDIR)/
endif
-CFLAGS := -O3 -funroll-loops -g
+CFLAGS := -O3 -funroll-loops -g -fPIC
all: libAFLDriver.a libAFLQemuDriver.a aflpp_qemu_driver_hook.so
@@ -33,10 +33,10 @@ libAFLQemuDriver.a: aflpp_qemu_driver.o
-cp -vf libAFLQemuDriver.a ../../
aflpp_qemu_driver_hook.so: aflpp_qemu_driver_hook.o
- -$(LLVM_BINDIR)clang -shared aflpp_qemu_driver_hook.o -o aflpp_qemu_driver_hook.so
+ -test -e aflpp_qemu_driver_hook.o && $(LLVM_BINDIR)clang -shared aflpp_qemu_driver_hook.o -o aflpp_qemu_driver_hook.so || echo "Note: Optional aflpp_qemu_driver_hook.so not built."
aflpp_qemu_driver_hook.o: aflpp_qemu_driver_hook.c
- -$(LLVM_BINDIR)clang -fPIC $(CFLAGS) -funroll-loops -c aflpp_qemu_driver_hook.c
+ -test -e ../../qemu_mode/qemuafl/qemuafl/api.h && $(LLVM_BINDIR)clang $(CFLAGS) -funroll-loops -c aflpp_qemu_driver_hook.c || echo "Note: Optional aflpp_qemu_driver_hook.o not built."
test: debug
#clang -S -emit-llvm -D_DEBUG=\"1\" -I../../include -Wl,--allow-multiple-definition -funroll-loops -o aflpp_driver_test.ll aflpp_driver_test.c
diff --git a/utils/aflpp_driver/README.md b/utils/aflpp_driver/README.md
index 01bd10c0..f03c2fe3 100644
--- a/utils/aflpp_driver/README.md
+++ b/utils/aflpp_driver/README.md
@@ -13,6 +13,12 @@ If this is the clang compile command to build for libfuzzer:
then just switch `clang++` with `afl-clang-fast++` and our compiler will
magically insert libAFLDriver.a :)
+To use shared-memory testcases, you need nothing to do.
+To use stdin testcases give `-` as the only command line parameter.
+To use file input testcases give `@@` as the only command line parameter.
+
+IMPORTANT: if you use `afl-cmin` or `afl-cmin.bash` then either pass `-`
+or `@@` as command line parameters.
## aflpp_qemu_driver
diff --git a/utils/aflpp_driver/aflpp_driver.c b/utils/aflpp_driver/aflpp_driver.c
index ad781e64..c094c425 100644
--- a/utils/aflpp_driver/aflpp_driver.c
+++ b/utils/aflpp_driver/aflpp_driver.c
@@ -174,11 +174,17 @@ size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize) {
static int ExecuteFilesOnyByOne(int argc, char **argv) {
unsigned char *buf = (unsigned char *)malloc(MAX_FILE);
+
for (int i = 1; i < argc; i++) {
- int fd = open(argv[i], O_RDONLY);
- if (fd == -1) continue;
+ int fd = 0;
+
+ if (strcmp(argv[i], "-") != 0) { fd = open(argv[i], O_RDONLY); }
+
+ if (fd == -1) { continue; }
+
ssize_t length = read(fd, buf, MAX_FILE);
+
if (length > 0) {
printf("Reading %zu bytes from %s\n", length, argv[i]);
@@ -187,7 +193,7 @@ static int ExecuteFilesOnyByOne(int argc, char **argv) {
}
- close(fd);
+ if (fd > 0) { close(fd); }
}
@@ -199,15 +205,19 @@ static int ExecuteFilesOnyByOne(int argc, char **argv) {
int main(int argc, char **argv) {
printf(
- "======================= INFO =========================\n"
+ "============================== INFO ================================\n"
"This binary is built for afl++.\n"
+ "To use with afl-cmin or afl-cmin.bash pass '-' as single command line "
+ "option\n"
"To run the target function on individual input(s) execute this:\n"
" %s INPUT_FILE1 [INPUT_FILE2 ... ]\n"
"To fuzz with afl-fuzz execute this:\n"
" afl-fuzz [afl-flags] -- %s [-N]\n"
"afl-fuzz will run N iterations before re-spawning the process (default: "
"INT_MAX)\n"
- "======================================================\n",
+ "For stdin input processing, pass '-' as single command line option.\n"
+ "For file input processing, pass '@@' as single command line option.\n"
+ "===================================================================\n",
argv[0], argv[0]);
if (getenv("AFL_GDB")) {
@@ -237,22 +247,35 @@ int main(int argc, char **argv) {
memcpy(dummy_input, (void *)AFL_PERSISTENT, sizeof(AFL_PERSISTENT));
memcpy(dummy_input + 32, (void *)AFL_DEFER_FORKSVR,
sizeof(AFL_DEFER_FORKSVR));
+
int N = INT_MAX;
- if (argc == 2 && argv[1][0] == '-')
+
+ if (argc == 2 && !strcmp(argv[1], "-")) {
+
+ __afl_sharedmem_fuzzing = 0;
+ __afl_manual_init();
+ return ExecuteFilesOnyByOne(argc, argv);
+
+ } else if (argc == 2 && argv[1][0] == '-') {
+
N = atoi(argv[1] + 1);
- else if (argc == 2 && (N = atoi(argv[1])) > 0)
+
+ } else if (argc == 2 && (N = atoi(argv[1])) > 0) {
+
printf("WARNING: using the deprecated call style `%s %d`\n", argv[0], N);
- else if (argc > 1) {
+
+ } else if (argc > 1) {
__afl_sharedmem_fuzzing = 0;
- __afl_manual_init();
+
+ if (argc == 2) { __afl_manual_init(); }
+
return ExecuteFilesOnyByOne(argc, argv);
}
assert(N > 0);
- // if (!getenv("AFL_DRIVER_DONT_DEFER"))
__afl_manual_init();
// Call LLVMFuzzerTestOneInput here so that coverage caused by initialization
@@ -271,6 +294,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "%02x", __afl_fuzz_ptr[i]);
fprintf(stderr, "\n");
#endif
+
if (*__afl_fuzz_len) {
num_runs++;
diff --git a/utils/aflpp_driver/aflpp_qemu_driver_hook.c b/utils/aflpp_driver/aflpp_qemu_driver_hook.c
index d3dd98b0..2979fadc 100644
--- a/utils/aflpp_driver/aflpp_qemu_driver_hook.c
+++ b/utils/aflpp_driver/aflpp_qemu_driver_hook.c
@@ -3,12 +3,12 @@
#include <stdint.h>
#include <string.h>
-void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
- uint8_t *input_buf, uint32_t input_buf_len) {
-
#define g2h(x) ((void *)((unsigned long)(x) + guest_base))
#define h2g(x) ((uint64_t)(x)-guest_base)
+void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
+ uint8_t *input_buf, uint32_t input_buf_len) {
+
// In this example the register RDI is pointing to the memory location
// of the target buffer, and the length of the input is in RSI.
// This can be seen with a debugger, e.g. gdb (and "disass main")
@@ -16,11 +16,11 @@ void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
memcpy(g2h(regs->rdi), input_buf, input_buf_len);
regs->rsi = input_buf_len;
+}
+
#undef g2h
#undef h2g
-}
-
int afl_persistent_hook_init(void) {
// 1 for shared memory input (faster), 0 for normal input (you have to use