Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration to libafl 0.11.1 #11

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hw_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libafl = { version = "0.9.0" }
libafl = { version = "0.11.1" }
libafl_bolts = { version = "0.11.1" }
num-traits = "0.2.15"
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
18 changes: 11 additions & 7 deletions hw_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use libafl::bolts::{AsIter, HasLen};
use libafl_bolts::{AsIter, HasLen, Named};
use libafl::corpus::Testcase;
use libafl::events::EventFirer;
use libafl::executors::ExitKind;
use libafl::feedbacks::{Feedback, MinMapFeedback};
use libafl::inputs::UsesInput;
use libafl::observers::Observer;
use libafl::observers::{MapObserver, ObserversTuple};
use libafl::prelude::{MaxMapFeedback, Named};
use libafl::feedbacks::{MaxMapFeedback};
use libafl::state::{HasClientPerfMonitor, HasNamedMetadata};
use libafl::Error;
use num_traits::Bounded;
Expand Down Expand Up @@ -81,7 +81,7 @@ where
map_obs,
u64::MAX,
);
let feedback = MinMapFeedback::new_tracking(&temp, track_indexes, track_novelties);
let feedback = MinMapFeedback::tracking(&temp, track_indexes, track_novelties);
Self::_new(feedback, u64::MAX, cycles_obs, map_obs, temp.take_name())
}
}
Expand All @@ -105,7 +105,7 @@ where
map_obs,
0,
);
let feedback = MaxMapFeedback::new_tracking(&temp, track_indexes, track_novelties);
let feedback = MaxMapFeedback::tracking(&temp, track_indexes, track_novelties);
Self::_new(feedback, 0, cycles_obs, map_obs, temp.take_name())
}
}
Expand Down Expand Up @@ -311,12 +311,16 @@ where
Ok(interesting)
}

