aboutsummaryrefslogtreecommitdiff
path: root/frida_mode/src
diff options
context:
space:
mode:
Diffstat (limited to 'frida_mode/src')
-rw-r--r--frida_mode/src/asan/asan.c14
-rw-r--r--frida_mode/src/cmplog/cmplog.c13
-rw-r--r--frida_mode/src/entry.c8
-rw-r--r--frida_mode/src/instrument/instrument.c28
-rw-r--r--frida_mode/src/instrument/instrument_coverage.c22
-rw-r--r--frida_mode/src/instrument/instrument_debug.c10
-rw-r--r--frida_mode/src/instrument/instrument_x64.c8
-rw-r--r--frida_mode/src/js/api.js9
-rw-r--r--frida_mode/src/js/js.c7
-rw-r--r--frida_mode/src/js/js_api.c6
-rw-r--r--frida_mode/src/lib/lib.c31
-rw-r--r--frida_mode/src/lib/lib_apple.c18
-rw-r--r--frida_mode/src/main.c20
-rw-r--r--frida_mode/src/output.c8
-rw-r--r--frida_mode/src/persistent/persistent.c15
-rw-r--r--frida_mode/src/persistent/persistent_arm64.c2
-rw-r--r--frida_mode/src/persistent/persistent_x64.c2
-rw-r--r--frida_mode/src/persistent/persistent_x86.c2
-rw-r--r--frida_mode/src/prefetch.c6
-rw-r--r--frida_mode/src/ranges.c78
-rw-r--r--frida_mode/src/seccomp/seccomp.c3
-rw-r--r--frida_mode/src/seccomp/seccomp_callback.c2
-rw-r--r--frida_mode/src/seccomp/seccomp_filter.c2
-rw-r--r--frida_mode/src/stalker.c10
-rw-r--r--frida_mode/src/stats/stats.c10
-rw-r--r--frida_mode/src/util.c22
26 files changed, 214 insertions, 142 deletions
diff --git a/frida_mode/src/asan/asan.c b/frida_mode/src/asan/asan.c
index 884bec53..cad409ee 100644
--- a/frida_mode/src/asan/asan.c
+++ b/frida_mode/src/asan/asan.c
@@ -9,21 +9,15 @@ gboolean asan_initialized = FALSE;
void asan_config(void) {
- if (getenv("AFL_USE_FASAN") != NULL) {
-
- FOKF("Frida ASAN mode enabled");
- asan_enabled = TRUE;
-
- } else {
-
- FOKF("Frida ASAN mode disabled");
-
- }
+ if (getenv("AFL_USE_FASAN") != NULL) { asan_enabled = TRUE; }
}
void asan_init(void) {
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "asan:" cYEL " [%c]",
+ asan_enabled ? 'X' : ' ');
+
if (asan_enabled) {
asan_arch_init();
diff --git a/frida_mode/src/cmplog/cmplog.c b/frida_mode/src/cmplog/cmplog.c
index 443baa1d..355df0b7 100644
--- a/frida_mode/src/cmplog/cmplog.c
+++ b/frida_mode/src/cmplog/cmplog.c
@@ -54,7 +54,7 @@ static gint cmplog_sort(gconstpointer a, gconstpointer b) {
static void cmplog_get_ranges(void) {
- FOKF("CMPLOG - Collecting ranges");
+ FVERBOSE("CMPLOG - Collecting ranges");
cmplog_ranges = g_array_sized_new(false, false, sizeof(GumMemoryRange), 100);
gum_process_enumerate_ranges(GUM_PAGE_READ, cmplog_range, cmplog_ranges);
@@ -68,18 +68,21 @@ void cmplog_config(void) {
void cmplog_init(void) {
- FOKF("CMPLOG - Enabled [%c]", __afl_cmp_map == NULL ? ' ' : 'X');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "cmplog:" cYEL " [%c]",
+ __afl_cmp_map == NULL ? ' ' : 'X');
if (__afl_cmp_map == NULL) { return; }
cmplog_get_ranges();
+ FVERBOSE("Cmplog Ranges");
+
for (guint i = 0; i < cmplog_ranges->len; i++) {
GumMemoryRange *range = &g_array_index(cmplog_ranges, GumMemoryRange, i);
- FOKF("CMPLOG Range - %3u: 0x%016" G_GINT64_MODIFIER
- "X - 0x%016" G_GINT64_MODIFIER "X",
- i, range->base_address, range->base_address + range->size);
+ FVERBOSE("\t%3u: 0x%016" G_GINT64_MODIFIER "X - 0x%016" G_GINT64_MODIFIER
+ "X",
+ i, range->base_address, range->base_address + range->size);
}
diff --git a/frida_mode/src/entry.c b/frida_mode/src/entry.c
index de645fdb..995f765f 100644
--- a/frida_mode/src/entry.c
+++ b/frida_mode/src/entry.c
@@ -24,7 +24,7 @@ gboolean entry_run = FALSE;
static void entry_launch(void) {
- FOKF("Entry point reached");
+ FVERBOSE("Entry point reached");
__afl_manual_init();
/* Child here */
@@ -69,8 +69,8 @@ void entry_config(void) {
void entry_init(void) {
- FOKF("entry_point: 0x%016" G_GINT64_MODIFIER "X", entry_point);
- FOKF("dumpable: [%c]", traceable ? 'X' : ' ');
+ FVERBOSE("Entry Point: 0x%016" G_GINT64_MODIFIER "X", entry_point);
+ FVERBOSE("Dumpable: [%c]", traceable ? 'X' : ' ');
if (dlopen(NULL, RTLD_NOW) == NULL) { FFATAL("Failed to dlopen: %d", errno); }
@@ -94,7 +94,7 @@ static void entry_callout(GumCpuContext *cpu_context, gpointer user_data) {
void entry_prologue(GumStalkerIterator *iterator, GumStalkerOutput *output) {
UNUSED_PARAMETER(output);
- FOKF("AFL_ENTRYPOINT reached");
+ FVERBOSE("AFL_ENTRYPOINT reached");
if (persistent_start == 0) {
diff --git a/frida_mode/src/instrument/instrument.c b/frida_mode/src/instrument/instrument.c
index 8ee21f5b..e3f3717e 100644
--- a/frida_mode/src/instrument/instrument.c
+++ b/frida_mode/src/instrument/instrument.c
@@ -274,14 +274,19 @@ void instrument_init(void) {
if (!instrument_is_coverage_optimize_supported()) instrument_optimize = false;
- FOKF("Instrumentation - optimize [%c]", instrument_optimize ? 'X' : ' ');
- FOKF("Instrumentation - tracing [%c]", instrument_tracing ? 'X' : ' ');
- FOKF("Instrumentation - unique [%c]", instrument_unique ? 'X' : ' ');
- FOKF("Instrumentation - fixed seed [%c] [0x%016" G_GINT64_MODIFIER "x]",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "optimize:" cYEL " [%c]",
+ instrument_optimize ? 'X' : ' ');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "tracing:" cYEL " [%c]",
+ instrument_tracing ? 'X' : ' ');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "unique:" cYEL " [%c]",
+ instrument_unique ? 'X' : ' ');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "fixed seed:" cYEL
+ " [%c] [0x%016" G_GINT64_MODIFIER "x]",
instrument_use_fixed_seed ? 'X' : ' ', instrument_fixed_seed);
- FOKF("Instrumentation - unstable coverage [%c] [%s]",
- instrument_coverage_unstable_filename == NULL ? ' ' : 'X',
- instrument_coverage_unstable_filename);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "unstable coverage:" cYEL " [%s]",
+ instrument_coverage_unstable_filename == NULL
+ ? " "
+ : instrument_coverage_unstable_filename);
if (instrument_tracing && instrument_optimize) {
@@ -366,15 +371,16 @@ void instrument_init(void) {
}
- FOKF("Instrumentation - seed [0x%016" G_GINT64_MODIFIER "x]",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "seed:" cYEL
+ " [0x%016" G_GINT64_MODIFIER "x]",
instrument_hash_seed);
instrument_hash_zero = instrument_get_offset_hash(0);
- instrument_coverage_optimize_init();
- instrument_debug_init();
- instrument_coverage_init();
asan_init();
cmplog_init();
+ instrument_coverage_init();
+ instrument_coverage_optimize_init();
+ instrument_debug_init();
}
diff --git a/frida_mode/src/instrument/instrument_coverage.c b/frida_mode/src/instrument/instrument_coverage.c
index c1984eb2..098e7269 100644
--- a/frida_mode/src/instrument/instrument_coverage.c
+++ b/frida_mode/src/instrument/instrument_coverage.c
@@ -659,17 +659,17 @@ void instrument_coverage_config(void) {
void instrument_coverage_normal_init(void) {
- FOKF("Coverage - enabled [%c]",
- instrument_coverage_filename == NULL ? ' ' : 'X');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "coverage:" cYEL " [%s]",
+ instrument_coverage_filename == NULL ? " "
+ : instrument_coverage_filename);
if (instrument_coverage_filename == NULL) { return; }
- FOKF("Coverage - file [%s]", instrument_coverage_filename);
-
char *path = g_canonicalize_filename(instrument_coverage_filename,
g_get_current_dir());
- FOKF("Coverage - path [%s]", path);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "coverage path:" cYEL " [%s]",
+ path);
normal_coverage_fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
@@ -718,7 +718,7 @@ void instrument_coverage_unstable_find_output(void) {
GDir *dir = g_dir_open(fds_name, 0, NULL);
- FOKF("Coverage Unstable - fds: %s", fds_name);
+ FVERBOSE("Coverage Unstable - fds: %s", fds_name);
for (const gchar *filename = g_dir_read_name(dir); filename != NULL;
filename = g_dir_read_name(dir)) {
@@ -782,18 +782,24 @@ void instrument_coverage_unstable_find_output(void) {
}
- FOKF("Fuzzer stats: %s", unstable_coverage_fuzzer_stats);
+ FVERBOSE("Fuzzer stats: %s", unstable_coverage_fuzzer_stats);
}
void instrument_coverage_unstable_init(void) {
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "unstable coverage:" cYEL " [%s]",
+ instrument_coverage_unstable_filename == NULL
+ ? " "
+ : instrument_coverage_unstable_filename);
if (instrument_coverage_unstable_filename == NULL) { return; }
char *path = g_canonicalize_filename(instrument_coverage_unstable_filename,
g_get_current_dir());
- FOKF("Coverage - unstable path [%s]", instrument_coverage_unstable_filename);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "unstable coverage path:" cYEL
+ " [%s]",
+ path == NULL ? " " : path);
unstable_coverage_fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
diff --git a/frida_mode/src/instrument/instrument_debug.c b/frida_mode/src/instrument/instrument_debug.c
index b5fdf988..a1f80467 100644
--- a/frida_mode/src/instrument/instrument_debug.c
+++ b/frida_mode/src/instrument/instrument_debug.c
@@ -94,19 +94,15 @@ void instrument_debug_config(void) {
void instrument_debug_init(void) {
- FOKF("Instrumentation debugging - enabled [%c]",
- instrument_debug_filename == NULL ? ' ' : 'X');
-
- if (instrument_debug_filename == NULL) { return; }
-
- FOKF("Instrumentation debugging - file [%s]", instrument_debug_filename);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "debugging:" cYEL " [%s]",
+ instrument_debug_filename == NULL ? " " : instrument_debug_filename);
if (instrument_debug_filename == NULL) { return; }
char *path =
g_canonicalize_filename(instrument_debug_filename, g_get_current_dir());
- FOKF("Instrumentation debugging - path [%s]", path);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "path:" cYEL " [%s]", path);
debugging_fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
diff --git a/frida_mode/src/instrument/instrument_x64.c b/frida_mode/src/instrument/instrument_x64.c
index b51cb697..b7b6ca6f 100644
--- a/frida_mode/src/instrument/instrument_x64.c
+++ b/frida_mode/src/instrument/instrument_x64.c
@@ -323,7 +323,7 @@ void instrument_coverage_optimize_init(void) {
gum_process_enumerate_ranges(GUM_PAGE_NO_ACCESS, instrument_coverage_find_low,
&low_address);
- FOKF("Low address: %p", low_address);
+ FVERBOSE("Low address: %p", low_address);
if (low_address == 0 ||
GPOINTER_TO_SIZE(low_address) > ((2UL << 20) - __afl_map_size)) {
@@ -335,7 +335,7 @@ void instrument_coverage_optimize_init(void) {
ranges_print_debug_maps();
char *shm_env = getenv(SHM_ENV_VAR);
- FOKF("SHM_ENV_VAR: %s", shm_env);
+ FVERBOSE("SHM_ENV_VAR: %s", shm_env);
if (shm_env == NULL) {
@@ -359,8 +359,8 @@ void instrument_coverage_optimize_init(void) {
}
- FOKF("__afl_area_ptr: %p", __afl_area_ptr);
- FOKF("instrument_previous_pc: %p", &instrument_previous_pc);
+ FVERBOSE("__afl_area_ptr: %p", __afl_area_ptr);
+ FVERBOSE("instrument_previous_pc: %p", &instrument_previous_pc);
}
diff --git a/frida_mode/src/js/api.js b/frida_mode/src/js/api.js
index 215fbdaf..52e9e45c 100644
--- a/frida_mode/src/js/api.js
+++ b/frida_mode/src/js/api.js
@@ -63,7 +63,7 @@ class Afl {
Afl.jsApiWrite(STDOUT_FILENO, buf, log.length);
}
/**
- * See `AFL_FRIDA_INST_NO_BACKPATCH`.
+ * See `AFL_FRIDA_STALKER_NO_BACKPATCH`.
*/
static setBackpatchDisable() {
Afl.jsApiSetBackpatchDisable();
@@ -268,6 +268,12 @@ class Afl {
static setTraceable() {
Afl.jsApiSetTraceable();
}
+ /**
+ * See `AFL_FRIDA_VERBOSE`
+ */
+ static setVerbose() {
+ Afl.jsApiSetVerbose();
+ }
static jsApiGetFunction(name, retType, argTypes) {
const addr = Afl.module.getExportByName(name);
return new NativeFunction(addr, retType, argTypes);
@@ -315,6 +321,7 @@ Afl.jsApiSetStatsInterval = Afl.jsApiGetFunction("js_api_set_stats_interval", "v
Afl.jsApiSetStdErr = Afl.jsApiGetFunction("js_api_set_stderr", "void", ["pointer"]);
Afl.jsApiSetStdOut = Afl.jsApiGetFunction("js_api_set_stdout", "void", ["pointer"]);
Afl.jsApiSetTraceable = Afl.jsApiGetFunction("js_api_set_traceable", "void", []);
+Afl.jsApiSetVerbose = Afl.jsApiGetFunction("js_api_set_verbose", "void", []);
Afl.jsApiWrite = new NativeFunction(
/* tslint:disable-next-line:no-null-keyword */
Module.getExportByName(null, "write"), "int", ["int", "pointer", "int"]);
diff --git a/frida_mode/src/js/js.c b/frida_mode/src/js/js.c
index 5f477388..1ca2237f 100644
--- a/frida_mode/src/js/js.c
+++ b/frida_mode/src/js/js.c
@@ -55,7 +55,10 @@ static gchar *js_get_script() {
} else {
- FOKF("Loaded AFL script: %s, %" G_GSIZE_MODIFIER "d bytes", filename,
+ FOKF(cBLU "Javascript" cRST " - " cGRN "script:" cYEL " [%s]",
+ filename == NULL ? " " : filename);
+ FOKF(cBLU "Javascript" cRST " - " cGRN "size: " cYEL "%" G_GSIZE_MODIFIER
+ "d bytes",
length);
gchar *source = g_malloc0(api_js_len + length + 1);
@@ -74,7 +77,7 @@ static void js_print_script(gchar *source) {
for (size_t i = 0; split[i] != NULL; i++) {
- FOKF("%3" G_GSIZE_MODIFIER "d. %s", i + 1, split[i]);
+ FVERBOSE("%3" G_GSIZE_MODIFIER "d. %s", i + 1, split[i]);
}
diff --git a/frida_mode/src/js/js_api.c b/frida_mode/src/js/js_api.c
index 5021b531..94ec8842 100644
--- a/frida_mode/src/js/js_api.c
+++ b/frida_mode/src/js/js_api.c
@@ -262,3 +262,9 @@ __attribute__((visibility("default"))) void js_api_set_js_main_hook(
}
+__attribute__((visibility("default"))) void js_api_set_verbose(void) {
+
+ util_verbose = TRUE;
+
+}
+
diff --git a/frida_mode/src/lib/lib.c b/frida_mode/src/lib/lib.c
index 48d2ea2a..39480ce9 100644
--- a/frida_mode/src/lib/lib.c
+++ b/frida_mode/src/lib/lib.c
@@ -93,17 +93,18 @@ static void lib_read_text_section(lib_details_t *lib_details, Elf_Ehdr *hdr) {
}
- FOKF("Image preferred load address 0x%016" G_GSIZE_MODIFIER "x",
- preferred_base);
+ FVERBOSE("\tpreferred load address: 0x%016" G_GSIZE_MODIFIER "x",
+ preferred_base);
shdr = (Elf_Shdr *)((char *)hdr + hdr->e_shoff);
shstrtab = &shdr[hdr->e_shstrndx];
shstr = (char *)hdr + shstrtab->sh_offset;
- FOKF("shdr: %p", shdr);
- FOKF("shstrtab: %p", shstrtab);
- FOKF("shstr: %p", shstr);
+ FVERBOSE("\tshdr: %p", shdr);
+ FVERBOSE("\tshstrtab: %p", shstrtab);
+ FVERBOSE("\tshstr: %p", shstr);
+ FVERBOSE("Sections:");
for (size_t i = 0; i < hdr->e_shnum; i++) {
curr = &shdr[i];
@@ -111,21 +112,23 @@ static void lib_read_text_section(lib_details_t *lib_details, Elf_Ehdr *hdr) {
if (curr->sh_name == 0) continue;
section_name = &shstr[curr->sh_name];
- FOKF("Section: %2" G_GSIZE_MODIFIER "u - base: 0x%016" G_GSIZE_MODIFIER
- "X size: 0x%016" G_GSIZE_MODIFIER "X %s",
- i, curr->sh_addr, curr->sh_size, section_name);
+ FVERBOSE("\t%2" G_GSIZE_MODIFIER "u - base: 0x%016" G_GSIZE_MODIFIER
+ "X size: 0x%016" G_GSIZE_MODIFIER "X %s",
+ i, curr->sh_addr, curr->sh_size, section_name);
if (memcmp(section_name, text_name, sizeof(text_name)) == 0 &&
text_base == 0) {
text_base = lib_details->base_address + curr->sh_addr - preferred_base;
text_limit = text_base + curr->sh_size;
- FOKF("> text_addr: 0x%016" G_GINT64_MODIFIER "X", text_base);
- FOKF("> text_limit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
}
}
+ FVERBOSE(".text\n");
+ FVERBOSE("\taddr: 0x%016" G_GINT64_MODIFIER "X", text_base);
+ FVERBOSE("\tlimit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
+
}
static void lib_get_text_section(lib_details_t *details) {
@@ -141,7 +144,7 @@ static void lib_get_text_section(lib_details_t *details) {
if (len == (off_t)-1) { FFATAL("Failed to lseek %s", details->path); }
- FOKF("len: %ld", len);
+ FVERBOSE("\tlength: %ld", len);
hdr = (Elf_Ehdr *)mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
if (hdr == MAP_FAILED) { FFATAL("Failed to map %s", details->path); }
@@ -162,8 +165,10 @@ void lib_init(void) {
lib_details_t lib_details;
gum_process_enumerate_modules(lib_find_exe, &lib_details);
- FOKF("Executable: 0x%016" G_GINT64_MODIFIER "x - %s",
- lib_details.base_address, lib_details.path);
+ FVERBOSE("Image");
+ FVERBOSE("\tbase: 0x%016" G_GINT64_MODIFIER "x",
+ lib_details.base_address);
+ FVERBOSE("\tpath: %s", lib_details.path);
lib_get_text_section(&lib_details);
}
diff --git a/frida_mode/src/lib/lib_apple.c b/frida_mode/src/lib/lib_apple.c
index 3bdb8c10..65c1d937 100644
--- a/frida_mode/src/lib/lib_apple.c
+++ b/frida_mode/src/lib/lib_apple.c
@@ -20,7 +20,7 @@ static gboolean lib_get_main_module(const GumModuleDetails *details,
details->path, mach_task_self(), details->range->base_address,
GUM_DARWIN_MODULE_FLAGS_NONE, NULL);
- FOKF("Found main module: %s", module->name);
+ FVERBOSE("Found main module: %s", module->name);
*ret = module;
@@ -35,21 +35,23 @@ gboolean lib_get_text_section(const GumDarwinSectionDetails *details,
static size_t idx = 0;
char text_name[] = "__text";
- FOKF("Section: %2lu - base: 0x%016" G_GINT64_MODIFIER
- "X size: 0x%016" G_GINT64_MODIFIER "X %s",
- idx++, details->vm_address, details->vm_address + details->size,
- details->section_name);
+ FVERBOSE("\t%2lu - base: 0x%016" G_GINT64_MODIFIER
+ "X size: 0x%016" G_GINT64_MODIFIER "X %s",
+ idx++, details->vm_address, details->vm_address + details->size,
+ details->section_name);
if (memcmp(details->section_name, text_name, sizeof(text_name)) == 0 &&
text_base == 0) {
text_base = details->vm_address;
text_limit = details->vm_address + details->size;
- FOKF("> text_addr: 0x%016" G_GINT64_MODIFIER "X", text_base);
- FOKF("> text_limit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
}
+ FVERBOSE(".text\n");
+ FVERBOSE("\taddr: 0x%016" G_GINT64_MODIFIER "X", text_base);
+ FVERBOSE("\tlimit: 0x%016" G_GINT64_MODIFIER "X", text_limit);
+
return TRUE;
}
@@ -62,6 +64,8 @@ void lib_init(void) {
GumDarwinModule *module = NULL;
gum_darwin_enumerate_modules(mach_task_self(), lib_get_main_module, &module);
+
+ FVERBOSE("Sections:");
gum_darwin_module_enumerate_sections(module, lib_get_text_section, NULL);
}
diff --git a/frida_mode/src/main.c b/frida_mode/src/main.c
index 1be63bc4..d8521300 100644
--- a/frida_mode/src/main.c
+++ b/frida_mode/src/main.c
@@ -111,11 +111,13 @@ static void afl_print_cmdline(void) {
int idx = 0;
+ FVERBOSE("Command Line");
+
for (ssize_t i = 0; i < bytes_read; i++) {
if (i == 0 || buffer[i - 1] == '\0') {
- FOKF("AFL - COMMANDLINE: argv[%d] = %s", idx++, &buffer[i]);
+ FVERBOSE("\targv[%d] = %s", idx++, &buffer[i]);
}
@@ -131,7 +133,7 @@ static void afl_print_cmdline(void) {
for (idx = 0; idx < nargv; idx++) {
- FOKF("AFL - COMMANDLINE: argv[%d] = %s", idx, argv[idx]);
+ FVERBOSE("\targv[%d] = %s", idx, argv[idx]);
}
@@ -161,11 +163,12 @@ static void afl_print_env(void) {
int idx = 0;
+ FVERBOSE("ENVIRONMENT");
for (ssize_t i = 0; i < bytes_read; i++) {
if (i == 0 || buffer[i - 1] == '\0') {
- FOKF("AFL - ENVIRONMENT %3d: %s", idx++, &buffer[i]);
+ FVERBOSE("\t%3d: %s", idx++, &buffer[i]);
}
@@ -179,6 +182,13 @@ static void afl_print_env(void) {
__attribute__((visibility("default"))) void afl_frida_start(void) {
+ FOKF(cRED "**********************");
+ FOKF(cRED "* " cYEL "******************" cRED " *");
+ FOKF(cRED "* " cYEL "* " cGRN "**************" cYEL " *" cRED " *");
+ FOKF(cRED "* " cYEL "* " cGRN "* FRIDA MODE *" cYEL " *" cRED " *");
+ FOKF(cRED "* " cYEL "* " cGRN "**************" cYEL " *" cRED " *");
+ FOKF(cRED "* " cYEL "******************" cRED " *");
+ FOKF(cRED "**********************");
afl_print_cmdline();
afl_print_env();
@@ -255,9 +265,9 @@ static void intercept_main(void) {
static void intercept_main(void) {
mach_port_t task = mach_task_self();
- FOKF("Task Id: %u", task);
+ FVERBOSE("Task Id: %u", task);
GumAddress entry = gum_darwin_find_entrypoint(task);
- FOKF("Entry Point: 0x%016" G_GINT64_MODIFIER "x", entry);
+ FVERBOSE("Entry Point: 0x%016" G_GINT64_MODIFIER "x", entry);
void *main = GSIZE_TO_POINTER(entry);
main_fn = main;
intercept_hook(main, on_main, NULL);
diff --git a/frida_mode/src/output.c b/frida_mode/src/output.c
index f570fe91..66208992 100644
--- a/frida_mode/src/output.c
+++ b/frida_mode/src/output.c
@@ -18,7 +18,7 @@ static void output_redirect(int fd, char *filename) {
path = g_canonicalize_filename(filename, g_get_current_dir());
- FOKF("Redirect %d -> '%s'", fd, path);
+ FVERBOSE("Redirect %d -> '%s'", fd, path);
int output_fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
@@ -46,8 +46,10 @@ void output_config(void) {
void output_init(void) {
- FOKF("Output - StdOut: %s", output_stdout);
- FOKF("Output - StdErr: %s", output_stderr);
+ FOKF(cBLU "Output" cRST " - " cGRN "stdout:" cYEL " [%s]",
+ output_stdout == NULL ? " " : output_stdout);
+ FOKF(cBLU "Output" cRST " - " cGRN "stderr:" cYEL " [%s]",
+ output_stderr == NULL ? " " : output_stderr);
output_redirect(STDOUT_FILENO, output_stdout);
output_redirect(STDERR_FILENO, output_stderr);
diff --git a/frida_mode/src/persistent/persistent.c b/frida_mode/src/persistent/persistent.c
index 817d9925..7fd7d351 100644
--- a/frida_mode/src/persistent/persistent.c
+++ b/frida_mode/src/persistent/persistent.c
@@ -72,13 +72,16 @@ void persistent_config(void) {
void persistent_init(void) {
- FOKF("Instrumentation - persistent mode [%c] (0x%016" G_GINT64_MODIFIER "X)",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "persistent mode:" cYEL
+ " [%c] (0x%016" G_GINT64_MODIFIER "X)",
persistent_start == 0 ? ' ' : 'X', persistent_start);
- FOKF("Instrumentation - persistent count [%c] (%" G_GINT64_MODIFIER "d)",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "persistent count:" cYEL
+ " [%c] (%" G_GINT64_MODIFIER "d)",
persistent_start == 0 ? ' ' : 'X', persistent_count);
- FOKF("Instrumentation - hook [%s]", hook_name);
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "hook:" cYEL " [%s]", hook_name);
- FOKF("Instrumentation - persistent ret [%c] (0x%016" G_GINT64_MODIFIER "X)",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "persistent ret:" cYEL
+ " [%c] (0x%016" G_GINT64_MODIFIER "X)",
persistent_ret == 0 ? ' ' : 'X', persistent_ret);
if (persistent_hook != NULL) { __afl_sharedmem_fuzzing = 1; }
@@ -87,7 +90,7 @@ void persistent_init(void) {
void persistent_prologue(GumStalkerOutput *output) {
- FOKF("AFL_FRIDA_PERSISTENT_ADDR reached");
+ FVERBOSE("AFL_FRIDA_PERSISTENT_ADDR reached");
entry_compiled = TRUE;
ranges_exclude();
stalker_trust();
@@ -97,7 +100,7 @@ void persistent_prologue(GumStalkerOutput *output) {
void persistent_epilogue(GumStalkerOutput *output) {
- FOKF("AFL_FRIDA_PERSISTENT_RET reached");
+ FVERBOSE("AFL_FRIDA_PERSISTENT_RET reached");
persistent_epilogue_arch(output);
}
diff --git a/frida_mode/src/persistent/persistent_arm64.c b/frida_mode/src/persistent/persistent_arm64.c
index c9159ca1..adad41be 100644
--- a/frida_mode/src/persistent/persistent_arm64.c
+++ b/frida_mode/src/persistent/persistent_arm64.c
@@ -324,7 +324,7 @@ void persistent_prologue_arch(GumStalkerOutput *output) {
gconstpointer loop = cw->code + 1;
- FOKF("Persistent loop reached");
+ FVERBOSE("Persistent loop reached");
instrument_persitent_save_regs(cw, &saved_regs);
diff --git a/frida_mode/src/persistent/persistent_x64.c b/frida_mode/src/persistent/persistent_x64.c
index 8cbde633..13d6a090 100644
--- a/frida_mode/src/persistent/persistent_x64.c
+++ b/frida_mode/src/persistent/persistent_x64.c
@@ -269,7 +269,7 @@ void persistent_prologue_arch(GumStalkerOutput *output) {
gconstpointer loop = cw->code + 1;
- FOKF("Persistent loop reached");
+ FVERBOSE("Persistent loop reached");
/* Pop the return value */
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_REG_RSP, GUM_REG_RSP, 8);
diff --git a/frida_mode/src/persistent/persistent_x86.c b/frida_mode/src/persistent/persistent_x86.c
index 5425b01b..3fe5891c 100644
--- a/frida_mode/src/persistent/persistent_x86.c
+++ b/frida_mode/src/persistent/persistent_x86.c
@@ -210,7 +210,7 @@ void persistent_prologue_arch(GumStalkerOutput *output) {
gconstpointer loop = cw->code + 1;
- FOKF("Persistent loop reached");
+ FVERBOSE("Persistent loop reached");
/* Pop the return value */
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_REG_ESP, GUM_REG_ESP, 4);
diff --git a/frida_mode/src/prefetch.c b/frida_mode/src/prefetch.c
index 8c9ce94d..fa0288cc 100644
--- a/frida_mode/src/prefetch.c
+++ b/frida_mode/src/prefetch.c
@@ -178,8 +178,10 @@ static void prefetch_hook_fork(void) {
void prefetch_init(void) {
- FOKF("Instrumentation - prefetch [%c]", prefetch_enable ? 'X' : ' ');
- FOKF("Instrumentation - prefetch_backpatch [%c]",
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "prefetch:" cYEL " [%c]",
+ prefetch_enable ? 'X' : ' ');
+ FOKF(cBLU "Instrumentation" cRST " - " cGRN "prefetch_backpatch:" cYEL
+ " [%c]",
prefetch_backpatch ? 'X' : ' ');
if (!prefetch_enable) { return; }
diff --git a/frida_mode/src/ranges.c b/frida_mode/src/ranges.c
index 9844c74c..84803453 100644
--- a/frida_mode/src/ranges.c
+++ b/frida_mode/src/ranges.c
@@ -122,10 +122,10 @@ static gboolean convert_name_token_for_module(const GumModuleDetails *details,
if (!g_str_has_suffix(details->path, ctx->suffix)) { return true; };
- FOKF("Found module - prefix: %s, 0x%016" G_GINT64_MODIFIER
- "x-0x%016" G_GINT64_MODIFIER "x %s",
- ctx->suffix, details->range->base_address,
- details->range->base_address + details->range->size, details->path);
+ FVERBOSE("Found module - prefix: %s, 0x%016" G_GINT64_MODIFIER
+ "x-0x%016" G_GINT64_MODIFIER "x %s",
+ ctx->suffix, details->range->base_address,
+ details->range->base_address + details->range->size, details->path);
*ctx->range = *details->range;
ctx->done = true;
@@ -158,9 +158,9 @@ static void convert_token(gchar *token, GumMemoryRange *range) {
}
- FOKF("Converted token: %s -> 0x%016" G_GINT64_MODIFIER
- "x-0x%016" G_GINT64_MODIFIER "x\n",
- token, range->base_address, range->base_address + range->size);
+ FVERBOSE("Converted token: %s -> 0x%016" G_GINT64_MODIFIER
+ "x-0x%016" G_GINT64_MODIFIER "x\n",
+ token, range->base_address, range->base_address + range->size);
}
@@ -192,24 +192,24 @@ static gboolean print_ranges_callback(const GumRangeDetails *details,
if (details->file == NULL) {
- FOKF("MAP - 0x%016" G_GINT64_MODIFIER "x - 0x%016" G_GINT64_MODIFIER
- "X %c%c%c",
- details->range->base_address,
- details->range->base_address + details->range->size,
- details->protection & GUM_PAGE_READ ? 'R' : '-',
- details->protection & GUM_PAGE_WRITE ? 'W' : '-',
- details->protection & GUM_PAGE_EXECUTE ? 'X' : '-');
+ FVERBOSE("\t0x%016" G_GINT64_MODIFIER "x-0x%016" G_GINT64_MODIFIER
+ "X %c%c%c",
+ details->range->base_address,
+ details->range->base_address + details->range->size,
+ details->protection & GUM_PAGE_READ ? 'R' : '-',
+ details->protection & GUM_PAGE_WRITE ? 'W' : '-',
+ details->protection & GUM_PAGE_EXECUTE ? 'X' : '-');
} else {
- FOKF("MAP - 0x%016" G_GINT64_MODIFIER "x - 0x%016" G_GINT64_MODIFIER
- "X %c%c%c %s(0x%016" G_GINT64_MODIFIER "x)",
- details->range->base_address,
- details->range->base_address + details->range->size,
- details->protection & GUM_PAGE_READ ? 'R' : '-',
- details->protection & GUM_PAGE_WRITE ? 'W' : '-',
- details->protection & GUM_PAGE_EXECUTE ? 'X' : '-',
- details->file->path, details->file->offset);
+ FVERBOSE("\t0x%016" G_GINT64_MODIFIER "x-0x%016" G_GINT64_MODIFIER
+ "X %c%c%c %s(0x%016" G_GINT64_MODIFIER "x)",
+ details->range->base_address,
+ details->range->base_address + details->range->size,
+ details->protection & GUM_PAGE_READ ? 'R' : '-',
+ details->protection & GUM_PAGE_WRITE ? 'W' : '-',
+ details->protection & GUM_PAGE_EXECUTE ? 'X' : '-',
+ details->file->path, details->file->offset);
}
@@ -219,14 +219,14 @@ static gboolean print_ranges_callback(const GumRangeDetails *details,
static void print_ranges(char *key, GArray *ranges) {
- FOKF("Range: %s Length: %d", key, ranges->len);
+ FVERBOSE("Range: [%s], Length: %d", key, ranges->len);
for (guint i = 0; i < ranges->len; i++) {
GumMemoryRange *curr = &g_array_index(ranges, GumMemoryRange, i);
GumAddress curr_limit = curr->base_address + curr->size;
- FOKF("Range: %s Idx: %3d - 0x%016" G_GINT64_MODIFIER
- "x-0x%016" G_GINT64_MODIFIER "x",
- key, i, curr->base_address, curr_limit);
+ FVERBOSE("\t%3d - 0x%016" G_GINT64_MODIFIER "x-0x%016" G_GINT64_MODIFIER
+ "x",
+ i, curr->base_address, curr_limit);
}
@@ -248,7 +248,7 @@ static GArray *collect_module_ranges(void) {
result = g_array_new(false, false, sizeof(GumMemoryRange));
gum_process_enumerate_ranges(GUM_PAGE_NO_ACCESS,
collect_module_ranges_callback, result);
- print_ranges("Modules", result);
+ print_ranges("modules", result);
return result;
}
@@ -348,7 +348,7 @@ static GArray *collect_libs_ranges(void) {
g_array_append_val(result, range);
- print_ranges("AFL_INST_LIBS", result);
+ print_ranges("libs", result);
return result;
@@ -382,7 +382,7 @@ static GArray *collect_jit_ranges(void) {
}
- print_ranges("JIT", result);
+ print_ranges("jit", result);
return result;
}
@@ -564,6 +564,7 @@ static GArray *merge_ranges(GArray *a) {
void ranges_print_debug_maps(void) {
+ FVERBOSE("Maps");
gum_process_enumerate_ranges(GUM_PAGE_NO_ACCESS, print_ranges_callback, NULL);
}
@@ -590,16 +591,15 @@ void ranges_init(void) {
GArray * step4;
GArray * step5;
- FOKF("Ranges - Instrument jit [%c]", ranges_inst_jit ? 'X' : ' ');
- FOKF("Ranges - Instrument libraries [%c]", ranges_inst_libs ? 'X' : ' ');
+ FOKF(cBLU "Ranges" cRST " - " cGRN "instrument jit:" cYEL " [%c]",
+ ranges_inst_jit ? 'X' : ' ');
+ FOKF(cBLU "Ranges" cRST " - " cGRN "instrument libraries:" cYEL " [%c]",
+ ranges_inst_libs ? 'X' : ' ');
+ FOKF(cBLU "Ranges" cRST " - " cGRN "instrument libraries:" cYEL " [%c]",
+ ranges_inst_libs ? 'X' : ' ');
- print_ranges("AFL_FRIDA_INST_RANGES", include_ranges);
- print_ranges("AFL_FRIDA_EXCLUDE_RANGES", exclude_ranges);
-
- FOKF("Ranges - Instrument libraries [%c]", ranges_inst_libs ? 'X' : ' ');
-
- print_ranges("AFL_FRIDA_INST_RANGES", include_ranges);
- print_ranges("AFL_FRIDA_EXCLUDE_RANGES", exclude_ranges);
+ print_ranges("include", include_ranges);
+ print_ranges("exclude", exclude_ranges);
module_ranges = collect_module_ranges();
libs_ranges = collect_libs_ranges();
@@ -673,7 +673,7 @@ void ranges_exclude() {
GumMemoryRange *r;
GumStalker * stalker = stalker_get();
- FOKF("Excluding ranges");
+ FVERBOSE("Excluding ranges");
for (guint i = 0; i < ranges->len; i++) {
diff --git a/frida_mode/src/seccomp/seccomp.c b/frida_mode/src/seccomp/seccomp.c
index 9d8fdd5d..984a3990 100644
--- a/frida_mode/src/seccomp/seccomp.c
+++ b/frida_mode/src/seccomp/seccomp.c
@@ -25,7 +25,8 @@ void seccomp_config(void) {
void seccomp_init(void) {
- FOKF("Seccomp - file [%s]", seccomp_filename);
+ FOKF(cBLU "Seccomp" cRST " - " cGRN "file:" cYEL " [%s]",
+ seccomp_filename == NULL ? " " : seccomp_filename);
if (seccomp_filename == NULL) { return; }
diff --git a/frida_mode/src/seccomp/seccomp_callback.c b/frida_mode/src/seccomp/seccomp_callback.c
index f7aaf78b..c86e753f 100644
--- a/frida_mode/src/seccomp/seccomp_callback.c
+++ b/frida_mode/src/seccomp/seccomp_callback.c
@@ -124,7 +124,7 @@ void seccomp_callback_initialize(void) {
path = g_canonicalize_filename(seccomp_filename, g_get_current_dir());
- FOKF("Seccomp - path [%s]", path);
+ FVERBOSE("Seccomp - path [%s]", path);
fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
diff --git a/frida_mode/src/seccomp/seccomp_filter.c b/frida_mode/src/seccomp/seccomp_filter.c
index 1d050303..075d793a 100644
--- a/frida_mode/src/seccomp/seccomp_filter.c
+++ b/frida_mode/src/seccomp/seccomp_filter.c
@@ -258,7 +258,7 @@ void seccomp_filter_run(int fd, seccomp_filter_callback_t callback) {
if (ioctl(fd, SECCOMP_IOCTL_NOTIF_SEND, resp) < 0) {
if (errno == ENOENT) { continue; }
- FOKF("SECCOMP_IOCTL_NOTIF_SEND");
+ FVERBOSE("SECCOMP_IOCTL_NOTIF_SEND");
continue;
}
diff --git a/frida_mode/src/stalker.c b/frida_mode/src/stalker.c
index caa16b3f..3a421867 100644
--- a/frida_mode/src/stalker.c
+++ b/frida_mode/src/stalker.c
@@ -93,10 +93,12 @@ static gboolean stalker_exclude_self(const GumRangeDetails *details,
void stalker_init(void) {
- FOKF("Instrumentation - backpatch [%c]", backpatch_enable ? 'X' : ' ');
-
- FOKF("Stalker - ic_entries [%u]", stalker_ic_entries);
- FOKF("Stalker - adjacent_blocks [%u]", stalker_adjacent_blocks);
+ FOKF(cBLU "Stalker" cRST " - " cGRN "backpatch:" cYEL " [%c]",
+ backpatch_enable ? 'X' : ' ');
+ FOKF(cBLU "Stalker" cRST " - " cGRN "ic_entries:" cYEL " [%u]",
+ stalker_ic_entries);
+ FOKF(cBLU "Stalker" cRST " - " cGRN "adjacent_blocks:" cYEL " [%u]",
+ stalker_adjacent_blocks);
#if !(defined(__x86_64__) || defined(__i386__))
if (getenv("AFL_FRIDA_STALKER_IC_ENTRIES") != NULL) {
diff --git a/frida_mode/src/stats/stats.c b/frida_mode/src/stats/stats.c
index 83ecf89a..39aca0db 100644
--- a/frida_mode/src/stats/stats.c
+++ b/frida_mode/src/stats/stats.c
@@ -329,8 +329,11 @@ void stats_config(void) {
void stats_init(void) {
- FOKF("Stats - file [%s]", stats_filename);
- FOKF("Stats - interval [%" G_GINT64_MODIFIER "u]", stats_interval);
+ FOKF(cBLU "Stats" cRST " - " cGRN "file:" cYEL " [%s]",
+ stats_filename == NULL ? " " : stats_filename);
+ FOKF(cBLU "Stats" cRST " - " cGRN "interval:" cYEL " [%" G_GINT64_MODIFIER
+ "u]",
+ stats_interval);
if (getenv("AFL_FRIDA_STATS_INTERVAL") != NULL &&
getenv("AFL_FRIDA_STATS_FILE") == NULL) {
@@ -347,7 +350,8 @@ void stats_init(void) {
char *path = g_canonicalize_filename(stats_filename, g_get_current_dir());
- FOKF("Stats - path [%s]", path);
+ FOKF(cBLU "Stats" cRST " - " cGRN "path:" cYEL " [%s]",
+ path == NULL ? " " : path);
stats_fd = open(path, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
diff --git a/frida_mode/src/util.c b/frida_mode/src/util.c
index 6f52b6cb..e4d2aaf2 100644
--- a/frida_mode/src/util.c
+++ b/frida_mode/src/util.c
@@ -1,5 +1,7 @@
#include "util.h"
+gboolean util_verbose = FALSE;
+
guint64 util_read_address(char *key, guint64 default_value) {
char *value_str = getenv(key);
@@ -87,12 +89,13 @@ guint64 util_read_num(char *key, guint64 default_value) {
gboolean util_output_enabled(void) {
static gboolean initialized = FALSE;
- static gboolean enabled = TRUE;
+ static gboolean enabled = FALSE;
if (!initialized) {
initialized = TRUE;
- if (getenv("AFL_DEBUG_CHILD") == NULL) { enabled = FALSE; }
+ if (getenv("AFL_DEBUG_CHILD") != NULL) { enabled = TRUE; }
+ if (util_verbose_enabled()) { enabled = TRUE; }
}
@@ -100,6 +103,21 @@ gboolean util_output_enabled(void) {
}
+gboolean util_verbose_enabled(void) {
+
+ static gboolean initialized = FALSE;
+
+ if (!initialized) {
+
+ initialized = TRUE;
+ if (getenv("AFL_FRIDA_VERBOSE") != NULL) { util_verbose = TRUE; }
+
+ }
+
+ return util_verbose;
+
+}
+
gsize util_rotate(gsize val, gsize shift, gsize size) {
if (shift == 0) { return val; }