aboutsummaryrefslogtreecommitdiff
path: root/frida_mode/src
diff options
context:
space:
mode:
authorWorksButNotTested <62701594+WorksButNotTested@users.noreply.github.com>2021-04-28 18:26:19 +0100
committerGitHub <noreply@github.com>2021-04-28 19:26:19 +0200
commit3a0d4fe0d0a585d152a59ca4601d1981cedbf113 (patch)
treee97c8c7662cb4588df48fe040b2ddde866d2f142 /frida_mode/src
parentf112357e6165b583924b9b4e44b5b6ef522f722f (diff)
downloadafl++-3a0d4fe0d0a585d152a59ca4601d1981cedbf113.tar.gz
Bumped warnings up to the max and fixed remaining issues (#890)
Co-authored-by: Your Name <you@example.com>
Diffstat (limited to 'frida_mode/src')
-rw-r--r--frida_mode/src/complog/complog.c3
-rw-r--r--frida_mode/src/complog/complog_x64.c50
-rw-r--r--frida_mode/src/instrument/instrument.c9
-rw-r--r--frida_mode/src/interceptor.c2
-rw-r--r--frida_mode/src/main.c7
-rw-r--r--frida_mode/src/persistent/persistent.c3
-rw-r--r--frida_mode/src/persistent/persistent_x64.c2
-rw-r--r--frida_mode/src/ranges.c19
8 files changed, 50 insertions, 45 deletions
diff --git a/frida_mode/src/complog/complog.c b/frida_mode/src/complog/complog.c
index 3b679a5c..1857ea3b 100644
--- a/frida_mode/src/complog/complog.c
+++ b/frida_mode/src/complog/complog.c
@@ -2,6 +2,7 @@
#include "debug.h"
#include "cmplog.h"
+#include "util.h"
extern struct cmp_map *__afl_cmp_map;
@@ -10,8 +11,10 @@ static GArray *complog_ranges = NULL;
static gboolean complog_range(const GumRangeDetails *details,
gpointer user_data) {
+ UNUSED_PARAMETER(user_data);
GumMemoryRange range = *details->range;
g_array_append_val(complog_ranges, range);
+ return TRUE;
}
diff --git a/frida_mode/src/complog/complog_x64.c b/frida_mode/src/complog/complog_x64.c
index 253ec041..28010e7f 100644
--- a/frida_mode/src/complog/complog_x64.c
+++ b/frida_mode/src/complog/complog_x64.c
@@ -4,6 +4,7 @@
#include "cmplog.h"
#include "complog.h"
+#include "util.h"
#if defined(__x86_64__)
@@ -148,7 +149,27 @@ static guint64 complog_read_mem(GumX64CpuContext *ctx, x86_op_mem *mem) {
}
-static void complog_handle_call(GumCpuContext *context, guint64 target) {
+static guint64 cmplog_get_operand_value(GumCpuContext *context,
+ complog_ctx_t *ctx) {
+
+ switch (ctx->type) {
+
+ case X86_OP_REG:
+ return complog_read_reg(context, ctx->reg);
+ case X86_OP_IMM:
+ return ctx->imm;
+ case X86_OP_MEM:
+ return complog_read_mem(context, &ctx->mem);
+ default:
+ FATAL("Invalid operand type: %d\n", ctx->type);
+
+ }
+
+}
+
+static void complog_call_callout(GumCpuContext *context, gpointer user_data) {
+
+ UNUSED_PARAMETER(user_data);
guint64 address = complog_read_reg(context, X86_REG_RIP);
guint64 rdi = complog_read_reg(context, X86_REG_RDI);
@@ -179,33 +200,6 @@ static void complog_handle_call(GumCpuContext *context, guint64 target) {
}
-static guint64 cmplog_get_operand_value(GumCpuContext *context,
- complog_ctx_t *ctx) {
-
- switch (ctx->type) {
-
- case X86_OP_REG:
- return complog_read_reg(context, ctx->reg);
- case X86_OP_IMM:
- return ctx->imm;
- case X86_OP_MEM:
- return complog_read_mem(context, &ctx->mem);
- default:
- FATAL("Invalid operand type: %d\n", ctx->type);
-
- }
-
-}
-
-static void complog_call_callout(GumCpuContext *context, gpointer user_data) {
-
- complog_ctx_t *ctx = (complog_ctx_t *)user_data;
-
- guint64 target = cmplog_get_operand_value(context, ctx);
- complog_handle_call(context, target);
-
-}
-
static void complog_instrument_put_operand(complog_ctx_t *ctx,
cs_x86_op * operand) {
diff --git a/frida_mode/src/instrument/instrument.c b/frida_mode/src/instrument/instrument.c
index 81080bee..3806136a 100644
--- a/frida_mode/src/instrument/instrument.c
+++ b/frida_mode/src/instrument/instrument.c
@@ -11,17 +11,18 @@
#include "prefetch.h"
#include "ranges.h"
#include "stalker.h"
+#include "util.h"
static gboolean tracing = false;
static gboolean optimize = false;
-static gboolean strict = false;
static GumStalkerTransformer *transformer = NULL;
-uint64_t __thread previous_pc = 0;
+__thread uint64_t previous_pc = 0;
__attribute__((hot)) static void on_basic_block(GumCpuContext *context,
gpointer user_data) {
+ UNUSED_PARAMETER(context);
/*
* This function is performance critical as it is called to instrument every
* basic block. By moving our print buffer to a global, we avoid it affecting
@@ -44,7 +45,7 @@ __attribute__((hot)) static void on_basic_block(GumCpuContext *context,
"x, previous_pc: 0x%016" G_GINT64_MODIFIER "x\n",
current_pc, previous_pc);
- write(STDOUT_FILENO, buffer, len + 1);
+ IGNORED_RERURN(write(STDOUT_FILENO, buffer, len + 1));
}
@@ -72,6 +73,8 @@ __attribute__((hot)) static void on_basic_block(GumCpuContext *context,
static void instr_basic_block(GumStalkerIterator *iterator,
GumStalkerOutput *output, gpointer user_data) {
+ UNUSED_PARAMETER(user_data);
+
const cs_insn *instr;
gboolean begin = TRUE;
while (gum_stalker_iterator_next(iterator, &instr)) {
diff --git a/frida_mode/src/interceptor.c b/frida_mode/src/interceptor.c
index 8d41b075..d2802752 100644
--- a/frida_mode/src/interceptor.c
+++ b/frida_mode/src/interceptor.c
@@ -10,7 +10,7 @@ void intercept(void *address, gpointer replacement, gpointer user_data) {
gum_interceptor_begin_transaction(interceptor);
GumReplaceReturn ret =
gum_interceptor_replace(interceptor, address, replacement, user_data);
- if (ret != GUM_ATTACH_OK) { FATAL("gum_interceptor_attach: %d", ret); }
+ if (ret != GUM_REPLACE_OK) { FATAL("gum_interceptor_attach: %d", ret); }
gum_interceptor_end_transaction(interceptor);
}
diff --git a/frida_mode/src/main.c b/frida_mode/src/main.c
index f712a8c0..11cf041c 100644
--- a/frida_mode/src/main.c
+++ b/frida_mode/src/main.c
@@ -21,6 +21,7 @@
#include "prefetch.h"
#include "ranges.h"
#include "stalker.h"
+#include "util.h"
#ifdef __APPLE__
extern mach_port_t mach_task_self();
@@ -36,8 +37,6 @@ typedef int *(*main_fn_t)(int argc, char **argv, char **envp);
static main_fn_t main_fn = NULL;
-static GumMemoryRange code_range = {0};
-
extern void __afl_manual_init();
static int on_fork(void) {
@@ -55,6 +54,8 @@ static void on_main_os(int argc, char **argv, char **envp) {
#else
static void on_main_os(int argc, char **argv, char **envp) {
+ UNUSED_PARAMETER(argc);
+
/* Personality doesn't affect the current process, it only takes effect on
* evec */
int persona = personality(ADDR_NO_RANDOMIZE);
@@ -97,7 +98,7 @@ static int *on_main(int argc, char **argv, char **envp) {
/* Child here */
previous_pc = 0;
stalker_resume();
- main_fn(argc, argv, envp);
+ return main_fn(argc, argv, envp);
}
diff --git a/frida_mode/src/persistent/persistent.c b/frida_mode/src/persistent/persistent.c
index 34e4093e..fe3a1d20 100644
--- a/frida_mode/src/persistent/persistent.c
+++ b/frida_mode/src/persistent/persistent.c
@@ -9,6 +9,9 @@
#include "util.h"
int __afl_sharedmem_fuzzing = 0;
+afl_persistent_hook_fn hook = NULL;
+guint64 persistent_start = 0;
+guint64 persistent_count = 0;
void persistent_init(void) {
diff --git a/frida_mode/src/persistent/persistent_x64.c b/frida_mode/src/persistent/persistent_x64.c
index 0cabbf24..5b8493b2 100644
--- a/frida_mode/src/persistent/persistent_x64.c
+++ b/frida_mode/src/persistent/persistent_x64.c
@@ -231,7 +231,7 @@ static int instrument_afl_persistent_loop_func(void) {
}
-static int instrument_afl_persistent_loop(GumX86Writer *cw) {
+static void instrument_afl_persistent_loop(GumX86Writer *cw) {
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_REG_RSP, GUM_REG_RSP,
-(GUM_RED_ZONE_SIZE));
diff --git a/frida_mode/src/ranges.c b/frida_mode/src/ranges.c
index 6fcbd258..e3f09f9e 100644
--- a/frida_mode/src/ranges.c
+++ b/frida_mode/src/ranges.c
@@ -5,6 +5,7 @@
#include "lib.h"
#include "ranges.h"
#include "stalker.h"
+#include "util.h"
#define MAX_RANGES 20
@@ -167,6 +168,7 @@ gint range_sort(gconstpointer a, gconstpointer b) {
static gboolean print_ranges_callback(const GumRangeDetails *details,
gpointer user_data) {
+ UNUSED_PARAMETER(user_data);
if (details->file == NULL) {
OKF("MAP - 0x%016" G_GINT64_MODIFIER "x - 0x%016" G_GINT64_MODIFIER "X",
@@ -190,7 +192,7 @@ static gboolean print_ranges_callback(const GumRangeDetails *details,
static void print_ranges(char *key, GArray *ranges) {
OKF("Range: %s Length: %d", key, ranges->len);
- for (int i = 0; i < ranges->len; i++) {
+ for (guint i = 0; i < ranges->len; i++) {
GumMemoryRange *curr = &g_array_index(ranges, GumMemoryRange, i);
GumAddress curr_limit = curr->base_address + curr->size;
@@ -345,10 +347,10 @@ static GArray *intersect_ranges(GArray *a, GArray *b) {
result = g_array_new(false, false, sizeof(GumMemoryRange));
- for (int i = 0; i < a->len; i++) {
+ for (guint i = 0; i < a->len; i++) {
ra = &g_array_index(a, GumMemoryRange, i);
- for (int j = 0; j < b->len; j++) {
+ for (guint j = 0; j < b->len; j++) {
rb = &g_array_index(b, GumMemoryRange, j);
@@ -377,11 +379,11 @@ static GArray *subtract_ranges(GArray *a, GArray *b) {
result = g_array_new(false, false, sizeof(GumMemoryRange));
- for (int i = 0; i < a->len; i++) {
+ for (guint i = 0; i < a->len; i++) {
ra = &g_array_index(a, GumMemoryRange, i);
ral = ra->base_address + ra->size;
- for (int j = 0; j < b->len; j++) {
+ for (guint j = 0; j < b->len; j++) {
rb = &g_array_index(b, GumMemoryRange, j);
@@ -453,7 +455,7 @@ static GArray *merge_ranges(GArray *a) {
rp = g_array_index(a, GumMemoryRange, 0);
- for (int i = 1; i < a->len; i++) {
+ for (guint i = 1; i < a->len; i++) {
r = &g_array_index(a, GumMemoryRange, i);
@@ -535,7 +537,7 @@ void ranges_init(void) {
stalker = stalker_get();
- for (int i = 0; i < ranges->len; i++) {
+ for (guint i = 0; i < ranges->len; i++) {
r = &g_array_index(ranges, GumMemoryRange, i);
gum_stalker_exclude(stalker, r);
@@ -551,12 +553,11 @@ void ranges_init(void) {
gboolean range_is_excluded(gpointer address) {
- int i;
GumAddress test = GUM_ADDRESS(address);
if (ranges == NULL) { return false; }
- for (i = 0; i < ranges->len; i++) {
+ for (guint i = 0; i < ranges->len; i++) {
GumMemoryRange *curr = &g_array_index(ranges, GumMemoryRange, i);
GumAddress curr_limit = curr->base_address + curr->size;