diff --git a/fuzzers/push_stage_harness/src/main.rs b/fuzzers/push_stage_harness/src/main.rs index 840fd01978..f2fed619bc 100644 --- a/fuzzers/push_stage_harness/src/main.rs +++ b/fuzzers/push_stage_harness/src/main.rs @@ -41,7 +41,7 @@ pub fn main() { let feedback_state = MapFeedbackState::with_observer(&observer); // Feedback to rate the interestingness of an input - let feedback = MaxMapFeedback::<_, BytesInput, _, _, _>::new(&feedback_state, &observer); + let feedback = MaxMapFeedback::::new(&feedback_state, &observer); // A feedback to choose if an input is a solution or not let objective = CrashFeedback::new(); diff --git a/fuzzers/tutorial/src/metadata.rs b/fuzzers/tutorial/src/metadata.rs index 4ec380751c..e41fc8dec8 100644 --- a/fuzzers/tutorial/src/metadata.rs +++ b/fuzzers/tutorial/src/metadata.rs @@ -29,8 +29,8 @@ impl FavFactor for PacketLenFavFactor { } } -pub type PacketLenMinimizerCorpusScheduler = - MinimizerCorpusScheduler; +pub type PacketLenMinimizerCorpusScheduler = + MinimizerCorpusScheduler; #[derive(Serialize, Deserialize, Default, Clone, Debug)] pub struct PacketLenFeedback { diff --git a/fuzzers/tutorial/src/mutator.rs b/fuzzers/tutorial/src/mutator.rs index d560967b2a..836edd8f57 100644 --- a/fuzzers/tutorial/src/mutator.rs +++ b/fuzzers/tutorial/src/mutator.rs @@ -10,23 +10,13 @@ use libafl::{ use crate::input::PacketData; -use core::marker::PhantomData; use lain::traits::Mutatable; -pub struct LainMutator -where - S: HasRand, - R: Rand, -{ +pub struct LainMutator { inner: lain::mutator::Mutator, - phantom: PhantomData<*const (R, S)>, } -impl Mutator for LainMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for LainMutator { fn mutate( &mut self, state: &mut S, @@ -40,35 +30,22 @@ where } } -impl Named for LainMutator -where - S: HasRand, - R: Rand, -{ +impl Named for LainMutator { fn name(&self) -> &str { "LainMutator" } } -impl LainMutator -where - S: HasRand, - R: Rand, -{ +impl LainMutator { #[must_use] pub fn new() -> Self { Self { inner: lain::mutator::Mutator::new(StdRand::with_seed(0)), - phantom: PhantomData, } } } -impl Default for LainMutator -where - S: HasRand, - R: Rand, -{ +impl Default for LainMutator { #[must_use] fn default() -> Self { Self::new() diff --git a/libafl/src/corpus/minimizer.rs b/libafl/src/corpus/minimizer.rs index e6b661fad2..5db16136c1 100644 --- a/libafl/src/corpus/minimizer.rs +++ b/libafl/src/corpus/minimizer.rs @@ -81,29 +81,26 @@ where /// corpus that exercise all the requested features (e.g. all the coverage seen so far) /// prioritizing [`Testcase`]`s` using [`FavFactor`] #[derive(Debug, Clone)] -pub struct MinimizerCorpusScheduler +pub struct MinimizerCorpusScheduler where CS: CorpusScheduler, F: FavFactor, I: Input, M: AsSlice + SerdeAny + HasRefCnt, - S: HasCorpus + HasMetadata, - C: Corpus, + S: HasCorpus + HasMetadata, { base: CS, skip_non_favored_prob: u64, - phantom: PhantomData<(C, F, I, M, R, S)>, + phantom: PhantomData<(F, I, M, S)>, } -impl CorpusScheduler for MinimizerCorpusScheduler +impl CorpusScheduler for MinimizerCorpusScheduler where CS: CorpusScheduler, F: FavFactor, I: Input, M: AsSlice + SerdeAny + HasRefCnt, - S: HasCorpus + HasMetadata + HasRand, - C: Corpus, - R: Rand, + S: HasCorpus + HasMetadata + HasRand, { /// Add an entry to the corpus and return its index fn on_add(&self, state: &mut S, idx: usize) -> Result<(), Error> { @@ -145,15 +142,13 @@ where } } -impl MinimizerCorpusScheduler +impl MinimizerCorpusScheduler where CS: CorpusScheduler, F: FavFactor, I: Input, M: AsSlice + SerdeAny + HasRefCnt, - S: HasCorpus + HasMetadata + HasRand, - C: Corpus, - R: Rand, + S: HasCorpus + HasMetadata + HasRand, { /// Update the `Corpus` score using the `MinimizerCorpusScheduler` #[allow(clippy::unused_self)] @@ -284,10 +279,10 @@ where } /// A [`MinimizerCorpusScheduler`] with [`LenTimeMulFavFactor`] to prioritize quick and small [`Testcase`]`s`. -pub type LenTimeMinimizerCorpusScheduler = - MinimizerCorpusScheduler, I, M, R, S>; +pub type LenTimeMinimizerCorpusScheduler = + MinimizerCorpusScheduler, I, M, S>; /// A [`MinimizerCorpusScheduler`] with [`LenTimeMulFavFactor`] to prioritize quick and small [`Testcase`]`s` /// that exercise all the entries registered in the [`MapIndexesMetadata`]. -pub type IndexesLenTimeMinimizerCorpusScheduler = - MinimizerCorpusScheduler, I, MapIndexesMetadata, R, S>; +pub type IndexesLenTimeMinimizerCorpusScheduler = + MinimizerCorpusScheduler, I, MapIndexesMetadata, S>; diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index 77a0b30d35..a474c16480 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -30,7 +30,7 @@ pub mod powersched; pub use powersched::PowerQueueCorpusScheduler; use alloc::borrow::ToOwned; -use core::{cell::RefCell, marker::PhantomData}; +use core::cell::RefCell; use crate::{ bolts::rands::Rand, @@ -108,22 +108,12 @@ where /// Feed the fuzzer simpply with a random testcase on request #[derive(Debug, Clone)] -pub struct RandCorpusScheduler -where - S: HasCorpus + HasRand, - C: Corpus, - I: Input, - R: Rand, -{ - phantom: PhantomData<(C, I, R, S)>, -} +pub struct RandCorpusScheduler; -impl CorpusScheduler for RandCorpusScheduler +impl CorpusScheduler for RandCorpusScheduler where - S: HasCorpus + HasRand, - C: Corpus, + S: HasCorpus + HasRand, I: Input, - R: Rand, { /// Gets the next entry at random fn next(&self, state: &mut S) -> Result { @@ -138,29 +128,15 @@ where } } -impl RandCorpusScheduler -where - S: HasCorpus + HasRand, - C: Corpus, - I: Input, - R: Rand, -{ +impl RandCorpusScheduler { /// Create a new [`RandCorpusScheduler`] that just schedules randomly. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } -impl Default for RandCorpusScheduler -where - S: HasCorpus + HasRand, - C: Corpus, - I: Input, - R: Rand, -{ +impl Default for RandCorpusScheduler { fn default() -> Self { Self::new() } @@ -168,4 +144,4 @@ where /// A [`StdCorpusScheduler`] uses the default scheduler in `LibAFL` to schedule [`Testcase`]s /// The current `Std` is a [`RandCorpusScheduler`], although this may change in the future, if another [`CorpusScheduler`] delivers better results. -pub type StdCorpusScheduler = RandCorpusScheduler; +pub type StdCorpusScheduler = RandCorpusScheduler; diff --git a/libafl/src/corpus/powersched.rs b/libafl/src/corpus/powersched.rs index 987ff55460..8d837508ea 100644 --- a/libafl/src/corpus/powersched.rs +++ b/libafl/src/corpus/powersched.rs @@ -1,7 +1,6 @@ //! The queue corpus scheduler for power schedules. use alloc::string::{String, ToString}; -use core::marker::PhantomData; use crate::{ corpus::{Corpus, CorpusScheduler, PowerScheduleTestcaseMetaData}, @@ -13,30 +12,17 @@ use crate::{ /// A corpus scheduler using power schedules #[derive(Clone, Debug)] -pub struct PowerQueueCorpusScheduler -where - S: HasCorpus + HasMetadata, - C: Corpus, - I: Input, -{ - phantom: PhantomData<(C, I, S)>, -} +pub struct PowerQueueCorpusScheduler; -impl Default for PowerQueueCorpusScheduler -where - S: HasCorpus + HasMetadata, - C: Corpus, - I: Input, -{ +impl Default for PowerQueueCorpusScheduler { fn default() -> Self { Self::new() } } -impl CorpusScheduler for PowerQueueCorpusScheduler +impl CorpusScheduler for PowerQueueCorpusScheduler where - S: HasCorpus + HasMetadata, - C: Corpus, + S: HasCorpus + HasMetadata, I: Input, { /// Add an entry to the corpus and return its index @@ -92,17 +78,10 @@ where } } -impl PowerQueueCorpusScheduler -where - S: HasCorpus + HasMetadata, - C: Corpus, - I: Input, -{ +impl PowerQueueCorpusScheduler { /// Create a new [`PowerQueueCorpusScheduler`] #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } diff --git a/libafl/src/corpus/queue.rs b/libafl/src/corpus/queue.rs index d434d1ab93..96a9bbfd39 100644 --- a/libafl/src/corpus/queue.rs +++ b/libafl/src/corpus/queue.rs @@ -1,7 +1,6 @@ //! The queue corpus scheduler implements an AFL-like queue mechanism use alloc::borrow::ToOwned; -use core::marker::PhantomData; use crate::{ corpus::{Corpus, CorpusScheduler}, @@ -12,19 +11,11 @@ use crate::{ /// Walk the corpus in a queue-like fashion #[derive(Debug, Clone)] -pub struct QueueCorpusScheduler -where - S: HasCorpus, - C: Corpus, - I: Input, -{ - phantom: PhantomData<(C, I, S)>, -} +pub struct QueueCorpusScheduler; -impl CorpusScheduler for QueueCorpusScheduler +impl CorpusScheduler for QueueCorpusScheduler where - S: HasCorpus, - C: Corpus, + S: HasCorpus, I: Input, { /// Gets the next entry in the queue @@ -48,27 +39,15 @@ where } } -impl QueueCorpusScheduler -where - S: HasCorpus, - C: Corpus, - I: Input, -{ +impl QueueCorpusScheduler { /// Creates a new `QueueCorpusScheduler` #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } -impl Default for QueueCorpusScheduler -where - S: HasCorpus, - C: Corpus, - I: Input, -{ +impl Default for QueueCorpusScheduler { fn default() -> Self { Self::new() } diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index c4197aa196..6c65301022 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -11,10 +11,7 @@ use crate::{ }; use alloc::{string::ToString, vec::Vec}; #[cfg(feature = "std")] -use core::{ - marker::PhantomData, - sync::atomic::{compiler_fence, Ordering}, -}; +use core::sync::atomic::{compiler_fence, Ordering}; #[cfg(feature = "std")] use serde::{de::DeserializeOwned, Serialize}; @@ -232,11 +229,9 @@ where #[cfg(feature = "std")] #[allow(clippy::default_trait_access)] #[derive(Debug, Clone)] -pub struct SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +pub struct SimpleRestartingEventManager where - C: Corpus, I: Input, - S: Serialize, SP: ShMemProvider, MT: Monitor, //CE: CustomEvent, { @@ -244,17 +239,12 @@ where simple_event_mgr: SimpleEventManager, /// [`StateRestorer`] for restarts staterestorer: StateRestorer, - /// Phantom data - _phantom: PhantomData<&'a (C, I, S, SC)>, } #[cfg(feature = "std")] -impl<'a, C, I, MT, S, SC, SP> EventFirer - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl EventFirer for SimpleRestartingEventManager where - C: Corpus, I: Input, - S: Serialize, SP: ShMemProvider, MT: Monitor, //CE: CustomEvent, { @@ -264,10 +254,8 @@ where } #[cfg(feature = "std")] -impl<'a, C, I, MT, S, SC, SP> EventRestarter - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl EventRestarter for SimpleRestartingEventManager where - C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, @@ -282,10 +270,8 @@ where } #[cfg(feature = "std")] -impl<'a, C, E, I, MT, S, SC, SP, Z> EventProcessor - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl EventProcessor for SimpleRestartingEventManager where - C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, @@ -297,10 +283,8 @@ where } #[cfg(feature = "std")] -impl<'a, C, E, I, MT, S, SC, SP, Z> EventManager - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl EventManager for SimpleRestartingEventManager where - C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, @@ -309,24 +293,18 @@ where } #[cfg(feature = "std")] -impl<'a, C, I, MT, S, SC, SP> ProgressReporter - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl ProgressReporter for SimpleRestartingEventManager where I: Input, - C: Corpus, - S: Serialize, SP: ShMemProvider, MT: Monitor, //CE: CustomEvent, { } #[cfg(feature = "std")] -impl<'a, C, I, MT, S, SC, SP> HasEventManagerId - for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl HasEventManagerId for SimpleRestartingEventManager where - C: Corpus, I: Input, - S: Serialize, SP: ShMemProvider, MT: Monitor, { @@ -337,12 +315,9 @@ where #[cfg(feature = "std")] #[allow(clippy::type_complexity, clippy::too_many_lines)] -impl<'a, C, I, MT, S, SC, SP> SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> +impl<'a, I, MT, SP> SimpleRestartingEventManager where - C: Corpus, I: Input, - S: DeserializeOwned + Serialize + HasCorpus + HasSolutions, - SC: Corpus, SP: ShMemProvider, MT: Monitor, //TODO CE: CustomEvent, { @@ -351,7 +326,6 @@ where Self { staterestorer, simple_event_mgr: SimpleEventManager::new(monitor), - _phantom: PhantomData {}, } } @@ -359,7 +333,10 @@ where /// This [`EventManager`] is simple and single threaded, /// but can still used shared maps to recover from crashes and timeouts. #[allow(clippy::similar_names)] - pub fn launch(mut monitor: MT, shmem_provider: &mut SP) -> Result<(Option, Self), Error> { + pub fn launch(mut monitor: MT, shmem_provider: &mut SP) -> Result<(Option, Self), Error> + where + S: DeserializeOwned + Serialize + HasCorpus + HasSolutions, + { // We start ourself as child process to actually fuzz let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() { // First, create a place to store state in, for restarts. diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 03c5531dce..2d177ca3e4 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -34,7 +34,6 @@ use crate::bolts::os::windows_exceptions::setup_exception_handler; use windows::Win32::System::Threading::SetThreadStackGuarantee; use crate::{ - corpus::Corpus, events::{EventFirer, EventRestarter}, executors::{Executor, ExitKind, HasObservers}, feedbacks::Feedback, @@ -127,7 +126,7 @@ where /// * `harness_fn` - the harness, executiong the function /// * `observers` - the observers observing the target during execution /// This may return an error on unix, if signal handler setup fails - pub fn new( + pub fn new( harness_fn: &'a mut H, observers: OT, _fuzzer: &mut Z, @@ -136,12 +135,11 @@ where ) -> Result where EM: EventFirer + EventRestarter, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { - let handlers = InProcessHandlers::new::()?; + let handlers = InProcessHandlers::new::()?; #[cfg(windows)] unsafe { /* @@ -267,15 +265,14 @@ impl InProcessHandlers { } /// Create new [`InProcessHandlers`]. - pub fn new() -> Result + pub fn new() -> Result where I: Input, E: HasObservers, OT: ObserversTuple, EM: EventFirer + EventRestarter, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { #[cfg(unix)] @@ -285,18 +282,10 @@ impl InProcessHandlers { compiler_fence(Ordering::SeqCst); Ok(Self { - crash_handler: unix_signal_handler::inproc_crash_handler:: + crash_handler: unix_signal_handler::inproc_crash_handler:: + as *const _, + timeout_handler: unix_signal_handler::inproc_timeout_handler:: as *const _, - timeout_handler: unix_signal_handler::inproc_timeout_handler::< - E, - EM, - I, - OC, - OF, - OT, - S, - Z, - > as *const _, }) } #[cfg(all(windows, feature = "std"))] @@ -310,7 +299,6 @@ impl InProcessHandlers { E, EM, I, - OC, OF, OT, S, @@ -320,7 +308,6 @@ impl InProcessHandlers { E, EM, I, - OC, OF, OT, S, @@ -493,7 +480,7 @@ mod unix_signal_handler { } #[cfg(unix)] - pub unsafe fn inproc_timeout_handler( + pub unsafe fn inproc_timeout_handler( _signal: Signal, _info: siginfo_t, _context: &mut ucontext_t, @@ -502,9 +489,8 @@ mod unix_signal_handler { E: HasObservers, EM: EventFirer + EventRestarter, OT: ObserversTuple, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -571,7 +557,7 @@ mod unix_signal_handler { /// Will be used for signal handling. /// It will store the current State to shmem, then exit. #[allow(clippy::too_many_lines)] - pub unsafe fn inproc_crash_handler( + pub unsafe fn inproc_crash_handler( signal: Signal, _info: siginfo_t, _context: &mut ucontext_t, @@ -580,9 +566,8 @@ mod unix_signal_handler { E: HasObservers, EM: EventFirer + EventRestarter, OT: ObserversTuple, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -748,7 +733,7 @@ mod windows_exception_handler { EnterCriticalSection, LeaveCriticalSection, RTL_CRITICAL_SECTION, }; - pub unsafe extern "system" fn inproc_timeout_handler( + pub unsafe extern "system" fn inproc_timeout_handler( _p0: *mut u8, global_state: *mut c_void, _p1: *mut u8, @@ -756,9 +741,8 @@ mod windows_exception_handler { E: HasObservers, EM: EventFirer + EventRestarter, OT: ObserversTuple, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -847,16 +831,15 @@ mod windows_exception_handler { // println!("TIMER INVOKED!"); } - pub unsafe fn inproc_crash_handler( + pub unsafe fn inproc_crash_handler( exception_pointers: *mut EXCEPTION_POINTERS, data: &mut InProcessExecutorHandlerData, ) where E: HasObservers, EM: EventFirer + EventRestarter, OT: ObserversTuple, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -1085,7 +1068,7 @@ where SP: ShMemProvider, { /// Creates a new [`InProcessForkExecutor`] - pub fn new( + pub fn new( harness_fn: &'a mut H, observers: OT, _fuzzer: &mut Z, @@ -1095,9 +1078,8 @@ where ) -> Result where EM: EventFirer + EventRestarter, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { Ok(Self { diff --git a/libafl/src/feedbacks/map.rs b/libafl/src/feedbacks/map.rs index 2fd6e24c5a..8abf2dd24d 100644 --- a/libafl/src/feedbacks/map.rs +++ b/libafl/src/feedbacks/map.rs @@ -9,11 +9,14 @@ use num_traits::PrimInt; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{tuples::Named, AsSlice, HasRefCnt}, + bolts::{ + tuples::{MatchName, Named}, + AsSlice, HasRefCnt, + }, corpus::Testcase, events::{Event, EventFirer}, executors::ExitKind, - feedbacks::{Feedback, FeedbackState, FeedbackStatesTuple}, + feedbacks::{Feedback, FeedbackState}, inputs::Input, monitors::UserStats, observers::{MapObserver, ObserversTuple}, @@ -22,21 +25,20 @@ use crate::{ }; /// A [`MapFeedback`] that implements the AFL algorithm using an [`OrReducer`] combining the bits for the history map and the bit from ``HitcountsMapObserver``. -pub type AflMapFeedback = MapFeedback; +pub type AflMapFeedback = MapFeedback; /// A [`MapFeedback`] that strives to maximize the map contents. -pub type MaxMapFeedback = MapFeedback; +pub type MaxMapFeedback = MapFeedback; /// A [`MapFeedback`] that strives to minimize the map contents. -pub type MinMapFeedback = MapFeedback; +pub type MinMapFeedback = MapFeedback; /// A [`MapFeedback`] that strives to maximize the map contents, /// but only, if a value is larger than `pow2` of the previous. -pub type MaxMapPow2Feedback = - MapFeedback; +pub type MaxMapPow2Feedback = MapFeedback; /// A [`MapFeedback`] that strives to maximize the map contents, /// but only, if a value is larger than `pow2` of the previous. -pub type MaxMapOneOrFilledFeedback = - MapFeedback; +pub type MaxMapOneOrFilledFeedback = + MapFeedback; /// A `Reducer` function is used to aggregate values for the novelty search pub trait Reducer: Serialize + serde::de::DeserializeOwned + 'static + Debug @@ -329,14 +331,13 @@ where /// The most common AFL-like feedback type #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(bound = "T: serde::de::DeserializeOwned")] -pub struct MapFeedback +pub struct MapFeedback where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, R: Reducer, O: MapObserver, N: IsNovel, - S: HasFeedbackStates, - FT: FeedbackStatesTuple, + S: HasFeedbackStates, { /// Indexes used in the last observation indexes: Option>, @@ -347,18 +348,17 @@ where /// Name identifier of the observer observer_name: String, /// Phantom Data of Reducer - phantom: PhantomData<(FT, I, N, S, R, O, T)>, + phantom: PhantomData<(I, N, S, R, O, T)>, } -impl Feedback for MapFeedback +impl Feedback for MapFeedback where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, R: Reducer, O: MapObserver, N: IsNovel, I: Input, - S: HasFeedbackStates + HasClientPerfMonitor + Debug, - FT: FeedbackStatesTuple, + S: HasFeedbackStates + HasClientPerfMonitor + Debug, { fn is_interesting( &mut self, @@ -459,14 +459,13 @@ where } } -impl Named for MapFeedback +impl Named for MapFeedback where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, R: Reducer, N: IsNovel, O: MapObserver, - S: HasFeedbackStates, - FT: FeedbackStatesTuple, + S: HasFeedbackStates, { #[inline] fn name(&self) -> &str { @@ -474,7 +473,7 @@ where } } -impl MapFeedback +impl MapFeedback where T: PrimInt + Default @@ -487,8 +486,7 @@ where R: Reducer, N: IsNovel, O: MapObserver, - S: HasFeedbackStates, - FT: FeedbackStatesTuple, + S: HasFeedbackStates, { /// Create new `MapFeedback` #[must_use] diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index e8d3d4476a..cc049bd84c 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -233,7 +233,7 @@ pub enum ExecuteInputResult { /// Your default fuzzer instance, for everyday use. #[derive(Debug)] -pub struct StdFuzzer +pub struct StdFuzzer where CS: CorpusScheduler, F: Feedback, @@ -244,11 +244,10 @@ where scheduler: CS, feedback: F, objective: OF, - phantom: PhantomData<(C, I, OT, S, SC)>, + phantom: PhantomData<(I, OT, S)>, } -impl HasCorpusScheduler - for StdFuzzer +impl HasCorpusScheduler for StdFuzzer where CS: CorpusScheduler, F: Feedback, @@ -265,7 +264,7 @@ where } } -impl HasFeedback for StdFuzzer +impl HasFeedback for StdFuzzer where CS: CorpusScheduler, F: Feedback, @@ -282,7 +281,7 @@ where } } -impl HasObjective for StdFuzzer +impl HasObjective for StdFuzzer where CS: CorpusScheduler, F: Feedback, @@ -299,17 +298,14 @@ where } } -impl ExecutionProcessor - for StdFuzzer +impl ExecutionProcessor for StdFuzzer where - C: Corpus, - SC: Corpus, CS: CorpusScheduler, F: Feedback, I: Input, OF: Feedback, OT: ObserversTuple + serde::Serialize + serde::de::DeserializeOwned, - S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, + S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, { /// Evaluate if a set of observation channels has an interesting state fn process_execution( @@ -416,17 +412,14 @@ where } } -impl EvaluatorObservers - for StdFuzzer +impl EvaluatorObservers for StdFuzzer where - C: Corpus, CS: CorpusScheduler, OT: ObserversTuple + serde::Serialize + serde::de::DeserializeOwned, F: Feedback, I: Input, OF: Feedback, - S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, - SC: Corpus, + S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, { /// Process one input, adding to the respective corpuses if needed and firing the right events #[inline] @@ -448,10 +441,8 @@ where } } -impl Evaluator - for StdFuzzer +impl Evaluator for StdFuzzer where - C: Corpus, CS: CorpusScheduler, E: Executor + HasObservers, OT: ObserversTuple + serde::Serialize + serde::de::DeserializeOwned, @@ -459,8 +450,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, - SC: Corpus, + S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, { /// Process one input, adding to the respective corpuses if needed and firing the right events #[inline] @@ -517,8 +507,7 @@ where } } -impl Fuzzer - for StdFuzzer +impl Fuzzer for StdFuzzer where CS: CorpusScheduler, EM: EventManager, @@ -568,7 +557,7 @@ where } } -impl StdFuzzer +impl StdFuzzer where CS: CorpusScheduler, F: Feedback, @@ -635,8 +624,7 @@ where OT: ObserversTuple; } -impl ExecutesInput - for StdFuzzer +impl ExecutesInput for StdFuzzer where CS: CorpusScheduler, F: Feedback, diff --git a/libafl/src/generators/gramatron.rs b/libafl/src/generators/gramatron.rs index c14cfbec30..13697f6b69 100644 --- a/libafl/src/generators/gramatron.rs +++ b/libafl/src/generators/gramatron.rs @@ -33,19 +33,17 @@ pub struct Automaton { #[derive(Clone, Debug)] /// Generates random inputs from a grammar automatron -pub struct GramatronGenerator<'a, R, S> +pub struct GramatronGenerator<'a, S> where - R: Rand, - S: HasRand, + S: HasRand, { automaton: &'a Automaton, - phantom: PhantomData<(R, S)>, + phantom: PhantomData, } -impl<'a, R, S> Generator for GramatronGenerator<'a, R, S> +impl<'a, S> Generator for GramatronGenerator<'a, S> where - R: Rand, - S: HasRand, + S: HasRand, { fn generate(&mut self, state: &mut S) -> Result { let mut input = GramatronInput::new(vec![]); @@ -58,10 +56,9 @@ where } } -impl<'a, R, S> GramatronGenerator<'a, R, S> +impl<'a, S> GramatronGenerator<'a, S> where - R: Rand, - S: HasRand, + S: HasRand, { /// Returns a new [`GramatronGenerator`] #[must_use] diff --git a/libafl/src/generators/mod.rs b/libafl/src/generators/mod.rs index 42d90d567b..e9871be5a3 100644 --- a/libafl/src/generators/mod.rs +++ b/libafl/src/generators/mod.rs @@ -35,19 +35,17 @@ where #[derive(Clone, Debug)] /// Generates random bytes -pub struct RandBytesGenerator +pub struct RandBytesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { max_size: usize, - phantom: PhantomData<(R, S)>, + phantom: PhantomData, } -impl Generator for RandBytesGenerator +impl Generator for RandBytesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { fn generate(&mut self, state: &mut S) -> Result { let mut size = state.rand_mut().below(self.max_size as u64); @@ -67,10 +65,9 @@ where } } -impl RandBytesGenerator +impl RandBytesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { /// Returns a new [`RandBytesGenerator`], generating up to `max_size` random bytes. #[must_use] @@ -84,19 +81,17 @@ where #[derive(Clone, Debug)] /// Generates random printable characters -pub struct RandPrintablesGenerator +pub struct RandPrintablesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { max_size: usize, - phantom: PhantomData<(R, S)>, + phantom: PhantomData, } -impl Generator for RandPrintablesGenerator +impl Generator for RandPrintablesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { fn generate(&mut self, state: &mut S) -> Result { let mut size = state.rand_mut().below(self.max_size as u64); @@ -117,10 +112,9 @@ where } } -impl RandPrintablesGenerator +impl RandPrintablesGenerator where - R: Rand, - S: HasRand, + S: HasRand, { /// Creates a new [`RandPrintablesGenerator`], generating up to `max_size` random printable characters. #[must_use] diff --git a/libafl/src/mutators/encoded_mutations.rs b/libafl/src/mutators/encoded_mutations.rs index 6e8d8c678a..89ef123dde 100644 --- a/libafl/src/mutators/encoded_mutations.rs +++ b/libafl/src/mutators/encoded_mutations.rs @@ -1,10 +1,7 @@ //! Mutations for [`EncodedInput`]s //! use alloc::vec::Vec; -use core::{ - cmp::{max, min}, - marker::PhantomData, -}; +use core::cmp::{max, min}; use crate::{ bolts::{ @@ -23,19 +20,9 @@ use crate::{ /// Set a code in the input as a random value #[derive(Debug, Default)] -pub struct EncodedRandMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedRandMutator; -impl Mutator for EncodedRandMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedRandMutator { fn mutate( &mut self, state: &mut S, @@ -52,45 +39,25 @@ where } } -impl Named for EncodedRandMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedRandMutator { fn name(&self) -> &str { "EncodedRandMutator" } } -impl EncodedRandMutator -where - S: HasRand, - R: Rand, -{ +impl EncodedRandMutator { /// Creates a new [`EncodedRandMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Increment a random code in the input #[derive(Debug, Default)] -pub struct EncodedIncMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedIncMutator; -impl Mutator for EncodedIncMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedIncMutator { fn mutate( &mut self, state: &mut S, @@ -107,45 +74,25 @@ where } } -impl Named for EncodedIncMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedIncMutator { fn name(&self) -> &str { "EncodedIncMutator" } } -impl EncodedIncMutator -where - S: HasRand, - R: Rand, -{ - /// Creates a new [`EncodedRandMutator`]. +impl EncodedIncMutator { + /// Creates a new [`EncodedIncMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Decrement a random code in the input #[derive(Debug, Default)] -pub struct EncodedDecMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedDecMutator; -impl Mutator for EncodedDecMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedDecMutator { fn mutate( &mut self, state: &mut S, @@ -162,45 +109,25 @@ where } } -impl Named for EncodedDecMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedDecMutator { fn name(&self) -> &str { "EncodedDecMutator" } } -impl EncodedDecMutator -where - S: HasRand, - R: Rand, -{ - /// Creates a new [`EncodedRandMutator`]. +impl EncodedDecMutator { + /// Creates a new [`EncodedDecMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Adds or subtracts a random value up to `ARITH_MAX` to a random place in the codes [`Vec`]. #[derive(Debug, Default)] -pub struct EncodedAddMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedAddMutator; -impl Mutator for EncodedAddMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedAddMutator { fn mutate( &mut self, state: &mut S, @@ -221,45 +148,25 @@ where } } -impl Named for EncodedAddMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedAddMutator { fn name(&self) -> &str { "EncodedAddMutator" } } -impl EncodedAddMutator -where - S: HasRand, - R: Rand, -{ +impl EncodedAddMutator { /// Creates a new [`EncodedAddMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Codes delete mutation for encoded inputs #[derive(Debug, Default)] -pub struct EncodedDeleteMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedDeleteMutator; -impl Mutator for EncodedDeleteMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedDeleteMutator { fn mutate( &mut self, state: &mut S, @@ -279,45 +186,29 @@ where } } -impl Named for EncodedDeleteMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedDeleteMutator { fn name(&self) -> &str { "EncodedDeleteMutator" } } -impl EncodedDeleteMutator -where - S: HasRand, - R: Rand, -{ +impl EncodedDeleteMutator { /// Creates a new [`EncodedDeleteMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Insert mutation for encoded inputs #[derive(Debug, Default)] -pub struct EncodedInsertCopyMutator -where - S: HasRand + HasMaxSize, - R: Rand, -{ +pub struct EncodedInsertCopyMutator { tmp_buf: Vec, - phantom: PhantomData<(R, S)>, } -impl Mutator for EncodedInsertCopyMutator +impl Mutator for EncodedInsertCopyMutator where - S: HasRand + HasMaxSize, - R: Rand, + S: HasRand + HasMaxSize, { fn mutate( &mut self, @@ -358,46 +249,25 @@ where } } -impl Named for EncodedInsertCopyMutator -where - S: HasRand + HasMaxSize, - R: Rand, -{ +impl Named for EncodedInsertCopyMutator { fn name(&self) -> &str { "EncodedInsertCopyMutator" } } -impl EncodedInsertCopyMutator -where - S: HasRand + HasMaxSize, - R: Rand, -{ +impl EncodedInsertCopyMutator { /// Creates a new [`EncodedInsertCopyMutator`]. #[must_use] pub fn new() -> Self { - Self { - tmp_buf: vec![], - phantom: PhantomData, - } + Self::default() } } /// Codes copy mutation for encoded inputs #[derive(Debug, Default)] -pub struct EncodedCopyMutator -where - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(R, S)>, -} +pub struct EncodedCopyMutator; -impl Mutator for EncodedCopyMutator -where - S: HasRand, - R: Rand, -{ +impl Mutator for EncodedCopyMutator { fn mutate( &mut self, state: &mut S, @@ -419,46 +289,27 @@ where } } -impl Named for EncodedCopyMutator -where - S: HasRand, - R: Rand, -{ +impl Named for EncodedCopyMutator { fn name(&self) -> &str { "EncodedCopyMutator" } } -impl EncodedCopyMutator -where - S: HasRand, - R: Rand, -{ +impl EncodedCopyMutator { /// Creates a new [`EncodedCopyMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Crossover insert mutation for encoded inputs #[derive(Debug, Default)] -pub struct EncodedCrossoverInsertMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ - phantom: PhantomData<(C, R, S)>, -} +pub struct EncodedCrossoverInsertMutator; -impl Mutator for EncodedCrossoverInsertMutator +impl Mutator for EncodedCrossoverInsertMutator where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, + S: HasRand + HasCorpus + HasMaxSize, { fn mutate( &mut self, @@ -512,48 +363,27 @@ where } } -impl Named for EncodedCrossoverInsertMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ +impl Named for EncodedCrossoverInsertMutator { fn name(&self) -> &str { "EncodedCrossoverInsertMutator" } } -impl EncodedCrossoverInsertMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ +impl EncodedCrossoverInsertMutator { /// Creates a new [`EncodedCrossoverInsertMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Crossover replace mutation for encoded inputs #[derive(Debug, Default)] -pub struct EncodedCrossoverReplaceMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus, -{ - phantom: PhantomData<(C, R, S)>, -} +pub struct EncodedCrossoverReplaceMutator; -impl Mutator for EncodedCrossoverReplaceMutator +impl Mutator for EncodedCrossoverReplaceMutator where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, { fn mutate( &mut self, @@ -599,50 +429,33 @@ where } } -impl Named for EncodedCrossoverReplaceMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus, -{ +impl Named for EncodedCrossoverReplaceMutator { fn name(&self) -> &str { "EncodedCrossoverReplaceMutator" } } -impl EncodedCrossoverReplaceMutator -where - C: Corpus, - R: Rand, - S: HasRand + HasCorpus, -{ +impl EncodedCrossoverReplaceMutator { /// Creates a new [`EncodedCrossoverReplaceMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Get the mutations that compose the encoded mutator #[must_use] -pub fn encoded_mutations() -> tuple_list_type!( - EncodedRandMutator, - EncodedIncMutator, - EncodedDecMutator, - EncodedAddMutator, - EncodedDeleteMutator, - EncodedInsertCopyMutator, - EncodedCopyMutator, - EncodedCrossoverInsertMutator, - EncodedCrossoverReplaceMutator, - ) -where - S: HasRand + HasCorpus + HasMaxSize, - C: Corpus, - R: Rand, -{ +pub fn encoded_mutations() -> tuple_list_type!( + EncodedRandMutator, + EncodedIncMutator, + EncodedDecMutator, + EncodedAddMutator, + EncodedDeleteMutator, + EncodedInsertCopyMutator, + EncodedCopyMutator, + EncodedCrossoverInsertMutator, + EncodedCrossoverReplaceMutator, +) { tuple_list!( EncodedRandMutator::new(), EncodedIncMutator::new(), diff --git a/libafl/src/mutators/gramatron.rs b/libafl/src/mutators/gramatron.rs index b1ec7e8f8a..ad49479aa3 100644 --- a/libafl/src/mutators/gramatron.rs +++ b/libafl/src/mutators/gramatron.rs @@ -1,7 +1,7 @@ //! Gramatron is the rewritten gramatron fuzzer in rust. //! See the original gramatron repo [`Gramatron`](https://github.com/HexHive/Gramatron) for more details. use alloc::vec::Vec; -use core::{cmp::max, marker::PhantomData}; +use core::cmp::max; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; @@ -17,18 +17,16 @@ use crate::{ /// A random mutator for grammar fuzzing #[derive(Debug)] -pub struct GramatronRandomMutator<'a, R, S> +pub struct GramatronRandomMutator<'a, S> where - S: HasRand + HasMetadata, - R: Rand, + S: HasRand + HasMetadata, { - generator: &'a GramatronGenerator<'a, R, S>, + generator: &'a GramatronGenerator<'a, S>, } -impl<'a, R, S> Mutator for GramatronRandomMutator<'a, R, S> +impl<'a, S> Mutator for GramatronRandomMutator<'a, S> where - S: HasRand + HasMetadata, - R: Rand, + S: HasRand + HasMetadata, { fn mutate( &mut self, @@ -48,24 +46,22 @@ where } } -impl<'a, R, S> Named for GramatronRandomMutator<'a, R, S> +impl<'a, S> Named for GramatronRandomMutator<'a, S> where - S: HasRand + HasMetadata, - R: Rand, + S: HasRand + HasMetadata, { fn name(&self) -> &str { "GramatronRandomMutator" } } -impl<'a, R, S> GramatronRandomMutator<'a, R, S> +impl<'a, S> GramatronRandomMutator<'a, S> where - S: HasRand + HasMetadata, - R: Rand, + S: HasRand + HasMetadata, { /// Creates a new [`GramatronRandomMutator`]. #[must_use] - pub fn new(generator: &'a GramatronGenerator<'a, R, S>) -> Self { + pub fn new(generator: &'a GramatronGenerator<'a, S>) -> Self { Self { generator } } } @@ -94,20 +90,11 @@ impl GramatronIdxMapMetadata { /// A [`Mutator`] that mutates a [`GramatronInput`] by splicing inputs together. #[derive(Default, Debug)] -pub struct GramatronSpliceMutator -where - C: Corpus, - S: HasRand + HasCorpus + HasMetadata, - R: Rand, -{ - phantom: PhantomData<(C, R, S)>, -} +pub struct GramatronSpliceMutator; -impl Mutator for GramatronSpliceMutator +impl Mutator for GramatronSpliceMutator where - C: Corpus, - S: HasRand + HasCorpus + HasMetadata, - R: Rand, + S: HasRand + HasCorpus + HasMetadata, { fn mutate( &mut self, @@ -155,49 +142,31 @@ where } } -impl Named for GramatronSpliceMutator -where - C: Corpus, - S: HasRand + HasCorpus + HasMetadata, - R: Rand, -{ +impl Named for GramatronSpliceMutator { fn name(&self) -> &str { "GramatronSpliceMutator" } } -impl<'a, C, R, S> GramatronSpliceMutator -where - C: Corpus, - S: HasRand + HasCorpus + HasMetadata, - R: Rand, -{ +impl GramatronSpliceMutator { /// Creates a new [`GramatronSpliceMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// A mutator that uses Gramatron for grammar fuzzing and mutation. #[derive(Default, Debug)] -pub struct GramatronRecursionMutator -where - S: HasRand + HasMetadata, - R: Rand, -{ +pub struct GramatronRecursionMutator { counters: HashMap, states: Vec, temp: Vec, - phantom: PhantomData<(R, S)>, } -impl Mutator for GramatronRecursionMutator +impl Mutator for GramatronRecursionMutator where - S: HasRand + HasMetadata, - R: Rand, + S: HasRand + HasMetadata, { fn mutate( &mut self, @@ -266,29 +235,16 @@ where } } -impl Named for GramatronRecursionMutator -where - S: HasRand + HasMetadata, - R: Rand, -{ +impl Named for GramatronRecursionMutator { fn name(&self) -> &str { "GramatronRecursionMutator" } } -impl GramatronRecursionMutator -where - S: HasRand + HasMetadata, - R: Rand, -{ +impl GramatronRecursionMutator { /// Creates a new [`GramatronRecursionMutator`]. #[must_use] pub fn new() -> Self { - Self { - counters: HashMap::default(), - states: vec![], - temp: vec![], - phantom: PhantomData, - } + Self::default() } } diff --git a/libafl/src/mutators/mopt_mutator.rs b/libafl/src/mutators/mopt_mutator.rs index c7bbc9ea17..4f99d0a3b5 100644 --- a/libafl/src/mutators/mopt_mutator.rs +++ b/libafl/src/mutators/mopt_mutator.rs @@ -360,29 +360,23 @@ pub enum MOptMode { /// This is the main struct of `MOpt`, an `AFL` mutator. /// See the original `MOpt` implementation in -pub struct StdMOptMutator +pub struct StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { mode: MOptMode, finds_before: usize, mutations: MT, - phantom: PhantomData<(C, I, R, S, SC)>, + phantom: PhantomData<(I, S)>, } -impl Debug for StdMOptMutator +impl Debug for StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -394,14 +388,11 @@ where } } -impl Mutator for StdMOptMutator +impl Mutator for StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { #[inline] fn mutate( @@ -532,14 +523,11 @@ where } } -impl StdMOptMutator +impl StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { /// Create a new [`StdMOptMutator`]. pub fn new(state: &mut S, mutations: MT, swarm_num: usize) -> Result { @@ -619,14 +607,11 @@ where } } -impl ComposedByMutations for StdMOptMutator +impl ComposedByMutations for StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { /// Get the mutations #[inline] @@ -641,14 +626,11 @@ where } } -impl ScheduledMutator for StdMOptMutator +impl ScheduledMutator for StdMOptMutator where - C: Corpus, I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand + HasMetadata + HasCorpus + HasSolutions, - SC: Corpus, + S: HasRand + HasMetadata + HasCorpus + HasSolutions, { /// Compute the number of iterations used to apply stacked mutations fn iterations(&self, state: &mut S, _: &I) -> u64 { diff --git a/libafl/src/mutators/mutations.rs b/libafl/src/mutators/mutations.rs index 6c021c78bd..9d9c065196 100644 --- a/libafl/src/mutators/mutations.rs +++ b/libafl/src/mutators/mutations.rs @@ -12,7 +12,6 @@ use crate::{ use alloc::{borrow::ToOwned, vec::Vec}; use core::{ cmp::{max, min}, - marker::PhantomData, mem::size_of, }; @@ -99,20 +98,12 @@ pub const INTERESTING_32: [i32; 27] = [ /// Bitflip mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BitFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BitFlipMutator; -impl Mutator for BitFlipMutator +impl Mutator for BitFlipMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -131,48 +122,28 @@ where } } -impl Named for BitFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BitFlipMutator { fn name(&self) -> &str { "BitFlipMutator" } } -impl BitFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BitFlipMutator { /// Creates a new [`BitFlipMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Byteflip mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct ByteFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct ByteFlipMutator; -impl Mutator for ByteFlipMutator +impl Mutator for ByteFlipMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -189,48 +160,28 @@ where } } -impl Named for ByteFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for ByteFlipMutator { fn name(&self) -> &str { "ByteFlipMutator" } } -impl ByteFlipMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl ByteFlipMutator { /// Creates a new [`ByteFlipMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Byte increment mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct ByteIncMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct ByteIncMutator; -impl Mutator for ByteIncMutator +impl Mutator for ByteIncMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -248,48 +199,28 @@ where } } -impl Named for ByteIncMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for ByteIncMutator { fn name(&self) -> &str { "ByteIncMutator" } } -impl ByteIncMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl ByteIncMutator { /// Creates a new [`ByteIncMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Byte decrement mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct ByteDecMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct ByteDecMutator; -impl Mutator for ByteDecMutator +impl Mutator for ByteDecMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -307,48 +238,28 @@ where } } -impl Named for ByteDecMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for ByteDecMutator { fn name(&self) -> &str { "ByteDecMutator" } } -impl ByteDecMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl ByteDecMutator { /// Creates a a new [`ByteDecMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Byte negate mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct ByteNegMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct ByteNegMutator; -impl Mutator for ByteNegMutator +impl Mutator for ByteNegMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -366,48 +277,28 @@ where } } -impl Named for ByteNegMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for ByteNegMutator { fn name(&self) -> &str { "ByteNegMutator" } } -impl ByteNegMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl ByteNegMutator { /// Creates a new [`ByteNegMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Byte random mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct ByteRandMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct ByteRandMutator; -impl Mutator for ByteRandMutator +impl Mutator for ByteRandMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -425,29 +316,17 @@ where } } -impl Named for ByteRandMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for ByteRandMutator { fn name(&self) -> &str { "ByteRandMutator" } } -impl ByteRandMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl ByteRandMutator { /// Creates a new [`ByteRandMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } @@ -457,21 +336,13 @@ macro_rules! add_mutator_impl { ($name: ident, $size: ty) => { /// Adds or subtracts a random value up to `ARITH_MAX` to a [`<$size>`] at a random place in the [`Vec`], in random byte order. #[derive(Default, Debug)] - pub struct $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { - phantom: PhantomData<(I, R, S)>, - } + pub struct $name; #[allow(trivial_numeric_casts)] - impl Mutator for $name + impl Mutator for $name where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -505,29 +376,17 @@ macro_rules! add_mutator_impl { } } - impl Named for $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { + impl Named for $name { fn name(&self) -> &str { stringify!($name) } } - impl $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { + impl $name { /// Creates a new [`$name`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } }; @@ -544,20 +403,12 @@ macro_rules! interesting_mutator_impl { ($name: ident, $size: ty, $interesting: ident) => { /// Inserts an interesting value at a random place in the input vector #[derive(Default, Debug)] - pub struct $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { - phantom: PhantomData<(I, R, S)>, - } + pub struct $name; - impl Mutator for $name + impl Mutator for $name where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { #[allow(clippy::cast_sign_loss)] fn mutate( @@ -583,29 +434,17 @@ macro_rules! interesting_mutator_impl { } } - impl Named for $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { + impl Named for $name { fn name(&self) -> &str { stringify!($name) } } - impl $name - where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, - { + impl $name { /// Creates a new [`$name`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } }; @@ -617,20 +456,12 @@ interesting_mutator_impl!(DwordInterestingMutator, u32, INTERESTING_32); /// Bytes delete mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesDeleteMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesDeleteMutator; -impl Mutator for BytesDeleteMutator +impl Mutator for BytesDeleteMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -651,48 +482,28 @@ where } } -impl Named for BytesDeleteMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BytesDeleteMutator { fn name(&self) -> &str { "BytesDeleteMutator" } } -impl BytesDeleteMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BytesDeleteMutator { /// Creates a new [`BytesDeleteMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes expand mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesExpandMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesExpandMutator; -impl Mutator for BytesExpandMutator +impl Mutator for BytesExpandMutator where I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, + S: HasRand + HasMaxSize, { fn mutate( &mut self, @@ -720,48 +531,28 @@ where } } -impl Named for BytesExpandMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl Named for BytesExpandMutator { fn name(&self) -> &str { "BytesExpandMutator" } } -impl BytesExpandMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl BytesExpandMutator { /// Creates a new [`BytesExpandMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes insert mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesInsertMutator; -impl Mutator for BytesInsertMutator +impl Mutator for BytesInsertMutator where I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, + S: HasRand + HasMaxSize, { fn mutate( &mut self, @@ -795,48 +586,28 @@ where } } -impl Named for BytesInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl Named for BytesInsertMutator { fn name(&self) -> &str { "BytesInsertMutator" } } -impl BytesInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl BytesInsertMutator { /// Creates a new [`BytesInsertMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes random insert mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesRandInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesRandInsertMutator; -impl Mutator for BytesRandInsertMutator +impl Mutator for BytesRandInsertMutator where I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, + S: HasRand + HasMaxSize, { fn mutate( &mut self, @@ -867,48 +638,28 @@ where } } -impl Named for BytesRandInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl Named for BytesRandInsertMutator { fn name(&self) -> &str { "BytesRandInsertMutator" } } -impl BytesRandInsertMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl BytesRandInsertMutator { /// Create a new [`BytesRandInsertMutator`] #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes set mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesSetMutator; -impl Mutator for BytesSetMutator +impl Mutator for BytesSetMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -931,48 +682,28 @@ where } } -impl Named for BytesSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BytesSetMutator { fn name(&self) -> &str { "BytesSetMutator" } } -impl BytesSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BytesSetMutator { /// Creates a new [`BytesSetMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes random set mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesRandSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesRandSetMutator; -impl Mutator for BytesRandSetMutator +impl Mutator for BytesRandSetMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -995,48 +726,28 @@ where } } -impl Named for BytesRandSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BytesRandSetMutator { fn name(&self) -> &str { "BytesRandSetMutator" } } -impl BytesRandSetMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BytesRandSetMutator { /// Creates a new [`BytesRandSetMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes copy mutation for inputs with a bytes vector #[derive(Default, Debug)] -pub struct BytesCopyMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesCopyMutator; -impl Mutator for BytesCopyMutator +impl Mutator for BytesCopyMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand, { fn mutate( &mut self, @@ -1059,49 +770,30 @@ where } } -impl Named for BytesCopyMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BytesCopyMutator { fn name(&self) -> &str { "BytesCopyMutator" } } -impl BytesCopyMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BytesCopyMutator { /// Creates a new [`BytesCopyMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Bytes insert and self copy mutation for inputs with a bytes vector #[derive(Debug, Default)] -pub struct BytesInsertCopyMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +pub struct BytesInsertCopyMutator { tmp_buf: Vec, - phantom: PhantomData<(I, R, S)>, } -impl Mutator for BytesInsertCopyMutator +impl Mutator for BytesInsertCopyMutator where I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, + S: HasRand + HasMaxSize, { fn mutate( &mut self, @@ -1142,49 +834,28 @@ where } } -impl Named for BytesInsertCopyMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl Named for BytesInsertCopyMutator { fn name(&self) -> &str { "BytesInsertCopyMutator" } } -impl BytesInsertCopyMutator -where - I: Input + HasBytesVec, - S: HasRand + HasMaxSize, - R: Rand, -{ +impl BytesInsertCopyMutator { /// Creates a new [`BytesInsertCopyMutator`]. #[must_use] pub fn new() -> Self { - Self { - tmp_buf: vec![], - phantom: PhantomData, - } + Self::default() } } /// Bytes swap mutation for inputs with a bytes vector #[derive(Debug, Default)] -pub struct BytesSwapMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct BytesSwapMutator; -impl Mutator for BytesSwapMutator +impl Mutator for BytesSwapMutator where I: Input + HasBytesVec, - S: HasRand, - R: Rand, + S: HasRand + HasCorpus + HasMaxSize, { fn mutate( &mut self, @@ -1209,50 +880,28 @@ where } } -impl Named for BytesSwapMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl Named for BytesSwapMutator { fn name(&self) -> &str { "BytesSwapMutator" } } -impl BytesSwapMutator -where - I: Input + HasBytesVec, - S: HasRand, - R: Rand, -{ +impl BytesSwapMutator { /// Creates a new [`BytesSwapMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Crossover insert mutation for inputs with a bytes vector #[derive(Debug, Default)] -pub struct CrossoverInsertMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ - phantom: PhantomData<(C, I, R, S)>, -} +pub struct CrossoverInsertMutator; -impl Mutator for CrossoverInsertMutator +impl Mutator for CrossoverInsertMutator where - C: Corpus, I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, + S: HasRand + HasCorpus + HasMaxSize, { fn mutate( &mut self, @@ -1306,52 +955,28 @@ where } } -impl Named for CrossoverInsertMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ +impl Named for CrossoverInsertMutator { fn name(&self) -> &str { "CrossoverInsertMutator" } } -impl CrossoverInsertMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus + HasMaxSize, -{ +impl CrossoverInsertMutator { /// Creates a new [`CrossoverInsertMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// Crossover replace mutation for inputs with a bytes vector #[derive(Debug, Default)] -pub struct CrossoverReplaceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ - phantom: PhantomData<(C, I, R, S)>, -} +pub struct CrossoverReplaceMutator; -impl Mutator for CrossoverReplaceMutator +impl Mutator for CrossoverReplaceMutator where - C: Corpus, I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, { fn mutate( &mut self, @@ -1397,31 +1022,17 @@ where } } -impl Named for CrossoverReplaceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ +impl Named for CrossoverReplaceMutator { fn name(&self) -> &str { "CrossoverReplaceMutator" } } -impl CrossoverReplaceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ +impl CrossoverReplaceMutator { /// Creates a new [`CrossoverReplaceMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } @@ -1443,22 +1054,12 @@ fn locate_diffs(this: &[u8], other: &[u8]) -> (i64, i64) { /// Splice mutation for inputs with a bytes vector #[derive(Debug, Default)] -pub struct SpliceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ - phantom: PhantomData<(C, I, R, S)>, -} +pub struct SpliceMutator; -impl Mutator for SpliceMutator +impl Mutator for SpliceMutator where - C: Corpus, I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, { #[allow(clippy::cast_sign_loss)] fn mutate( @@ -1506,31 +1107,17 @@ where } } -impl Named for SpliceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ +impl Named for SpliceMutator { fn name(&self) -> &str { "SpliceMutator" } } -impl SpliceMutator -where - C: Corpus, - I: Input + HasBytesVec, - R: Rand, - S: HasRand + HasCorpus, -{ +impl SpliceMutator { /// Creates a new [`SpliceMutator`]. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } @@ -1591,12 +1178,10 @@ mod tests { state::{HasMetadata, StdState}, }; - fn test_mutations() -> impl MutatorsTuple + fn test_mutations() -> impl MutatorsTuple where I: Input + HasBytesVec, - S: HasRand + HasCorpus + HasMetadata + HasMaxSize, - C: Corpus, - R: Rand, + S: HasRand + HasCorpus + HasMetadata + HasMaxSize, { tuple_list!( BitFlipMutator::new(), diff --git a/libafl/src/mutators/nautilus.rs b/libafl/src/mutators/nautilus.rs index 7703c636da..782290189c 100644 --- a/libafl/src/mutators/nautilus.rs +++ b/libafl/src/mutators/nautilus.rs @@ -2,7 +2,6 @@ use crate::{ bolts::tuples::Named, - corpus::Corpus, feedbacks::NautilusChunksMetadata, generators::nautilus::NautilusContext, inputs::nautilus::NautilusInput, @@ -11,7 +10,7 @@ use crate::{ Error, }; -use core::{fmt::Debug, marker::PhantomData}; +use core::fmt::Debug; use grammartec::mutator::Mutator as BackingMutator; use grammartec::{ context::Context, @@ -30,7 +29,7 @@ impl Debug for NautilusRandomMutator<'_> { } } -impl<'a, S> Mutator for NautilusRandomMutator<'a> { +impl Mutator for NautilusRandomMutator<'_> { fn mutate( &mut self, _state: &mut S, @@ -60,7 +59,7 @@ impl<'a, S> Mutator for NautilusRandomMutator<'a> { } } -impl<'a> Named for NautilusRandomMutator<'a> { +impl Named for NautilusRandomMutator<'_> { fn name(&self) -> &str { "NautilusRandomMutator" } @@ -91,7 +90,7 @@ impl Debug for NautilusRecursionMutator<'_> { } } -impl<'a, S> Mutator for NautilusRecursionMutator<'a> { +impl Mutator for NautilusRecursionMutator<'_> { fn mutate( &mut self, _state: &mut S, @@ -124,7 +123,7 @@ impl<'a, S> Mutator for NautilusRecursionMutator<'a> { } } -impl<'a> Named for NautilusRecursionMutator<'a> { +impl Named for NautilusRecursionMutator<'_> { fn name(&self) -> &str { "NautilusRecursionMutator" } @@ -143,22 +142,20 @@ impl<'a> NautilusRecursionMutator<'a> { } /// The splicing mutator for `Nautilus` that can splice inputs together -pub struct NautilusSpliceMutator<'a, C> { +pub struct NautilusSpliceMutator<'a> { ctx: &'a Context, mutator: BackingMutator, - phantom: PhantomData, } -impl Debug for NautilusSpliceMutator<'_, ()> { +impl Debug for NautilusSpliceMutator<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "NautilusSpliceMutator {{}}") } } -impl<'a, S, C> Mutator for NautilusSpliceMutator<'a, C> +impl Mutator for NautilusSpliceMutator<'_> where - C: Corpus, - S: HasCorpus + HasMetadata, + S: HasCorpus + HasMetadata, { fn mutate( &mut self, @@ -194,13 +191,13 @@ where } } -impl<'a, C> Named for NautilusSpliceMutator<'a, C> { +impl Named for NautilusSpliceMutator<'_> { fn name(&self) -> &str { "NautilusSpliceMutator" } } -impl<'a, C> NautilusSpliceMutator<'a, C> { +impl<'a> NautilusSpliceMutator<'a> { /// Creates a new [`NautilusSpliceMutator`]. #[must_use] pub fn new(context: &'a NautilusContext) -> Self { @@ -208,7 +205,6 @@ impl<'a, C> NautilusSpliceMutator<'a, C> { Self { ctx: &context.ctx, mutator, - phantom: PhantomData, } } } diff --git a/libafl/src/mutators/scheduled.rs b/libafl/src/mutators/scheduled.rs index 9a23a6a3a0..55da803579 100644 --- a/libafl/src/mutators/scheduled.rs +++ b/libafl/src/mutators/scheduled.rs @@ -14,9 +14,9 @@ use crate::{ AsSlice, }, corpus::Corpus, - inputs::{HasBytesVec, Input}, + inputs::Input, mutators::{MutationResult, Mutator, MutatorsTuple}, - state::{HasCorpus, HasMaxSize, HasMetadata, HasRand}, + state::{HasCorpus, HasMetadata, HasRand}, Error, }; @@ -95,24 +95,22 @@ where } /// A [`Mutator`] that schedules one of the embedded mutations on each call. -pub struct StdScheduledMutator +pub struct StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { mutations: MT, max_iterations: u64, - phantom: PhantomData<(I, R, S)>, + phantom: PhantomData<(I, S)>, } -impl Debug for StdScheduledMutator +impl Debug for StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -124,12 +122,11 @@ where } } -impl Mutator for StdScheduledMutator +impl Mutator for StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { #[inline] fn mutate( @@ -142,12 +139,11 @@ where } } -impl ComposedByMutations for StdScheduledMutator +impl ComposedByMutations for StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { /// Get the mutations #[inline] @@ -162,12 +158,11 @@ where } } -impl ScheduledMutator for StdScheduledMutator +impl ScheduledMutator for StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { /// Compute the number of iterations used to apply stacked mutations fn iterations(&self, state: &mut S, _: &I) -> u64 { @@ -181,12 +176,11 @@ where } } -impl StdScheduledMutator +impl StdScheduledMutator where I: Input, MT: MutatorsTuple, - R: Rand, - S: HasRand, + S: HasRand, { /// Create a new [`StdScheduledMutator`] instance specifying mutations pub fn new(mutations: MT) -> Self { @@ -209,41 +203,35 @@ where /// Get the mutations that compose the Havoc mutator #[must_use] -pub fn havoc_mutations() -> tuple_list_type!( - BitFlipMutator, - ByteFlipMutator, - ByteIncMutator, - ByteDecMutator, - ByteNegMutator, - ByteRandMutator, - ByteAddMutator, - WordAddMutator, - DwordAddMutator, - QwordAddMutator, - ByteInterestingMutator, - WordInterestingMutator, - DwordInterestingMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesExpandMutator, - BytesInsertMutator, - BytesRandInsertMutator, - BytesSetMutator, - BytesRandSetMutator, - BytesCopyMutator, - BytesInsertCopyMutator, - BytesSwapMutator, - CrossoverInsertMutator, - CrossoverReplaceMutator, - ) -where - I: Input + HasBytesVec, - S: HasRand + HasCorpus + HasMetadata + HasMaxSize, - C: Corpus, - R: Rand, -{ +pub fn havoc_mutations() -> tuple_list_type!( + BitFlipMutator, + ByteFlipMutator, + ByteIncMutator, + ByteDecMutator, + ByteNegMutator, + ByteRandMutator, + ByteAddMutator, + WordAddMutator, + DwordAddMutator, + QwordAddMutator, + ByteInterestingMutator, + WordInterestingMutator, + DwordInterestingMutator, + BytesDeleteMutator, + BytesDeleteMutator, + BytesDeleteMutator, + BytesDeleteMutator, + BytesExpandMutator, + BytesInsertMutator, + BytesRandInsertMutator, + BytesSetMutator, + BytesRandSetMutator, + BytesCopyMutator, + BytesInsertCopyMutator, + BytesSwapMutator, + CrossoverInsertMutator, + CrossoverReplaceMutator, +) { tuple_list!( BitFlipMutator::new(), ByteFlipMutator::new(), @@ -277,39 +265,28 @@ where /// Get the mutations that uses the Tokens metadata #[must_use] -pub fn tokens_mutations( -) -> tuple_list_type!(TokenInsert, TokenReplace) -where - I: Input + HasBytesVec, - S: HasRand + HasCorpus + HasMetadata + HasMaxSize, - C: Corpus, - R: Rand, -{ +pub fn tokens_mutations() -> tuple_list_type!(TokenInsert, TokenReplace) { tuple_list!(TokenInsert::new(), TokenReplace::new(),) } /// A logging [`Mutator`] that wraps around a [`StdScheduledMutator`]. -pub struct LoggerScheduledMutator +pub struct LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { scheduled: SM, mutation_log: Vec, - phantom: PhantomData<(C, I, MT, R, S)>, + phantom: PhantomData<(I, MT, S)>, } -impl Debug for LoggerScheduledMutator +impl Debug for LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -322,13 +299,11 @@ where } } -impl Mutator for LoggerScheduledMutator +impl Mutator for LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { fn mutate( @@ -362,14 +337,11 @@ where } } -impl ComposedByMutations - for LoggerScheduledMutator +impl ComposedByMutations for LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { #[inline] @@ -383,13 +355,11 @@ where } } -impl ScheduledMutator for LoggerScheduledMutator +impl ScheduledMutator for LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { /// Compute the number of iterations used to apply stacked mutations @@ -428,13 +398,11 @@ where } } -impl LoggerScheduledMutator +impl LoggerScheduledMutator where - C: Corpus, I: Input, MT: MutatorsTuple + NamedTuple, - R: Rand, - S: HasRand + HasCorpus, + S: HasRand + HasCorpus, SM: ScheduledMutator, { /// Create a new [`StdScheduledMutator`] instance without mutations and corpus diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 94435ffb61..e7f3e389cf 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -1,7 +1,7 @@ //! Tokens are what afl calls extras or dictionaries. //! They may be inserted as part of mutations during fuzzing. use alloc::vec::Vec; -use core::{marker::PhantomData, mem::size_of}; +use core::mem::size_of; use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] @@ -127,20 +127,12 @@ impl Tokens { /// Inserts a random token at a random position in the `Input`. #[derive(Debug, Default)] -pub struct TokenInsert -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct TokenInsert; -impl Mutator for TokenInsert +impl Mutator for TokenInsert where I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, + S: HasMetadata + HasRand + HasMaxSize, { fn mutate( &mut self, @@ -184,49 +176,29 @@ where } } -impl Named for TokenInsert -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl Named for TokenInsert { fn name(&self) -> &str { "TokenInsert" } } -impl TokenInsert -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl TokenInsert { /// Create a `TokenInsert` `Mutation`. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// A `TokenReplace` [`Mutator`] replaces a random part of the input with one of a range of tokens. /// From AFL terms, this is called as `Dictionary` mutation (which doesn't really make sense ;) ). #[derive(Debug, Default)] -pub struct TokenReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct TokenReplace; -impl Mutator for TokenReplace +impl Mutator for TokenReplace where I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, + S: HasMetadata + HasRand + HasMaxSize, { fn mutate( &mut self, @@ -266,49 +238,29 @@ where } } -impl Named for TokenReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl Named for TokenReplace { fn name(&self) -> &str { "TokenReplace" } } -impl TokenReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl TokenReplace { /// Creates a new `TokenReplace` struct. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } /// A `I2SRandReplace` [`Mutator`] replaces a random matching input-2-state comparison operand with the other. /// it needs a valid [`CmpValuesMetadata`] in the state. #[derive(Debug, Default)] -pub struct I2SRandReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ - phantom: PhantomData<(I, R, S)>, -} +pub struct I2SRandReplace; -impl Mutator for I2SRandReplace +impl Mutator for I2SRandReplace where I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, + S: HasMetadata + HasRand + HasMaxSize, { #[allow(clippy::too_many_lines)] fn mutate( @@ -471,29 +423,17 @@ where } } -impl Named for I2SRandReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl Named for I2SRandReplace { fn name(&self) -> &str { "I2SRandReplace" } } -impl I2SRandReplace -where - I: Input + HasBytesVec, - S: HasMetadata + HasRand + HasMaxSize, - R: Rand, -{ +impl I2SRandReplace { /// Creates a new `I2SRandReplace` struct. #[must_use] pub fn new() -> Self { - Self { - phantom: PhantomData, - } + Self } } diff --git a/libafl/src/stages/calibrate.rs b/libafl/src/stages/calibrate.rs index 824b7e0576..3aa24b8d6e 100644 --- a/libafl/src/stages/calibrate.rs +++ b/libafl/src/stages/calibrate.rs @@ -2,10 +2,11 @@ use crate::{ bolts::current_time, + bolts::tuples::MatchName, corpus::{Corpus, PowerScheduleTestcaseMetaData}, events::{EventFirer, LogSeverity}, executors::{Executor, ExitKind, HasObservers}, - feedbacks::{FeedbackStatesTuple, MapFeedbackState}, + feedbacks::MapFeedbackState, fuzzer::Evaluator, inputs::Input, observers::{MapObserver, ObserversTuple}, @@ -23,40 +24,31 @@ use serde::{Deserialize, Serialize}; /// 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 where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, - E: Executor + HasObservers, - EM: EventFirer, - FT: FeedbackStatesTuple, I: Input, O: MapObserver, OT: ObserversTuple, - S: HasCorpus + HasMetadata, - Z: Evaluator, + S: HasCorpus + HasMetadata, { map_observer_name: String, stage_max: usize, - #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, E, EM, FT, I, O, OT, S, T, Z)>, + phantom: PhantomData<(I, O, OT, S, T)>, } const CAL_STAGE_START: usize = 4; const CAL_STAGE_MAX: usize = 16; -impl Stage - for CalibrationStage +impl Stage for CalibrationStage where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, E: Executor + HasObservers, EM: EventFirer, - FT: FeedbackStatesTuple, I: Input, O: MapObserver, OT: ObserversTuple, - S: HasCorpus + HasMetadata + HasFeedbackStates + HasClientPerfMonitor, + S: HasCorpus + HasMetadata + HasFeedbackStates + HasClientPerfMonitor, Z: Evaluator, { #[inline] @@ -314,18 +306,13 @@ impl PowerScheduleMetadata { crate::impl_serdeany!(PowerScheduleMetadata); -impl CalibrationStage +impl CalibrationStage where T: PrimInt + Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, - E: Executor + HasObservers, - EM: EventFirer, - FT: FeedbackStatesTuple, I: Input, O: MapObserver, OT: ObserversTuple, - S: HasCorpus + HasMetadata, - Z: Evaluator, + S: HasCorpus + HasMetadata, { /// Create a new [`CalibrationStage`]. pub fn new(state: &mut S, map_observer_name: &O) -> Self { diff --git a/libafl/src/stages/concolic.rs b/libafl/src/stages/concolic.rs index adbedd751e..a8250eee42 100644 --- a/libafl/src/stages/concolic.rs +++ b/libafl/src/stages/concolic.rs @@ -17,25 +17,23 @@ use super::{Stage, TracingStage}; /// Wraps a [`TracingStage`] to add concolic observing. #[derive(Clone, Debug)] -pub struct ConcolicTracingStage +pub struct ConcolicTracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { - inner: TracingStage, + inner: TracingStage, observer_name: String, } -impl Stage for ConcolicTracingStage +impl Stage for ConcolicTracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { #[inline] fn perform( @@ -67,16 +65,15 @@ where } } -impl ConcolicTracingStage +impl ConcolicTracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default tracing stage using the given [`Executor`], observing traces from a [`ConcolicObserver`] with the given name. - pub fn new(inner: TracingStage, observer_name: String) -> Self { + pub fn new(inner: TracingStage, observer_name: String) -> Self { Self { inner, observer_name, @@ -345,21 +342,19 @@ fn generate_mutations(iter: impl Iterator) -> Vec< /// A mutational stage that uses Z3 to solve concolic constraints attached to the [`crate::corpus::Testcase`] by the [`ConcolicTracingStage`]. #[derive(Clone, Debug)] -pub struct SimpleConcolicMutationalStage +pub struct SimpleConcolicMutationalStage where I: Input, - C: Corpus, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { - _phantom: PhantomData<(C, EM, I, S, Z)>, + _phantom: PhantomData<(EM, I, S, Z)>, } #[cfg(feature = "concolic_mutation")] -impl Stage for SimpleConcolicMutationalStage +impl Stage for SimpleConcolicMutationalStage where I: Input + HasBytesVec, - C: Corpus, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, Z: Evaluator, { #[inline] @@ -399,11 +394,10 @@ where } } -impl Default for SimpleConcolicMutationalStage +impl Default for SimpleConcolicMutationalStage where I: Input, - C: Corpus, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { fn default() -> Self { Self { diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index cd60b1553c..b09f81bafe 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -32,8 +32,7 @@ pub mod sync; pub use sync::*; use crate::{ - bolts::rands::Rand, - corpus::{Corpus, CorpusScheduler}, + corpus::CorpusScheduler, events::{EventFirer, EventRestarter, HasEventManagerId, ProgressReporter}, executors::{Executor, HasObservers}, inputs::Input, @@ -164,32 +163,28 @@ where /// Allows us to use a [`push::PushStage`] as a normal [`Stage`] #[allow(clippy::type_complexity)] #[derive(Debug)] -pub struct PushStageAdapter +pub struct PushStageAdapter where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, OT: ObserversTuple, - PS: PushStage, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + PS: PushStage, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { push_stage: PS, - phantom: PhantomData<(C, CS, EM, I, OT, R, S, Z)>, + phantom: PhantomData<(CS, EM, I, OT, S, Z)>, } -impl PushStageAdapter +impl PushStageAdapter where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, OT: ObserversTuple, - PS: PushStage, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + PS: PushStage, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Create a new [`PushStageAdapter`], warpping the given [`PushStage`] @@ -203,18 +198,15 @@ where } } -impl Stage - for PushStageAdapter +impl Stage for PushStageAdapter where - C: Corpus, CS: CorpusScheduler, E: Executor + HasObservers, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, OT: ObserversTuple, - PS: PushStage, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + PS: PushStage, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutesInput + ExecutionProcessor + EvaluatorObservers diff --git a/libafl/src/stages/mutational.rs b/libafl/src/stages/mutational.rs index 317557d700..664e18bcff 100644 --- a/libafl/src/stages/mutational.rs +++ b/libafl/src/stages/mutational.rs @@ -24,12 +24,11 @@ use crate::monitors::PerfFeature; /// A Mutational stage is the stage in a fuzzing run that mutates inputs. /// Mutational stages will usually have a range of mutations that are /// being applied to the input one by one, between executions. -pub trait MutationalStage: Stage +pub trait MutationalStage: Stage where - C: Corpus, M: Mutator, I: Input, - S: HasClientPerfMonitor + HasCorpus, + S: HasClientPerfMonitor + HasCorpus, Z: Evaluator, { /// The mutator registered for this stage @@ -84,28 +83,23 @@ pub static DEFAULT_MUTATIONAL_MAX_ITERATIONS: u64 = 128; /// The default mutational stage #[derive(Clone, Debug)] -pub struct StdMutationalStage +pub struct StdMutationalStage where - C: Corpus, M: Mutator, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { mutator: M, #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, E, EM, I, R, S, Z)>, + phantom: PhantomData<(E, EM, I, S, Z)>, } -impl MutationalStage - for StdMutationalStage +impl MutationalStage for StdMutationalStage where - C: Corpus, M: Mutator, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { /// The mutator, added to this stage @@ -126,13 +120,11 @@ where } } -impl Stage for StdMutationalStage +impl Stage for StdMutationalStage where - C: Corpus, M: Mutator, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { #[inline] @@ -154,13 +146,11 @@ where } } -impl StdMutationalStage +impl StdMutationalStage where - C: Corpus, M: Mutator, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { /// Creates a new default mutational stage diff --git a/libafl/src/stages/power.rs b/libafl/src/stages/power.rs index eb88f33287..250723589b 100644 --- a/libafl/src/stages/power.rs +++ b/libafl/src/stages/power.rs @@ -34,16 +34,15 @@ const HAVOC_MAX_MULT: f64 = 64.0; /// The mutational stage using power schedules #[derive(Clone, Debug)] -pub struct PowerMutationalStage +pub struct PowerMutationalStage where T: PrimInt + Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, E: Executor + HasObservers, I: Input, M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfMonitor + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { map_observer_name: String, @@ -51,20 +50,19 @@ where /// The employed power schedule strategy strat: PowerSchedule, #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, E, EM, I, O, OT, S, T, Z)>, + phantom: PhantomData<(E, EM, I, O, OT, S, T, Z)>, } -impl MutationalStage - for PowerMutationalStage +impl MutationalStage + for PowerMutationalStage where T: PrimInt + Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, E: Executor + HasObservers, I: Input, M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfMonitor + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { /// The mutator, added to this stage @@ -155,17 +153,16 @@ where } } -impl Stage - for PowerMutationalStage +impl Stage + for PowerMutationalStage where T: PrimInt + Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, E: Executor + HasObservers, I: Input, M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfMonitor + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { #[inline] @@ -183,16 +180,15 @@ where } } -impl PowerMutationalStage +impl PowerMutationalStage where T: PrimInt + Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned + Debug, - C: Corpus, E: Executor + HasObservers, I: Input, M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfMonitor + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { /// Creates a new [`PowerMutationalStage`] diff --git a/libafl/src/stages/push/mod.rs b/libafl/src/stages/push/mod.rs index 6ceb7e001e..56a422a524 100644 --- a/libafl/src/stages/push/mod.rs +++ b/libafl/src/stages/push/mod.rs @@ -16,8 +16,8 @@ use core::{ }; use crate::{ - bolts::{current_time, rands::Rand}, - corpus::{Corpus, CorpusScheduler}, + bolts::current_time, + corpus::CorpusScheduler, events::{EventFirer, EventRestarter, HasEventManagerId, ProgressReporter}, executors::ExitKind, inputs::Input, @@ -32,15 +32,13 @@ const STATS_TIMEOUT_DEFAULT: Duration = Duration::from_secs(15); // The shared state for all [`PushStage`]s /// Should be stored inside a `[Rc>`] #[derive(Clone, Debug)] -pub struct PushStageSharedState +pub struct PushStageSharedState where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// The [`crate::state::State`] @@ -51,18 +49,16 @@ where pub event_mgr: EM, /// The [`crate::observers::ObserversTuple`] pub observers: OT, - phantom: PhantomData<(C, CS, I, OT, R, S, Z)>, + phantom: PhantomData<(CS, I, OT, S, Z)>, } -impl PushStageSharedState +impl PushStageSharedState where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Create a new `PushStageSharedState` that can be used by all [`PushStage`]s @@ -80,15 +76,13 @@ where /// Helper class for the [`PushStage`] trait, taking care of borrowing the shared state #[derive(Clone, Debug)] -pub struct PushStageHelper +pub struct PushStageHelper where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// If this stage has already been initalized. @@ -98,7 +92,7 @@ where pub last_monitor_time: Duration, /// The shared state, keeping track of the corpus and the fuzzer #[allow(clippy::type_complexity)] - pub shared_state: Rc>>>, + pub shared_state: Rc>>>, /// If the last iteraation failed pub errored: bool, @@ -109,26 +103,24 @@ where pub current_input: Option, // Todo: Get rid of copy #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, CS, (), EM, I, R, OT, S, Z)>, + phantom: PhantomData<(CS, (), EM, I, OT, S, Z)>, exit_kind: Rc>>, } -impl PushStageHelper +impl PushStageHelper where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Create a new [`PushStageHelper`] #[must_use] #[allow(clippy::type_complexity)] pub fn new( - shared_state: Rc>>>, + shared_state: Rc>>>, exit_kind_ref: Rc>>, ) -> Self { Self { @@ -145,17 +137,14 @@ where /// Sets the shared state for this helper (and all other helpers owning the same [`RefCell`]) #[inline] - pub fn set_shared_state( - &mut self, - shared_state: PushStageSharedState, - ) { + pub fn set_shared_state(&mut self, shared_state: PushStageSharedState) { (&mut *self.shared_state.borrow_mut()).replace(shared_state); } /// Takes the shared state from this helper, replacing it with `None` #[inline] #[allow(clippy::type_complexity)] - pub fn take_shared_state(&mut self) -> Option> { + pub fn take_shared_state(&mut self) -> Option> { let shared_state_ref = &mut (*self.shared_state).borrow_mut(); shared_state_ref.take() } @@ -176,7 +165,7 @@ where /// Resets this state after a full stage iter. fn end_of_iter( &mut self, - shared_state: PushStageSharedState, + shared_state: PushStageSharedState, errored: bool, ) { self.set_shared_state(shared_state); @@ -191,21 +180,19 @@ where /// A push stage is a generator that returns a single testcase for each call. /// It's an iterator so we can chain it. /// After it has finished once, we will call it agan for the next fuzzer round. -pub trait PushStage: Iterator +pub trait PushStage: Iterator where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Gets the [`PushStageHelper`] - fn push_stage_helper(&self) -> &PushStageHelper; + fn push_stage_helper(&self) -> &PushStageHelper; /// Gets the [`PushStageHelper`], mut - fn push_stage_helper_mut(&mut self) -> &mut PushStageHelper; + fn push_stage_helper_mut(&mut self) -> &mut PushStageHelper; /// Set the current corpus index this stagve works on fn set_current_corpus_idx(&mut self, corpus_idx: usize) { diff --git a/libafl/src/stages/push/mutational.rs b/libafl/src/stages/push/mutational.rs index fabe4966a3..83b8737d49 100644 --- a/libafl/src/stages/push/mutational.rs +++ b/libafl/src/stages/push/mutational.rs @@ -35,16 +35,14 @@ pub static DEFAULT_MUTATIONAL_MAX_ITERATIONS: u64 = 128; /// /// The default mutational push stage #[derive(Clone, Debug)] -pub struct StdMutationalPushStage +pub struct StdMutationalPushStage where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, M: Mutator, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { current_corpus_idx: Option, @@ -55,19 +53,17 @@ where mutator: M, - psh: PushStageHelper, + psh: PushStageHelper, } -impl StdMutationalPushStage +impl StdMutationalPushStage where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, M: Mutator, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Gets the number of iterations as a random number @@ -82,17 +78,15 @@ where } } -impl PushStage - for StdMutationalPushStage +impl PushStage + for StdMutationalPushStage where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, M: Mutator, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Creates a new default mutational stage @@ -186,26 +180,24 @@ where } #[inline] - fn push_stage_helper(&self) -> &PushStageHelper { + fn push_stage_helper(&self) -> &PushStageHelper { &self.psh } #[inline] - fn push_stage_helper_mut(&mut self) -> &mut PushStageHelper { + fn push_stage_helper_mut(&mut self) -> &mut PushStageHelper { &mut self.psh } } -impl Iterator for StdMutationalPushStage +impl Iterator for StdMutationalPushStage where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId + ProgressReporter, I: Input, M: Mutator, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasExecutions, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { type Item = Result; @@ -215,16 +207,14 @@ where } } -impl StdMutationalPushStage +impl StdMutationalPushStage where - C: Corpus, CS: CorpusScheduler, EM: EventFirer + EventRestarter + HasEventManagerId, I: Input, M: Mutator, OT: ObserversTuple, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + HasCorpusScheduler, { /// Creates a new default mutational stage @@ -232,7 +222,7 @@ where #[allow(clippy::type_complexity)] pub fn new( mutator: M, - shared_state: Rc>>>, + shared_state: Rc>>>, exit_kind: Rc>>, stage_idx: i32, ) -> Self { diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 488bb74f33..8da43f4fda 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -10,8 +10,6 @@ use std::{ }; use crate::{ - bolts::rands::Rand, - corpus::Corpus, fuzzer::Evaluator, inputs::Input, stages::Stage, @@ -38,28 +36,24 @@ impl SyncFromDiskMetadata { /// A stage that loads testcases from disk to sync with other fuzzers such as AFL++ #[derive(Debug)] -pub struct SyncFromDiskStage +pub struct SyncFromDiskStage where - C: Corpus, CB: FnMut(&mut Z, &mut S, &Path) -> Result, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, Z: Evaluator, { sync_dir: PathBuf, load_callback: CB, #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, E, EM, I, R, S, Z)>, + phantom: PhantomData<(E, EM, I, S, Z)>, } -impl Stage for SyncFromDiskStage +impl Stage for SyncFromDiskStage where - C: Corpus, CB: FnMut(&mut Z, &mut S, &Path) -> Result, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, Z: Evaluator, { #[inline] @@ -99,13 +93,11 @@ where } } -impl SyncFromDiskStage +impl SyncFromDiskStage where - C: Corpus, CB: FnMut(&mut Z, &mut S, &Path) -> Result, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, Z: Evaluator, { /// Creates a new [`SyncFromDiskStage`] @@ -163,13 +155,11 @@ where } } -impl - SyncFromDiskStage Result, E, EM, I, R, S, Z> +impl + SyncFromDiskStage Result, E, EM, I, S, Z> where - C: Corpus, I: Input, - R: Rand, - S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasRand + HasMetadata, Z: Evaluator, { /// Creates a new [`SyncFromDiskStage`] invoking `Input::from_file` to load inputs diff --git a/libafl/src/stages/tracing.rs b/libafl/src/stages/tracing.rs index 166c8b5b39..9ff10a6b02 100644 --- a/libafl/src/stages/tracing.rs +++ b/libafl/src/stages/tracing.rs @@ -19,26 +19,24 @@ use crate::monitors::PerfFeature; /// A stage that runs a tracer executor #[derive(Clone, Debug)] -pub struct TracingStage +pub struct TracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { tracer_executor: TE, #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, EM, I, OT, S, TE, Z)>, + phantom: PhantomData<(EM, I, OT, S, TE, Z)>, } -impl Stage for TracingStage +impl Stage for TracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { #[inline] fn perform( @@ -82,13 +80,12 @@ where } } -impl TracingStage +impl TracingStage where I: Input, - C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default stage pub fn new(tracer_executor: TE) -> Self { @@ -106,20 +103,19 @@ where /// A stage that runs the shadow executor using also the shadow observers #[derive(Clone, Debug)] -pub struct ShadowTracingStage { +pub struct ShadowTracingStage { #[allow(clippy::type_complexity)] - phantom: PhantomData<(C, E, EM, I, OT, S, SOT, Z)>, + phantom: PhantomData<(E, EM, I, OT, S, SOT, Z)>, } -impl Stage, EM, S, Z> - for ShadowTracingStage +impl Stage, EM, S, Z> + for ShadowTracingStage where I: Input, - C: Corpus, E: Executor + HasObservers, OT: ObserversTuple, SOT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus + Debug, + S: HasClientPerfMonitor + HasExecutions + HasCorpus + Debug, { #[inline] fn perform( @@ -163,14 +159,13 @@ where } } -impl ShadowTracingStage +impl ShadowTracingStage where I: Input, - C: Corpus, E: Executor + HasObservers, OT: ObserversTuple, SOT: ObserversTuple, - S: HasClientPerfMonitor + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default stage pub fn new(_executor: &mut ShadowExecutor) -> Self { diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index 8a84f1c048..a85bcf9306 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -32,15 +32,13 @@ pub const DEFAULT_MAX_SIZE: usize = 1_048_576; pub trait State: Serialize + DeserializeOwned {} /// Trait for elements offering a corpus -pub trait HasCorpus -where - C: Corpus, - I: Input, -{ +pub trait HasCorpus { + /// The associated type implementing [`Corpus`]. + type Corpus: Corpus; /// The testcase corpus - fn corpus(&self) -> &C; + fn corpus(&self) -> &Self::Corpus; /// The testcase corpus (mut) - fn corpus_mut(&mut self) -> &mut C; + fn corpus_mut(&mut self) -> &mut Self::Corpus; } /// Interact with the maximum size @@ -52,26 +50,23 @@ pub trait HasMaxSize { } /// Trait for elements offering a corpus of solutions -pub trait HasSolutions -where - C: Corpus, - I: Input, -{ +pub trait HasSolutions { + /// The associated type implementing [`Corpus`] for solutions + type Solutions: Corpus; /// The solutions corpus - fn solutions(&self) -> &C; + fn solutions(&self) -> &Self::Solutions; /// The solutions corpus (mut) - fn solutions_mut(&mut self) -> &mut C; + fn solutions_mut(&mut self) -> &mut Self::Solutions; } /// Trait for elements offering a rand -pub trait HasRand -where - R: Rand, -{ +pub trait HasRand { + /// The associated type implementing [`Rand`] + type Rand: Rand; /// The rand instance - fn rand(&self) -> &R; + fn rand(&self) -> &Self::Rand; /// The rand instance (mut) - fn rand_mut(&mut self) -> &mut R; + fn rand_mut(&mut self) -> &mut Self::Rand; } /// Trait for offering a [`ClientPerfMonitor`] @@ -116,15 +111,14 @@ pub trait HasMetadata { } /// Trait for elements offering a feedback -pub trait HasFeedbackStates -where - FT: FeedbackStatesTuple, -{ +pub trait HasFeedbackStates { + /// The associated feedback type implementing [`FeedbackStatesTuple`]. + type FeedbackStates: FeedbackStatesTuple; /// The feedback states - fn feedback_states(&self) -> &FT; + fn feedback_states(&self) -> &Self::FeedbackStates; /// The feedback states (mut) - fn feedback_states_mut(&mut self) -> &mut FT; + fn feedback_states_mut(&mut self) -> &mut Self::FeedbackStates; } /// Trait for the execution counter @@ -192,7 +186,7 @@ where { } -impl HasRand for StdState +impl HasRand for StdState where C: Corpus, I: Input, @@ -200,20 +194,22 @@ where FT: FeedbackStatesTuple, SC: Corpus, { + type Rand = R; + /// The rand instance #[inline] - fn rand(&self) -> &R { + fn rand(&self) -> &Self::Rand { &self.rand } /// The rand instance (mut) #[inline] - fn rand_mut(&mut self) -> &mut R { + fn rand_mut(&mut self) -> &mut Self::Rand { &mut self.rand } } -impl HasCorpus for StdState +impl HasCorpus for StdState where C: Corpus, I: Input, @@ -221,6 +217,8 @@ where FT: FeedbackStatesTuple, SC: Corpus, { + type Corpus = C; + /// Returns the corpus #[inline] fn corpus(&self) -> &C { @@ -234,7 +232,7 @@ where } } -impl HasSolutions for StdState +impl HasSolutions for StdState where C: Corpus, I: Input, @@ -242,6 +240,8 @@ where FT: FeedbackStatesTuple, SC: Corpus, { + type Solutions = SC; + /// Returns the solutions corpus #[inline] fn solutions(&self) -> &SC { @@ -276,7 +276,7 @@ where } } -impl HasFeedbackStates for StdState +impl HasFeedbackStates for StdState where C: Corpus, I: Input, @@ -284,6 +284,8 @@ where FT: FeedbackStatesTuple, SC: Corpus, { + type FeedbackStates = FT; + /// The feedback states #[inline] fn feedback_states(&self) -> &FT { diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index 9bdd0f89db..8805ce15ba 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -7,7 +7,6 @@ use core::{ }; use libafl::{ - corpus::Corpus, events::{EventFirer, EventRestarter}, executors::{ inprocess::inprocess_get_state, Executor, ExitKind, HasObservers, InProcessExecutor, @@ -474,7 +473,7 @@ where OT: ObserversTuple, QT: QemuHelperTuple, { - pub fn new( + pub fn new( harness_fn: &'a mut H, emulator: &'a Emulator, helpers: QT, @@ -485,9 +484,8 @@ where ) -> Result where EM: EventFirer + EventRestarter, - OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfMonitor, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { let slf = Self {