Skip to content
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

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions libafl/src/monitors/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ impl Monitor for TuiMonitor {
client.executions(),
exec_sec
);

// Display "Current Testcase Index" if available
if let Some(stat) = client.get_user_stats("Current Testcase Index") {
write!(fmt, ", Testcase Index: {}", stat.value()).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try if this is needed? Becaus ethe loop below already prints all user stats(?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried and thought it was necessary can remove it

}

for (key, val) in client.user_stats() {
write!(fmt, ", {key}: {val}").unwrap();
}
Expand Down
28 changes: 28 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,29 @@ 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 {
if 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 +682,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 +707,7 @@ where
version: String::default(),
target_mode: String::default(),
phantom_data: PhantomData,
report_current_corpus_idx: false,
}
}

Expand Down Expand Up @@ -817,7 +843,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