renamed Afl stuff
This commit is contained in:
parent
1d1ab50698
commit
7578fbd790
@ -1,6 +1,6 @@
|
||||
use std::fmt::Debug;
|
||||
use std::collections::HashMap;
|
||||
use crate::AflError;
|
||||
use crate::Error;
|
||||
use crate::utils::Rand;
|
||||
use crate::inputs::Input;
|
||||
|
||||
@ -10,7 +10,7 @@ pub trait TestcaseMetadata: Debug {
|
||||
|
||||
pub trait Testcase: Debug {
|
||||
|
||||
fn load_input(&mut self) -> Result<&Box<dyn Input>, AflError>;
|
||||
fn load_input(&mut self) -> Result<&Box<dyn Input>, Error>;
|
||||
fn is_on_disk(&self) -> bool;
|
||||
fn get_filename(&self) -> &str;
|
||||
fn get_metadatas(&mut self) -> &mut HashMap<String, Box<dyn TestcaseMetadata>>;
|
||||
@ -29,10 +29,10 @@ pub trait Corpus: Debug {
|
||||
fn remove(&mut self, entry: &dyn Testcase) -> Option<Box<dyn Testcase>>;
|
||||
|
||||
/// Gets a random entry
|
||||
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, AflError>;
|
||||
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, Error>;
|
||||
|
||||
/// Gets the next entry
|
||||
fn get(&mut self) -> Result<&Box<dyn Testcase>, AflError>;
|
||||
fn get(&mut self) -> Result<&Box<dyn Testcase>, Error>;
|
||||
|
||||
}
|
||||
|
||||
@ -84,15 +84,15 @@ impl Corpus for DefaultQueue<'_> {
|
||||
}
|
||||
|
||||
/// Gets a random entry
|
||||
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, AflError> {
|
||||
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, Error> {
|
||||
let id = self.rand.below(self.entries.len() as u64) as usize;
|
||||
Ok(self.entries.get_mut(id).unwrap())
|
||||
}
|
||||
|
||||
/// Gets the next entry
|
||||
fn get(&mut self) -> Result<&Box<dyn Testcase>, AflError> {
|
||||
fn get(&mut self) -> Result<&Box<dyn Testcase>, Error> {
|
||||
if self.entries.len() == 0 {
|
||||
return Err(AflError::Unknown)
|
||||
return Err(Error::Unknown)
|
||||
}
|
||||
self.pos = self.pos + 1;
|
||||
if self.pos >= self.entries.len() {
|
||||
@ -140,9 +140,9 @@ struct SimpleTestcase {
|
||||
|
||||
impl Testcase for SimpleTestcase {
|
||||
|
||||
fn load_input(&mut self) -> Result<&Box<dyn Input>, AflError> {
|
||||
fn load_input(&mut self) -> Result<&Box<dyn Input>, Error> {
|
||||
// TODO: Implement
|
||||
Err(AflError::Unknown)
|
||||
Err(Error::Unknown)
|
||||
}
|
||||
|
||||
fn is_on_disk(&self) -> bool {
|
||||
@ -174,11 +174,11 @@ mod tests {
|
||||
use crate::corpus::Corpus;
|
||||
use crate::corpus::DefaultQueue;
|
||||
use crate::corpus::SimpleTestcase;
|
||||
use crate::utils::AflRand;
|
||||
use crate::utils::Xoshiro256StarRand;
|
||||
|
||||
#[test]
|
||||
fn test_defaultqueue() {
|
||||
let mut rand = AflRand::new();
|
||||
let mut rand = Xoshiro256StarRand::new();
|
||||
let mut q = DefaultQueue::new(&mut rand, "fancy/path");
|
||||
q.add(Box::new(SimpleTestcase::new("fancyfile")));
|
||||
let filename = q.get().unwrap().get_filename().to_owned();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::AflError;
|
||||
use crate::Error;
|
||||
use crate::inputs::Input;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -8,10 +8,10 @@ pub struct BytesInput {
|
||||
|
||||
impl Input for BytesInput {
|
||||
|
||||
fn serialize(&self) -> Result<&[u8], AflError> {
|
||||
fn serialize(&self) -> Result<&[u8], Error> {
|
||||
Ok(&self.bytes)
|
||||
}
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError> {
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error> {
|
||||
self.bytes.truncate(0);
|
||||
self.bytes.extend_from_slice(buf);
|
||||
Ok(())
|
||||
|
@ -4,17 +4,17 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::io::Read;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::Error;
|
||||
|
||||
pub trait Input {
|
||||
|
||||
fn to_file(&self, path: &str) -> Result<(), AflError> {
|
||||
fn to_file(&self, path: &str) -> Result<(), Error> {
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(self.serialize()?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn from_file(&mut self, path: &str) -> Result<(), AflError> {
|
||||
fn from_file(&mut self, path: &str) -> Result<(), Error> {
|
||||
let mut file = File::create(path)?;
|
||||
let mut buf = vec![];
|
||||
file.read_to_end(&mut buf)?;
|
||||
@ -22,8 +22,8 @@ pub trait Input {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize(&self) -> Result<&[u8], AflError>;
|
||||
fn serialize(&self) -> Result<&[u8], Error>;
|
||||
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError>;
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error>;
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ pub mod stages;
|
||||
pub mod utils;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum AflError {
|
||||
pub enum Error {
|
||||
#[error("Error in Serialization: `{0}`")]
|
||||
Serialize(String),
|
||||
#[error("File IO failed")]
|
||||
|
14
src/utils.rs
14
src/utils.rs
@ -47,7 +47,7 @@ const HASH_CONST: u64 = 0xa5b35705;
|
||||
/// XXH3 Based, hopefully speedy, rnd implementation
|
||||
///
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct AflRand {
|
||||
pub struct Xoshiro256StarRand {
|
||||
|
||||
|
||||
rand_seed: [u64; 4],
|
||||
@ -55,7 +55,7 @@ pub struct AflRand {
|
||||
|
||||
}
|
||||
|
||||
impl Rand for AflRand {
|
||||
impl Rand for Xoshiro256StarRand {
|
||||
|
||||
|
||||
|
||||
@ -88,11 +88,11 @@ impl Rand for AflRand {
|
||||
|
||||
}
|
||||
|
||||
impl AflRand {
|
||||
impl Xoshiro256StarRand {
|
||||
|
||||
pub fn new() -> AflRand {
|
||||
pub fn new() -> Xoshiro256StarRand {
|
||||
|
||||
let mut ret: AflRand = Default::default();
|
||||
let mut ret: Xoshiro256StarRand = Default::default();
|
||||
ret.set_seed(0); // TODO: Proper random seed?
|
||||
ret
|
||||
}
|
||||
@ -116,11 +116,11 @@ fn next_pow2(val: u64) -> u64 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::{Rand, AflRand, next_pow2};
|
||||
use crate::utils::{Rand, Xoshiro256StarRand, next_pow2};
|
||||
|
||||
#[test]
|
||||
fn test_rand() {
|
||||
let mut rand = AflRand::new();
|
||||
let mut rand = Xoshiro256StarRand::new();
|
||||
assert_ne!(rand.next(), rand.next());
|
||||
assert!(rand.below(100) < 100);
|
||||
assert_eq!(rand.below(1), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user