From 83a2a8aa141ee6a7937b670217d764862b8cb4aa Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Mon, 28 Apr 2025 20:09:24 -0400 Subject: [PATCH] Color `AFL_NO_UI` output --- src/afl-fuzz-one.c | 5 +++-- src/afl-fuzz-stats.c | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/afl-fuzz-one.c b/src/afl-fuzz-one.c index dfd3c779..bccfe45f 100644 --- a/src/afl-fuzz-one.c +++ b/src/afl-fuzz-one.c @@ -411,11 +411,12 @@ u8 fuzz_one_original(afl_state_t *afl) { u_simplestring_time_diff(time_tmp, afl->prev_run_time + get_cur_time(), afl->start_time); ACTF( - "Fuzzing test case #%u (%u total, %llu crashes saved, state: %s, " + "Fuzzing test case #%u (%u total, %s%llu crashes saved%s, state: %s, " "mode=%s, " "perf_score=%0.0f, weight=%0.0f, favorite=%u, was_fuzzed=%u, " "exec_us=%llu, hits=%u, map=%u, ascii=%u, run_time=%s)...", - afl->current_entry, afl->queued_items, afl->saved_crashes, + afl->current_entry, afl->queued_items, + afl->saved_crashes != 0 ? cRED : "", afl->saved_crashes, cRST, get_fuzzing_state(afl), afl->fuzz_mode ? "exploit" : "explore", afl->queue_cur->perf_score, afl->queue_cur->weight, afl->queue_cur->favored, afl->queue_cur->was_fuzzed, diff --git a/src/afl-fuzz-stats.c b/src/afl-fuzz-stats.c index 8c13cd65..cfa87e48 100644 --- a/src/afl-fuzz-stats.c +++ b/src/afl-fuzz-stats.c @@ -28,8 +28,13 @@ #include "envs.h" #include -static char fuzzing_state[4][12] = {"started :-)", "in progress", "final phase", - "finished..."}; +// 7 is the number of characters in a color control code +// 11 is the number of characters in the fuzzing state itself +// 5 is the number of characters in `cRST` +// 1 is for the null character +static char fuzzing_state[4][7 + 11 + 5 + 1] = { + + "started :-)", "in progress", "final phase", cRED "finished..." cRST}; char *get_fuzzing_state(afl_state_t *afl) {