Changes to support defaults for configuration options
MODIFY
frida_mode/include/util.h
frida_mode/include/util.h
#define UNUSED_PARAMETER(x) (void)(x)
#define IGNORED_RETURN(x) (void)!(x)
-guint64 util_read_address(char *key);
-guint64 util_read_num(char *key);
+guint64 util_read_address(char *key, guint64 default_value);
+guint64 util_read_num(char *key, guint64 default_value);
gboolean util_output_enabled(void);
gsize util_rotate(gsize val, gsize shift, gsize size);
gsize util_log2(gsize val);

MODIFY
frida_mode/src/entry.c
frida_mode/src/entry.c
@@ -62,7 +62,7 @@ void entry_on_fork(void) {
void entry_config(void) {
- entry_point = util_read_address("AFL_ENTRYPOINT");
+ entry_point = util_read_address("AFL_ENTRYPOINT", 0);
if (getenv("AFL_FRIDA_TRACEABLE") != NULL) { traceable = TRUE; }
}

MODIFY
frida_mode/src/instrument/instrument.c
frida_mode/src/instrument/instrument.c
@@ -246,7 +246,7 @@ void instrument_config(void) {
instrument_tracing = (getenv("AFL_FRIDA_INST_TRACE") != NULL);
instrument_unique = (getenv("AFL_FRIDA_INST_TRACE_UNIQUE") != NULL);
instrument_use_fixed_seed = (getenv("AFL_FRIDA_INST_SEED") != NULL);
- instrument_fixed_seed = util_read_num("AFL_FRIDA_INST_SEED");
+ instrument_fixed_seed = util_read_num("AFL_FRIDA_INST_SEED", 0);
instrument_coverage_unstable_filename =
(getenv("AFL_FRIDA_INST_UNSTABLE_COVERAGE_FILE"));

MODIFY
frida_mode/src/persistent/persistent.c
frida_mode/src/persistent/persistent.c
@@ -22,9 +22,9 @@ gboolean persistent_debug = FALSE;
void persistent_config(void) {
hook_name = getenv("AFL_FRIDA_PERSISTENT_HOOK");
- persistent_start = util_read_address("AFL_FRIDA_PERSISTENT_ADDR");
- persistent_count = util_read_num("AFL_FRIDA_PERSISTENT_CNT");
- persistent_ret = util_read_address("AFL_FRIDA_PERSISTENT_RET");
+ persistent_start = util_read_address("AFL_FRIDA_PERSISTENT_ADDR", 0);
+ persistent_count = util_read_num("AFL_FRIDA_PERSISTENT_CNT", 0);
+ persistent_ret = util_read_address("AFL_FRIDA_PERSISTENT_RET", 0);
if (getenv("AFL_FRIDA_PERSISTENT_DEBUG") != NULL) { persistent_debug = TRUE; }

MODIFY
frida_mode/src/stalker.c
frida_mode/src/stalker.c
@@ -61,9 +61,10 @@ void stalker_config(void) {
backpatch_enable = (getenv("AFL_FRIDA_INST_NO_BACKPATCH") == NULL);
- stalker_adjacent_blocks = util_read_num("AFL_FRIDA_STALKER_ADJACENT_BLOCKS");
+ stalker_ic_entries = util_read_num("AFL_FRIDA_STALKER_IC_ENTRIES", 32);
- stalker_ic_entries = util_read_num("AFL_FRIDA_STALKER_IC_ENTRIES");
+ stalker_adjacent_blocks =
+ util_read_num("AFL_FRIDA_STALKER_ADJACENT_BLOCKS", 32);
observer = g_object_new(GUM_TYPE_AFL_STALKER_OBSERVER, NULL);
@@ -98,33 +99,32 @@ void stalker_init(void) {
FOKF("Stalker - adjacent_blocks [%u]", stalker_adjacent_blocks);
#if !(defined(__x86_64__) || defined(__i386__))
- if (stalker_ic_entries != 0) {
+ if (getenv("AFL_FRIDA_STALKER_IC_ENTRIES") != NULL) {
FFATAL("AFL_FRIDA_STALKER_IC_ENTRIES not supported");
}
- if (stalker_adjacent_blocks != 0) {
+ if (getenv("AFL_FRIDA_STALKER_ADJACENT_BLOCKS") != NULL) {
FFATAL("AFL_FRIDA_STALKER_ADJACENT_BLOCKS not supported");
}
#endif
- if (stalker_ic_entries == 0) { stalker_ic_entries = 32; }
- if (instrument_coverage_filename == NULL) {
+ if (instrument_coverage_filename != NULL) {
- if (stalker_adjacent_blocks == 0) { stalker_adjacent_blocks = 32; }
-
- } else {
-
- if (stalker_adjacent_blocks != 0) {
+ if (getenv("AFL_FRIDA_STALKER_ADJACENT_BLOCKS") != NULL) {
FFATAL(
"AFL_FRIDA_STALKER_ADJACENT_BLOCKS and AFL_FRIDA_INST_COVERAGE_FILE "
"are incompatible");
+ } else {
+
+ stalker_adjacent_blocks = 0;
+
}
}

MODIFY
frida_mode/src/stats/stats.c
frida_mode/src/stats/stats.c
@@ -323,7 +323,7 @@ static void stats_observer_init(GumStalkerObserver *observer) {
void stats_config(void) {
stats_filename = getenv("AFL_FRIDA_STATS_FILE");
- stats_interval = util_read_num("AFL_FRIDA_STATS_INTERVAL");
+ stats_interval = util_read_num("AFL_FRIDA_STATS_INTERVAL", 10);
}
@@ -332,7 +332,8 @@ void stats_init(void) {
FOKF("Stats - file [%s]", stats_filename);
FOKF("Stats - interval [%" G_GINT64_MODIFIER "u]", stats_interval);
- if (stats_interval != 0 && stats_filename == NULL) {
+ if (getenv("AFL_FRIDA_STATS_INTERVAL") != NULL &&
+ getenv("AFL_FRIDA_STATS_FILE") == NULL) {
FFATAL(
"AFL_FRIDA_STATS_FILE must be specified if "
@@ -340,7 +341,6 @@ void stats_init(void) {
}
- if (stats_interval == 0) { stats_interval = 10; }
stats_interval_us = stats_interval * MICRO_TO_SEC;
if (stats_filename == NULL) { return; }

MODIFY
frida_mode/src/util.c
frida_mode/src/util.c
#include "util.h"
-guint64 util_read_address(char *key) {
+guint64 util_read_address(char *key, guint64 default_value) {
char *value_str = getenv(key);
char *end_ptr;
- if (value_str == NULL) { return 0; }
+ if (value_str == NULL) { return default_value; }
if (!g_str_has_prefix(value_str, "0x")) {
@@ -46,12 +46,12 @@ guint64 util_read_address(char *key) {
}
-guint64 util_read_num(char *key) {
+guint64 util_read_num(char *key, guint64 default_value) {
char *value_str = getenv(key);
char *end_ptr;
- if (value_str == NULL) { return 0; }
+ if (value_str == NULL) { return default_value; }
for (char *c = value_str; *c != '\0'; c++) {

Changes to support defaults for configuration options