Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
tokatoka committed Jan 11, 2025
1 parent 6e8b88c commit a352779
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions libafl_targets/src/sancov_pcguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,20 @@ use core::marker::PhantomData;
#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly]
#[derive(Debug, Clone, Copy)]
pub struct NgramHook<S>
where
S: libafl::inputs::UsesInput,
pub struct NgramHook<I, S>
{
phantom: PhantomData<S>,
phantom: PhantomData<(I, S)>,
}

/// The hook to initialize ctx everytime we run the harness
#[cfg(feature = "sancov_ctx")]
#[derive(Debug, Clone, Copy)]
pub struct CtxHook<S> {
phantom: PhantomData<S>,
pub struct CtxHook<I, S> {
phantom: PhantomData<(I, S)>,
}

#[cfg(feature = "sancov_ctx")]
impl<S> CtxHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> CtxHook<I, S>
{
/// The constructor for this struct
#[must_use]
Expand All @@ -109,9 +105,7 @@ where
}

#[cfg(feature = "sancov_ctx")]
impl<S> Default for CtxHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> Default for CtxHook<I, S>
{
fn default() -> Self {
Self::new()
Expand All @@ -120,12 +114,10 @@ where

#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly]
impl<S> ExecutorHook<S> for NgramHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> ExecutorHook<I, S> for NgramHook<I, S>
{
fn init<E: HasObservers>(&mut self, _state: &mut S) {}
fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) {
fn pre_exec(&mut self, _state: &mut S, _input: &I) {
#[cfg(feature = "sancov_ngram4")]
unsafe {
PREV_ARRAY_4 = Ngram4::from_array([0, 0, 0, 0]);
Expand All @@ -136,14 +128,12 @@ where
PREV_ARRAY_8 = Ngram8::from_array([0, 0, 0, 0, 0, 0, 0, 0]);
}
}
fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {}
fn post_exec(&mut self, _state: &mut S, _input: &I) {}
}

#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly]
impl<S> NgramHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> NgramHook<I, S>
{
/// The constructor for this struct
#[must_use]
Expand All @@ -156,27 +146,23 @@ where

#[cfg(any(feature = "sancov_ngram4", feature = "sancov_ngram8"))]
#[rustversion::nightly]
impl<S> Default for NgramHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> Default for NgramHook<I, S>
{
fn default() -> Self {
Self::new()
}
}

#[cfg(feature = "sancov_ctx")]
impl<S> ExecutorHook<S> for CtxHook<S>
where
S: libafl::inputs::UsesInput,
impl<I, S> ExecutorHook<I, S> for CtxHook<I, S>
{
fn init<E: HasObservers>(&mut self, _state: &mut S) {}
fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) {
fn pre_exec(&mut self, _state: &mut S, _input: &I) {
unsafe {
__afl_prev_ctx = 0;
}
}
fn post_exec(&mut self, _state: &mut S, _input: &S::Input) {}
fn post_exec(&mut self, _state: &mut S, _input: &I) {}
}

#[rustversion::nightly]
Expand Down

0 comments on commit a352779

Please sign in to comment.