about summary refs log tree commit diff
path: root/custom_mutators/examples/custom_send.c
diff options
context:
space:
mode:
authorMaik Betka <9078425+voidptr127@users.noreply.github.com>2023-04-21 16:47:19 +0200
committerGitHub <noreply@github.com>2023-04-21 16:47:19 +0200
commitde717cd2255f05361b6a7b8eaeec40b15cb878af (patch)
tree64bcf9c170649d9c487e3ff41be6244e5907ae7e /custom_mutators/examples/custom_send.c
parent9ab902402cd33156257fc0355c0105e7e03f5ba3 (diff)
parent779a72ef8c2457430b824f7830eba731745fb6ee (diff)
downloadafl++-de717cd2255f05361b6a7b8eaeec40b15cb878af.tar.gz
Merge pull request #1 from voidptr127/atnwalk
fixed AFL_POST_PROCESS_KEEP_ORIGINAL for version 4.07a
Diffstat (limited to 'custom_mutators/examples/custom_send.c')
-rw-r--r--custom_mutators/examples/custom_send.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/custom_mutators/examples/custom_send.c b/custom_mutators/examples/custom_send.c
new file mode 100644
index 00000000..9cc4b160
--- /dev/null
+++ b/custom_mutators/examples/custom_send.c
@@ -0,0 +1,63 @@
+//
+// This is an example on how to use afl_custom_send
+// It writes each mutated data set to /tmp/foo
+// You can modify this to send to IPC, shared memory, etc.
+//
+// cc -O3 -fPIC -shared -g -o custom_send.so -I../../include custom_send.c
+// cd ../..
+// afl-cc -o test-instr test-instr.c
+// AFL_CUSTOM_MUTATOR_LIBRARY=custom_mutators/examples/custom_send.so \
+//   afl-fuzz -i in -o out -- ./test-instr -f /tmp/foo
+//
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "afl-fuzz.h"
+
+typedef struct my_mutator {
+
+  afl_state_t *afl;
+
+} my_mutator_t;
+
+my_mutator_t *afl_custom_init(afl_state_t *afl, unsigned int seed) {
+
+  my_mutator_t *data = calloc(1, sizeof(my_mutator_t));
+  if (!data) {
+
+    perror("afl_custom_init alloc");
+    return NULL;
+
+  }
+
+  data->afl = afl;
+
+  return data;
+
+}
+
+void afl_custom_fuzz_send(my_mutator_t *data, uint8_t *buf, size_t buf_size) {
+
+  int fd = open("/tmp/foo", O_CREAT | O_NOFOLLOW | O_TRUNC | O_RDWR, 0644);
+
+  if (fd >= 0) {
+
+    (void)write(fd, buf, buf_size);
+    close(fd);
+
+  }
+
+  return;
+
+}
+
+void afl_custom_deinit(my_mutator_t *data) {
+
+  free(data);
+
+}
+