Skip to content

Commit

Permalink
Merge pull request #6 from AFLplusplus/upd_and_stub
Browse files Browse the repository at this point in the history
MOpt
  • Loading branch information
tokatoka authored May 10, 2023
2 parents 00e7777 + 9105470 commit ea867bb
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"value_profile_cmplog",
"rand_scheduler",
"cov_accounting",
"mopt",
"gramatron",
"grimoire",
"nautilus",
Expand Down
4 changes: 2 additions & 2 deletions grimoire/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use libafl::{
tuples::tuple_list,
AsSlice,
},
corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down Expand Up @@ -316,7 +316,7 @@ fn fuzz(
// RNG
StdRand::with_seed(current_nanos()),
// Corpus that will be evolved, we keep it in memory for performance
CachedOnDiskCorpus::new(corpus_dir, 4096).unwrap(),
InMemoryOnDiskCorpus::new(corpus_dir).unwrap(),
// Corpus in which we store solutions (crashes in this example),
// on disk so the user can get them after stopping the fuzzer
OnDiskCorpus::new(objective_dir).unwrap(),
Expand Down
17 changes: 17 additions & 0 deletions mopt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "mopt"
version = "0.0.1"
authors = ["Andrea Fioraldi <[email protected]>", "Dominik Maier <[email protected]>"]
edition = "2021"

[dependencies]
libafl = { path = "../LibAFL/libafl/" }
libafl_targets = { path = "../LibAFL/libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] }
# TODO Include it only when building cc
libafl_cc = { path = "../LibAFL/libafl_cc/" }
clap = { version = "4.0", features = ["default"] }
nix = "0.26"
mimalloc = { version = "*", default-features = false }

[lib]
crate-type = ["staticlib"]
41 changes: 41 additions & 0 deletions mopt/src/bin/mopt_cc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use libafl_cc::{ClangWrapper, CompilerWrapper, LLVMPasses};
use std::env;

pub fn main() {
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
let mut dir = env::current_exe().unwrap();
let wrapper_name = dir.file_name().unwrap().to_str().unwrap();

let is_cpp = match wrapper_name[wrapper_name.len()-2..].to_lowercase().as_str() {
"cc" => false,
"++" | "pp" | "xx" => true,
_ => panic!("Could not figure out if c or c++ warpper was called. Expected {:?} to end with c or cxx", dir),
};

dir.pop();

let mut cc = ClangWrapper::new();

#[cfg(target_os = "linux")]
cc.add_pass(LLVMPasses::AutoTokens);

if let Some(code) = cc
.cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts.
.silence(true)
// add arguments only if --libafl or --libafl-no-link are present
.need_libafl_arg(true)
.parse_args(&args)
.expect("Failed to parse the command line")
.link_staticlib(&dir, env!("CARGO_PKG_NAME"))
.add_arg("-fsanitize-coverage=trace-pc-guard")
.run()
.expect("Failed to run the wrapped compiler")
{
std::process::exit(code);
}
} else {
panic!("LibAFL CC: No Arguments given");
}
}
5 changes: 5 additions & 0 deletions mopt/src/bin/naive_cxx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod mopt_cc;

fn main() {
mopt_cc::main()
}
Loading

0 comments on commit ea867bb

Please sign in to comment.