Skip to content

Commit

Permalink
Round 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tokatoka committed Oct 2, 2024
1 parent 76d52bc commit c4bd3d4
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 329 deletions.
2 changes: 0 additions & 2 deletions libafl/src/corpus/minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub type StdCorpusMinimizer<C, E, O, T> = MapCorpusMinimizer<C, E, O, T, LenTime

impl<C, E, O, T, TS> MapCorpusMinimizer<C, E, O, T, TS>
where
E: UsesState,
E::State: HasCorpus + HasMetadata,
TS: TestcaseScore<E::State>,
C: Named,
Expand All @@ -55,7 +54,6 @@ where

impl<C, E, O, T, TS> MapCorpusMinimizer<C, E, O, T, TS>
where
E: UsesState,
for<'a> O: MapObserver<Entry = T> + AsIter<'a, Item = T>,
C: AsRef<O>,
E::State: HasMetadata + HasCorpus + HasExecutions,
Expand Down
40 changes: 15 additions & 25 deletions libafl/src/events/events_hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@
//! other clients
use libafl_bolts::ClientId;

use crate::{events::Event, state::State, Error};
use crate::{events::Event, Error};

/// The `broker_hooks` that are run before and after the event manager calls `handle_in_client`
pub trait EventManagerHook<S>
where
S: State,
{
pub trait EventManagerHook<I, S> {
/// The hook that runs before `handle_in_client`
/// Return false if you want to cancel the subsequent event handling
fn pre_exec(
&mut self,
state: &mut S,
client_id: ClientId,
event: &Event<S::Input>,
event: &Event<I>,
) -> Result<bool, Error>;

/// Triggered when the even manager decides to fire the event after processing
fn on_fire(
&mut self,
_state: &mut S,
_client_id: ClientId,
_event: &Event<S::Input>,
_event: &Event<I>,
) -> Result<(), Error> {
Ok(())
}
Expand All @@ -38,40 +35,34 @@ where
}

/// The tuples contains `broker_hooks` to be executed for `handle_in_client`
pub trait EventManagerHooksTuple<S>
where
S: State,
{
pub trait EventManagerHooksTuple<I, S> {
/// The hook that runs before `handle_in_client`
fn pre_exec_all(
&mut self,
state: &mut S,
client_id: ClientId,
event: &Event<S::Input>,
event: &Event<I>,
) -> Result<bool, Error>;

/// Ran when the Event Manager decides to accept an event and propagates it
fn on_fire_all(
&mut self,
state: &mut S,
client_id: ClientId,
event: &Event<S::Input>,
event: &Event<I>,
) -> Result<(), Error>;

/// The hook that runs after `handle_in_client`
fn post_exec_all(&mut self, state: &mut S, client_id: ClientId) -> Result<bool, Error>;
}

impl<S> EventManagerHooksTuple<S> for ()
where
S: State,
{
impl<I, S> EventManagerHooksTuple<I, S> for () {
/// The hook that runs before `handle_in_client`
fn pre_exec_all(
&mut self,
_state: &mut S,
_client_id: ClientId,
_event: &Event<S::Input>,
_event: &Event<I>,
) -> Result<bool, Error> {
Ok(true)
}
Expand All @@ -80,7 +71,7 @@ where
&mut self,
_state: &mut S,
_client_id: ClientId,
_event: &Event<S::Input>,
_event: &Event<I>,
) -> Result<(), Error> {
Ok(())
}
Expand All @@ -91,18 +82,17 @@ where
}
}

impl<Head, Tail, S> EventManagerHooksTuple<S> for (Head, Tail)
impl<Head, Tail, I, S> EventManagerHooksTuple<I, S> for (Head, Tail)
where
Head: EventManagerHook<S>,
Tail: EventManagerHooksTuple<S>,
S: State,
Head: EventManagerHook<I, S>,
Tail: EventManagerHooksTuple<I, S>,
{
/// The hook that runs before `handle_in_client`
fn pre_exec_all(
&mut self,
state: &mut S,
client_id: ClientId,
event: &Event<S::Input>,
event: &Event<I>,
) -> Result<bool, Error> {
let first = self.0.pre_exec(state, client_id, event)?;
let second = self.1.pre_exec_all(state, client_id, event)?;
Expand All @@ -113,7 +103,7 @@ where
&mut self,
state: &mut S,
client_id: ClientId,
event: &Event<S::Input>,
event: &Event<I>,
) -> Result<(), Error> {
self.0.on_fire(state, client_id, event)?;
self.1.on_fire_all(state, client_id, event)
Expand Down
Loading

0 comments on commit c4bd3d4

Please sign in to comment.