started corpus

This commit is contained in:
Dominik Maier 2020-10-26 03:07:48 +01:00
parent d91717a34c
commit abc3eb8664
5 changed files with 29 additions and 20 deletions

View File

@ -8,3 +8,4 @@ edition = "2018"
[dependencies] [dependencies]
xxhrs = { version = "2.0.0", features = [] } #"random_entropy"] } xxhrs = { version = "2.0.0", features = [] } #"random_entropy"] }
thiserror = "1.0"

View File

@ -1,7 +1,8 @@
use crate::inputs::Input;
use std::io::Error; use std::io::Error;
use crate::AflError;
use crate::inputs::Input;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct BytesInput { pub struct BytesInput {
bytes: Vec<u8>, bytes: Vec<u8>,
@ -9,10 +10,10 @@ pub struct BytesInput {
impl Input for BytesInput { impl Input for BytesInput {
fn serialize(&self) -> Result<&[u8], Error> { fn serialize(&self) -> Result<&[u8], AflError> {
Ok(&self.bytes) Ok(&self.bytes)
} }
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error> { fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError> {
self.bytes.truncate(0); self.bytes.truncate(0);
self.bytes.extend_from_slice(buf); self.bytes.extend_from_slice(buf);
Ok(()) Ok(())

View File

@ -5,15 +5,17 @@ use std::fs::File;
use std::io::Write; use std::io::Write;
use std::io::Read; use std::io::Read;
use crate::AflError;
pub trait Input { pub trait Input {
fn to_file(&self, path: &str) -> Result<(), Error> { fn to_file(&self, path: &str) -> Result<(), AflError> {
let mut file = File::create(path)?; let mut file = File::create(path)?;
file.write_all(self.serialize()?)?; file.write_all(self.serialize()?)?;
Ok(()) Ok(())
} }
fn from_file(&mut self, path: &str) -> Result<(), Error> { fn from_file(&mut self, path: &str) -> Result<(), AflError> {
let mut file = File::create(path)?; let mut file = File::create(path)?;
let mut buf = vec![]; let mut buf = vec![];
file.read_to_end(&mut buf)?; file.read_to_end(&mut buf)?;
@ -21,8 +23,8 @@ pub trait Input {
Ok(()) Ok(())
} }
fn serialize(&self) -> Result<&[u8], Error>; fn serialize(&self) -> Result<&[u8], AflError>;
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error>; fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError>;
} }

View File

@ -1,3 +1,7 @@
use std::io;
use thiserror::Error;
pub mod corpus;
pub mod engines; pub mod engines;
pub mod executors; pub mod executors;
pub mod feedbacks; pub mod feedbacks;
@ -7,6 +11,19 @@ pub mod mutators;
pub mod stages; pub mod stages;
pub mod utils; pub mod utils;
#[derive(Error, Debug)]
pub enum AflError {
#[error("Error in Serialization: `{0}`")]
Serialize(String),
#[error("File IO failed")]
File(#[from] io::Error),
#[error("Key `{0}` not in Corpus")]
KeyNotFound(String),
#[error("Unknown error")]
Unknown,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]

View File

@ -1,12 +0,0 @@
pub mod engines;
pub mod executors;
pub mod feedbacks;
pub mod inputs;
pub mod monitors;
pub mod mutators;
pub mod stages;
pub mod utils;
fn main() {
println!("Hello, world!");
}