Skip to content

Enhanced TuiMonitor display to include Current Testcase Index and use… #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libafl/src/monitors/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ impl Monitor for TuiMonitor {
client.executions(),
exec_sec
);

for (key, val) in client.user_stats() {
write!(fmt, ", {key}: {val}").unwrap();
}
Expand Down
26 changes: 26 additions & 0 deletions libafl/src/stages/afl_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub struct AflStatsStage<C, E, EM, I, O, S, Z> {
/// The core we are bound to
core_id: CoreId,
phantom_data: PhantomData<(E, EM, I, O, S, Z)>,
report_current_corpus_idx: bool,
last_sent_corpus_idx: Option<usize>,
}

/// AFL++'s `fuzzer_stats`
Expand Down Expand Up @@ -268,7 +270,27 @@ where
"state is not currently processing a corpus index",
));
};
// Clone or copy the required data from `state`
let corpus_idx_value = corpus_idx.0; // Extract `usize` value from `CorpusId`

// Fire the UpdateUserStats event with the corpus index
if self.report_current_corpus_idx && self.last_sent_corpus_idx != Some(corpus_idx_value) {
manager.fire(
state,
Event::UpdateUserStats {
name: Cow::Borrowed("Current Testcase Index"),
value: UserStats::new(
UserStatsValue::Number(corpus_idx_value as u64),
AggregatorOps::Sum,
),
phantom: PhantomData,
},
)?;
// Update the last_sent_corpus_idx to the current value
self.last_sent_corpus_idx = Some(corpus_idx_value);
}
let testcase = state.corpus().get(corpus_idx)?.borrow();

// NOTE: scheduled_count represents the amount of fuzz runs a
// testcase has had. Since this stage is kept at the very end of stage list,
// the entry would have been fuzzed already (and should contain IsFavoredMetadata) but would have a scheduled count of zero
Expand Down Expand Up @@ -658,6 +680,7 @@ pub struct AflStatsStageBuilder<C, E, EM, I, O, S, Z> {
version: String,
target_mode: String,
phantom_data: PhantomData<(E, EM, I, O, S, Z)>,
report_current_corpus_idx: bool,
}

impl<C, E, EM, I, O, S, Z> AflStatsStageBuilder<C, E, EM, I, O, S, Z>
Expand All @@ -682,6 +705,7 @@ where
version: String::default(),
target_mode: String::default(),
phantom_data: PhantomData,
report_current_corpus_idx: false,
}
}

Expand Down Expand Up @@ -817,7 +841,9 @@ where
dict_count: self.dict_count,
core_id: self.core_id.unwrap_or(CoreId(0)),
autotokens_enabled: self.uses_autotokens,
report_current_corpus_idx: self.report_current_corpus_idx, // Set field
phantom_data: PhantomData,
last_sent_corpus_idx: None,
})
}
}
Loading