tidying code
This commit is contained in:
parent
003c346439
commit
dec37fcfdd
@ -98,8 +98,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new Testcase instace given an input behind a Rc RefCell
|
/// Create a new Testcase instace given an input behind a Rc RefCell
|
||||||
pub fn new_rr(input: I) -> Rc<RefCell<Self>> {
|
pub fn new_rr<T>(input: T) -> Rc<RefCell<Self>>
|
||||||
Rc::new(RefCell::new(Self::new(input)))
|
where
|
||||||
|
T: Into<I>,
|
||||||
|
{
|
||||||
|
Rc::new(RefCell::new(Self::new(input.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new Testcase instace given an input and a filename behind a Rc RefCell
|
/// Create a new Testcase instace given an input and a filename behind a Rc RefCell
|
||||||
|
@ -110,10 +110,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_engine() {
|
fn test_engine() {
|
||||||
let rand = DefaultRand::preseeded_rr();
|
let rand: Rc<_> = DefaultRand::preseeded().into();
|
||||||
|
|
||||||
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(vec![0; 4]);
|
||||||
corpus.add(testcase);
|
corpus.add(testcase);
|
||||||
let executor: Rc<RefCell<InMemoryExecutor<BytesInput>>> = InMemoryExecutor::new_rr(harness);
|
let executor: Rc<RefCell<InMemoryExecutor<BytesInput>>> = InMemoryExecutor::new_rr(harness);
|
||||||
let mut engine = DefaultEngine::new();
|
let mut engine = DefaultEngine::new();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
use core::convert::From;
|
||||||
|
|
||||||
use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
|
use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
|
|
||||||
@ -35,6 +37,18 @@ impl HasTargetBytes for BytesInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Vec<u8>> for BytesInput {
|
||||||
|
fn from(bytes: Vec<u8>) -> Self {
|
||||||
|
Self::new(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&[u8]> for BytesInput {
|
||||||
|
fn from(bytes: &[u8]) -> Self {
|
||||||
|
Self::new(bytes.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BytesInput {
|
impl BytesInput {
|
||||||
/// Creates a new bytes input using the given bytes
|
/// Creates a new bytes input using the given bytes
|
||||||
pub fn new(bytes: Vec<u8>) -> Self {
|
pub fn new(bytes: Vec<u8>) -> Self {
|
||||||
|
@ -14,6 +14,7 @@ pub mod utils;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
/// Main error struct for AFL
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum AflError {
|
pub enum AflError {
|
||||||
#[error("Error in Serialization: `{0}`")]
|
#[error("Error in Serialization: `{0}`")]
|
||||||
|
@ -281,6 +281,7 @@ where
|
|||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
S: ScheduledMutator<C, I>,
|
S: ScheduledMutator<C, I>,
|
||||||
{
|
{
|
||||||
|
/// Mutate bytes
|
||||||
fn mutate(&mut self, corpus: &mut C, input: &mut I, stage_idx: i32) -> Result<(), AflError> {
|
fn mutate(&mut self, corpus: &mut C, input: &mut I, stage_idx: i32) -> Result<(), AflError> {
|
||||||
self.scheduled.mutate(corpus, input, stage_idx)
|
self.scheduled.mutate(corpus, input, stage_idx)
|
||||||
}
|
}
|
||||||
|
13
src/utils.rs
13
src/utils.rs
@ -109,6 +109,13 @@ impl Rand for Xoshiro256StarRand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::convert::Into;
|
||||||
|
impl Into<Rc<RefCell<Self>>> for Xoshiro256StarRand {
|
||||||
|
fn into(self) -> Rc<RefCell<Self>> {
|
||||||
|
Rc::new(RefCell::new(self))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Xoshiro256StarRand {
|
impl Xoshiro256StarRand {
|
||||||
/// Creates a new Xoshiro rand with the given seed
|
/// Creates a new Xoshiro rand with the given seed
|
||||||
pub fn new(seed: u64) -> Self {
|
pub fn new(seed: u64) -> Self {
|
||||||
@ -117,6 +124,10 @@ impl Xoshiro256StarRand {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_rc_refcell(self) -> Rc<RefCell<Self>> {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new Xoshiro rand with the given seed, wrapped in a Rc<RefCell<T>>.
|
/// Creates a new Xoshiro rand with the given seed, wrapped in a Rc<RefCell<T>>.
|
||||||
pub fn new_rr(seed: u64) -> Rc<RefCell<Self>> {
|
pub fn new_rr(seed: u64) -> Rc<RefCell<Self>> {
|
||||||
Rc::new(RefCell::new(Self::new(seed)))
|
Rc::new(RefCell::new(Self::new(seed)))
|
||||||
@ -137,8 +148,8 @@ impl Xoshiro256StarRand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
/// fake rand, for testing purposes
|
/// fake rand, for testing purposes
|
||||||
|
#[cfg(test)]
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub struct XKCDRand {
|
pub struct XKCDRand {
|
||||||
val: u64,
|
val: u64,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user