about summary refs log tree commit diff
path: root/frida_mode/src/complog/complog.c
diff options
context:
space:
mode:
authorWorksButNotTested <62701594+WorksButNotTested@users.noreply.github.com>2021-04-28 09:25:26 +0100
committerGitHub <noreply@github.com>2021-04-28 10:25:26 +0200
commit39ad3b89467d6de12cbb9d08ccd77d331c0d1f9e (patch)
tree18bdf509d47e0d971bd9d7faf56d27758b23b09c /frida_mode/src/complog/complog.c
parent8da5cba4012080afca5e7f7da9aaa6aa6e263f3e (diff)
downloadafl++-39ad3b89467d6de12cbb9d08ccd77d331c0d1f9e.tar.gz
Frida persistent (#880)
* Added x64 support for persistent mode (function call only), in-memory teest cases and complog

* Review changes, fix NeverZero and code to parse the .text section of the main executable. Excluded ranges TBC

* Various minor fixes and finished support for AFL_INST_LIBS

* Review changes

Co-authored-by: Your Name <you@example.com>
Diffstat (limited to 'frida_mode/src/complog/complog.c')
-rw-r--r--frida_mode/src/complog/complog.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/frida_mode/src/complog/complog.c b/frida_mode/src/complog/complog.c
new file mode 100644
index 00000000..3b679a5c
--- /dev/null
+++ b/frida_mode/src/complog/complog.c
@@ -0,0 +1,72 @@
+#include "frida-gum.h"
+
+#include "debug.h"
+#include "cmplog.h"
+
+extern struct cmp_map *__afl_cmp_map;
+
+static GArray *complog_ranges = NULL;
+
+static gboolean complog_range(const GumRangeDetails *details,
+                              gpointer               user_data) {
+
+  GumMemoryRange range = *details->range;
+  g_array_append_val(complog_ranges, range);
+
+}
+
+static gint complog_sort(gconstpointer a, gconstpointer b) {
+
+  return ((GumMemoryRange *)b)->base_address -
+         ((GumMemoryRange *)a)->base_address;
+
+}
+
+void complog_init(void) {
+
+  if (__afl_cmp_map != NULL) { OKF("CompLog mode enabled"); }
+
+  complog_ranges = g_array_sized_new(false, false, sizeof(GumMemoryRange), 100);
+  gum_process_enumerate_ranges(GUM_PAGE_READ, complog_range, NULL);
+  g_array_sort(complog_ranges, complog_sort);
+
+  for (guint i = 0; i < complog_ranges->len; i++) {
+
+    GumMemoryRange *range = &g_array_index(complog_ranges, GumMemoryRange, i);
+    OKF("CompLog Range - 0x%016lX - 0x%016lX", range->base_address,
+        range->base_address + range->size);
+
+  }
+
+}
+
+static gboolean complog_contains(GumAddress inner_base, GumAddress inner_limit,
+                                 GumAddress outer_base,
+                                 GumAddress outer_limit) {
+
+  return (inner_base >= outer_base && inner_limit <= outer_limit);
+
+}
+
+gboolean complog_is_readable(void *addr, size_t size) {
+
+  if (complog_ranges == NULL) FATAL("CompLog not initialized");
+
+  GumAddress inner_base = GUM_ADDRESS(addr);
+  GumAddress inner_limit = inner_base + size;
+
+  for (guint i = 0; i < complog_ranges->len; i++) {
+
+    GumMemoryRange *range = &g_array_index(complog_ranges, GumMemoryRange, i);
+    GumAddress      outer_base = range->base_address;
+    GumAddress      outer_limit = outer_base + range->size;
+
+    if (complog_contains(inner_base, inner_limit, outer_base, outer_limit))
+      return true;
+
+  }
+
+  return false;
+
+}
+