DefaultRand, tidied up imports

This commit is contained in:
Dominik Maier 2020-11-12 11:08:56 +01:00
parent 538ad8edde
commit 1533c87775
15 changed files with 60 additions and 48 deletions

View File

@ -1,16 +1,17 @@
extern crate alloc; extern crate alloc;
pub mod testcase; pub mod testcase;
pub use testcase::{Testcase, TestcaseMetadata}; pub use testcase::{Testcase, TestcaseMetadata};
use crate::inputs::Input;
use crate::utils::{HasRand, Rand};
use crate::AflError;
use alloc::rc::Rc; use alloc::rc::Rc;
use core::cell::RefCell; use core::cell::RefCell;
use core::marker::PhantomData; use core::marker::PhantomData;
use std::path::PathBuf; use std::path::PathBuf;
use crate::inputs::Input;
use crate::utils::{HasRand, Rand};
use crate::AflError;
pub trait HasEntriesVec<I> pub trait HasEntriesVec<I>
where where
I: Input, I: Input,
@ -307,14 +308,14 @@ mod tests {
use crate::corpus::Testcase; use crate::corpus::Testcase;
use crate::corpus::{OnDiskCorpus, QueueCorpus}; use crate::corpus::{OnDiskCorpus, QueueCorpus};
use crate::inputs::bytes::BytesInput; use crate::inputs::bytes::BytesInput;
use crate::utils::Xoshiro256StarRand; use crate::utils::DefaultRand;
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[test]
fn test_queuecorpus() { fn test_queuecorpus() {
let rand = Xoshiro256StarRand::preseeded_rr(); let rand = DefaultRand::preseeded_rr();
let mut q = QueueCorpus::new(OnDiskCorpus::new(&rand, PathBuf::from("fancy/path"))); let mut q = QueueCorpus::new(OnDiskCorpus::new(&rand, PathBuf::from("fancy/path")));
let i = BytesInput::new(vec![0; 4]); let i = BytesInput::new(vec![0; 4]);
let t = Testcase::with_filename_rr(i, PathBuf::from("fancyfile")); let t = Testcase::with_filename_rr(i, PathBuf::from("fancyfile"));

View File

@ -1,4 +1,5 @@
extern crate alloc; extern crate alloc;
use crate::inputs::Input; use crate::inputs::Input;
use crate::AflError; use crate::AflError;

View File

@ -1,15 +1,15 @@
//! The engine is the core piece of every good fuzzer //! The engine is the core piece of every good fuzzer
extern crate alloc; extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;
use crate::corpus::Corpus; use crate::corpus::Corpus;
use crate::feedbacks::Feedback; use crate::feedbacks::Feedback;
use crate::inputs::Input; use crate::inputs::Input;
use crate::stages::Stage; use crate::stages::Stage;
use crate::AflError; use crate::AflError;
use alloc::rc::Rc;
use core::cell::RefCell;
pub trait Engine<C, I> pub trait Engine<C, I>
where where
C: Corpus<I>, C: Corpus<I>,
@ -89,6 +89,10 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use alloc::rc::Rc;
use core::cell::RefCell;
use crate::corpus::{Corpus, InMemoryCorpus, Testcase}; use crate::corpus::{Corpus, InMemoryCorpus, Testcase};
use crate::engines::{DefaultEngine, Engine}; use crate::engines::{DefaultEngine, Engine};
use crate::executors::inmemory::InMemoryExecutor; use crate::executors::inmemory::InMemoryExecutor;
@ -98,10 +102,7 @@ mod tests {
mutation_bitflip, ComposedByMutations, DefaultScheduledMutator, mutation_bitflip, ComposedByMutations, DefaultScheduledMutator,
}; };
use crate::stages::mutational::DefaultMutationalStage; use crate::stages::mutational::DefaultMutationalStage;
use alloc::rc::Rc; use crate::utils::DefaultRand;
use core::cell::RefCell;
use crate::utils::Xoshiro256StarRand;
fn harness<I>(_executor: &dyn Executor<I>, _buf: &[u8]) -> ExitKind { fn harness<I>(_executor: &dyn Executor<I>, _buf: &[u8]) -> ExitKind {
ExitKind::Ok ExitKind::Ok
@ -109,7 +110,7 @@ mod tests {
#[test] #[test]
fn test_engine() { fn test_engine() {
let rand = Xoshiro256StarRand::preseeded_rr(); let rand = DefaultRand::preseeded_rr();
let mut corpus = InMemoryCorpus::<BytesInput, _>::new(&rand); let mut corpus = InMemoryCorpus::<BytesInput, _>::new(&rand);
let testcase = Testcase::new_rr(BytesInput::new(vec![0; 4])); let testcase = Testcase::new_rr(BytesInput::new(vec![0; 4]));

View File

@ -1,15 +1,15 @@
extern crate alloc; extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;
use std::os::raw::c_void;
use std::ptr;
use crate::executors::{Executor, ExitKind};
use crate::feedbacks::Feedback; use crate::feedbacks::Feedback;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::Observer; use crate::observers::Observer;
use crate::AflError; use crate::AflError;
use alloc::rc::Rc;
use core::cell::RefCell;
use crate::executors::{Executor, ExitKind};
use std::os::raw::c_void;
use std::ptr;
type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind; type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind;

View File

@ -1,14 +1,15 @@
extern crate alloc; extern crate alloc;
pub mod inmemory; pub mod inmemory;
use alloc::rc::Rc;
use core::cell::RefCell;
use crate::corpus::Testcase; use crate::corpus::Testcase;
use crate::corpus::TestcaseMetadata; use crate::corpus::TestcaseMetadata;
use crate::feedbacks::Feedback; use crate::feedbacks::Feedback;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::Observer; use crate::observers::Observer;
use crate::AflError; use crate::AflError;
use alloc::rc::Rc;
use core::cell::RefCell;
pub enum ExitKind { pub enum ExitKind {
Ok, Ok,

View File

@ -1,14 +1,14 @@
extern crate alloc; extern crate alloc;
extern crate num; extern crate num;
use crate::corpus::TestcaseMetadata;
use crate::inputs::Input;
use crate::observers::MapObserver;
use core::cell::RefCell; use core::cell::RefCell;
use core::marker::PhantomData; use core::marker::PhantomData;
use num::Integer; use num::Integer;
use crate::corpus::TestcaseMetadata;
use crate::inputs::Input;
use crate::observers::MapObserver;
pub trait Feedback<I> pub trait Feedback<I>
where where
I: Input, I: Input,

View File

@ -1,4 +1,5 @@
extern crate alloc; extern crate alloc;
use crate::inputs::{HasBytesVec, HasTargetBytes, Input}; use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
use crate::AflError; use crate::AflError;
@ -43,11 +44,11 @@ impl BytesInput {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::utils::{next_pow2, Rand, Xoshiro256StarRand}; use crate::utils::{next_pow2, DefaultRand, Rand};
#[test] #[test]
fn test_input() { fn test_input() {
let mut rand = Xoshiro256StarRand::preseeded(); let mut rand = DefaultRand::preseeded();
assert_ne!(rand.next(), rand.next()); assert_ne!(rand.next(), rand.next());
assert!(rand.below(100) < 100); assert!(rand.below(100) < 100);
assert_eq!(rand.below(1), 0); assert_eq!(rand.below(1), 0);

View File

@ -1,8 +1,9 @@
extern crate alloc; extern crate alloc;
pub mod bytes; pub mod bytes;
pub use bytes::BytesInput; pub use bytes::BytesInput;
use std::clone::Clone; use core::clone::Clone;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::io::Write; use std::io::Write;

View File

@ -1,6 +1,4 @@
extern crate alloc; extern crate alloc;
use std::io;
use thiserror::Error;
pub mod corpus; pub mod corpus;
pub mod engines; pub mod engines;
@ -13,6 +11,9 @@ pub mod observers;
pub mod stages; pub mod stages;
pub mod utils; pub mod utils;
use std::io;
use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum AflError { pub enum AflError {
#[error("Error in Serialization: `{0}`")] #[error("Error in Serialization: `{0}`")]

View File

@ -1,11 +1,12 @@
extern crate alloc; extern crate alloc;
pub mod scheduled; pub mod scheduled;
use crate::corpus::Corpus;
pub use scheduled::ComposedByMutations; pub use scheduled::ComposedByMutations;
pub use scheduled::DefaultScheduledMutator; pub use scheduled::DefaultScheduledMutator;
pub use scheduled::HavocBytesMutator; pub use scheduled::HavocBytesMutator;
pub use scheduled::ScheduledMutator; pub use scheduled::ScheduledMutator;
use crate::corpus::Corpus;
use crate::inputs::Input; use crate::inputs::Input;
use crate::utils::HasRand; use crate::utils::HasRand;
use crate::AflError; use crate::AflError;

View File

@ -1,4 +1,5 @@
extern crate alloc; extern crate alloc;
use crate::inputs::{HasBytesVec, Input}; use crate::inputs::{HasBytesVec, Input};
use crate::mutators::Corpus; use crate::mutators::Corpus;
use crate::mutators::Mutator; use crate::mutators::Mutator;
@ -326,12 +327,12 @@ mod tests {
use crate::corpus::{Corpus, InMemoryCorpus}; use crate::corpus::{Corpus, InMemoryCorpus};
use crate::inputs::{BytesInput, HasBytesVec}; use crate::inputs::{BytesInput, HasBytesVec};
use crate::mutators::scheduled::mutation_splice; use crate::mutators::scheduled::mutation_splice;
use crate::utils::{DefaultHasRand, Xoshiro256StarRand}; use crate::utils::{DefaultHasRand, DefaultRand};
#[test] #[test]
fn test_mut_splice() { fn test_mut_splice() {
// With the current impl, seed of 1 will result in a split at pos 2. // With the current impl, seed of 1 will result in a split at pos 2.
let rand = &Xoshiro256StarRand::new_rr(1); let rand = &DefaultRand::new_rr(1);
let mut has_rand = DefaultHasRand::new(&rand); let mut has_rand = DefaultHasRand::new(&rand);
let mut corpus = InMemoryCorpus::new(&rand); let mut corpus = InMemoryCorpus::new(&rand);
corpus.add_input(BytesInput::new(vec!['a' as u8, 'b' as u8, 'c' as u8])); corpus.add_input(BytesInput::new(vec!['a' as u8, 'b' as u8, 'c' as u8]));

View File

@ -1,8 +1,8 @@
extern crate alloc; extern crate alloc;
extern crate num; extern crate num;
use core::slice::from_raw_parts_mut;
use num::Integer; use num::Integer;
use std::slice::from_raw_parts_mut;
use crate::AflError; use crate::AflError;

View File

@ -1,8 +1,9 @@
extern crate alloc; extern crate alloc;
pub mod mutational; pub mod mutational;
use crate::corpus::Corpus;
pub use mutational::DefaultMutationalStage; pub use mutational::DefaultMutationalStage;
use crate::corpus::Corpus;
use crate::inputs::Input; use crate::inputs::Input;
use crate::AflError; use crate::AflError;

View File

@ -1,4 +1,9 @@
extern crate alloc; extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::marker::PhantomData;
use crate::corpus::testcase::Testcase; use crate::corpus::testcase::Testcase;
use crate::executors::Executor; use crate::executors::Executor;
use crate::inputs::Input; use crate::inputs::Input;
@ -8,10 +13,6 @@ use crate::stages::Stage;
use crate::utils::{HasRand, Rand}; use crate::utils::{HasRand, Rand};
use crate::AflError; use crate::AflError;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::marker::PhantomData;
// TODO create HasMutatorsVec trait // TODO create HasMutatorsVec trait
pub trait MutationalStage<C, I, M, E>: Stage<C, I> + HasRand pub trait MutationalStage<C, I, M, E>: Stage<C, I> + HasRand

View File

@ -3,12 +3,13 @@ extern crate alloc;
use alloc::rc::Rc; use alloc::rc::Rc;
use core::cell::RefCell; use core::cell::RefCell;
use std::debug_assert; use core::debug_assert;
use std::fmt::Debug; use core::fmt::Debug;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use xxhash_rust::xxh3::xxh3_64_with_seed; use xxhash_rust::xxh3::xxh3_64_with_seed;
pub type DefaultRand = Xoshiro256StarRand;
/// Ways to get random around here /// Ways to get random around here
pub trait Rand: Debug { pub trait Rand: Debug {
// Sets the seed of this Rand // Sets the seed of this Rand
@ -171,7 +172,7 @@ where
} }
/// Get the next higher power of two /// Get the next higher power of two
pub fn next_pow2(val: u64) -> u64 { pub const fn next_pow2(val: u64) -> u64 {
let mut out = val.wrapping_sub(1); let mut out = val.wrapping_sub(1);
out |= out >> 1; out |= out >> 1;
out |= out >> 2; out |= out >> 2;
@ -183,11 +184,11 @@ pub fn next_pow2(val: u64) -> u64 {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::utils::{next_pow2, DefaultHasRand, HasRand, Rand, Xoshiro256StarRand}; use crate::utils::{next_pow2, DefaultHasRand, DefaultRand, HasRand, Rand};
#[test] #[test]
fn test_rand() { fn test_rand() {
let mut rand = Xoshiro256StarRand::preseeded(); let mut rand = DefaultRand::preseeded();
assert_ne!(rand.next(), rand.next()); assert_ne!(rand.next(), rand.next());
assert!(rand.below(100) < 100); assert!(rand.below(100) < 100);
assert_eq!(rand.below(1), 0); assert_eq!(rand.below(1), 0);
@ -197,7 +198,7 @@ mod tests {
#[test] #[test]
fn test_has_rand() { fn test_has_rand() {
let rand = Xoshiro256StarRand::preseeded_rr(); let rand = DefaultRand::preseeded_rr();
let has_rand = DefaultHasRand::new(&rand); let has_rand = DefaultHasRand::new(&rand);
assert!(has_rand.rand_below(100) < 100); assert!(has_rand.rand_below(100) < 100);