Use Self::State as much as possible and remove unnecessary type bounds (#2263)

* use Self::State as much as possible

* makeing progress, little by little

* more

* add

* more and more

* more

* more

* mre

* fix

* a

* pp

* fix

* fix

* more

* version

* fix cargo fuzz
This commit is contained in:
Dongjia "toka" Zhang 2024-06-05 15:16:43 +02:00 committed by GitHub
parent a7bb5196ea
commit 6373a1e1b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 429 additions and 653 deletions

View File

@ -749,14 +749,15 @@ where
fn receive_from_secondary<E, Z>(
&mut self,
fuzzer: &mut Z,
state: &mut EM::State,
state: &mut <Self as UsesState>::State,
executor: &mut E,
) -> Result<usize, Error>
where
E: Executor<Self, Z> + HasObservers<State = EM::State>,
EM::State: UsesInput + HasExecutions + HasMetadata,
E: Executor<Self, Z> + HasObservers<State = <Self as UsesState>::State>,
<Self as UsesState>::State: UsesInput + HasExecutions + HasMetadata,
for<'a> E::Observers: Deserialize<'a>,
Z: ExecutionProcessor<E::Observers, State = EM::State> + EvaluatorObservers<E::Observers>,
Z: ExecutionProcessor<E::Observers, State = <Self as UsesState>::State>
+ EvaluatorObservers<E::Observers>,
{
// TODO: Get around local event copy by moving handle_in_client
let self_id = self.client.sender().id();
@ -781,7 +782,7 @@ where
} else {
msg
};
let event: Event<<<EM as UsesState>::State as UsesInput>::Input> =
let event: Event<<<Self as UsesState>::State as UsesInput>::Input> =
postcard::from_bytes(event_bytes)?;
self.handle_in_main(fuzzer, executor, state, client_id, event)?;
count += 1;
@ -794,15 +795,16 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut EM::State,
state: &mut <Self as UsesState>::State,
client_id: ClientId,
event: Event<<EM::State as UsesInput>::Input>,
event: Event<<<Self as UsesState>::State as UsesInput>::Input>,
) -> Result<(), Error>
where
E: Executor<Self, Z> + HasObservers<State = EM::State>,
EM::State: UsesInput + HasExecutions + HasMetadata,
E: Executor<Self, Z> + HasObservers<State = <Self as UsesState>::State>,
<Self as UsesState>::State: UsesInput + HasExecutions + HasMetadata,
for<'a> E::Observers: Deserialize<'a>,
Z: ExecutionProcessor<E::Observers, State = EM::State> + EvaluatorObservers<E::Observers>,
Z: ExecutionProcessor<E::Observers, State = <Self as UsesState>::State>
+ EvaluatorObservers<E::Observers>,
{
match event {
Event::NewTestcase {

View File

@ -80,15 +80,7 @@ const LIBAFL_DEBUG_OUTPUT: &str = "LIBAFL_DEBUG_OUTPUT";
clippy::ignored_unit_patterns
)]
#[derive(TypedBuilder)]
pub struct Launcher<'a, CF, EMH, MT, S, SP>
where
CF: FnOnce(Option<S>, LlmpRestartingEventManager<EMH, S, SP>, CoreId) -> Result<(), Error>,
EMH: EventManagerHooksTuple<S>,
S::Input: 'a,
MT: Monitor,
SP: ShMemProvider + 'static,
S: State + 'a,
{
pub struct Launcher<'a, CF, EMH, MT, S, SP> {
/// The `ShmemProvider` to use
shmem_provider: SP,
/// The monitor instance to use
@ -472,23 +464,7 @@ where
#[cfg(all(unix, feature = "std", feature = "fork"))]
#[derive(TypedBuilder)]
#[allow(clippy::type_complexity, missing_debug_implementations)]
pub struct CentralizedLauncher<'a, CF, MF, MT, S, SP>
where
CF: FnOnce(
Option<S>,
CentralizedEventManager<LlmpRestartingEventManager<(), S, SP>, SP>, // No hooks for centralized EM
CoreId,
) -> Result<(), Error>,
MF: FnOnce(
Option<S>,
CentralizedEventManager<LlmpRestartingEventManager<(), S, SP>, SP>, // No hooks for centralized EM
CoreId,
) -> Result<(), Error>,
S::Input: 'a,
MT: Monitor,
SP: ShMemProvider + 'static,
S: State + 'a,
{
pub struct CentralizedLauncher<'a, CF, MF, MT, S, SP> {
/// The `ShmemProvider` to use
shmem_provider: SP,
/// The monitor instance to use
@ -552,22 +528,7 @@ where
}
#[cfg(all(unix, feature = "std", feature = "fork"))]
impl<CF, MF, MT, S, SP> Debug for CentralizedLauncher<'_, CF, MF, MT, S, SP>
where
CF: FnOnce(
Option<S>,
CentralizedEventManager<LlmpRestartingEventManager<(), S, SP>, SP>,
CoreId,
) -> Result<(), Error>,
MF: FnOnce(
Option<S>,
CentralizedEventManager<LlmpRestartingEventManager<(), S, SP>, SP>, // No hooks for centralized EM
CoreId,
) -> Result<(), Error>,
MT: Monitor + Clone,
SP: ShMemProvider + 'static,
S: State,
{
impl<CF, MF, MT, S, SP> Debug for CentralizedLauncher<'_, CF, MF, MT, S, SP> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Launcher")
.field("configuration", &self.configuration)

View File

@ -21,10 +21,7 @@ use crate::{
#[derive(Debug)]
pub struct LlmpEventBroker<I, MT, SP>
where
I: Input,
SP: ShMemProvider + 'static,
MT: Monitor,
//CE: CustomEvent<I>,
{
monitor: MT,
llmp: llmp::LlmpBroker<SP>,

View File

@ -787,7 +787,7 @@ where
impl<E, EM, M, Z> EventManager<E, Z> for MonitorTypedEventManager<EM, M>
where
EM: EventManager<E, Z>,
EM::State: HasLastReportTime + HasExecutions + HasMetadata,
Self::State: HasLastReportTime + HasExecutions + HasMetadata,
{
}
@ -811,7 +811,7 @@ impl<EM, M> ProgressReporter for MonitorTypedEventManager<EM, M>
where
Self: UsesState,
EM: ProgressReporter<State = Self::State>,
EM::State: HasLastReportTime + HasExecutions + HasMetadata,
Self::State: HasLastReportTime + HasExecutions + HasMetadata,
{
#[inline]
fn maybe_report_progress(

View File

@ -24,9 +24,9 @@ impl<A, B> CombinedExecutor<A, B> {
pub fn new<EM, Z>(primary: A, secondary: B) -> Self
where
A: Executor<EM, Z>,
B: Executor<EM, Z, State = A::State>,
EM: UsesState<State = A::State>,
Z: UsesState<State = A::State>,
B: Executor<EM, Z, State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
Self { primary, secondary }
}
@ -45,10 +45,10 @@ impl<A, B> CombinedExecutor<A, B> {
impl<A, B, EM, Z> Executor<EM, Z> for CombinedExecutor<A, B>
where
A: Executor<EM, Z>,
B: Executor<EM, Z, State = A::State>,
EM: UsesState<State = A::State>,
EM::State: HasExecutions,
Z: UsesState<State = A::State>,
B: Executor<EM, Z, State = <Self as UsesState>::State>,
Self::State: HasExecutions,
EM: UsesState<State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
fn run_target(
&mut self,

View File

@ -31,10 +31,10 @@ impl<A, B, DOT, OTA, OTB> DiffExecutor<A, B, DOT, OTA, OTB> {
pub fn new(primary: A, secondary: B, observers: DOT) -> Self
where
A: UsesState + HasObservers<Observers = OTA>,
B: UsesState<State = A::State> + HasObservers<Observers = OTB>,
DOT: DifferentialObserversTuple<OTA, OTB, A::State>,
OTA: ObserversTuple<A::State>,
OTB: ObserversTuple<A::State>,
B: UsesState<State = <Self as UsesState>::State> + HasObservers<Observers = OTB>,
DOT: DifferentialObserversTuple<OTA, OTB, <Self as UsesState>::State>,
OTA: ObserversTuple<<Self as UsesState>::State>,
OTB: ObserversTuple<<Self as UsesState>::State>,
{
Self {
primary,
@ -61,10 +61,10 @@ impl<A, B, DOT, OTA, OTB> DiffExecutor<A, B, DOT, OTA, OTB> {
impl<A, B, DOT, EM, Z> Executor<EM, Z> for DiffExecutor<A, B, DOT, A::Observers, B::Observers>
where
A: Executor<EM, Z> + HasObservers,
B: Executor<EM, Z, State = A::State> + HasObservers,
EM: UsesState<State = A::State>,
DOT: DifferentialObserversTuple<A::Observers, B::Observers, A::State>,
Z: UsesState<State = A::State>,
B: Executor<EM, Z, State = <Self as UsesState>::State> + HasObservers,
EM: UsesState<State = <Self as UsesState>::State>,
DOT: DifferentialObserversTuple<A::Observers, B::Observers, <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
fn run_target(
&mut self,
@ -196,10 +196,10 @@ impl<A, B, DOT> ProxyObserversTuple<A, B, DOT> {
impl<A, B, DOT, OTA, OTB> UsesObservers for DiffExecutor<A, B, DOT, OTA, OTB>
where
A: HasObservers<Observers = OTA>,
B: HasObservers<Observers = OTB, State = A::State>,
OTA: ObserversTuple<A::State>,
OTB: ObserversTuple<A::State>,
DOT: DifferentialObserversTuple<OTA, OTB, A::State>,
B: HasObservers<Observers = OTB, State = <Self as UsesState>::State>,
OTA: ObserversTuple<<Self as UsesState>::State>,
OTB: ObserversTuple<<Self as UsesState>::State>,
DOT: DifferentialObserversTuple<OTA, OTB, <Self as UsesState>::State>,
{
type Observers = ProxyObserversTuple<OTA, OTB, DOT>;
}
@ -207,7 +207,6 @@ where
impl<A, B, DOT, OTA, OTB> UsesState for DiffExecutor<A, B, DOT, OTA, OTB>
where
A: UsesState,
B: UsesState<State = A::State>,
{
type State = A::State;
}
@ -215,10 +214,10 @@ where
impl<A, B, DOT, OTA, OTB> HasObservers for DiffExecutor<A, B, DOT, OTA, OTB>
where
A: HasObservers<Observers = OTA>,
B: HasObservers<Observers = OTB, State = A::State>,
OTA: ObserversTuple<A::State>,
OTB: ObserversTuple<A::State>,
DOT: DifferentialObserversTuple<OTA, OTB, A::State>,
B: HasObservers<Observers = OTB, State = <Self as UsesState>::State>,
OTA: ObserversTuple<<Self as UsesState>::State>,
OTB: ObserversTuple<<Self as UsesState>::State>,
DOT: DifferentialObserversTuple<OTA, OTB, <Self as UsesState>::State>,
{
#[inline]
fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> {

View File

@ -21,8 +21,8 @@ pub struct ShadowExecutor<E, SOT> {
impl<E, SOT> Debug for ShadowExecutor<E, SOT>
where
E: UsesState + Debug,
SOT: ObserversTuple<E::State> + Debug,
E: Debug,
SOT: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("ShadowExecutor")
@ -35,7 +35,7 @@ where
impl<E, SOT> ShadowExecutor<E, SOT>
where
E: HasObservers,
SOT: ObserversTuple<E::State>,
SOT: ObserversTuple<<Self as UsesState>::State>,
{
/// Create a new `ShadowExecutor`, wrapping the given `executor`.
pub fn new(executor: E, shadow_observers: SOT) -> Self {
@ -61,9 +61,9 @@ where
impl<E, EM, SOT, Z> Executor<EM, Z> for ShadowExecutor<E, SOT>
where
E: Executor<EM, Z> + HasObservers,
SOT: ObserversTuple<E::State>,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
SOT: ObserversTuple<Self::State>,
EM: UsesState<State = Self::State>,
Z: UsesState<State = Self::State>,
{
fn run_target(
&mut self,
@ -93,7 +93,7 @@ where
impl<E, SOT> HasObservers for ShadowExecutor<E, SOT>
where
E: HasObservers,
SOT: ObserversTuple<E::State>,
SOT: ObserversTuple<Self::State>,
{
#[inline]
fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> {

View File

@ -21,8 +21,8 @@ pub struct WithObservers<E, OT> {
impl<E, EM, OT, Z> Executor<EM, Z> for WithObservers<E, OT>
where
E: Executor<EM, Z>,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
EM: UsesState<State = Self::State>,
Z: UsesState<State = Self::State>,
{
fn run_target(
&mut self,
@ -45,7 +45,7 @@ where
impl<E, OT> UsesObservers for WithObservers<E, OT>
where
E: UsesState,
OT: ObserversTuple<E::State>,
OT: ObserversTuple<Self::State>,
{
type Observers = OT;
}
@ -53,7 +53,7 @@ where
impl<E, OT> HasObservers for WithObservers<E, OT>
where
E: UsesState,
OT: ObserversTuple<E::State>,
OT: ObserversTuple<Self::State>,
{
fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> {
RefIndexable::from(&self.observers)

View File

@ -50,7 +50,7 @@ where
}
}
impl<F, I, S, T> FeedbackFactory<CustomFilenameToTestcaseFeedback<F, I, S>, S, T>
impl<F, I, S, T> FeedbackFactory<CustomFilenameToTestcaseFeedback<F, I, S>, T>
for CustomFilenameToTestcaseFeedback<F, I, S>
where
I: Input,

View File

@ -100,7 +100,7 @@ where
}
}
impl<F, I, O1, O2, S, T> FeedbackFactory<DiffFeedback<F, I, O1, O2, S>, S, T>
impl<F, I, O1, O2, S, T> FeedbackFactory<DiffFeedback<F, I, O1, O2, S>, T>
for DiffFeedback<F, I, O1, O2, S>
where
F: FnMut(&O1, &O2) -> DiffResult + Clone,

View File

@ -310,11 +310,11 @@ where
}
}
impl<A, B, FL, S, T> FeedbackFactory<CombinedFeedback<A, B, FL, S>, S, T>
impl<A, B, FL, S, T> FeedbackFactory<CombinedFeedback<A, B, FL, S>, T>
for CombinedFeedback<A, B, FL, S>
where
A: Feedback<S> + FeedbackFactory<A, S, T>,
B: Feedback<S> + FeedbackFactory<B, S, T>,
A: Feedback<S> + FeedbackFactory<A, T>,
B: Feedback<S> + FeedbackFactory<B, T>,
FL: FeedbackLogic<A, B, S>,
S: State,
{
@ -383,20 +383,14 @@ where
/// Factory for feedbacks which should be sensitive to an existing context, e.g. observer(s) from a
/// specific execution
pub trait FeedbackFactory<F, S, T>
where
F: Feedback<S>,
S: State,
{
pub trait FeedbackFactory<F, T> {
/// Create the feedback from the provided context
fn create_feedback(&self, ctx: &T) -> F;
}
impl<FE, FU, S, T> FeedbackFactory<FE, S, T> for FU
impl<FE, FU, T> FeedbackFactory<FE, T> for FU
where
FU: Fn(&T) -> FE,
FE: Feedback<S>,
S: State,
{
fn create_feedback(&self, ctx: &T) -> FE {
self(ctx)
@ -982,7 +976,7 @@ impl Default for CrashFeedback {
}
}
impl<S: State, T> FeedbackFactory<CrashFeedback, S, T> for CrashFeedback {
impl<T> FeedbackFactory<CrashFeedback, T> for CrashFeedback {
fn create_feedback(&self, _ctx: &T) -> CrashFeedback {
CrashFeedback::new()
}
@ -1053,7 +1047,7 @@ impl Default for TimeoutFeedback {
}
/// A feedback factory for timeout feedbacks
impl<S: State, T> FeedbackFactory<TimeoutFeedback, S, T> for TimeoutFeedback {
impl<T> FeedbackFactory<TimeoutFeedback, T> for TimeoutFeedback {
fn create_feedback(&self, _ctx: &T) -> TimeoutFeedback {
TimeoutFeedback::new()
}
@ -1123,7 +1117,7 @@ impl Default for DiffExitKindFeedback {
}
/// A feedback factory for diff exit kind feedbacks
impl<S: State, T> FeedbackFactory<DiffExitKindFeedback, S, T> for DiffExitKindFeedback {
impl<T> FeedbackFactory<DiffExitKindFeedback, T> for DiffExitKindFeedback {
fn create_feedback(&self, _ctx: &T) -> DiffExitKindFeedback {
DiffExitKindFeedback::new()
}

View File

@ -130,11 +130,7 @@ pub trait EvaluatorObservers<OT>: UsesState + Sized {
}
/// Evaluate an input modifying the state of the fuzzer
pub trait Evaluator<E, EM>: UsesState
where
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
{
pub trait Evaluator<E, EM>: UsesState {
/// Runs the input and triggers observers and feedback,
/// returns if is interesting an (option) the index of the new [`crate::corpus::Testcase`] in the corpus
fn evaluate_input(
@ -204,7 +200,7 @@ where
&mut self,
stages: &mut ST,
executor: &mut E,
state: &mut EM::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<CorpusId, Error>;
@ -213,7 +209,7 @@ where
&mut self,
stages: &mut ST,
executor: &mut E,
state: &mut EM::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let monitor_timeout = STATS_TIMEOUT_DEFAULT;
@ -237,7 +233,7 @@ where
&mut self,
stages: &mut ST,
executor: &mut E,
state: &mut EM::State,
state: &mut Self::State,
manager: &mut EM,
iters: u64,
) -> Result<CorpusId, Error> {
@ -280,13 +276,7 @@ pub enum ExecuteInputResult {
/// Your default fuzzer instance, for everyday use.
#[derive(Debug)]
pub struct StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasCorpus,
{
pub struct StdFuzzer<CS, F, OF, OT> {
scheduler: CS,
feedback: F,
objective: OF,
@ -296,8 +286,6 @@ where
impl<CS, F, OF, OT> UsesState for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasCorpus,
{
type State = CS::State;
@ -306,8 +294,6 @@ where
impl<CS, F, OF, OT> HasScheduler for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
CS::State: HasCorpus,
{
type Scheduler = CS;
@ -324,8 +310,8 @@ where
impl<CS, F, OF, OT> HasFeedback for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
CS::State: HasCorpus,
{
type Feedback = F;
@ -342,8 +328,8 @@ where
impl<CS, F, OF, OT> HasObjective for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
CS::State: HasCorpus,
{
type Objective = OF;
@ -360,9 +346,9 @@ where
impl<CS, F, OF, OT> ExecutionProcessor<OT> for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
OT: ObserversTuple<CS::State> + Serialize + DeserializeOwned,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
OT: ObserversTuple<Self::State> + Serialize + DeserializeOwned,
CS::State: HasCorpus
+ HasSolutions
+ HasExecutions
@ -537,9 +523,9 @@ where
impl<CS, F, OF, OT> EvaluatorObservers<OT> for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
OT: ObserversTuple<CS::State> + Serialize + DeserializeOwned,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
OT: ObserversTuple<Self::State> + Serialize + DeserializeOwned,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
CS::State: HasCorpus + HasSolutions + HasExecutions + HasImported,
{
/// Process one input, adding to the respective corpora if needed and firing the right events
@ -568,11 +554,11 @@ where
impl<CS, E, EM, F, OF, OT> Evaluator<E, EM> for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
E: HasObservers<State = CS::State, Observers = OT> + Executor<EM, Self>,
EM: EventFirer<State = CS::State>,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
OT: ObserversTuple<CS::State> + Serialize + DeserializeOwned,
E: HasObservers<State = Self::State, Observers = OT> + Executor<EM, Self>,
EM: EventFirer<State = Self::State>,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
OT: ObserversTuple<Self::State> + Serialize + DeserializeOwned,
CS::State: HasCorpus + HasSolutions + HasExecutions + HasImported,
{
/// Process one input, adding to the respective corpora if needed and firing the right events
@ -699,10 +685,10 @@ where
impl<CS, E, EM, F, OF, OT, ST> Fuzzer<E, EM, ST> for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
E: UsesState<State = CS::State>,
EM: ProgressReporter + EventProcessor<E, Self, State = CS::State>,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
E: UsesState<State = Self::State>,
EM: ProgressReporter + EventProcessor<E, Self, State = Self::State>,
F: Feedback<Self::State>,
OF: Feedback<Self::State>,
CS::State: HasExecutions
+ HasMetadata
+ HasCorpus
@ -711,13 +697,13 @@ where
+ HasLastReportTime
+ HasCurrentCorpusId
+ HasCurrentStage,
ST: StagesTuple<E, EM, CS::State, Self>,
ST: StagesTuple<E, EM, Self::State, Self>,
{
fn fuzz_one(
&mut self,
stages: &mut ST,
executor: &mut E,
state: &mut CS::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<CorpusId, Error> {
// Init timer for scheduler
@ -772,8 +758,8 @@ where
impl<CS, F, OF, OT> StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
F: Feedback<<Self as UsesState>::State>,
OF: Feedback<<Self as UsesState>::State>,
CS::State: UsesInput + HasExecutions + HasCorpus,
{
/// Create a new `StdFuzzer` with standard behavior.
@ -789,15 +775,15 @@ where
/// Runs the input and triggers observers and feedback
pub fn execute_input<E, EM>(
&mut self,
state: &mut CS::State,
state: &mut <Self as UsesState>::State,
executor: &mut E,
event_mgr: &mut EM,
input: &<CS::State as UsesInput>::Input,
input: &<<Self as UsesState>::State as UsesInput>::Input,
) -> Result<ExitKind, Error>
where
E: Executor<EM, Self> + HasObservers<Observers = OT, State = CS::State>,
EM: UsesState<State = CS::State>,
OT: ObserversTuple<CS::State>,
E: Executor<EM, Self> + HasObservers<Observers = OT, State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
OT: ObserversTuple<<Self as UsesState>::State>,
{
start_timer!(state);
executor.observers_mut().pre_exec_all(state, input)?;
@ -833,22 +819,22 @@ where
) -> Result<ExitKind, Error>;
}
impl<CS, E, EM, F, OF> ExecutesInput<E, EM> for StdFuzzer<CS, F, OF, E::Observers>
impl<CS, E, EM, F, OF, OT> ExecutesInput<E, EM> for StdFuzzer<CS, F, OF, OT>
where
CS: Scheduler,
F: Feedback<CS::State>,
OF: Feedback<CS::State>,
E: Executor<EM, Self> + HasObservers<State = CS::State>,
EM: UsesState<State = CS::State>,
F: Feedback<<Self as UsesState>::State>,
OF: Feedback<<Self as UsesState>::State>,
E: Executor<EM, Self> + HasObservers<State = Self::State>,
EM: UsesState<State = Self::State>,
CS::State: UsesInput + HasExecutions + HasCorpus,
{
/// Runs the input and triggers observers and feedback
fn execute_input(
&mut self,
state: &mut CS::State,
state: &mut <Self as UsesState>::State,
executor: &mut E,
event_mgr: &mut EM,
input: &<CS::State as UsesInput>::Input,
input: &<<Self as UsesState>::State as UsesInput>::Input,
) -> Result<ExitKind, Error> {
start_timer!(state);
executor.observers_mut().pre_exec_all(state, input)?;
@ -912,9 +898,9 @@ pub mod test {
impl<ST, E, EM> Fuzzer<E, EM, ST> for NopFuzzer<E::State>
where
E: UsesState,
EM: ProgressReporter<State = E::State>,
ST: StagesTuple<E, EM, E::State, Self>,
E::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage,
EM: ProgressReporter<State = Self::State>,
ST: StagesTuple<E, EM, Self::State, Self>,
Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage,
{
fn fuzz_one(
&mut self,

View File

@ -131,8 +131,9 @@ where
impl<'a, CS, O> Scheduler for CoverageAccountingScheduler<'a, CS, O>
where
CS: Scheduler,
CS::State: HasCorpus + HasMetadata + HasRand + Debug,
<CS::State as UsesInput>::Input: HasLen,
Self::State: HasCorpus + HasMetadata + HasRand,
CS::State: Debug,
<Self::State as UsesInput>::Input: HasLen,
O: CanTrack,
{
fn on_add(&mut self, state: &mut Self::State, idx: CorpusId) -> Result<(), Error> {

View File

@ -88,17 +88,17 @@ where
impl<CS, F, M, O> RemovableScheduler for MinimizerScheduler<CS, F, M, O>
where
CS: RemovableScheduler,
F: TestcaseScore<CS::State>,
F: TestcaseScore<<Self as UsesState>::State>,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
CS::State: HasCorpus + HasMetadata + HasRand,
<Self as UsesState>::State: HasCorpus + HasMetadata + HasRand,
O: CanTrack,
{
/// Replaces the testcase at the given idx
fn on_replace(
&mut self,
state: &mut CS::State,
state: &mut <Self as UsesState>::State,
idx: CorpusId,
testcase: &Testcase<<CS::State as UsesInput>::Input>,
testcase: &Testcase<<<Self as UsesState>::State as UsesInput>::Input>,
) -> Result<(), Error> {
self.base.on_replace(state, idx, testcase)?;
self.update_score(state, idx)
@ -107,9 +107,9 @@ where
/// Removes an entry from the corpus
fn on_remove(
&mut self,
state: &mut CS::State,
state: &mut <Self as UsesState>::State,
idx: CorpusId,
testcase: &Option<Testcase<<CS::State as UsesInput>::Input>>,
testcase: &Option<Testcase<<<Self as UsesState>::State as UsesInput>::Input>>,
) -> Result<(), Error> {
self.base.on_remove(state, idx, testcase)?;
let mut entries =
@ -196,13 +196,13 @@ where
impl<CS, F, M, O> Scheduler for MinimizerScheduler<CS, F, M, O>
where
CS: Scheduler,
F: TestcaseScore<CS::State>,
F: TestcaseScore<Self::State>,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
CS::State: HasCorpus + HasMetadata + HasRand,
Self::State: HasCorpus + HasMetadata + HasRand,
O: CanTrack,
{
/// Called when a [`Testcase`] is added to the corpus
fn on_add(&mut self, state: &mut CS::State, idx: CorpusId) -> Result<(), Error> {
fn on_add(&mut self, state: &mut Self::State, idx: CorpusId) -> Result<(), Error> {
self.base.on_add(state, idx)?;
self.update_score(state, idx)
}
@ -221,7 +221,7 @@ where
}
/// Gets the next entry
fn next(&mut self, state: &mut CS::State) -> Result<CorpusId, Error> {
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
self.cull(state)?;
let mut idx = self.base.next(state)?;
while {
@ -252,15 +252,19 @@ where
impl<CS, F, M, O> MinimizerScheduler<CS, F, M, O>
where
CS: Scheduler,
F: TestcaseScore<CS::State>,
F: TestcaseScore<<Self as UsesState>::State>,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
CS::State: HasCorpus + HasMetadata + HasRand,
<Self as UsesState>::State: HasCorpus + HasMetadata + HasRand,
O: CanTrack,
{
/// Update the [`Corpus`] score using the [`MinimizerScheduler`]
#[allow(clippy::unused_self)]
#[allow(clippy::cast_possible_wrap)]
pub fn update_score(&self, state: &mut CS::State, idx: CorpusId) -> Result<(), Error> {
pub fn update_score(
&self,
state: &mut <Self as UsesState>::State,
idx: CorpusId,
) -> Result<(), Error> {
// Create a new top rated meta if not existing
if state.metadata_map().get::<TopRatedsMetadata>().is_none() {
state.add_metadata(TopRatedsMetadata::new());
@ -334,7 +338,7 @@ where
/// Cull the [`Corpus`] using the [`MinimizerScheduler`]
#[allow(clippy::unused_self)]
pub fn cull(&self, state: &CS::State) -> Result<(), Error> {
pub fn cull(&self, state: &<Self as UsesState>::State) -> Result<(), Error> {
let Some(top_rated) = state.metadata_map().get::<TopRatedsMetadata>() else {
return Ok(());
};

View File

@ -14,12 +14,11 @@ use crate::{
executors::{Executor, ExitKind, HasObservers},
feedbacks::{map::MapFeedbackMetadata, HasObserverHandle},
fuzzer::Evaluator,
inputs::UsesInput,
monitors::{AggregatorOps, UserStats, UserStatsValue},
observers::{MapObserver, ObserversTuple},
schedulers::powersched::SchedulerMetadata,
stages::{ExecutionCountRestartHelper, Stage},
state::{HasCorpus, HasCurrentTestcase, HasExecutions, State, UsesState},
state::{HasCorpus, HasCurrentTestcase, HasExecutions, UsesState},
Error, HasMetadata, HasNamedMetadata,
};
@ -70,7 +69,7 @@ impl Default for UnstableEntriesMetadata {
pub const CALIBRATION_STAGE_NAME: &str = "calibration";
/// The calibration stage will measure the average exec time and the target's stability for this input.
#[derive(Clone, Debug)]
pub struct CalibrationStage<C, O, OT, S> {
pub struct CalibrationStage<C, E, O, OT> {
map_observer_handle: Handle<C>,
map_name: Cow<'static, str>,
name: Cow<'static, str>,
@ -78,29 +77,29 @@ pub struct CalibrationStage<C, O, OT, S> {
/// If we should track stability
track_stability: bool,
restart_helper: ExecutionCountRestartHelper,
phantom: PhantomData<(O, OT, S)>,
phantom: PhantomData<(E, O, OT)>,
}
const CAL_STAGE_START: usize = 4; // AFL++'s CAL_CYCLES_FAST + 1
const CAL_STAGE_MAX: usize = 8; // AFL++'s CAL_CYCLES + 1
impl<C, O, OT, S> UsesState for CalibrationStage<C, O, OT, S>
impl<C, E, O, OT> UsesState for CalibrationStage<C, E, O, OT>
where
S: State,
E: UsesState,
{
type State = S;
type State = E::State;
}
impl<C, E, EM, O, OT, Z> Stage<E, EM, Z> for CalibrationStage<C, O, OT, E::State>
impl<C, E, EM, O, OT, Z> Stage<E, EM, Z> for CalibrationStage<C, E, O, OT>
where
E: Executor<EM, Z> + HasObservers<Observers = OT>,
EM: EventFirer<State = E::State>,
EM: EventFirer<State = Self::State>,
O: MapObserver,
C: AsRef<O>,
for<'de> <O as MapObserver>::Entry: Serialize + Deserialize<'de> + 'static,
OT: ObserversTuple<E::State>,
E::State: HasCorpus + HasMetadata + HasNamedMetadata + HasExecutions,
Z: Evaluator<E, EM, State = E::State>,
OT: ObserversTuple<Self::State>,
Self::State: HasCorpus + HasMetadata + HasNamedMetadata + HasExecutions,
Z: Evaluator<E, EM, State = Self::State>,
{
#[inline]
#[allow(
@ -112,7 +111,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
mgr: &mut EM,
) -> Result<(), Error> {
// Run this stage only once for each corpus entry and only if we haven't already inspected it
@ -345,13 +344,13 @@ where
}
}
impl<C, O, OT, S> CalibrationStage<C, O, OT, S>
impl<C, E, O, OT> CalibrationStage<C, E, O, OT>
where
O: MapObserver,
for<'it> O: AsIter<'it, Item = O::Entry>,
C: AsRef<O>,
OT: ObserversTuple<S>,
S: UsesInput + HasNamedMetadata,
OT: ObserversTuple<<Self as UsesState>::State>,
E: UsesState,
{
/// Create a new [`CalibrationStage`].
#[must_use]
@ -388,7 +387,7 @@ where
}
}
impl<C, O, OT, S> Named for CalibrationStage<C, O, OT, S> {
impl<C, E, O, OT> Named for CalibrationStage<C, E, O, OT> {
fn name(&self) -> &Cow<'static, str> {
&self.name
}

View File

@ -81,13 +81,13 @@ where
impl<C, E, EM, O, Z> Stage<E, EM, Z> for ColorizationStage<C, E, EM, O, Z>
where
EM: UsesState<State = E::State> + EventFirer,
EM: UsesState<State = Self::State> + EventFirer,
E: HasObservers + Executor<EM, Z>,
E::State: HasCorpus + HasMetadata + HasRand + HasNamedMetadata,
Self::State: HasCorpus + HasMetadata + HasRand + HasNamedMetadata,
E::Input: HasMutatorBytes,
O: MapObserver,
C: AsRef<O> + Named,
Z: UsesState<State = E::State>,
Z: UsesState<State = Self::State>,
{
#[inline]
#[allow(clippy::let_and_return)]
@ -95,7 +95,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E, // don't need the *main* executor for tracing
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
// Run with the mutated input
@ -156,20 +156,20 @@ libafl_bolts::impl_serdeany!(TaintMetadata);
impl<C, E, EM, O, Z> ColorizationStage<C, E, EM, O, Z>
where
EM: UsesState<State = E::State> + EventFirer,
EM: UsesState<State = <Self as UsesState>::State> + EventFirer,
O: MapObserver,
C: AsRef<O> + Named,
E: HasObservers + Executor<EM, Z>,
E::State: HasCorpus + HasMetadata + HasRand,
<Self as UsesState>::State: HasCorpus + HasMetadata + HasRand,
E::Input: HasMutatorBytes,
Z: UsesState<State = E::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
#[inline]
#[allow(clippy::let_and_return)]
fn colorize(
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
observer_handle: &Handle<C>,
) -> Result<E::Input, Error> {
@ -320,7 +320,7 @@ where
fn get_raw_map_hash_run(
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
input: E::Input,
observer_handle: &Handle<C>,
@ -346,7 +346,7 @@ where
/// Replace bytes with random values but following certain rules
#[allow(clippy::needless_range_loop)]
fn type_replace(bytes: &mut [u8], state: &mut E::State) {
fn type_replace(bytes: &mut [u8], state: &mut <Self as UsesState>::State) {
let len = bytes.len();
for idx in 0..len {
let c = match bytes[idx] {

View File

@ -58,18 +58,18 @@ impl<EM, TE, Z> Named for ConcolicTracingStage<'_, EM, TE, Z> {
impl<E, EM, TE, Z> Stage<E, EM, Z> for ConcolicTracingStage<'_, EM, TE, Z>
where
E: UsesState<State = TE::State>,
EM: UsesState<State = TE::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
TE: Executor<EM, Z> + HasObservers,
TE::State: HasExecutions + HasCorpus + HasNamedMetadata,
Z: UsesState<State = TE::State>,
Self::State: HasExecutions + HasCorpus + HasNamedMetadata,
Z: UsesState<State = Self::State>,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
_executor: &mut E,
state: &mut TE::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
self.inner.trace(fuzzer, state, manager)?;
@ -369,18 +369,18 @@ where
#[cfg(feature = "concolic_mutation")]
impl<E, EM, Z> Stage<E, EM, Z> for SimpleConcolicMutationalStage<Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
Z: Evaluator<E, EM>,
Z::Input: HasMutatorBytes,
Z::State: State + HasExecutions + HasCorpus + HasMetadata,
Self::State: State + HasExecutions + HasCorpus + HasMetadata,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
{

View File

@ -46,18 +46,18 @@ where
impl<CB, E, EM, Z> Stage<E, EM, Z> for DumpToDiskStage<CB, EM, Z>
where
CB: FnMut(&<Z::State as UsesInput>::Input, &Z::State) -> Vec<u8>,
EM: UsesState<State = Z::State>,
E: UsesState<State = Z::State>,
Z: UsesState,
Z::State: HasCorpus + HasSolutions + HasRand + HasMetadata,
CB: FnMut(&<Self::State as UsesInput>::Input, &Self::State) -> Vec<u8>,
EM: UsesState,
E: UsesState<State = Self::State>,
Z: UsesState<State = Self::State>,
Self::State: HasCorpus + HasSolutions + HasRand + HasMetadata,
{
#[inline]
fn perform(
&mut self,
_fuzzer: &mut Z,
_executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
_manager: &mut EM,
) -> Result<(), Error> {
let (mut corpus_idx, mut solutions_idx) =
@ -129,9 +129,9 @@ where
impl<CB, EM, Z> DumpToDiskStage<CB, EM, Z>
where
EM: UsesState<State = Z::State>,
EM: UsesState,
Z: UsesState,
Z::State: HasCorpus + HasSolutions + HasRand + HasMetadata,
<Self as UsesState>::State: HasCorpus + HasSolutions + HasRand + HasMetadata,
{
/// Create a new [`DumpToDiskStage`]
pub fn new<A, B>(to_bytes: CB, corpus_dir: A, solutions_dir: B) -> Result<Self, Error>

View File

@ -58,7 +58,6 @@ impl<C, EM, O, OT, Z> Named for GeneralizationStage<C, EM, O, OT, Z> {
impl<C, EM, O, OT, Z> UsesState for GeneralizationStage<C, EM, O, OT, Z>
where
EM: UsesState,
EM::State: UsesInput<Input = BytesInput>,
{
type State = EM::State;
}
@ -67,12 +66,11 @@ impl<C, E, EM, O, Z> Stage<E, EM, Z> for GeneralizationStage<C, EM, O, E::Observ
where
O: MapObserver,
C: CanTrack + AsRef<O> + Named,
E: Executor<EM, Z> + HasObservers,
E::Observers: ObserversTuple<E::State>,
E::State:
E: Executor<EM, Z, State = Self::State> + HasObservers,
Self::State:
UsesInput<Input = BytesInput> + HasExecutions + HasMetadata + HasCorpus + HasNamedMetadata,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
EM: UsesState,
Z: UsesState<State = Self::State>,
{
#[inline]
#[allow(clippy::too_many_lines)]
@ -80,7 +78,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let Some(corpus_idx) = state.current_corpus_id()? else {
@ -339,8 +337,9 @@ where
EM: UsesState,
O: MapObserver,
C: CanTrack + AsRef<O> + Named,
OT: ObserversTuple<EM::State>,
EM::State: UsesInput<Input = BytesInput> + HasExecutions + HasMetadata + HasCorpus,
OT: ObserversTuple<<Self as UsesState>::State>,
<Self as UsesState>::State:
UsesInput<Input = BytesInput> + HasExecutions + HasMetadata + HasCorpus,
{
/// Create a new [`GeneralizationStage`].
#[must_use]
@ -356,14 +355,14 @@ where
&self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut EM::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
novelties: &[usize],
input: &BytesInput,
) -> Result<bool, Error>
where
E: Executor<EM, Z> + HasObservers<Observers = OT, State = EM::State>,
Z: UsesState<State = EM::State>,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
start_timer!(state);
executor.observers_mut().pre_exec_all(state, input)?;
@ -398,7 +397,7 @@ where
&self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut EM::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
payload: &mut Vec<Option<u8>>,
novelties: &[usize],
@ -406,8 +405,8 @@ where
split_char: u8,
) -> Result<(), Error>
where
E: Executor<EM, Z> + HasObservers<Observers = OT, State = EM::State>,
Z: UsesState<State = EM::State>,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
let mut start = 0;
while start < payload.len() {
@ -437,7 +436,7 @@ where
&self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut EM::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
payload: &mut Vec<Option<u8>>,
novelties: &[usize],
@ -445,8 +444,8 @@ where
closing_char: u8,
) -> Result<(), Error>
where
E: Executor<EM, Z> + HasObservers<Observers = OT, State = EM::State>,
Z: UsesState<State = EM::State>,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
let mut index = 0;
while index < payload.len() {

View File

@ -17,16 +17,9 @@ use crate::{
///
/// This stage can be used to construct black-box (e.g., grammar-based) fuzzers.
#[derive(Debug)]
pub struct GenStage<G, Z>(G, PhantomData<Z>)
where
Z: UsesState,
G: Generator<<<Z as UsesState>::State as UsesInput>::Input, Z::State>;
pub struct GenStage<G, Z>(G, PhantomData<Z>);
impl<G, Z> GenStage<G, Z>
where
Z: UsesState,
G: Generator<<<Z as UsesState>::State as UsesInput>::Input, Z::State>,
{
impl<G, Z> GenStage<G, Z> {
/// Create a new [`GenStage`].
pub fn new(g: G) -> Self {
Self(g, PhantomData)
@ -36,25 +29,24 @@ where
impl<G, Z> UsesState for GenStage<G, Z>
where
Z: UsesState,
G: Generator<<<Z as UsesState>::State as UsesInput>::Input, Z::State>,
{
type State = Z::State;
}
impl<E, EM, Z, G> Stage<E, EM, Z> for GenStage<G, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
G: Generator<<<Z as UsesState>::State as UsesInput>::Input, Z::State>,
Self::State: HasCorpus + HasRand,
G: Generator<<<Self as UsesState>::State as UsesInput>::Input, Self::State>,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let input = self.0.generate(state)?;

View File

@ -32,14 +32,7 @@ impl NestedStageRestartHelper {
#[derive(Debug)]
/// Perform the stage while the closure evaluates to true
pub struct WhileStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
pub struct WhileStage<CB, E, EM, ST, Z> {
closure: CB,
stages: ST,
phantom: PhantomData<(E, EM, Z)>,
@ -47,29 +40,25 @@ where
impl<CB, E, EM, ST, Z> UsesState for WhileStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}
impl<CB, E, EM, ST, Z> Stage<E, EM, Z> for WhileStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
E::State: HasNestedStageStatus,
ST: StagesTuple<E, EM, Self::State, Z>,
Z: UsesState<State = Self::State>,
Self::State: HasNestedStageStatus,
{
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
while state.current_stage_idx()?.is_some()
@ -92,11 +81,8 @@ where
impl<CB, E, EM, ST, Z> WhileStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut <Self as UsesState>::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
/// Constructor
pub fn new(closure: CB, stages: ST) -> Self {
@ -111,14 +97,7 @@ where
/// A conditionally enabled stage.
/// If the closure returns true, the wrapped stage will be executed, else it will be skipped.
#[derive(Debug)]
pub struct IfStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
pub struct IfStage<CB, E, EM, ST, Z> {
closure: CB,
if_stages: ST,
phantom: PhantomData<(E, EM, Z)>,
@ -126,29 +105,25 @@ where
impl<CB, E, EM, ST, Z> UsesState for IfStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}
impl<CB, E, EM, ST, Z> Stage<E, EM, Z> for IfStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
E::State: HasNestedStageStatus,
EM: UsesState<State = Self::State>,
ST: StagesTuple<E, EM, Self::State, Z>,
Z: UsesState<State = Self::State>,
Self::State: HasNestedStageStatus,
{
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
if state.current_stage_idx()?.is_some() || (self.closure)(fuzzer, executor, state, manager)?
@ -170,11 +145,8 @@ where
impl<CB, E, EM, ST, Z> IfStage<CB, E, EM, ST, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut <Self as UsesState>::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
/// Constructor for this conditionally enabled stage.
/// If the closure returns true, the wrapped stage will be executed, else it will be skipped.
@ -189,15 +161,7 @@ where
/// Perform the stage if closure evaluates to true
#[derive(Debug)]
pub struct IfElseStage<CB, E, EM, ST1, ST2, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST1: StagesTuple<E, EM, E::State, Z>,
ST2: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
pub struct IfElseStage<CB, E, EM, ST1, ST2, Z> {
closure: CB,
if_stages: ST1,
else_stages: ST2,
@ -206,31 +170,26 @@ where
impl<CB, E, EM, ST1, ST2, Z> UsesState for IfElseStage<CB, E, EM, ST1, ST2, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST1: StagesTuple<E, EM, E::State, Z>,
ST2: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}
impl<CB, E, EM, ST1, ST2, Z> Stage<E, EM, Z> for IfElseStage<CB, E, EM, ST1, ST2, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST1: StagesTuple<E, EM, E::State, Z>,
ST2: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
E::State: HasNestedStageStatus,
EM: UsesState<State = Self::State>,
ST1: StagesTuple<E, EM, Self::State, Z>,
ST2: StagesTuple<E, EM, Self::State, Z>,
Z: UsesState<State = Self::State>,
Self::State: HasNestedStageStatus,
{
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let current = state.current_stage_idx()?;
@ -271,12 +230,8 @@ where
impl<CB, E, EM, ST1, ST2, Z> IfElseStage<CB, E, EM, ST1, ST2, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<bool, Error>,
CB: FnMut(&mut Z, &mut E, &mut <Self as UsesState>::State, &mut EM) -> Result<bool, Error>,
E: UsesState,
EM: UsesState<State = E::State>,
ST1: StagesTuple<E, EM, E::State, Z>,
ST2: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
/// Constructor
pub fn new(closure: CB, if_stages: ST1, else_stages: ST2) -> Self {
@ -291,13 +246,7 @@ where
/// A stage wrapper where the stages do not need to be initialized, but can be [`None`].
#[derive(Debug)]
pub struct OptionalStage<E, EM, ST, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
pub struct OptionalStage<E, EM, ST, Z> {
stages: Option<ST>,
phantom: PhantomData<(E, EM, Z)>,
}
@ -305,9 +254,6 @@ where
impl<E, EM, ST, Z> UsesState for OptionalStage<E, EM, ST, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}
@ -315,16 +261,16 @@ where
impl<E, EM, ST, Z> Stage<E, EM, Z> for OptionalStage<E, EM, ST, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
E::State: HasNestedStageStatus,
EM: UsesState<State = Self::State>,
ST: StagesTuple<E, EM, Self::State, Z>,
Z: UsesState<State = Self::State>,
Self::State: HasNestedStageStatus,
{
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
if let Some(stages) = &mut self.stages {
@ -343,13 +289,7 @@ where
}
}
impl<E, EM, ST, Z> OptionalStage<E, EM, ST, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
ST: StagesTuple<E, EM, E::State, Z>,
Z: UsesState<State = E::State>,
{
impl<E, EM, ST, Z> OptionalStage<E, EM, ST, Z> {
/// Constructor for this conditionally enabled stage.
#[must_use]
pub fn new(stages: Option<ST>) -> Self {

View File

@ -285,28 +285,19 @@ where
/// A [`Stage`] that will call a closure
#[derive(Debug)]
pub struct ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
E: UsesState,
{
pub struct ClosureStage<CB, E, EM, Z> {
closure: CB,
phantom: PhantomData<(E, EM, Z)>,
}
impl<CB, E, EM, Z> UsesState for ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
E: UsesState,
{
type State = E::State;
}
impl<CB, E, EM, Z> Named for ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
E: UsesState,
{
impl<CB, E, EM, Z> Named for ClosureStage<CB, E, EM, Z> {
fn name(&self) -> &Cow<'static, str> {
static NAME: Cow<'static, str> = Cow::Borrowed("<unnamed fn>");
&NAME
@ -315,11 +306,11 @@ where
impl<CB, E, EM, Z> Stage<E, EM, Z> for ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result<(), Error>,
E: UsesState,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
E::State: HasNamedMetadata,
EM: UsesState<State = Self::State>,
Z: UsesState<State = Self::State>,
Self::State: HasNamedMetadata,
{
fn perform(
&mut self,
@ -344,11 +335,7 @@ where
}
/// A stage that takes a closure
impl<CB, E, EM, Z> ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
E: UsesState,
{
impl<CB, E, EM, Z> ClosureStage<CB, E, EM, Z> {
/// Create a new [`ClosureStage`]
#[must_use]
pub fn new(closure: CB) -> Self {
@ -361,7 +348,7 @@ where
impl<CB, E, EM, Z> From<CB> for ClosureStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>,
CB: FnMut(&mut Z, &mut E, &mut <Self as UsesState>::State, &mut EM) -> Result<(), Error>,
E: UsesState,
{
#[must_use]
@ -400,17 +387,17 @@ where
impl<CS, E, EM, OT, PS, Z> Stage<E, EM, Z> for PushStageAdapter<CS, EM, OT, PS, Z>
where
CS: Scheduler,
CS::State:
Self::State:
HasExecutions + HasMetadata + HasRand + HasCorpus + HasLastReportTime + HasCurrentCorpusId,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = CS::State>,
EM: EventFirer<State = CS::State>
E: Executor<EM, Z> + HasObservers<Observers = OT, State = Self::State>,
EM: EventFirer<State = Self::State>
+ EventRestarter
+ HasEventManagerId
+ ProgressReporter<State = CS::State>,
OT: ObserversTuple<CS::State>,
+ ProgressReporter<State = Self::State>,
OT: ObserversTuple<Self::State>,
PS: PushStage<CS, EM, OT, Z>,
Z: ExecutesInput<E, EM, State = CS::State>
+ ExecutionProcessor<OT, State = CS::State>
Z: ExecutesInput<E, EM, State = Self::State>
+ ExecutionProcessor<OT, State = Self::State>
+ EvaluatorObservers<OT>
+ HasScheduler<Scheduler = CS>,
{

View File

@ -92,10 +92,10 @@ where
fn mutator_mut(&mut self) -> &mut M;
/// Gets the number of iterations this mutator should run for.
fn iterations(&self, state: &mut Z::State) -> Result<usize, Error>;
fn iterations(&self, state: &mut Self::State) -> Result<usize, Error>;
/// Gets the number of executions this mutator already did since it got first called in this fuzz round.
fn execs_since_progress_start(&mut self, state: &mut Z::State) -> Result<u64, Error>;
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error>;
/// Runs this (mutational) stage for the given testcase
#[allow(clippy::cast_possible_wrap)] // more than i32 stages on 32 bit system - highly unlikely...
@ -103,7 +103,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
start_timer!(state);
@ -167,11 +167,11 @@ pub struct StdMutationalStage<E, EM, I, M, Z> {
impl<E, EM, I, M, Z> MutationalStage<E, EM, I, M, Z> for StdMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
M: Mutator<I, Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasExecutions + HasMetadata,
Self::State: HasCorpus + HasRand + HasExecutions + HasMetadata,
I: MutatedTransform<Self::Input, Self::State> + Clone,
{
/// The mutator, added to this stage
@ -187,33 +187,29 @@ where
}
/// Gets the number of iterations as a random number
fn iterations(&self, state: &mut Z::State) -> Result<usize, Error> {
fn iterations(&self, state: &mut Self::State) -> Result<usize, Error> {
Ok(1 + state.rand_mut().below(self.max_iterations))
}
fn execs_since_progress_start(&mut self, state: &mut <Z>::State) -> Result<u64, Error> {
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error> {
self.restart_helper.execs_since_progress_start(state)
}
}
impl<E, EM, I, M, Z> UsesState for StdMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
Z: UsesState,
{
type State = Z::State;
}
impl<E, EM, I, M, Z> Stage<E, EM, Z> for StdMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
M: Mutator<I, Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasMetadata + HasExecutions,
Self::State: HasCorpus + HasRand + HasMetadata + HasExecutions,
I: MutatedTransform<Self::Input, Self::State> + Clone,
{
#[inline]
@ -222,7 +218,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let ret = self.perform_mutational(fuzzer, executor, state, manager);
@ -246,11 +242,11 @@ where
impl<E, EM, M, Z> StdMutationalStage<E, EM, Z::Input, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<Z::Input, Z::State>,
E: UsesState<State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
M: Mutator<Z::Input, <Self as UsesState>::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
<Self as UsesState>::State: HasCorpus + HasRand,
{
/// Creates a new default mutational stage
pub fn new(mutator: M) -> Self {
@ -265,11 +261,11 @@ where
impl<E, EM, I, M, Z> StdMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
M: Mutator<I, <Self as UsesState>::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
<Self as UsesState>::State: HasCorpus + HasRand,
{
/// Creates a new transforming mutational stage with the default max iterations
pub fn transforming(mutator: M) -> Self {
@ -297,23 +293,12 @@ pub struct MultiMutationalStage<E, EM, I, M, Z> {
impl<E, EM, I, M, Z> UsesState for MultiMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: MultiMutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
Z: UsesState,
{
type State = Z::State;
}
impl<E, EM, I, M, Z> Named for MultiMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: MultiMutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
{
impl<E, EM, I, M, Z> Named for MultiMutationalStage<E, EM, I, M, Z> {
fn name(&self) -> &Cow<'static, str> {
static NAME: Cow<'static, str> = Cow::Borrowed("MultiMutational");
&NAME
@ -322,11 +307,11 @@ where
impl<E, EM, I, M, Z> Stage<E, EM, Z> for MultiMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: MultiMutator<I, Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
M: MultiMutator<I, Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasNamedMetadata,
Self::State: HasCorpus + HasRand + HasNamedMetadata,
I: MutatedTransform<Self::Input, Self::State> + Clone,
{
#[inline]
@ -348,7 +333,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let mut testcase = state.current_testcase_mut()?;
@ -374,11 +359,7 @@ where
impl<E, EM, M, Z> MultiMutationalStage<E, EM, Z::Input, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: MultiMutator<Z::Input, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
Z: UsesState,
{
/// Creates a new [`MultiMutationalStage`]
pub fn new(mutator: M) -> Self {
@ -386,14 +367,7 @@ where
}
}
impl<E, EM, I, M, Z> MultiMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: MultiMutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand,
{
impl<E, EM, I, M, Z> MultiMutationalStage<E, EM, I, M, Z> {
/// Creates a new transforming mutational stage
pub fn transforming(mutator: M) -> Self {
Self {

View File

@ -44,12 +44,12 @@ impl<E, F, EM, I, M, Z> Named for PowerMutationalStage<E, F, EM, I, M, Z> {
impl<E, F, EM, I, M, Z> MutationalStage<E, EM, I, M, Z> for PowerMutationalStage<E, F, EM, I, M, Z>
where
E: Executor<EM, Z> + HasObservers,
EM: UsesState<State = E::State>,
F: TestcaseScore<E::State>,
M: Mutator<I, E::State>,
E::State: HasCorpus + HasMetadata + HasRand + HasExecutions,
Z: Evaluator<E, EM, State = E::State>,
I: MutatedTransform<E::Input, E::State> + Clone,
EM: UsesState<State = Self::State>,
F: TestcaseScore<Self::State>,
M: Mutator<I, Self::State>,
Self::State: HasCorpus + HasMetadata + HasRand + HasExecutions,
Z: Evaluator<E, EM, State = Self::State>,
I: MutatedTransform<E::Input, Self::State> + Clone,
{
/// The mutator, added to this stage
#[inline]
@ -65,7 +65,7 @@ where
/// Gets the number of iterations as a random number
#[allow(clippy::cast_sign_loss)]
fn iterations(&self, state: &mut E::State) -> Result<usize, Error> {
fn iterations(&self, state: &mut Self::State) -> Result<usize, Error> {
// Update handicap
let mut testcase = state.current_testcase_mut()?;
let score = F::compute(state, &mut testcase)? as usize;
@ -73,7 +73,7 @@ where
Ok(score)
}
fn execs_since_progress_start(&mut self, state: &mut <Z>::State) -> Result<u64, Error> {
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error> {
self.restart_helper.execs_since_progress_start(state)
}
}
@ -81,12 +81,12 @@ where
impl<E, F, EM, I, M, Z> Stage<E, EM, Z> for PowerMutationalStage<E, F, EM, I, M, Z>
where
E: Executor<EM, Z> + HasObservers,
EM: UsesState<State = E::State>,
F: TestcaseScore<E::State>,
M: Mutator<I, E::State>,
E::State: HasCorpus + HasMetadata + HasRand + HasExecutions,
Z: Evaluator<E, EM, State = E::State>,
I: MutatedTransform<E::Input, E::State> + Clone,
EM: UsesState<State = Self::State>,
F: TestcaseScore<Self::State>,
M: Mutator<I, Self::State>,
Self::State: HasCorpus + HasMetadata + HasRand + HasExecutions,
Z: Evaluator<E, EM, State = Self::State>,
I: MutatedTransform<Self::Input, Self::State> + Clone,
{
#[inline]
#[allow(clippy::let_and_return)]
@ -94,7 +94,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let ret = self.perform_mutational(fuzzer, executor, state, manager);
@ -115,11 +115,11 @@ where
impl<E, F, EM, M, Z> PowerMutationalStage<E, F, EM, E::Input, M, Z>
where
E: Executor<EM, Z> + HasObservers,
EM: UsesState<State = E::State>,
F: TestcaseScore<E::State>,
M: Mutator<E::Input, E::State>,
E::State: HasCorpus + HasMetadata + HasRand,
Z: Evaluator<E, EM, State = E::State>,
EM: UsesState<State = <Self as UsesState>::State>,
F: TestcaseScore<<Self as UsesState>::State>,
M: Mutator<E::Input, <Self as UsesState>::State>,
<Self as UsesState>::State: HasCorpus + HasMetadata + HasRand,
Z: Evaluator<E, EM, State = <Self as UsesState>::State>,
{
/// Creates a new [`PowerMutationalStage`]
pub fn new(mutator: M) -> Self {

View File

@ -24,12 +24,7 @@ use crate::{
/// The [`AflStatsStage`] is a simple stage that computes and reports some stats.
#[derive(Debug, Clone)]
pub struct AflStatsStage<E, EM, Z>
where
E: UsesState,
EM: EventFirer<State = E::State>,
Z: UsesState<State = E::State>,
{
pub struct AflStatsStage<E, EM, Z> {
// the number of testcases that have been fuzzed
has_fuzzed_size: usize,
// the number of "favored" testcases
@ -49,8 +44,6 @@ where
impl<E, EM, Z> UsesState for AflStatsStage<E, EM, Z>
where
E: UsesState,
EM: EventFirer<State = E::State>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}
@ -58,15 +51,15 @@ where
impl<E, EM, Z> Stage<E, EM, Z> for AflStatsStage<E, EM, Z>
where
E: UsesState,
EM: EventFirer<State = E::State>,
Z: UsesState<State = E::State>,
E::State: HasImported + HasCorpus + HasMetadata,
EM: EventFirer<State = Self::State>,
Z: UsesState<State = Self::State>,
Self::State: HasImported + HasCorpus + HasMetadata,
{
fn perform(
&mut self,
_fuzzer: &mut Z,
_executor: &mut E,
state: &mut E::State,
state: &mut Self::State,
_manager: &mut EM,
) -> Result<(), Error> {
let Some(corpus_idx) = state.current_corpus_id()? else {
@ -145,13 +138,7 @@ where
}
}
impl<E, EM, Z> AflStatsStage<E, EM, Z>
where
E: UsesState,
EM: EventFirer<State = E::State>,
Z: UsesState<State = E::State>,
E::State: HasImported + HasCorpus + HasMetadata,
{
impl<E, EM, Z> AflStatsStage<E, EM, Z> {
/// create a new instance of the [`AflStatsStage`]
#[must_use]
pub fn new(interval: Duration) -> Self {
@ -162,13 +149,7 @@ where
}
}
impl<E, EM, Z> Default for AflStatsStage<E, EM, Z>
where
E: UsesState,
EM: EventFirer<State = E::State>,
Z: UsesState<State = E::State>,
E::State: HasImported + HasCorpus + HasMetadata,
{
impl<E, EM, Z> Default for AflStatsStage<E, EM, Z> {
/// the default instance of the [`AflStatsStage`]
#[must_use]
fn default() -> Self {

View File

@ -65,15 +65,12 @@ pub struct SyncFromDiskStage<CB, E, EM, Z> {
impl<CB, E, EM, Z> UsesState for SyncFromDiskStage<CB, E, EM, Z>
where
E: UsesState,
Z: UsesState,
{
type State = E::State;
type State = Z::State;
}
impl<CB, E, EM, Z> Named for SyncFromDiskStage<CB, E, EM, Z>
where
E: UsesState,
{
impl<CB, E, EM, Z> Named for SyncFromDiskStage<CB, E, EM, Z> {
fn name(&self) -> &Cow<'static, str> {
&self.name
}
@ -81,18 +78,18 @@ where
impl<CB, E, EM, Z> Stage<E, EM, Z> for SyncFromDiskStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut Z::State, &Path) -> Result<<Z::State as UsesInput>::Input, Error>,
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
CB: FnMut(&mut Z, &mut Self::State, &Path) -> Result<<Self::State as UsesInput>::Input, Error>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasMetadata + HasNamedMetadata,
Self::State: HasCorpus + HasRand + HasMetadata + HasNamedMetadata,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
log::debug!("Syncing from disk: {:?}", self.sync_dir);
@ -164,14 +161,7 @@ where
}
}
impl<CB, E, EM, Z> SyncFromDiskStage<CB, E, EM, Z>
where
CB: FnMut(&mut Z, &mut Z::State, &Path) -> Result<<Z::State as UsesInput>::Input, Error>,
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasMetadata,
{
impl<CB, E, EM, Z> SyncFromDiskStage<CB, E, EM, Z> {
/// Creates a new [`SyncFromDiskStage`]
#[must_use]
pub fn new(sync_dir: PathBuf, load_callback: CB) -> Self {
@ -232,10 +222,9 @@ pub type SyncFromDiskFunction<S, Z> =
impl<E, EM, Z> SyncFromDiskStage<SyncFromDiskFunction<Z::State, Z>, E, EM, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
E: UsesState<State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasMetadata,
{
/// Creates a new [`SyncFromDiskStage`] invoking `Input::from_file` to load inputs
#[must_use]
@ -318,7 +307,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
if self.client.can_convert() {

View File

@ -14,13 +14,13 @@ use crate::feedbacks::premature_last_result_err;
use crate::{
corpus::{Corpus, HasCurrentCorpusId, Testcase},
events::EventFirer,
executors::{Executor, ExitKind, HasObservers},
executors::{ExitKind, HasObservers},
feedbacks::{Feedback, FeedbackFactory, HasObserverHandle},
inputs::UsesInput,
mark_feature_time,
mutators::{MutationResult, Mutator},
observers::{MapObserver, ObserversTuple},
schedulers::{RemovableScheduler, Scheduler},
schedulers::RemovableScheduler,
stages::{
mutational::{MutatedTransform, MutatedTransformPost},
ExecutionCountRestartHelper, Stage,
@ -36,24 +36,22 @@ use crate::{monitors::PerfFeature, state::HasClientPerfMonitor};
/// Mutational stage which minimizes corpus entries.
///
/// You must provide at least one mutator that actually reduces size.
pub trait TMinMutationalStage<CS, E, EM, F1, F2, I, IP, M, OT, Z>:
Stage<E, EM, Z> + FeedbackFactory<F2, CS::State, OT>
pub trait TMinMutationalStage<E, EM, F, IP, M, Z>:
Stage<E, EM, Z> + FeedbackFactory<F, E::Observers>
where
Self::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize,
<Self::State as UsesInput>::Input: HasLen + Hash,
CS: Scheduler<State = Self::State> + RemovableScheduler,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = Self::State>,
EM: EventFirer<State = Self::State>,
F1: Feedback<Self::State>,
F2: Feedback<Self::State>,
M: Mutator<I, Self::State>,
OT: ObserversTuple<CS::State>,
Z: ExecutionProcessor<OT, State = Self::State>
E: UsesState<State = Self::State> + HasObservers,
EM: UsesState<State = Self::State> + EventFirer,
F: Feedback<Self::State>,
Self::State: HasMaxSize + HasCorpus + HasSolutions + HasExecutions,
Self::Input: MutatedTransform<Self::Input, Self::State, Post = IP> + Clone + Hash + HasLen,
IP: Clone + MutatedTransformPost<Self::State>,
M: Mutator<Self::Input, Self::State>,
Z: UsesState<State = Self::State>
+ HasScheduler
+ HasFeedback
+ ExecutesInput<E, EM>
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
IP: MutatedTransformPost<Self::State> + Clone,
I: MutatedTransform<Self::Input, Self::State, Post = IP> + Clone,
+ ExecutionProcessor<E::Observers>,
Z::Scheduler: RemovableScheduler<State = Self::State>,
{
/// The mutator registered for this stage
fn mutator(&self) -> &M;
@ -62,7 +60,7 @@ where
fn mutator_mut(&mut self) -> &mut M;
/// Gets the number of iterations this mutator should run for.
fn iterations(&self, state: &mut CS::State) -> Result<usize, Error>;
fn iterations(&self, state: &mut Self::State) -> Result<usize, Error>;
/// Runs this (mutational) stage for new objectives
#[allow(clippy::cast_possible_wrap)] // more than i32 stages on 32 bit system - highly unlikely...
@ -70,7 +68,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut CS::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let Some(base_corpus_idx) = state.current_corpus_id()? else {
@ -85,7 +83,8 @@ where
- usize::try_from(self.execs_since_progress_start(state)?).unwrap();
start_timer!(state);
let transformed = I::try_transform_from(state.current_testcase_mut()?.borrow_mut(), state)?;
let transformed =
Self::Input::try_transform_from(state.current_testcase_mut()?.borrow_mut(), state)?;
let mut base = state.current_input_cloned()?;
// potential post operation if base is replaced by a shorter input
let mut base_post = None;
@ -198,12 +197,12 @@ where
}
/// Gets the number of executions this mutator already did since it got first called in this fuzz round.
fn execs_since_progress_start(&mut self, state: &mut Z::State) -> Result<u64, Error>;
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error>;
}
/// The default corpus entry minimising mutational stage
#[derive(Clone, Debug)]
pub struct StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> {
pub struct StdTMinMutationalStage<E, EM, F, FF, IP, M, Z> {
/// The mutator(s) this stage uses
mutator: M,
/// The factory
@ -213,41 +212,28 @@ pub struct StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> {
/// The progress helper for this stage, keeping track of resumes after timeouts/crashes
restart_helper: ExecutionCountRestartHelper,
#[allow(clippy::type_complexity)]
phantom: PhantomData<(CS, E, EM, F1, F2, I, IP, OT, Z)>,
phantom: PhantomData<(E, EM, F, IP, Z)>,
}
impl<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> UsesState
for StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
impl<E, EM, F, FF, IP, M, Z> UsesState for StdTMinMutationalStage<E, EM, F, FF, IP, M, Z>
where
CS: Scheduler,
M: Mutator<I, CS::State>,
Z: ExecutionProcessor<OT, State = CS::State>,
CS::State: HasCorpus,
IP: MutatedTransformPost<CS::State> + Clone,
I: MutatedTransform<CS::Input, CS::State, Post = IP> + Clone,
Z: UsesState,
{
type State = CS::State;
type State = Z::State;
}
impl<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> Stage<E, EM, Z>
for StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
impl<E, EM, F, FF, IP, M, Z> Stage<E, EM, Z> for StdTMinMutationalStage<E, EM, F, FF, IP, M, Z>
where
CS: Scheduler + RemovableScheduler,
CS::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize + HasCorpus + HasMetadata,
<CS::State as UsesInput>::Input: HasLen + Hash,
E: Executor<EM, Z> + HasObservers<Observers = OT, State = CS::State>,
EM: EventFirer<State = CS::State>,
F1: Feedback<CS::State>,
F2: Feedback<CS::State>,
FF: FeedbackFactory<F2, CS::State, OT>,
M: Mutator<I, CS::State>,
OT: ObserversTuple<CS::State>,
Z: ExecutionProcessor<OT, State = CS::State>
+ ExecutesInput<E, EM>
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
IP: MutatedTransformPost<CS::State> + Clone,
I: MutatedTransform<CS::Input, CS::State, Post = IP> + Clone,
Z: HasScheduler + ExecutionProcessor<E::Observers> + ExecutesInput<E, EM> + HasFeedback,
Z::Scheduler: RemovableScheduler,
E: HasObservers<State = Self::State>,
EM: EventFirer<State = Self::State>,
FF: FeedbackFactory<F, E::Observers>,
F: Feedback<Self::State>,
Self::Input: MutatedTransform<Self::Input, Self::State, Post = IP> + Clone + HasLen + Hash,
Self::State: HasMetadata + HasExecutions + HasSolutions + HasCorpus + HasMaxSize,
M: Mutator<Self::Input, Self::State>,
IP: MutatedTransformPost<Self::State> + Clone,
{
fn restart_progress_should_run(&mut self, state: &mut Self::State) -> Result<bool, Error> {
self.restart_helper.restart_progress_should_run(state)
@ -261,7 +247,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut CS::State,
state: &mut Z::State,
manager: &mut EM,
) -> Result<(), Error> {
self.perform_minification(fuzzer, executor, state, manager)?;
@ -273,37 +259,30 @@ where
}
}
impl<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> FeedbackFactory<F2, Z::State, OT>
for StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
impl<E, EM, F, FF, IP, M, Z> FeedbackFactory<F, E::Observers>
for StdTMinMutationalStage<E, EM, F, FF, IP, M, Z>
where
F2: Feedback<Z::State>,
FF: FeedbackFactory<F2, Z::State, OT>,
Z: UsesState,
E: HasObservers,
FF: FeedbackFactory<F, E::Observers>,
{
fn create_feedback(&self, ctx: &OT) -> F2 {
fn create_feedback(&self, ctx: &E::Observers) -> F {
self.factory.create_feedback(ctx)
}
}
impl<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z> TMinMutationalStage<CS, E, EM, F1, F2, I, IP, M, OT, Z>
for StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
impl<E, EM, F, FF, IP, M, Z> TMinMutationalStage<E, EM, F, IP, M, Z>
for StdTMinMutationalStage<E, EM, F, FF, IP, M, Z>
where
CS: Scheduler + RemovableScheduler,
E: HasObservers<Observers = OT, State = CS::State> + Executor<EM, Z>,
EM: EventFirer<State = CS::State>,
F1: Feedback<CS::State>,
F2: Feedback<CS::State>,
FF: FeedbackFactory<F2, CS::State, OT>,
<CS::State as UsesInput>::Input: HasLen + Hash,
M: Mutator<I, CS::State>,
OT: ObserversTuple<CS::State>,
CS::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize + HasMetadata,
Z: ExecutionProcessor<OT, State = CS::State>
+ ExecutesInput<E, EM>
+ HasFeedback<Feedback = F1>
+ HasScheduler<Scheduler = CS>,
IP: MutatedTransformPost<CS::State> + Clone,
I: MutatedTransform<CS::Input, CS::State, Post = IP> + Clone,
Z: HasScheduler + ExecutionProcessor<E::Observers> + ExecutesInput<E, EM> + HasFeedback,
Z::Scheduler: RemovableScheduler,
E: HasObservers<State = Self::State>,
EM: EventFirer<State = Self::State>,
FF: FeedbackFactory<F, E::Observers>,
F: Feedback<Self::State>,
Self::Input: MutatedTransform<Self::Input, Self::State, Post = IP> + Clone + HasLen + Hash,
Self::State: HasMetadata + HasExecutions + HasSolutions + HasCorpus + HasMaxSize,
M: Mutator<Self::Input, Self::State>,
IP: MutatedTransformPost<Self::State> + Clone,
{
/// The mutator, added to this stage
#[inline]
@ -318,25 +297,16 @@ where
}
/// Gets the number of iterations from a fixed number of runs
fn iterations(&self, _state: &mut CS::State) -> Result<usize, Error> {
fn iterations(&self, _state: &mut Self::State) -> Result<usize, Error> {
Ok(self.runs)
}
fn execs_since_progress_start(&mut self, state: &mut <Z>::State) -> Result<u64, Error> {
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error> {
self.restart_helper.execs_since_progress_start(state)
}
}
impl<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
StdTMinMutationalStage<CS, E, EM, F1, F2, FF, I, IP, M, OT, Z>
where
CS: Scheduler,
M: Mutator<I, CS::State>,
Z: ExecutionProcessor<OT, State = CS::State>,
CS::State: HasCorpus,
IP: MutatedTransformPost<CS::State> + Clone,
I: MutatedTransform<CS::Input, CS::State, Post = IP> + Clone,
{
impl<E, EM, F, FF, IP, M, Z> StdTMinMutationalStage<E, EM, F, FF, IP, M, Z> {
/// Creates a new minimizing mutational stage that will minimize provided corpus entries
pub fn new(mutator: M, factory: FF, runs: usize) -> Self {
Self {
@ -439,13 +409,12 @@ impl<C, M, S> HasObserverHandle for MapEqualityFactory<C, M, S> {
}
}
impl<C, M, OT, S> FeedbackFactory<MapEqualityFeedback<C, M, S>, S, OT>
for MapEqualityFactory<C, M, S>
impl<C, M, OT, S> FeedbackFactory<MapEqualityFeedback<C, M, S>, OT> for MapEqualityFactory<C, M, S>
where
M: MapObserver,
C: AsRef<M> + Handled,
OT: ObserversTuple<S>,
S: State + Debug,
S: UsesInput,
{
fn create_feedback(&self, observers: &OT) -> MapEqualityFeedback<C, M, S> {
let obs = observers

View File

@ -36,9 +36,9 @@ where
impl<EM, TE, Z> TracingStage<EM, TE, Z>
where
TE: Executor<EM, Z> + HasObservers,
TE::State: HasExecutions + HasCorpus + HasNamedMetadata,
EM: UsesState<State = TE::State>,
Z: UsesState<State = TE::State>,
<Self as UsesState>::State: HasExecutions + HasCorpus + HasNamedMetadata,
EM: UsesState<State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
/// Perform tracing on the given `CorpusId`. Useful for if wrapping [`TracingStage`] with your
/// own stage and you need to manage [`super::NestedStageRestartHelper`] differently; see
@ -46,7 +46,7 @@ where
pub fn trace(
&mut self,
fuzzer: &mut Z,
state: &mut TE::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
) -> Result<(), Error> {
start_timer!(state);
@ -80,18 +80,18 @@ where
impl<E, EM, TE, Z> Stage<E, EM, Z> for TracingStage<EM, TE, Z>
where
E: UsesState<State = TE::State>,
E: UsesState<State = <Self as UsesState>::State>,
TE: Executor<EM, Z> + HasObservers,
TE::State: HasExecutions + HasCorpus + HasNamedMetadata,
EM: UsesState<State = TE::State>,
Z: UsesState<State = TE::State>,
<Self as UsesState>::State: HasExecutions + HasCorpus + HasNamedMetadata,
EM: UsesState<State = <Self as UsesState>::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
_executor: &mut E,
state: &mut TE::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
) -> Result<(), Error> {
self.trace(fuzzer, state, manager)
@ -170,17 +170,17 @@ where
impl<E, EM, SOT, Z> Stage<ShadowExecutor<E, SOT>, EM, Z> for ShadowTracingStage<E, EM, SOT, Z>
where
E: Executor<EM, Z> + HasObservers,
EM: UsesState<State = E::State>,
EM: UsesState<State = <Self as UsesState>::State>,
SOT: ObserversTuple<E::State>,
Z: UsesState<State = E::State>,
E::State: State + HasExecutions + HasCorpus + HasNamedMetadata + Debug,
Z: UsesState<State = <Self as UsesState>::State>,
<Self as UsesState>::State: State + HasExecutions + HasCorpus + HasNamedMetadata + Debug,
{
#[inline]
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut ShadowExecutor<E, SOT>,
state: &mut E::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
) -> Result<(), Error> {
start_timer!(state);
@ -225,10 +225,10 @@ where
impl<E, EM, SOT, Z> ShadowTracingStage<E, EM, SOT, Z>
where
E: Executor<EM, Z> + HasObservers,
E::State: State + HasExecutions + HasCorpus,
EM: UsesState<State = E::State>,
<Self as UsesState>::State: State + HasExecutions + HasCorpus,
EM: UsesState<State = <Self as UsesState>::State>,
SOT: ObserversTuple<E::State>,
Z: UsesState<State = E::State>,
Z: UsesState<State = <Self as UsesState>::State>,
{
/// Creates a new default stage
pub fn new(_executor: &mut ShadowExecutor<E, SOT>) -> Self {

View File

@ -160,12 +160,12 @@ pub struct TuneableMutationalStage<E, EM, I, M, Z> {
impl<E, EM, I, M, Z> MutationalStage<E, EM, I, M, Z> for TuneableMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
M: Mutator<I, Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Z::Input, Z::State> + Clone,
Self::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Z::Input, Self::State> + Clone,
{
/// Runs this (mutational) stage for the given `testcase`
/// Exactly the same functionality as [`MutationalStage::perform_mutational`], but with added timeout support.
@ -173,7 +173,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let fuzz_time = self.seed_fuzz_time(state)?;
@ -242,38 +242,33 @@ where
}
/// Gets the number of iterations as a random number
fn iterations(&self, state: &mut Z::State) -> Result<usize, Error> {
fn iterations(&self, state: &mut Self::State) -> Result<usize, Error> {
Ok(
// fall back to random
1 + state.rand_mut().below(DEFAULT_MUTATIONAL_MAX_ITERATIONS),
)
}
fn execs_since_progress_start(&mut self, state: &mut <Z>::State) -> Result<u64, Error> {
fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result<u64, Error> {
self.restart_helper.execs_since_progress_start(state)
}
}
impl<E, EM, I, M, Z> UsesState for TuneableMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasExecutions,
I: MutatedTransform<Z::Input, Z::State> + Clone,
{
type State = Z::State;
}
impl<E, EM, I, M, Z> Stage<E, EM, Z> for TuneableMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = Self::State>,
EM: UsesState<State = Self::State>,
M: Mutator<I, Self::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Z::Input, Z::State> + Clone,
Self::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Self::Input, Self::State> + Clone,
{
#[inline]
#[allow(clippy::let_and_return)]
@ -281,7 +276,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut Self::State,
manager: &mut EM,
) -> Result<(), Error> {
let ret = self.perform_mutational(fuzzer, executor, state, manager);
@ -303,21 +298,22 @@ where
impl<E, EM, I, M, Z> TuneableMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
M: Mutator<I, Z::State>,
E: UsesState<State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
M: Mutator<I, <Self as UsesState>::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Z::Input, Z::State> + Clone,
<Self as UsesState>::State:
HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions,
I: MutatedTransform<Z::Input, <Self as UsesState>::State> + Clone,
{
/// Creates a new default tuneable mutational stage
#[must_use]
pub fn new(state: &mut Z::State, mutator: M) -> Self {
pub fn new(state: &mut <Self as UsesState>::State, mutator: M) -> Self {
Self::transforming(state, mutator, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
/// Crates a new tuneable mutational stage with the given name
pub fn with_name(state: &mut Z::State, mutator: M, name: &str) -> Self {
pub fn with_name(state: &mut <Self as UsesState>::State, mutator: M, name: &str) -> Self {
Self::transforming(state, mutator, name)
}
@ -330,7 +326,7 @@ where
}
/// Set the number of iterations to be used by the std [`TuneableMutationalStage`]
pub fn set_iters_std(state: &mut Z::State, iters: u64) -> Result<(), Error> {
pub fn set_iters_std(state: &mut <Self as UsesState>::State, iters: u64) -> Result<(), Error> {
set_iters_by_name(state, iters, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
@ -351,7 +347,7 @@ where
}
/// Get the set iterations for the std [`TuneableMutationalStage`], if any
pub fn iters_std(state: &Z::State) -> Result<Option<u64>, Error> {
pub fn iters_std(state: &<Self as UsesState>::State) -> Result<Option<u64>, Error> {
get_iters_by_name(state, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
@ -372,7 +368,10 @@ where
}
/// Set the time to mutate a single input in the std [`TuneableMutationalStage`]
pub fn set_seed_fuzz_time_std(state: &mut Z::State, fuzz_time: Duration) -> Result<(), Error> {
pub fn set_seed_fuzz_time_std(
state: &mut <Self as UsesState>::State,
fuzz_time: Duration,
) -> Result<(), Error> {
set_seed_fuzz_time_by_name(state, fuzz_time, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
@ -397,7 +396,10 @@ where
}
/// Set the time to mutate a single input for the std [`TuneableMutationalStage`]
pub fn seed_fuzz_time_std(&self, state: &Z::State) -> Result<Option<Duration>, Error> {
pub fn seed_fuzz_time_std(
&self,
state: &<Self as UsesState>::State,
) -> Result<Option<Duration>, Error> {
get_seed_fuzz_time_by_name(state, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
@ -422,7 +424,7 @@ where
}
/// Reset the std stage to a normal, randomized, stage
pub fn reset_std(state: &mut Z::State) -> Result<(), Error> {
pub fn reset_std(state: &mut <Self as UsesState>::State) -> Result<(), Error> {
reset_by_name(state, STD_TUNEABLE_MUTATIONAL_STAGE_NAME)
}
@ -438,7 +440,7 @@ where
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut Z::State,
state: &mut <Self as UsesState>::State,
manager: &mut EM,
input: &I,
) -> Result<(), Error> {
@ -467,15 +469,15 @@ where
impl<E, EM, I, M, Z> TuneableMutationalStage<E, EM, I, M, Z>
where
E: UsesState<State = Z::State>,
EM: UsesState<State = Z::State>,
E: UsesState<State = <Self as UsesState>::State>,
EM: UsesState<State = <Self as UsesState>::State>,
M: Mutator<I, Z::State>,
Z: Evaluator<E, EM>,
Z::State: HasCorpus + HasRand + HasNamedMetadata,
<Self as UsesState>::State: HasCorpus + HasRand + HasNamedMetadata,
{
/// Creates a new transforming mutational stage
#[must_use]
pub fn transforming(state: &mut Z::State, mutator: M, name: &str) -> Self {
pub fn transforming(state: &mut <Self as UsesState>::State, mutator: M, name: &str) -> Self {
let _ = state.named_metadata_or_insert_with(name, TuneableMutationalStageMetadata::default);
Self {
mutator,

View File

@ -36,7 +36,7 @@ libafl_bolts = { path = "../../libafl_bolts", default-features = false, features
libafl_targets = { path = "../../libafl_targets", features = ["sancov_8bit", "sancov_cmplog", "sancov_pcguard", "libfuzzer", "libfuzzer_oom", "libfuzzer_define_run_driver", "libfuzzer_interceptors", "sanitizers_flags", "whole_archive", "sanitizer_interfaces"] }
ahash = { version = "0.8.3", default-features = false }
libc = "0.2.139"
libc = "0.2.1"
log = "0.4.20"
mimalloc = { version = "0.1.34", default-features = false }
num-traits = "0.2.15"

View File

@ -23,7 +23,7 @@ where
TE: UsesState,
{
tracer_executor: TE,
cmplog_observer_handle: Option<Handle<AFLppCmpLogObserver<'a, TE::State>>>,
cmplog_observer_handle: Option<Handle<AFLppCmpLogObserver<'a, <Self as UsesState>::State>>>,
#[allow(clippy::type_complexity)]
phantom: PhantomData<(EM, TE, Z)>,
}
@ -47,12 +47,12 @@ where
impl<E, EM, TE, Z> Stage<E, EM, Z> for AFLppCmplogTracingStage<'_, EM, TE, Z>
where
E: UsesState<State = TE::State>,
E: UsesState<State = Self::State>,
TE: Executor<EM, Z> + HasObservers,
TE::State:
Self::State:
HasExecutions + HasCorpus + HasMetadata + UsesInput<Input = BytesInput> + HasNamedMetadata,
EM: UsesState<State = TE::State>,
Z: UsesState<State = TE::State>,
EM: UsesState<State = Self::State>,
Z: UsesState<State = Self::State>,
{
#[inline]
fn perform(