now trying to add functionality
This commit is contained in:
parent
16a79bfbbc
commit
6c3e60df20
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
use std::fs;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::corpus::{Corpus, Testcase};
|
use crate::corpus::{Corpus, Testcase};
|
||||||
@ -195,6 +196,100 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_from_directory<G, C, E, ET, EM>(
|
||||||
|
&mut self,
|
||||||
|
corpus: &mut C,
|
||||||
|
generator: &mut G,
|
||||||
|
engine: &mut Engine<E, OT, ET, I>,
|
||||||
|
manager: &mut EM,
|
||||||
|
in_dir: String,
|
||||||
|
)-> Result<(), AflError>
|
||||||
|
where
|
||||||
|
G: Generator<I, R>,
|
||||||
|
C: Corpus<I, R>,
|
||||||
|
E: Executor<I> + HasObservers<OT>,
|
||||||
|
ET: ExecutorsTuple<I>,
|
||||||
|
EM: EventManager<C, E, OT, FT, I, R>,
|
||||||
|
{
|
||||||
|
for entry in fs::read_dir(in_dir)? {
|
||||||
|
|
||||||
|
let entry = entry?;
|
||||||
|
|
||||||
|
let file = entry.path().display().to_string();
|
||||||
|
|
||||||
|
let attributes = fs::metadata(file.clone());
|
||||||
|
|
||||||
|
if !attributes.is_ok() {
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let attr = attributes?;
|
||||||
|
|
||||||
|
if attr.is_file() {
|
||||||
|
|
||||||
|
println!("Load file {}", file);
|
||||||
|
//let input = read_file(file);
|
||||||
|
//let fitness = self.evaluate_input(&input, engine.executor_mut())?;
|
||||||
|
//if !self.add_if_interesting(corpus, input, fitness)?.is_none() {
|
||||||
|
// added += 1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
} else if attr.is_dir() {
|
||||||
|
|
||||||
|
let _x = load_from_directory(
|
||||||
|
&mut corpus,
|
||||||
|
&mut generator,
|
||||||
|
&mut engine,
|
||||||
|
&mut manager,
|
||||||
|
file,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn load_initial_inputs<G, C, E, ET, EM>(
|
||||||
|
&mut self,
|
||||||
|
corpus: &mut C,
|
||||||
|
generator: &mut G,
|
||||||
|
engine: &mut Engine<E, OT, ET, I>,
|
||||||
|
manager: &mut EM,
|
||||||
|
in_dir: Vec<String>,
|
||||||
|
)-> Result<(), AflError>
|
||||||
|
where
|
||||||
|
G: Generator<I, R>,
|
||||||
|
C: Corpus<I, R>,
|
||||||
|
E: Executor<I> + HasObservers<OT>,
|
||||||
|
ET: ExecutorsTuple<I>,
|
||||||
|
EM: EventManager<C, E, OT, FT, I, R>,
|
||||||
|
{
|
||||||
|
let mut added = 0 as u32;
|
||||||
|
for directory in in_dir {
|
||||||
|
|
||||||
|
let _x = load_from_directory(
|
||||||
|
&mut corpus,
|
||||||
|
&mut generator,
|
||||||
|
&mut engine,
|
||||||
|
&mut manager,
|
||||||
|
directory,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
manager.log(
|
||||||
|
0,
|
||||||
|
format!("Loaded {} initial testcases", 123), // get corpus count
|
||||||
|
)?;
|
||||||
|
manager.process(self, corpus)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_initial_inputs<G, C, E, ET, EM>(
|
pub fn generate_initial_inputs<G, C, E, ET, EM>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
|
@ -131,16 +131,28 @@ pub extern "C" fn afl_libfuzzer_main() {
|
|||||||
|
|
||||||
let mut engine = Engine::new(executor);
|
let mut engine = Engine::new(executor);
|
||||||
|
|
||||||
state
|
if input != None {
|
||||||
.generate_initial_inputs(
|
state
|
||||||
&mut rand,
|
.load_initial_inputs(
|
||||||
&mut corpus,
|
&mut corpus,
|
||||||
&mut generator,
|
&mut generator,
|
||||||
&mut engine,
|
&mut engine,
|
||||||
&mut mgr,
|
&mut mgr,
|
||||||
4,
|
input.unwrap(),
|
||||||
)
|
)
|
||||||
.expect("Failed to load initial inputs");
|
.expect("Failed to load initial corpus");
|
||||||
|
} else {
|
||||||
|
state
|
||||||
|
.generate_initial_inputs(
|
||||||
|
&mut rand,
|
||||||
|
&mut corpus,
|
||||||
|
&mut generator,
|
||||||
|
&mut engine,
|
||||||
|
&mut mgr,
|
||||||
|
4,
|
||||||
|
)
|
||||||
|
.expect("Failed to load initial inputs");
|
||||||
|
}
|
||||||
|
|
||||||
let mut mutator = HavocBytesMutator::new_default();
|
let mut mutator = HavocBytesMutator::new_default();
|
||||||
mutator.set_max_size(4096);
|
mutator.set_max_size(4096);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user