always using paths

This commit is contained in:
Dominik Maier 2020-12-20 16:21:28 +01:00
parent 8c0735623f
commit f327e0e4ea
2 changed files with 33 additions and 30 deletions

View File

@ -3,7 +3,10 @@
use core::fmt::Debug; use core::fmt::Debug;
use core::marker::PhantomData; use core::marker::PhantomData;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs, path::Path}; use std::{
fs,
path::{Path, PathBuf},
};
use crate::corpus::{Corpus, Testcase}; use crate::corpus::{Corpus, Testcase};
use crate::events::EventManager; use crate::events::EventManager;
@ -83,7 +86,7 @@ where
if attr.is_file() { if attr.is_file() {
println!("Load file {:?}", &path); println!("Load file {:?}", &path);
let bytes = std::fs::read(path)?; let bytes = std::fs::read(&path)?;
let input = BytesInput::new(bytes); let input = BytesInput::new(bytes);
let fitness = self.evaluate_input(&input, engine.executor_mut())?; let fitness = self.evaluate_input(&input, engine.executor_mut())?;
if self.add_if_interesting(corpus, input, fitness)?.is_none() { if self.add_if_interesting(corpus, input, fitness)?.is_none() {
@ -103,7 +106,7 @@ where
generator: &mut G, generator: &mut G,
engine: &mut Engine<E, OT, ET, BytesInput>, engine: &mut Engine<E, OT, ET, BytesInput>,
manager: &mut EM, manager: &mut EM,
in_dir: Vec<String>, in_dirs: &[PathBuf],
) -> Result<(), AflError> ) -> Result<(), AflError>
where where
G: Generator<BytesInput, R>, G: Generator<BytesInput, R>,
@ -112,12 +115,12 @@ where
ET: ExecutorsTuple<BytesInput>, ET: ExecutorsTuple<BytesInput>,
EM: EventManager<C, E, OT, FT, BytesInput, R>, EM: EventManager<C, E, OT, FT, BytesInput, R>,
{ {
for directory in &in_dir { for in_dir in in_dirs {
self.load_from_directory(corpus, generator, engine, manager, Path::new(directory))?; self.load_from_directory(corpus, generator, engine, manager, in_dir)?;
} }
manager.log( manager.log(
0, 0,
format!("Loaded {} initial testcases", in_dir.len()), // get corpus count format!("Loaded {} initial testcases", in_dirs.len()), // get corpus count
)?; )?;
manager.process(self, corpus)?; manager.process(self, corpus)?;
Ok(()) Ok(())

View File

@ -6,6 +6,7 @@ extern crate alloc;
use clap::{App, Arg}; use clap::{App, Arg};
use std::env; use std::env;
use std::path::PathBuf;
use afl::corpus::InMemoryCorpus; use afl::corpus::InMemoryCorpus;
use afl::engines::Engine; use afl::engines::Engine;
@ -87,15 +88,15 @@ pub extern "C" fn afl_libfuzzer_main() {
env::current_dir().unwrap().to_string_lossy().to_string() env::current_dir().unwrap().to_string_lossy().to_string()
}; };
let mut dictionary: Option<Vec<String>> = None; let mut dictionary: Option<Vec<PathBuf>> = None;
if matches.is_present("dictionary") { if matches.is_present("dictionary") {
dictionary = Some(values_t!(matches, "dictionary", String).unwrap_or_else(|e| e.exit())); dictionary = Some(values_t!(matches, "dictionary", PathBuf).unwrap_or_else(|e| e.exit()));
} }
let mut input: Option<Vec<String>> = None; let mut input: Option<Vec<PathBuf>> = None;
if matches.is_present("workdir") { if matches.is_present("workdir") {
input = Some(values_t!(matches, "workdir", String).unwrap_or_else(|e| e.exit())); input = Some(values_t!(matches, "workdir", PathBuf).unwrap_or_else(|e| e.exit()));
} }
if dictionary != None || input != None { if dictionary != None || input != None {
@ -104,19 +105,25 @@ pub extern "C" fn afl_libfuzzer_main() {
// debug prints // debug prints
println!("workdir: {}", workdir); println!("workdir: {:?}", workdir);
if dictionary != None { match dictionary {
for file in dictionary.unwrap() { Some(ref x) => {
println!("dic: {}", file); for file in x {
println!("dic: {:?}", file);
} }
} }
None => (),
}
if input != None { match input {
for indir in input.clone().unwrap() { Some(ref x) => {
println!("in: {}", indir); for indir in x {
println!("in: {:?}", indir);
} }
} }
None => (),
}
// original code // original code
@ -149,18 +156,11 @@ pub extern "C" fn afl_libfuzzer_main() {
// } // }
// } // }
if input != None { match input {
state Some(x) => state
.load_initial_inputs( .load_initial_inputs(&mut corpus, &mut generator, &mut engine, &mut mgr, &x)
&mut corpus, .expect("Failed to load initial corpus"),
&mut generator, None => state
&mut engine,
&mut mgr,
input.unwrap(),
)
.expect("Failed to load initial corpus");
} else {
state
.generate_initial_inputs( .generate_initial_inputs(
&mut rand, &mut rand,
&mut corpus, &mut corpus,
@ -169,7 +169,7 @@ pub extern "C" fn afl_libfuzzer_main() {
&mut mgr, &mut mgr,
4, 4,
) )
.expect("Failed to load initial inputs"); .expect("Failed to load initial inputs"),
} }
let mut mutator = HavocBytesMutator::new_default(); let mut mutator = HavocBytesMutator::new_default();