diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs index 02b9e4c276..5055e00011 100644 --- a/libafl/src/events/centralized.rs +++ b/libafl/src/events/centralized.rs @@ -749,14 +749,15 @@ where fn receive_from_secondary( &mut self, fuzzer: &mut Z, - state: &mut EM::State, + state: &mut ::State, executor: &mut E, ) -> Result where - E: Executor + HasObservers, - EM::State: UsesInput + HasExecutions + HasMetadata, + E: Executor + HasObservers::State>, + ::State: UsesInput + HasExecutions + HasMetadata, for<'a> E::Observers: Deserialize<'a>, - Z: ExecutionProcessor + EvaluatorObservers, + Z: ExecutionProcessor::State> + + EvaluatorObservers, { // 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<<::State as UsesInput>::Input> = + let event: Event<<::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 ::State, client_id: ClientId, - event: Event<::Input>, + event: Event<<::State as UsesInput>::Input>, ) -> Result<(), Error> where - E: Executor + HasObservers, - EM::State: UsesInput + HasExecutions + HasMetadata, + E: Executor + HasObservers::State>, + ::State: UsesInput + HasExecutions + HasMetadata, for<'a> E::Observers: Deserialize<'a>, - Z: ExecutionProcessor + EvaluatorObservers, + Z: ExecutionProcessor::State> + + EvaluatorObservers, { match event { Event::NewTestcase { diff --git a/libafl/src/events/launcher.rs b/libafl/src/events/launcher.rs index 3012123953..7833e9d199 100644 --- a/libafl/src/events/launcher.rs +++ b/libafl/src/events/launcher.rs @@ -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, LlmpRestartingEventManager, CoreId) -> Result<(), Error>, - EMH: EventManagerHooksTuple, - 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, - CentralizedEventManager, SP>, // No hooks for centralized EM - CoreId, - ) -> Result<(), Error>, - MF: FnOnce( - Option, - CentralizedEventManager, 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 Debug for CentralizedLauncher<'_, CF, MF, MT, S, SP> -where - CF: FnOnce( - Option, - CentralizedEventManager, SP>, - CoreId, - ) -> Result<(), Error>, - MF: FnOnce( - Option, - CentralizedEventManager, SP>, // No hooks for centralized EM - CoreId, - ) -> Result<(), Error>, - MT: Monitor + Clone, - SP: ShMemProvider + 'static, - S: State, -{ +impl Debug for CentralizedLauncher<'_, CF, MF, MT, S, SP> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Launcher") .field("configuration", &self.configuration) diff --git a/libafl/src/events/llmp/broker.rs b/libafl/src/events/llmp/broker.rs index 6d968bb575..44bc8eb719 100644 --- a/libafl/src/events/llmp/broker.rs +++ b/libafl/src/events/llmp/broker.rs @@ -21,10 +21,7 @@ use crate::{ #[derive(Debug)] pub struct LlmpEventBroker where - I: Input, SP: ShMemProvider + 'static, - MT: Monitor, - //CE: CustomEvent, { monitor: MT, llmp: llmp::LlmpBroker, diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index e4bd6cba00..4fb32f0480 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -787,7 +787,7 @@ where impl EventManager for MonitorTypedEventManager where EM: EventManager, - EM::State: HasLastReportTime + HasExecutions + HasMetadata, + Self::State: HasLastReportTime + HasExecutions + HasMetadata, { } @@ -811,7 +811,7 @@ impl ProgressReporter for MonitorTypedEventManager where Self: UsesState, EM: ProgressReporter, - EM::State: HasLastReportTime + HasExecutions + HasMetadata, + Self::State: HasLastReportTime + HasExecutions + HasMetadata, { #[inline] fn maybe_report_progress( diff --git a/libafl/src/executors/combined.rs b/libafl/src/executors/combined.rs index e48df9ec5c..245327106b 100644 --- a/libafl/src/executors/combined.rs +++ b/libafl/src/executors/combined.rs @@ -24,9 +24,9 @@ impl CombinedExecutor { pub fn new(primary: A, secondary: B) -> Self where A: Executor, - B: Executor, - EM: UsesState, - Z: UsesState, + B: Executor::State>, + EM: UsesState::State>, + Z: UsesState::State>, { Self { primary, secondary } } @@ -45,10 +45,10 @@ impl CombinedExecutor { impl Executor for CombinedExecutor where A: Executor, - B: Executor, - EM: UsesState, - EM::State: HasExecutions, - Z: UsesState, + B: Executor::State>, + Self::State: HasExecutions, + EM: UsesState::State>, + Z: UsesState::State>, { fn run_target( &mut self, diff --git a/libafl/src/executors/differential.rs b/libafl/src/executors/differential.rs index 22fdf36a93..3cfaaa8e86 100644 --- a/libafl/src/executors/differential.rs +++ b/libafl/src/executors/differential.rs @@ -31,10 +31,10 @@ impl DiffExecutor { pub fn new(primary: A, secondary: B, observers: DOT) -> Self where A: UsesState + HasObservers, - B: UsesState + HasObservers, - DOT: DifferentialObserversTuple, - OTA: ObserversTuple, - OTB: ObserversTuple, + B: UsesState::State> + HasObservers, + DOT: DifferentialObserversTuple::State>, + OTA: ObserversTuple<::State>, + OTB: ObserversTuple<::State>, { Self { primary, @@ -61,10 +61,10 @@ impl DiffExecutor { impl Executor for DiffExecutor where A: Executor + HasObservers, - B: Executor + HasObservers, - EM: UsesState, - DOT: DifferentialObserversTuple, - Z: UsesState, + B: Executor::State> + HasObservers, + EM: UsesState::State>, + DOT: DifferentialObserversTuple::State>, + Z: UsesState::State>, { fn run_target( &mut self, @@ -196,10 +196,10 @@ impl ProxyObserversTuple { impl UsesObservers for DiffExecutor where A: HasObservers, - B: HasObservers, - OTA: ObserversTuple, - OTB: ObserversTuple, - DOT: DifferentialObserversTuple, + B: HasObservers::State>, + OTA: ObserversTuple<::State>, + OTB: ObserversTuple<::State>, + DOT: DifferentialObserversTuple::State>, { type Observers = ProxyObserversTuple; } @@ -207,7 +207,6 @@ where impl UsesState for DiffExecutor where A: UsesState, - B: UsesState, { type State = A::State; } @@ -215,10 +214,10 @@ where impl HasObservers for DiffExecutor where A: HasObservers, - B: HasObservers, - OTA: ObserversTuple, - OTB: ObserversTuple, - DOT: DifferentialObserversTuple, + B: HasObservers::State>, + OTA: ObserversTuple<::State>, + OTB: ObserversTuple<::State>, + DOT: DifferentialObserversTuple::State>, { #[inline] fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> { diff --git a/libafl/src/executors/shadow.rs b/libafl/src/executors/shadow.rs index 242fca8413..876f98401b 100644 --- a/libafl/src/executors/shadow.rs +++ b/libafl/src/executors/shadow.rs @@ -21,8 +21,8 @@ pub struct ShadowExecutor { impl Debug for ShadowExecutor where - E: UsesState + Debug, - SOT: ObserversTuple + Debug, + E: Debug, + SOT: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("ShadowExecutor") @@ -35,7 +35,7 @@ where impl ShadowExecutor where E: HasObservers, - SOT: ObserversTuple, + SOT: ObserversTuple<::State>, { /// Create a new `ShadowExecutor`, wrapping the given `executor`. pub fn new(executor: E, shadow_observers: SOT) -> Self { @@ -61,9 +61,9 @@ where impl Executor for ShadowExecutor where E: Executor + HasObservers, - SOT: ObserversTuple, - EM: UsesState, - Z: UsesState, + SOT: ObserversTuple, + EM: UsesState, + Z: UsesState, { fn run_target( &mut self, @@ -93,7 +93,7 @@ where impl HasObservers for ShadowExecutor where E: HasObservers, - SOT: ObserversTuple, + SOT: ObserversTuple, { #[inline] fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> { diff --git a/libafl/src/executors/with_observers.rs b/libafl/src/executors/with_observers.rs index 6924b9e401..17cb0ba1e1 100644 --- a/libafl/src/executors/with_observers.rs +++ b/libafl/src/executors/with_observers.rs @@ -21,8 +21,8 @@ pub struct WithObservers { impl Executor for WithObservers where E: Executor, - EM: UsesState, - Z: UsesState, + EM: UsesState, + Z: UsesState, { fn run_target( &mut self, @@ -45,7 +45,7 @@ where impl UsesObservers for WithObservers where E: UsesState, - OT: ObserversTuple, + OT: ObserversTuple, { type Observers = OT; } @@ -53,7 +53,7 @@ where impl HasObservers for WithObservers where E: UsesState, - OT: ObserversTuple, + OT: ObserversTuple, { fn observers(&self) -> RefIndexable<&Self::Observers, Self::Observers> { RefIndexable::from(&self.observers) diff --git a/libafl/src/feedbacks/custom_filename.rs b/libafl/src/feedbacks/custom_filename.rs index f1073506a4..e3e4ea7633 100644 --- a/libafl/src/feedbacks/custom_filename.rs +++ b/libafl/src/feedbacks/custom_filename.rs @@ -50,7 +50,7 @@ where } } -impl FeedbackFactory, S, T> +impl FeedbackFactory, T> for CustomFilenameToTestcaseFeedback where I: Input, diff --git a/libafl/src/feedbacks/differential.rs b/libafl/src/feedbacks/differential.rs index 420f5572bc..708c729783 100644 --- a/libafl/src/feedbacks/differential.rs +++ b/libafl/src/feedbacks/differential.rs @@ -100,7 +100,7 @@ where } } -impl FeedbackFactory, S, T> +impl FeedbackFactory, T> for DiffFeedback where F: FnMut(&O1, &O2) -> DiffResult + Clone, diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index 5a80358930..29bff15fbc 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -310,11 +310,11 @@ where } } -impl FeedbackFactory, S, T> +impl FeedbackFactory, T> for CombinedFeedback where - A: Feedback + FeedbackFactory, - B: Feedback + FeedbackFactory, + A: Feedback + FeedbackFactory, + B: Feedback + FeedbackFactory, FL: FeedbackLogic, 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 -where - F: Feedback, - S: State, -{ +pub trait FeedbackFactory { /// Create the feedback from the provided context fn create_feedback(&self, ctx: &T) -> F; } -impl FeedbackFactory for FU +impl FeedbackFactory for FU where FU: Fn(&T) -> FE, - FE: Feedback, - S: State, { fn create_feedback(&self, ctx: &T) -> FE { self(ctx) @@ -982,7 +976,7 @@ impl Default for CrashFeedback { } } -impl FeedbackFactory for CrashFeedback { +impl FeedbackFactory 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 FeedbackFactory for TimeoutFeedback { +impl FeedbackFactory 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 FeedbackFactory for DiffExitKindFeedback { +impl FeedbackFactory for DiffExitKindFeedback { fn create_feedback(&self, _ctx: &T) -> DiffExitKindFeedback { DiffExitKindFeedback::new() } diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index 4d03c117cc..86b9111855 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -130,11 +130,7 @@ pub trait EvaluatorObservers: UsesState + Sized { } /// Evaluate an input modifying the state of the fuzzer -pub trait Evaluator: UsesState -where - E: UsesState, - EM: UsesState, -{ +pub trait Evaluator: 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; @@ -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 { @@ -280,13 +276,7 @@ pub enum ExecuteInputResult { /// Your default fuzzer instance, for everyday use. #[derive(Debug)] -pub struct StdFuzzer -where - CS: Scheduler, - F: Feedback, - OF: Feedback, - CS::State: HasCorpus, -{ +pub struct StdFuzzer { scheduler: CS, feedback: F, objective: OF, @@ -296,8 +286,6 @@ where impl UsesState for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, CS::State: HasCorpus, { type State = CS::State; @@ -306,8 +294,6 @@ where impl HasScheduler for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, CS::State: HasCorpus, { type Scheduler = CS; @@ -324,8 +310,8 @@ where impl HasFeedback for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, + F: Feedback, + OF: Feedback, CS::State: HasCorpus, { type Feedback = F; @@ -342,8 +328,8 @@ where impl HasObjective for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, + F: Feedback, + OF: Feedback, CS::State: HasCorpus, { type Objective = OF; @@ -360,9 +346,9 @@ where impl ExecutionProcessor for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, - OT: ObserversTuple + Serialize + DeserializeOwned, + F: Feedback, + OF: Feedback, + OT: ObserversTuple + Serialize + DeserializeOwned, CS::State: HasCorpus + HasSolutions + HasExecutions @@ -537,9 +523,9 @@ where impl EvaluatorObservers for StdFuzzer where CS: Scheduler, - OT: ObserversTuple + Serialize + DeserializeOwned, - F: Feedback, - OF: Feedback, + OT: ObserversTuple + Serialize + DeserializeOwned, + F: Feedback, + OF: Feedback, 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 Evaluator for StdFuzzer where CS: Scheduler, - E: HasObservers + Executor, - EM: EventFirer, - F: Feedback, - OF: Feedback, - OT: ObserversTuple + Serialize + DeserializeOwned, + E: HasObservers + Executor, + EM: EventFirer, + F: Feedback, + OF: Feedback, + OT: ObserversTuple + 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 Fuzzer for StdFuzzer where CS: Scheduler, - E: UsesState, - EM: ProgressReporter + EventProcessor, - F: Feedback, - OF: Feedback, + E: UsesState, + EM: ProgressReporter + EventProcessor, + F: Feedback, + OF: Feedback, CS::State: HasExecutions + HasMetadata + HasCorpus @@ -711,13 +697,13 @@ where + HasLastReportTime + HasCurrentCorpusId + HasCurrentStage, - ST: StagesTuple, + ST: StagesTuple, { fn fuzz_one( &mut self, stages: &mut ST, executor: &mut E, - state: &mut CS::State, + state: &mut Self::State, manager: &mut EM, ) -> Result { // Init timer for scheduler @@ -772,8 +758,8 @@ where impl StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, + F: Feedback<::State>, + OF: Feedback<::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( &mut self, - state: &mut CS::State, + state: &mut ::State, executor: &mut E, event_mgr: &mut EM, - input: &::Input, + input: &<::State as UsesInput>::Input, ) -> Result where - E: Executor + HasObservers, - EM: UsesState, - OT: ObserversTuple, + E: Executor + HasObservers::State>, + EM: UsesState::State>, + OT: ObserversTuple<::State>, { start_timer!(state); executor.observers_mut().pre_exec_all(state, input)?; @@ -833,22 +819,22 @@ where ) -> Result; } -impl ExecutesInput for StdFuzzer +impl ExecutesInput for StdFuzzer where CS: Scheduler, - F: Feedback, - OF: Feedback, - E: Executor + HasObservers, - EM: UsesState, + F: Feedback<::State>, + OF: Feedback<::State>, + E: Executor + HasObservers, + EM: UsesState, CS::State: UsesInput + HasExecutions + HasCorpus, { /// Runs the input and triggers observers and feedback fn execute_input( &mut self, - state: &mut CS::State, + state: &mut ::State, executor: &mut E, event_mgr: &mut EM, - input: &::Input, + input: &<::State as UsesInput>::Input, ) -> Result { start_timer!(state); executor.observers_mut().pre_exec_all(state, input)?; @@ -912,9 +898,9 @@ pub mod test { impl Fuzzer for NopFuzzer where E: UsesState, - EM: ProgressReporter, - ST: StagesTuple, - E::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage, + EM: ProgressReporter, + ST: StagesTuple, + Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage, { fn fuzz_one( &mut self, diff --git a/libafl/src/schedulers/accounting.rs b/libafl/src/schedulers/accounting.rs index e28e71cb82..a65f391b9b 100644 --- a/libafl/src/schedulers/accounting.rs +++ b/libafl/src/schedulers/accounting.rs @@ -131,8 +131,9 @@ where impl<'a, CS, O> Scheduler for CoverageAccountingScheduler<'a, CS, O> where CS: Scheduler, - CS::State: HasCorpus + HasMetadata + HasRand + Debug, - ::Input: HasLen, + Self::State: HasCorpus + HasMetadata + HasRand, + CS::State: Debug, + ::Input: HasLen, O: CanTrack, { fn on_add(&mut self, state: &mut Self::State, idx: CorpusId) -> Result<(), Error> { diff --git a/libafl/src/schedulers/minimizer.rs b/libafl/src/schedulers/minimizer.rs index ddf871185b..6ba37cdbc0 100644 --- a/libafl/src/schedulers/minimizer.rs +++ b/libafl/src/schedulers/minimizer.rs @@ -88,17 +88,17 @@ where impl RemovableScheduler for MinimizerScheduler where CS: RemovableScheduler, - F: TestcaseScore, + F: TestcaseScore<::State>, M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt, - CS::State: HasCorpus + HasMetadata + HasRand, + ::State: HasCorpus + HasMetadata + HasRand, O: CanTrack, { /// Replaces the testcase at the given idx fn on_replace( &mut self, - state: &mut CS::State, + state: &mut ::State, idx: CorpusId, - testcase: &Testcase<::Input>, + testcase: &Testcase<<::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 ::State, idx: CorpusId, - testcase: &Option::Input>>, + testcase: &Option::State as UsesInput>::Input>>, ) -> Result<(), Error> { self.base.on_remove(state, idx, testcase)?; let mut entries = @@ -196,13 +196,13 @@ where impl Scheduler for MinimizerScheduler where CS: Scheduler, - F: TestcaseScore, + F: TestcaseScore, 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 { + fn next(&mut self, state: &mut Self::State) -> Result { self.cull(state)?; let mut idx = self.base.next(state)?; while { @@ -252,15 +252,19 @@ where impl MinimizerScheduler where CS: Scheduler, - F: TestcaseScore, + F: TestcaseScore<::State>, M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt, - CS::State: HasCorpus + HasMetadata + HasRand, + ::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 ::State, + idx: CorpusId, + ) -> Result<(), Error> { // Create a new top rated meta if not existing if state.metadata_map().get::().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: &::State) -> Result<(), Error> { let Some(top_rated) = state.metadata_map().get::() else { return Ok(()); }; diff --git a/libafl/src/stages/calibrate.rs b/libafl/src/stages/calibrate.rs index 14e5ed043c..1d46d72a9a 100644 --- a/libafl/src/stages/calibrate.rs +++ b/libafl/src/stages/calibrate.rs @@ -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 { +pub struct CalibrationStage { map_observer_handle: Handle, map_name: Cow<'static, str>, name: Cow<'static, str>, @@ -78,29 +77,29 @@ pub struct CalibrationStage { /// 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 UsesState for CalibrationStage +impl UsesState for CalibrationStage where - S: State, + E: UsesState, { - type State = S; + type State = E::State; } -impl Stage for CalibrationStage +impl Stage for CalibrationStage where E: Executor + HasObservers, - EM: EventFirer, + EM: EventFirer, O: MapObserver, C: AsRef, for<'de> ::Entry: Serialize + Deserialize<'de> + 'static, - OT: ObserversTuple, - E::State: HasCorpus + HasMetadata + HasNamedMetadata + HasExecutions, - Z: Evaluator, + OT: ObserversTuple, + Self::State: HasCorpus + HasMetadata + HasNamedMetadata + HasExecutions, + Z: Evaluator, { #[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 CalibrationStage +impl CalibrationStage where O: MapObserver, for<'it> O: AsIter<'it, Item = O::Entry>, C: AsRef, - OT: ObserversTuple, - S: UsesInput + HasNamedMetadata, + OT: ObserversTuple<::State>, + E: UsesState, { /// Create a new [`CalibrationStage`]. #[must_use] @@ -388,7 +387,7 @@ where } } -impl Named for CalibrationStage { +impl Named for CalibrationStage { fn name(&self) -> &Cow<'static, str> { &self.name } diff --git a/libafl/src/stages/colorization.rs b/libafl/src/stages/colorization.rs index 25dd0860a2..a3f8844a69 100644 --- a/libafl/src/stages/colorization.rs +++ b/libafl/src/stages/colorization.rs @@ -81,13 +81,13 @@ where impl Stage for ColorizationStage where - EM: UsesState + EventFirer, + EM: UsesState + EventFirer, E: HasObservers + Executor, - E::State: HasCorpus + HasMetadata + HasRand + HasNamedMetadata, + Self::State: HasCorpus + HasMetadata + HasRand + HasNamedMetadata, E::Input: HasMutatorBytes, O: MapObserver, C: AsRef + Named, - Z: UsesState, + Z: UsesState, { #[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 ColorizationStage where - EM: UsesState + EventFirer, + EM: UsesState::State> + EventFirer, O: MapObserver, C: AsRef + Named, E: HasObservers + Executor, - E::State: HasCorpus + HasMetadata + HasRand, + ::State: HasCorpus + HasMetadata + HasRand, E::Input: HasMutatorBytes, - Z: UsesState, + Z: UsesState::State>, { #[inline] #[allow(clippy::let_and_return)] fn colorize( fuzzer: &mut Z, executor: &mut E, - state: &mut E::State, + state: &mut ::State, manager: &mut EM, observer_handle: &Handle, ) -> Result { @@ -320,7 +320,7 @@ where fn get_raw_map_hash_run( fuzzer: &mut Z, executor: &mut E, - state: &mut E::State, + state: &mut ::State, manager: &mut EM, input: E::Input, observer_handle: &Handle, @@ -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 ::State) { let len = bytes.len(); for idx in 0..len { let c = match bytes[idx] { diff --git a/libafl/src/stages/concolic.rs b/libafl/src/stages/concolic.rs index 5151b7b2d5..515b615870 100644 --- a/libafl/src/stages/concolic.rs +++ b/libafl/src/stages/concolic.rs @@ -58,18 +58,18 @@ impl Named for ConcolicTracingStage<'_, EM, TE, Z> { impl Stage for ConcolicTracingStage<'_, EM, TE, Z> where - E: UsesState, - EM: UsesState, + E: UsesState, + EM: UsesState, TE: Executor + HasObservers, - TE::State: HasExecutions + HasCorpus + HasNamedMetadata, - Z: UsesState, + Self::State: HasExecutions + HasCorpus + HasNamedMetadata, + Z: UsesState, { #[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 Stage for SimpleConcolicMutationalStage where - E: UsesState, - EM: UsesState, + E: UsesState, + EM: UsesState, Z: Evaluator, 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> { { diff --git a/libafl/src/stages/dump.rs b/libafl/src/stages/dump.rs index be1bd9cfc1..7976226257 100644 --- a/libafl/src/stages/dump.rs +++ b/libafl/src/stages/dump.rs @@ -46,18 +46,18 @@ where impl Stage for DumpToDiskStage where - CB: FnMut(&::Input, &Z::State) -> Vec, - EM: UsesState, - E: UsesState, - Z: UsesState, - Z::State: HasCorpus + HasSolutions + HasRand + HasMetadata, + CB: FnMut(&::Input, &Self::State) -> Vec, + EM: UsesState, + E: UsesState, + Z: UsesState, + 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 DumpToDiskStage where - EM: UsesState, + EM: UsesState, Z: UsesState, - Z::State: HasCorpus + HasSolutions + HasRand + HasMetadata, + ::State: HasCorpus + HasSolutions + HasRand + HasMetadata, { /// Create a new [`DumpToDiskStage`] pub fn new(to_bytes: CB, corpus_dir: A, solutions_dir: B) -> Result diff --git a/libafl/src/stages/generalization.rs b/libafl/src/stages/generalization.rs index 19bae170a8..d1bcadbd80 100644 --- a/libafl/src/stages/generalization.rs +++ b/libafl/src/stages/generalization.rs @@ -58,7 +58,6 @@ impl Named for GeneralizationStage { impl UsesState for GeneralizationStage where EM: UsesState, - EM::State: UsesInput, { type State = EM::State; } @@ -67,12 +66,11 @@ impl Stage for GeneralizationStage + Named, - E: Executor + HasObservers, - E::Observers: ObserversTuple, - E::State: + E: Executor + HasObservers, + Self::State: UsesInput + HasExecutions + HasMetadata + HasCorpus + HasNamedMetadata, - EM: UsesState, - Z: UsesState, + EM: UsesState, + Z: UsesState, { #[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 + Named, - OT: ObserversTuple, - EM::State: UsesInput + HasExecutions + HasMetadata + HasCorpus, + OT: ObserversTuple<::State>, + ::State: + UsesInput + 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 ::State, manager: &mut EM, novelties: &[usize], input: &BytesInput, ) -> Result where - E: Executor + HasObservers, - Z: UsesState, + E: Executor + HasObservers::State>, + Z: 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 ::State, manager: &mut EM, payload: &mut Vec>, novelties: &[usize], @@ -406,8 +405,8 @@ where split_char: u8, ) -> Result<(), Error> where - E: Executor + HasObservers, - Z: UsesState, + E: Executor + HasObservers::State>, + Z: 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 ::State, manager: &mut EM, payload: &mut Vec>, novelties: &[usize], @@ -445,8 +444,8 @@ where closing_char: u8, ) -> Result<(), Error> where - E: Executor + HasObservers, - Z: UsesState, + E: Executor + HasObservers::State>, + Z: UsesState::State>, { let mut index = 0; while index < payload.len() { diff --git a/libafl/src/stages/generation.rs b/libafl/src/stages/generation.rs index 8df777a28a..46f7200c10 100644 --- a/libafl/src/stages/generation.rs +++ b/libafl/src/stages/generation.rs @@ -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, PhantomData) -where - Z: UsesState, - G: Generator<<::State as UsesInput>::Input, Z::State>; +pub struct GenStage(G, PhantomData); -impl GenStage -where - Z: UsesState, - G: Generator<<::State as UsesInput>::Input, Z::State>, -{ +impl GenStage { /// Create a new [`GenStage`]. pub fn new(g: G) -> Self { Self(g, PhantomData) @@ -36,25 +29,24 @@ where impl UsesState for GenStage where Z: UsesState, - G: Generator<<::State as UsesInput>::Input, Z::State>, { type State = Z::State; } impl Stage for GenStage where - E: UsesState, - EM: UsesState, + E: UsesState, + EM: UsesState, Z: Evaluator, - Z::State: HasCorpus + HasRand, - G: Generator<<::State as UsesInput>::Input, Z::State>, + Self::State: HasCorpus + HasRand, + G: Generator<<::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)?; diff --git a/libafl/src/stages/logics.rs b/libafl/src/stages/logics.rs index 5f431fca38..cb1ff665f5 100644 --- a/libafl/src/stages/logics.rs +++ b/libafl/src/stages/logics.rs @@ -32,14 +32,7 @@ impl NestedStageRestartHelper { #[derive(Debug)] /// Perform the stage while the closure evaluates to true -pub struct WhileStage -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, - E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, -{ +pub struct WhileStage { closure: CB, stages: ST, phantom: PhantomData<(E, EM, Z)>, @@ -47,29 +40,25 @@ where impl UsesState for WhileStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, { type State = E::State; } impl Stage for WhileStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result, E: UsesState, EM: UsesState, - ST: StagesTuple, - Z: UsesState, - E::State: HasNestedStageStatus, + ST: StagesTuple, + Z: UsesState, + 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 WhileStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut ::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, { /// 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 -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, - E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, -{ +pub struct IfStage { closure: CB, if_stages: ST, phantom: PhantomData<(E, EM, Z)>, @@ -126,29 +105,25 @@ where impl UsesState for IfStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, { type State = E::State; } impl Stage for IfStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, - E::State: HasNestedStageStatus, + EM: UsesState, + ST: StagesTuple, + Z: UsesState, + 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 IfStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut ::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, { /// 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 -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, - E: UsesState, - EM: UsesState, - ST1: StagesTuple, - ST2: StagesTuple, - Z: UsesState, -{ +pub struct IfElseStage { closure: CB, if_stages: ST1, else_stages: ST2, @@ -206,31 +170,26 @@ where impl UsesState for IfElseStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST1: StagesTuple, - ST2: StagesTuple, - Z: UsesState, { type State = E::State; } impl Stage for IfElseStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut Self::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST1: StagesTuple, - ST2: StagesTuple, - Z: UsesState, - E::State: HasNestedStageStatus, + EM: UsesState, + ST1: StagesTuple, + ST2: StagesTuple, + Z: UsesState, + 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 IfElseStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result, + CB: FnMut(&mut Z, &mut E, &mut ::State, &mut EM) -> Result, E: UsesState, - EM: UsesState, - ST1: StagesTuple, - ST2: StagesTuple, - Z: UsesState, { /// 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 -where - E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, -{ +pub struct OptionalStage { stages: Option, phantom: PhantomData<(E, EM, Z)>, } @@ -305,9 +254,6 @@ where impl UsesState for OptionalStage where E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, { type State = E::State; } @@ -315,16 +261,16 @@ where impl Stage for OptionalStage where E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, - E::State: HasNestedStageStatus, + EM: UsesState, + ST: StagesTuple, + Z: UsesState, + 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 OptionalStage -where - E: UsesState, - EM: UsesState, - ST: StagesTuple, - Z: UsesState, -{ +impl OptionalStage { /// Constructor for this conditionally enabled stage. #[must_use] pub fn new(stages: Option) -> Self { diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index 96638b3fb3..674fa7d045 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -285,28 +285,19 @@ where /// A [`Stage`] that will call a closure #[derive(Debug)] -pub struct ClosureStage -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>, - E: UsesState, -{ +pub struct ClosureStage { closure: CB, phantom: PhantomData<(E, EM, Z)>, } impl UsesState for ClosureStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>, E: UsesState, { type State = E::State; } -impl Named for ClosureStage -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>, - E: UsesState, -{ +impl Named for ClosureStage { fn name(&self) -> &Cow<'static, str> { static NAME: Cow<'static, str> = Cow::Borrowed(""); &NAME @@ -315,11 +306,11 @@ where impl Stage for ClosureStage 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, - Z: UsesState, - E::State: HasNamedMetadata, + EM: UsesState, + Z: UsesState, + Self::State: HasNamedMetadata, { fn perform( &mut self, @@ -344,11 +335,7 @@ where } /// A stage that takes a closure -impl ClosureStage -where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>, - E: UsesState, -{ +impl ClosureStage { /// Create a new [`ClosureStage`] #[must_use] pub fn new(closure: CB) -> Self { @@ -361,7 +348,7 @@ where impl From for ClosureStage where - CB: FnMut(&mut Z, &mut E, &mut E::State, &mut EM) -> Result<(), Error>, + CB: FnMut(&mut Z, &mut E, &mut ::State, &mut EM) -> Result<(), Error>, E: UsesState, { #[must_use] @@ -400,17 +387,17 @@ where impl Stage for PushStageAdapter where CS: Scheduler, - CS::State: + Self::State: HasExecutions + HasMetadata + HasRand + HasCorpus + HasLastReportTime + HasCurrentCorpusId, - E: Executor + HasObservers, - EM: EventFirer + E: Executor + HasObservers, + EM: EventFirer + EventRestarter + HasEventManagerId - + ProgressReporter, - OT: ObserversTuple, + + ProgressReporter, + OT: ObserversTuple, PS: PushStage, - Z: ExecutesInput - + ExecutionProcessor + Z: ExecutesInput + + ExecutionProcessor + EvaluatorObservers + HasScheduler, { diff --git a/libafl/src/stages/mutational.rs b/libafl/src/stages/mutational.rs index 19ea5cfa99..31d07a2e68 100644 --- a/libafl/src/stages/mutational.rs +++ b/libafl/src/stages/mutational.rs @@ -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; + fn iterations(&self, state: &mut Self::State) -> Result; /// 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; + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result; /// 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 { impl MutationalStage for StdMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState, + EM: UsesState, + M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasExecutions + HasMetadata, + Self::State: HasCorpus + HasRand + HasExecutions + HasMetadata, I: MutatedTransform + 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 { + fn iterations(&self, state: &mut Self::State) -> Result { Ok(1 + state.rand_mut().below(self.max_iterations)) } - fn execs_since_progress_start(&mut self, state: &mut ::State) -> Result { + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result { self.restart_helper.execs_since_progress_start(state) } } impl UsesState for StdMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, - Z: Evaluator, - Z::State: HasCorpus + HasRand, + Z: UsesState, { type State = Z::State; } impl Stage for StdMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState, + EM: UsesState, + M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasMetadata + HasExecutions, + Self::State: HasCorpus + HasRand + HasMetadata + HasExecutions, I: MutatedTransform + 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 StdMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState::State>, + EM: UsesState::State>, + M: Mutator::State>, Z: Evaluator, - Z::State: HasCorpus + HasRand, + ::State: HasCorpus + HasRand, { /// Creates a new default mutational stage pub fn new(mutator: M) -> Self { @@ -265,11 +261,11 @@ where impl StdMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState::State>, + EM: UsesState::State>, + M: Mutator::State>, Z: Evaluator, - Z::State: HasCorpus + HasRand, + ::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 { impl UsesState for MultiMutationalStage where - E: UsesState, - EM: UsesState, - M: MultiMutator, - Z: Evaluator, - Z::State: HasCorpus + HasRand, + Z: UsesState, { type State = Z::State; } -impl Named for MultiMutationalStage -where - E: UsesState, - EM: UsesState, - M: MultiMutator, - Z: Evaluator, - Z::State: HasCorpus + HasRand, -{ +impl Named for MultiMutationalStage { fn name(&self) -> &Cow<'static, str> { static NAME: Cow<'static, str> = Cow::Borrowed("MultiMutational"); &NAME @@ -322,11 +307,11 @@ where impl Stage for MultiMutationalStage where - E: UsesState, - EM: UsesState, - M: MultiMutator, + E: UsesState, + EM: UsesState, + M: MultiMutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasNamedMetadata, + Self::State: HasCorpus + HasRand + HasNamedMetadata, I: MutatedTransform + 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 MultiMutationalStage where - E: UsesState, - EM: UsesState, - M: MultiMutator, - Z: Evaluator, - Z::State: HasCorpus + HasRand, + Z: UsesState, { /// Creates a new [`MultiMutationalStage`] pub fn new(mutator: M) -> Self { @@ -386,14 +367,7 @@ where } } -impl MultiMutationalStage -where - E: UsesState, - EM: UsesState, - M: MultiMutator, - Z: Evaluator, - Z::State: HasCorpus + HasRand, -{ +impl MultiMutationalStage { /// Creates a new transforming mutational stage pub fn transforming(mutator: M) -> Self { Self { diff --git a/libafl/src/stages/power.rs b/libafl/src/stages/power.rs index 9cc7d7b615..41c3abea40 100644 --- a/libafl/src/stages/power.rs +++ b/libafl/src/stages/power.rs @@ -44,12 +44,12 @@ impl Named for PowerMutationalStage { impl MutationalStage for PowerMutationalStage where E: Executor + HasObservers, - EM: UsesState, - F: TestcaseScore, - M: Mutator, - E::State: HasCorpus + HasMetadata + HasRand + HasExecutions, - Z: Evaluator, - I: MutatedTransform + Clone, + EM: UsesState, + F: TestcaseScore, + M: Mutator, + Self::State: HasCorpus + HasMetadata + HasRand + HasExecutions, + Z: Evaluator, + I: MutatedTransform + 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 { + fn iterations(&self, state: &mut Self::State) -> Result { // 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 ::State) -> Result { + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result { self.restart_helper.execs_since_progress_start(state) } } @@ -81,12 +81,12 @@ where impl Stage for PowerMutationalStage where E: Executor + HasObservers, - EM: UsesState, - F: TestcaseScore, - M: Mutator, - E::State: HasCorpus + HasMetadata + HasRand + HasExecutions, - Z: Evaluator, - I: MutatedTransform + Clone, + EM: UsesState, + F: TestcaseScore, + M: Mutator, + Self::State: HasCorpus + HasMetadata + HasRand + HasExecutions, + Z: Evaluator, + I: MutatedTransform + 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 PowerMutationalStage where E: Executor + HasObservers, - EM: UsesState, - F: TestcaseScore, - M: Mutator, - E::State: HasCorpus + HasMetadata + HasRand, - Z: Evaluator, + EM: UsesState::State>, + F: TestcaseScore<::State>, + M: Mutator::State>, + ::State: HasCorpus + HasMetadata + HasRand, + Z: Evaluator::State>, { /// Creates a new [`PowerMutationalStage`] pub fn new(mutator: M) -> Self { diff --git a/libafl/src/stages/stats.rs b/libafl/src/stages/stats.rs index fdb6282090..61ed96419b 100644 --- a/libafl/src/stages/stats.rs +++ b/libafl/src/stages/stats.rs @@ -24,12 +24,7 @@ use crate::{ /// The [`AflStatsStage`] is a simple stage that computes and reports some stats. #[derive(Debug, Clone)] -pub struct AflStatsStage -where - E: UsesState, - EM: EventFirer, - Z: UsesState, -{ +pub struct AflStatsStage { // the number of testcases that have been fuzzed has_fuzzed_size: usize, // the number of "favored" testcases @@ -49,8 +44,6 @@ where impl UsesState for AflStatsStage where E: UsesState, - EM: EventFirer, - Z: UsesState, { type State = E::State; } @@ -58,15 +51,15 @@ where impl Stage for AflStatsStage where E: UsesState, - EM: EventFirer, - Z: UsesState, - E::State: HasImported + HasCorpus + HasMetadata, + EM: EventFirer, + Z: UsesState, + 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 AflStatsStage -where - E: UsesState, - EM: EventFirer, - Z: UsesState, - E::State: HasImported + HasCorpus + HasMetadata, -{ +impl AflStatsStage { /// create a new instance of the [`AflStatsStage`] #[must_use] pub fn new(interval: Duration) -> Self { @@ -162,13 +149,7 @@ where } } -impl Default for AflStatsStage -where - E: UsesState, - EM: EventFirer, - Z: UsesState, - E::State: HasImported + HasCorpus + HasMetadata, -{ +impl Default for AflStatsStage { /// the default instance of the [`AflStatsStage`] #[must_use] fn default() -> Self { diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 3a83a2fe3e..bf8f416188 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -65,15 +65,12 @@ pub struct SyncFromDiskStage { impl UsesState for SyncFromDiskStage where - E: UsesState, + Z: UsesState, { - type State = E::State; + type State = Z::State; } -impl Named for SyncFromDiskStage -where - E: UsesState, -{ +impl Named for SyncFromDiskStage { fn name(&self) -> &Cow<'static, str> { &self.name } @@ -81,18 +78,18 @@ where impl Stage for SyncFromDiskStage where - CB: FnMut(&mut Z, &mut Z::State, &Path) -> Result<::Input, Error>, - E: UsesState, - EM: UsesState, + CB: FnMut(&mut Z, &mut Self::State, &Path) -> Result<::Input, Error>, + E: UsesState, + EM: UsesState, Z: Evaluator, - 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 SyncFromDiskStage -where - CB: FnMut(&mut Z, &mut Z::State, &Path) -> Result<::Input, Error>, - E: UsesState, - EM: UsesState, - Z: Evaluator, - Z::State: HasCorpus + HasRand + HasMetadata, -{ +impl SyncFromDiskStage { /// Creates a new [`SyncFromDiskStage`] #[must_use] pub fn new(sync_dir: PathBuf, load_callback: CB) -> Self { @@ -232,10 +222,9 @@ pub type SyncFromDiskFunction = impl SyncFromDiskStage, E, EM, Z> where - E: UsesState, - EM: UsesState, + E: UsesState::State>, + EM: UsesState::State>, Z: Evaluator, - 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() { diff --git a/libafl/src/stages/tmin.rs b/libafl/src/stages/tmin.rs index e3850a7565..6135390022 100644 --- a/libafl/src/stages/tmin.rs +++ b/libafl/src/stages/tmin.rs @@ -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: - Stage + FeedbackFactory +pub trait TMinMutationalStage: + Stage + FeedbackFactory where - Self::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize, - ::Input: HasLen + Hash, - CS: Scheduler + RemovableScheduler, - E: Executor + HasObservers, - EM: EventFirer, - F1: Feedback, - F2: Feedback, - M: Mutator, - OT: ObserversTuple, - Z: ExecutionProcessor + E: UsesState + HasObservers, + EM: UsesState + EventFirer, + F: Feedback, + Self::State: HasMaxSize + HasCorpus + HasSolutions + HasExecutions, + Self::Input: MutatedTransform + Clone + Hash + HasLen, + IP: Clone + MutatedTransformPost, + M: Mutator, + Z: UsesState + + HasScheduler + + HasFeedback + ExecutesInput - + HasFeedback - + HasScheduler, - IP: MutatedTransformPost + Clone, - I: MutatedTransform + Clone, + + ExecutionProcessor, + Z::Scheduler: RemovableScheduler, { /// 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; + fn iterations(&self, state: &mut Self::State) -> Result; /// 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; + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result; } /// The default corpus entry minimising mutational stage #[derive(Clone, Debug)] -pub struct StdTMinMutationalStage { +pub struct StdTMinMutationalStage { /// The mutator(s) this stage uses mutator: M, /// The factory @@ -213,41 +212,28 @@ pub struct StdTMinMutationalStage { /// 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 UsesState - for StdTMinMutationalStage +impl UsesState for StdTMinMutationalStage where - CS: Scheduler, - M: Mutator, - Z: ExecutionProcessor, - CS::State: HasCorpus, - IP: MutatedTransformPost + Clone, - I: MutatedTransform + Clone, + Z: UsesState, { - type State = CS::State; + type State = Z::State; } -impl Stage - for StdTMinMutationalStage +impl Stage for StdTMinMutationalStage where - CS: Scheduler + RemovableScheduler, - CS::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize + HasCorpus + HasMetadata, - ::Input: HasLen + Hash, - E: Executor + HasObservers, - EM: EventFirer, - F1: Feedback, - F2: Feedback, - FF: FeedbackFactory, - M: Mutator, - OT: ObserversTuple, - Z: ExecutionProcessor - + ExecutesInput - + HasFeedback - + HasScheduler, - IP: MutatedTransformPost + Clone, - I: MutatedTransform + Clone, + Z: HasScheduler + ExecutionProcessor + ExecutesInput + HasFeedback, + Z::Scheduler: RemovableScheduler, + E: HasObservers, + EM: EventFirer, + FF: FeedbackFactory, + F: Feedback, + Self::Input: MutatedTransform + Clone + HasLen + Hash, + Self::State: HasMetadata + HasExecutions + HasSolutions + HasCorpus + HasMaxSize, + M: Mutator, + IP: MutatedTransformPost + Clone, { fn restart_progress_should_run(&mut self, state: &mut Self::State) -> Result { 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 FeedbackFactory - for StdTMinMutationalStage +impl FeedbackFactory + for StdTMinMutationalStage where - F2: Feedback, - FF: FeedbackFactory, - Z: UsesState, + E: HasObservers, + FF: FeedbackFactory, { - fn create_feedback(&self, ctx: &OT) -> F2 { + fn create_feedback(&self, ctx: &E::Observers) -> F { self.factory.create_feedback(ctx) } } -impl TMinMutationalStage - for StdTMinMutationalStage +impl TMinMutationalStage + for StdTMinMutationalStage where - CS: Scheduler + RemovableScheduler, - E: HasObservers + Executor, - EM: EventFirer, - F1: Feedback, - F2: Feedback, - FF: FeedbackFactory, - ::Input: HasLen + Hash, - M: Mutator, - OT: ObserversTuple, - CS::State: HasCorpus + HasSolutions + HasExecutions + HasMaxSize + HasMetadata, - Z: ExecutionProcessor - + ExecutesInput - + HasFeedback - + HasScheduler, - IP: MutatedTransformPost + Clone, - I: MutatedTransform + Clone, + Z: HasScheduler + ExecutionProcessor + ExecutesInput + HasFeedback, + Z::Scheduler: RemovableScheduler, + E: HasObservers, + EM: EventFirer, + FF: FeedbackFactory, + F: Feedback, + Self::Input: MutatedTransform + Clone + HasLen + Hash, + Self::State: HasMetadata + HasExecutions + HasSolutions + HasCorpus + HasMaxSize, + M: Mutator, + IP: MutatedTransformPost + 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 { + fn iterations(&self, _state: &mut Self::State) -> Result { Ok(self.runs) } - fn execs_since_progress_start(&mut self, state: &mut ::State) -> Result { + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result { self.restart_helper.execs_since_progress_start(state) } } -impl - StdTMinMutationalStage -where - CS: Scheduler, - M: Mutator, - Z: ExecutionProcessor, - CS::State: HasCorpus, - IP: MutatedTransformPost + Clone, - I: MutatedTransform + Clone, -{ +impl StdTMinMutationalStage { /// 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 HasObserverHandle for MapEqualityFactory { } } -impl FeedbackFactory, S, OT> - for MapEqualityFactory +impl FeedbackFactory, OT> for MapEqualityFactory where M: MapObserver, C: AsRef + Handled, OT: ObserversTuple, - S: State + Debug, + S: UsesInput, { fn create_feedback(&self, observers: &OT) -> MapEqualityFeedback { let obs = observers diff --git a/libafl/src/stages/tracing.rs b/libafl/src/stages/tracing.rs index 0bc40360a1..14127ac69e 100644 --- a/libafl/src/stages/tracing.rs +++ b/libafl/src/stages/tracing.rs @@ -36,9 +36,9 @@ where impl TracingStage where TE: Executor + HasObservers, - TE::State: HasExecutions + HasCorpus + HasNamedMetadata, - EM: UsesState, - Z: UsesState, + ::State: HasExecutions + HasCorpus + HasNamedMetadata, + EM: UsesState::State>, + Z: 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 ::State, manager: &mut EM, ) -> Result<(), Error> { start_timer!(state); @@ -80,18 +80,18 @@ where impl Stage for TracingStage where - E: UsesState, + E: UsesState::State>, TE: Executor + HasObservers, - TE::State: HasExecutions + HasCorpus + HasNamedMetadata, - EM: UsesState, - Z: UsesState, + ::State: HasExecutions + HasCorpus + HasNamedMetadata, + EM: UsesState::State>, + Z: UsesState::State>, { #[inline] fn perform( &mut self, fuzzer: &mut Z, _executor: &mut E, - state: &mut TE::State, + state: &mut ::State, manager: &mut EM, ) -> Result<(), Error> { self.trace(fuzzer, state, manager) @@ -170,17 +170,17 @@ where impl Stage, EM, Z> for ShadowTracingStage where E: Executor + HasObservers, - EM: UsesState, + EM: UsesState::State>, SOT: ObserversTuple, - Z: UsesState, - E::State: State + HasExecutions + HasCorpus + HasNamedMetadata + Debug, + Z: UsesState::State>, + ::State: State + HasExecutions + HasCorpus + HasNamedMetadata + Debug, { #[inline] fn perform( &mut self, fuzzer: &mut Z, executor: &mut ShadowExecutor, - state: &mut E::State, + state: &mut ::State, manager: &mut EM, ) -> Result<(), Error> { start_timer!(state); @@ -225,10 +225,10 @@ where impl ShadowTracingStage where E: Executor + HasObservers, - E::State: State + HasExecutions + HasCorpus, - EM: UsesState, + ::State: State + HasExecutions + HasCorpus, + EM: UsesState::State>, SOT: ObserversTuple, - Z: UsesState, + Z: UsesState::State>, { /// Creates a new default stage pub fn new(_executor: &mut ShadowExecutor) -> Self { diff --git a/libafl/src/stages/tuneable.rs b/libafl/src/stages/tuneable.rs index 7ed57a880e..8e58ef5509 100644 --- a/libafl/src/stages/tuneable.rs +++ b/libafl/src/stages/tuneable.rs @@ -160,12 +160,12 @@ pub struct TuneableMutationalStage { impl MutationalStage for TuneableMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState, + EM: UsesState, + M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, - I: MutatedTransform + Clone, + Self::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, + I: MutatedTransform + 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 { + fn iterations(&self, state: &mut Self::State) -> Result { Ok( // fall back to random 1 + state.rand_mut().below(DEFAULT_MUTATIONAL_MAX_ITERATIONS), ) } - fn execs_since_progress_start(&mut self, state: &mut ::State) -> Result { + fn execs_since_progress_start(&mut self, state: &mut Self::State) -> Result { self.restart_helper.execs_since_progress_start(state) } } impl UsesState for TuneableMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasExecutions, - I: MutatedTransform + Clone, { type State = Z::State; } impl Stage for TuneableMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState, + EM: UsesState, + M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, - I: MutatedTransform + Clone, + Self::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, + I: MutatedTransform + 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 TuneableMutationalStage where - E: UsesState, - EM: UsesState, - M: Mutator, + E: UsesState::State>, + EM: UsesState::State>, + M: Mutator::State>, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, - I: MutatedTransform + Clone, + ::State: + HasCorpus + HasRand + HasNamedMetadata + HasMetadata + HasExecutions, + I: MutatedTransform::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 ::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 ::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 ::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, Error> { + pub fn iters_std(state: &::State) -> Result, 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 ::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, Error> { + pub fn seed_fuzz_time_std( + &self, + state: &::State, + ) -> Result, 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 ::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 ::State, manager: &mut EM, input: &I, ) -> Result<(), Error> { @@ -467,15 +469,15 @@ where impl TuneableMutationalStage where - E: UsesState, - EM: UsesState, + E: UsesState::State>, + EM: UsesState::State>, M: Mutator, Z: Evaluator, - Z::State: HasCorpus + HasRand + HasNamedMetadata, + ::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 ::State, mutator: M, name: &str) -> Self { let _ = state.named_metadata_or_insert_with(name, TuneableMutationalStageMetadata::default); Self { mutator, diff --git a/libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml b/libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml index dbd7e95029..97178a8453 100644 --- a/libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml +++ b/libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml @@ -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" diff --git a/libafl_targets/src/cmps/stages/aflpptracing.rs b/libafl_targets/src/cmps/stages/aflpptracing.rs index 877385cb95..790fb4bbcd 100644 --- a/libafl_targets/src/cmps/stages/aflpptracing.rs +++ b/libafl_targets/src/cmps/stages/aflpptracing.rs @@ -23,7 +23,7 @@ where TE: UsesState, { tracer_executor: TE, - cmplog_observer_handle: Option>>, + cmplog_observer_handle: Option::State>>>, #[allow(clippy::type_complexity)] phantom: PhantomData<(EM, TE, Z)>, } @@ -47,12 +47,12 @@ where impl Stage for AFLppCmplogTracingStage<'_, EM, TE, Z> where - E: UsesState, + E: UsesState, TE: Executor + HasObservers, - TE::State: + Self::State: HasExecutions + HasCorpus + HasMetadata + UsesInput + HasNamedMetadata, - EM: UsesState, - Z: UsesState, + EM: UsesState, + Z: UsesState, { #[inline] fn perform(