about summary refs log tree commit diff
path: root/custom_mutators/aflpp/aflpp.c
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2023-04-04 15:47:53 +0200
committervanhauser-thc <vh@thc.org>2023-04-04 15:47:53 +0200
commitfcd21256780fd21c55e72e9338b3992c60db22dc (patch)
tree2f800ee67c168b84221ea11bf5ec768a4cf40708 /custom_mutators/aflpp/aflpp.c
parent635da39bd135b7db3529a4b3b059b85260ce14a5 (diff)
downloadafl++-fcd21256780fd21c55e72e9338b3992c60db22dc.tar.gz
prepare for strategies
Diffstat (limited to 'custom_mutators/aflpp/aflpp.c')
-rw-r--r--custom_mutators/aflpp/aflpp.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/custom_mutators/aflpp/aflpp.c b/custom_mutators/aflpp/aflpp.c
new file mode 100644
index 00000000..2b69ad9c
--- /dev/null
+++ b/custom_mutators/aflpp/aflpp.c
@@ -0,0 +1,68 @@
+#include "afl-mutations.h"
+
+typedef struct my_mutator {
+
+  afl_state_t *afl;
+  u8          *buf;
+
+} my_mutator_t;
+
+my_mutator_t *afl_custom_init(afl_state_t *afl, unsigned int seed) {
+
+  (void)seed;
+
+  my_mutator_t *data = calloc(1, sizeof(my_mutator_t));
+  if (!data) {
+
+    perror("afl_custom_init alloc");
+    return NULL;
+
+  }
+
+  data->buf = malloc(MAX_FILE);
+  if (!data->buf) {
+
+    perror("afl_custom_init alloc");
+    return NULL;
+
+  }
+
+  data->afl = afl;
+
+  return data;
+
+}
+
+/* here we run the AFL++ mutator, which is the best! */
+
+size_t afl_custom_fuzz(my_mutator_t *data, uint8_t *buf, size_t buf_size,
+                       u8 **out_buf, uint8_t *add_buf, size_t add_buf_size,
+                       size_t max_size) {
+
+  u32 havoc_steps = 1 + rand_below(data->afl, 16);
+
+  /* set everything up, costly ... :( */
+  memcpy(data->buf, buf, buf_size);
+
+  /* the mutation */
+  u32 out_buf_len = afl_mutate(data->afl, data->buf, buf_size, havoc_steps,
+                               false, true, add_buf, add_buf_size);
+
+  /* return size of mutated data */
+  *out_buf = data->buf;
+  return out_buf_len;
+
+}
+
+/**
+ * Deinitialize everything
+ *
+ * @param data The data ptr from afl_custom_init
+ */
+void afl_custom_deinit(my_mutator_t *data) {
+
+  free(data->buf);
+  free(data);
+
+}
+