fn append_metadata(
fn append_metadata<OT>(
&mut self,
state: &mut S,
observers: &OT,
testcase: &mut Testcase<S::Input>,
) -> Result<(), Error> {
self.inner.append_metadata(state, testcase)
) -> Result<(), Error>
where
OT: ObserversTuple<S>
{
self.inner.append_metadata(state, observers, testcase)
}

fn discard_metadata(&mut self, state: &mut S, input: &S::Input) -> Result<(), Error> {
Expand Down
3 changes: 2 additions & 1 deletion libafl_verdi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ cc = "1"

[dependencies]
clap = { version = "3.2", features = ["default"] }
libafl = { version = "0.9.0" }
libafl = { version = "0.11.1" }
libafl_bolts = { version = "0.11.1" }
nix = "0.24"
num-traits = { version = "0.2", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
Expand Down
13 changes: 9 additions & 4 deletions libafl_verdi/src/verdi_feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use core::{
};
use serde::{Deserialize, Serialize};
use libafl::{
bolts::tuples::Named,
corpus::Testcase,
events::EventFirer,
executors::ExitKind,
Expand All @@ -18,7 +17,9 @@ use libafl::{
Error,
feedbacks::Feedback
};
use libafl::bolts::AsSlice;

use libafl_bolts::Named;
use libafl_bolts::AsSlice;
use libafl::monitors::UserStats;
use libafl::events::{Event};
use crate::verdi_observer::VerdiShMapObserver as VerdiObserver;
Expand Down Expand Up @@ -158,11 +159,15 @@ where
}

#[inline]
fn append_metadata(
fn append_metadata<OT>(
&mut self,
_state: &mut S,
observers: &OT,
_testcase: &mut Testcase<S::Input>,
) -> Result<(), Error> {
) -> Result<(), Error>
where
OT: ObserversTuple<S>,
{
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions libafl_verdi/src/verdi_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: Apache-2.0

use libafl::{
bolts::{tuples::Named, AsIter, HasLen, AsMutSlice, AsSlice},
executors::{ExitKind},
observers::{MapObserver, Observer},
observers::{DifferentialObserver, ObserversTuple},
Expand All @@ -17,11 +16,12 @@ use core::{
slice::IterMut,
slice::Iter,
};
use libafl::prelude::AsIterMut;
use serde::{Deserialize, Serialize};
use libc::{c_uint, c_char, c_void};
use nix::{sys::wait::waitpid,unistd::{fork, ForkResult}};
use libafl::prelude::OwnedMutSlice;
use libafl_bolts::{
ownedref::OwnedMutSlice, AsIter, AsIterMut, AsMutSlice, AsSlice, HasLen, Named,
};

extern crate fs_extra;
use std::{
Expand Down Expand Up @@ -553,7 +553,7 @@ mod tests {
use std::process;
use crate::verdi_observer::*;
use libafl::prelude::StdShMemProvider;
use libafl::{bolts::{shmem::{ShMem, ShMemProvider}}};
use libafl_bolts::shmem::{ShMem, ShMemProvider};

const MAP_SIZE: usize = 65536 * 4;

Expand Down
3 changes: 2 additions & 1 deletion libafl_verilator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ cc = "1"
[dependencies]
clap = { version = "3.2", features = ["default"] }
# libafl = { path = "../dep/libafl/libafl" }
libafl = { version = "0.8.2" }
libafl = { version = "0.11.1" }
libafl_bolts = { version = "0.11.1" }
nix = "0.24"
num-traits = { version = "0.2", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
Expand Down
22 changes: 12 additions & 10 deletions libafl_verilator/src/verilator_feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
};
use serde::{Deserialize, Serialize};
use libafl::{
bolts::tuples::Named,
corpus::Testcase,
events::EventFirer,
executors::ExitKind,
inputs::Input,
inputs::{Input, UsesInput},

Check warning on line 14 in libafl_verilator/src/verilator_feedback.rs

View workflow job for this annotation

GitHub Actions / Run rust-clippy analyzing

unused import: `Input`
observers::{ObserversTuple},
state::HasClientPerfMonitor,
Error,
feedbacks::Feedback
};
use libafl_bolts::Named;
use crate::verilator_observer::VerilatorObserver;
extern crate fs_extra;

Expand All @@ -32,23 +32,22 @@
outdir: String,
}

impl<I, S> Feedback<I, S> for VerilatorFeedback
impl<S> Feedback<S> for VerilatorFeedback
where
I: Input,
S: HasClientPerfMonitor,
S: UsesInput + HasClientPerfMonitor,
{
#[allow(clippy::wrong_self_convention)]
fn is_interesting<EM, OT>(
&mut self,
_state: &mut S,
_manager: &mut EM,
_input: &I,
_input: &S::Input,
observers: &OT,
_exit_kind: &ExitKind,
) -> Result<bool, Error>
where
EM: EventFirer<I>,
OT: ObserversTuple<I, S>,
EM: EventFirer<State = S>,
OT: ObserversTuple<S>,
{
let observer = observers.match_name::<VerilatorObserver>(self.name()).unwrap();

Expand All @@ -73,13 +72,16 @@

/// Append to the testcase the generated metadata in case of a new corpus item
#[inline]
fn append_metadata(&mut self, _state: &mut S, _testcase: &mut Testcase<I>) -> Result<(), Error> {
fn append_metadata<OT>(&mut self, _state: &mut S, observers: &OT ,_testcase: &mut Testcase<S::Input>) -> Result<(), Error>

Check warning on line 75 in libafl_verilator/src/verilator_feedback.rs

View workflow job for this annotation

GitHub Actions / Run rust-clippy analyzing

unused variable: `observers`
where
OT: ObserversTuple<S>,
{
Ok(())
}

/// Discard the stored metadata in case that the testcase is not added to the corpus
#[inline]
fn discard_metadata(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> {
fn discard_metadata(&mut self, _state: &mut S, _input: &S::Input) -> Result<(), Error> {
Ok(())
}
}
Expand Down
16 changes: 8 additions & 8 deletions libafl_verilator/src/verilator_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

#[cfg(not(feature = "tui"))]
use libafl::{
bolts::{tuples::Named, AsIter, HasLen},
executors::ExitKind,
observers::{MapObserver, Observer},
Error,
};
use libafl_bolts::{Named, AsIter, HasLen};
use std::str;
use core::{
fmt::Debug,
};
// use std::path::Path;
use libafl::prelude::UsesInput;

use ahash::AHasher;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -74,8 +75,11 @@ impl VerilatorObserver {

}

impl<I, S> Observer<I, S> for VerilatorObserver {
fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> {
impl<S> Observer<S> for VerilatorObserver
where
S: UsesInput,
{
fn pre_exec(&mut self, _state: &mut S, _input: &S::Input) -> Result<(), Error> {

// let's clean the map
let initial = self.initial;
Expand All @@ -88,7 +92,7 @@ impl<I, S> Observer<I, S> for VerilatorObserver {
fn post_exec(
&mut self,
_state: &mut S,
_input: &I,
_input: &S::Input,
_exit_kind: &ExitKind,
) -> Result<(), Error> {

Expand Down Expand Up @@ -174,10 +178,6 @@ impl MapObserver for VerilatorObserver {
0
}

fn initial_mut(&mut self) -> &mut <Self as MapObserver>::Entry {
&mut self.initial
}

fn reset_map(&mut self) -> Result<(), Error> {
let len = self.map.len();
self.map.clear();
Expand Down
Loading