Skip to content

Update Dependencies and Address Clippy Lints #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2018"
[dependencies]
fuzz_runner={path="../fuzz_runner"}
colored = "2.0.0"
clap="2.33.0"
clap="4"
172 changes: 85 additions & 87 deletions acat/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use fuzz_runner::nyx::aux_buffer;

use clap::{App, Arg, AppSettings};
use clap::{Arg, Command};

use std::fs::{OpenOptions};
use std::str;
Expand All @@ -10,126 +10,124 @@ use colored::*;


fn print_aux_buffer(aux_buffer: &aux_buffer::AuxBuffer, target_file: &String, show_header: bool, show_cap: bool, show_config: bool, show_result: bool, show_misc: bool, colored_output: bool){
println!("\n{} {} {}", "**************", target_file.green().bold(), "**************");


println!(
"\n************** {} **************",
target_file.green().bold()
);

colored::control::set_override(colored_output);


if show_header{
println!("\n{} {}", "=>", "HEADER".blue().bold());
println!("\n=> {}", "HEADER".blue().bold());
print!("{}", format!("{:#?}", aux_buffer.header).yellow());
}

if show_cap{
println!("\n{} {}", "=>", "CAP".blue().bold());
println!("\n=> {}", "CAP".blue().bold());
print!("{}", format!("{:#?}", aux_buffer.cap).yellow());
}

if show_config{
println!("\n{} {}", "=>", "CONFIG".blue().bold());
println!("\n=> {}", "CONFIG".blue().bold());
print!("{}", format!("{:#?}", aux_buffer.config).yellow());
}

if show_result{
println!("\n{} {}", "=>", "RESULT".blue().bold());
println!("\n=> {}", "RESULT".blue().bold());
print!("{}", format!("{:#?}", aux_buffer.result).yellow());
}

if show_misc{
if aux_buffer.misc.len != 0 {
println!("\n{} {}", "=>", "MISC".blue().bold());
let len = aux_buffer.misc.len;
println!("{}", str::from_utf8(&aux_buffer.misc.data[0..len as usize]).unwrap().red());
}
if show_misc && aux_buffer.misc.len != 0 {
println!("\n=> {}", "MISC".blue().bold());
let len = aux_buffer.misc.len;
println!("{}", str::from_utf8(&aux_buffer.misc.data[0..len as usize]).unwrap().red());
}
}

fn main() {

let matches = App::new("acat")
let matches = Command::new("acat")
.about("Fancy tool to debug aux buffers!")
.arg(
Arg::with_name("target_file")
.short("f")
Arg::new("target_file")
.short('f')
.long("target_file")
.value_name("TARGET")
.takes_value(true)
.num_args(1)
.help("specifies target file (aux buffer)"),
)
.arg(
Arg::with_name("show_header")
.long("show_header")
.value_name("SHOW_HEADER")
.required(false)
.takes_value(false)
.help("show header section"),
)
.arg(
Arg::with_name("show_cap")
.long("show_cap")
.value_name("SHOW_CAP")
.required(false)
.takes_value(false)
.help("show capabilities section"),
)
.arg(
Arg::with_name("show_config")
.long("show_config")
.value_name("SHOW_CONFIG")
.required(false)
.takes_value(false)
.help("show config section"),
)
.arg(
Arg::with_name("ignore_result")
.long("ignore_result")
.value_name("IGNORE_RESULT")
.required(false)
.takes_value(false)
.help("dont't show result section"),
)
.arg(
Arg::with_name("show_misc")
.long("show_misc")
.value_name("SHOW_MISC")
.required(false)
.takes_value(false)
.help("show misc section"),
)
.arg(
Arg::with_name("show_all")
.short("a")
.long("show_all")
.value_name("SHOW_ALL")
.required(false)
.takes_value(false)
.help("show all sections"),
)
.arg(
Arg::with_name("disable_color")
.short("c")
.long("disable_color")
.value_name("SHOW_ALL")
.required(false)
.takes_value(false)
.help("show all sections"),
)
.setting(AppSettings::ArgRequiredElseHelp)
)
.arg(
Arg::new("show_header")
.long("show_header")
.value_name("SHOW_HEADER")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show header section"),
)
.arg(
Arg::new("show_cap")
.long("show_cap")
.value_name("SHOW_CAP")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show capabilities section"),
)
.arg(
Arg::new("show_config")
.long("show_config")
.value_name("SHOW_CONFIG")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show config section"),
)
.arg(
Arg::new("ignore_result")
.long("ignore_result")
.value_name("IGNORE_RESULT")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("dont't show result section"),
)
.arg(
Arg::new("show_misc")
.long("show_misc")
.value_name("SHOW_MISC")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show misc section"),
)
.arg(
Arg::new("show_all")
.short('a')
.long("show_all")
.value_name("SHOW_ALL")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show all sections"),
)
.arg(
Arg::new("disable_color")
.short('c')
.long("disable_color")
.value_name("SHOW_ALL")
.required(false)
.action(clap::ArgAction::SetTrue)
.help("show all sections"),
)
//.setting(AppSettings::ArgRequiredElseHelp)
.get_matches();


let show_header: bool = matches.is_present("show_header");
let show_cap: bool = matches.is_present("show_cap");
let show_config: bool = matches.is_present("show_config");
let show_result: bool = !matches.is_present("ignore_result");
let show_misc: bool = matches.is_present("show_misc");
let colered_output: bool = !matches.is_present("disable_color");
let show_header: bool = matches.get_flag("show_header");
let show_cap: bool = matches.get_flag("show_cap");
let show_config: bool = matches.get_flag("show_config");
let show_result: bool = !matches.get_flag("ignore_result");
let show_misc: bool = matches.get_flag("show_misc");
let colered_output: bool = !matches.get_flag("disable_color");



let aux_buffer_file = matches.value_of("target_file").expect("file not found");
let aux_buffer_file = matches.get_one::<String>("target_file").expect("file not found");
let aux_shm_f = OpenOptions::new()
.write(false)
.read(true)
Expand All @@ -139,7 +137,7 @@ fn main() {

aux_buffer.validate_header().unwrap();

if matches.is_present("show_all"){
if matches.get_flag("show_all"){
print_aux_buffer(&aux_buffer, &aux_buffer_file.to_string(), true, true, true, true, true, colered_output);
}
else{
Expand Down
5 changes: 2 additions & 3 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde ="1.0.104"
serde_derive ="1.0.104"
ron="0.6.2"
serde = { version = "1.0.104", features = ["derive"] }
ron="0.8"
45 changes: 22 additions & 23 deletions config/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::Duration;
use serde_derive::Serialize;
use serde_derive::Deserialize;
use serde::{Deserialize, Serialize};
use std::fs::File;
use std::path::{Path};
use crate::loader::*;
Expand All @@ -9,7 +8,7 @@ fn into_absolute_path(path_to_sharedir: &str, path_to_file: String) -> String {
let path_to_default_config = Path::new(&path_to_file);

if path_to_default_config.is_relative(){
let path = &format!("{}/{}", path_to_sharedir, path_to_file);
let path = &format!("{path_to_sharedir}/{path_to_file}");
let absolute_path = Path::new(&path);
return absolute_path.canonicalize().unwrap().to_str().unwrap().to_string();
}
Expand Down Expand Up @@ -45,10 +44,10 @@ impl QemuKernelConfig{

let qemu_args = "nokaslr oops=panic nopti ignore_rlimit_data".to_string();
Self{
qemu_binary: qemu_binary,
kernel: kernel,
ramfs: ramfs,
qemu_args: qemu_args,
qemu_binary,
kernel,
ramfs,
qemu_args,
debug: config.debug.or(default.debug).expect("no debug specified"),
}
}
Expand Down Expand Up @@ -81,9 +80,9 @@ impl QemuSnapshotConfig{
presnapshot = into_absolute_path(default_config_folder, presnapshot);

Self{
qemu_binary: qemu_binary,
hda: hda,
presnapshot: presnapshot,
qemu_binary,
hda,
presnapshot,
snapshot_path: config.snapshot_path.or(default.snapshot_path).expect("no snapshot_path specified"),
debug: config.debug.or(default.debug).expect("no debug specified"),
}
Expand Down Expand Up @@ -117,7 +116,7 @@ pub enum SnapshotPlacement {
}

impl std::str::FromStr for SnapshotPlacement {
type Err = ron::Error;
type Err = ron::error::SpannedError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
ron::de::from_str(s)
}
Expand Down Expand Up @@ -151,11 +150,11 @@ impl FuzzerConfig{
None
}
else{
Some(into_absolute_path(&sharedir, seed_path))
Some(into_absolute_path(sharedir, seed_path))
};

Self{
spec_path: format!("{}/spec.msgp",sharedir),
spec_path: format!("{sharedir}/spec.msgp"),
workdir_path: config.workdir_path.or(default.workdir_path).expect("no workdir_path specified"),
bitmap_size: config.bitmap_size.or(default.bitmap_size).expect("no bitmap_size specified"),
input_buffer_size: config.input_buffer_size,
Expand All @@ -170,7 +169,7 @@ impl FuzzerConfig{
dump_python_code_for_inputs: config.dump_python_code_for_inputs.or(default.dump_python_code_for_inputs),
exit_after_first_crash: config.exit_after_first_crash.unwrap_or(default.exit_after_first_crash.unwrap_or(false)),
write_protected_input_buffer: config.write_protected_input_buffer,
cow_primary_size: if config.cow_primary_size != 0 { Some( config.cow_primary_size as u64) } else { None },
cow_primary_size: if config.cow_primary_size != 0 { Some( config.cow_primary_size) } else { None },
ipt_filters: [
config.ip0,
config.ip1,
Expand All @@ -190,27 +189,27 @@ pub struct Config {
impl Config{
pub fn new_from_loader(sharedir: &str, default_config_folder: &str, default: ConfigLoader, config: ConfigLoader) -> Self{
Self{
runner: FuzzRunnerConfig::new_from_loader(&default_config_folder, default.runner, config.runner),
fuzz: FuzzerConfig::new_from_loader(&sharedir, default.fuzz, config.fuzz),
runner: FuzzRunnerConfig::new_from_loader(default_config_folder, default.runner, config.runner),
fuzz: FuzzerConfig::new_from_loader(sharedir, default.fuzz, config.fuzz),
}
}

pub fn new_from_sharedir(sharedir: &str) -> Result<Self, String> {
let path_to_config = format!("{}/config.ron", sharedir);
let path_to_config = format!("{sharedir}/config.ron");

let cfg_file = match File::open(&path_to_config){
Ok(x) => {x},
Err(_) => return Err(format!("file or folder not found ({})!", path_to_config)),
Err(_) => return Err(format!("file or folder not found ({path_to_config})!")),
};

let mut cfg: ConfigLoader = match ron::de::from_reader(cfg_file){
Ok(x) => {x},
Err(x) => return Err(format!("invalid configuration ({})!", x)),
Err(x) => return Err(format!("invalid configuration ({x})!")),
};

let include_default_config_path = match cfg.include_default_config_path{
Some(x) => {x},
None => return Err(format!("no path to default configuration given!")),
None => return Err("no path to default configuration given!".to_string()),
};

let default_path = into_absolute_path(sharedir, include_default_config_path);
Expand All @@ -219,14 +218,14 @@ impl Config{

let default_file = match File::open(default_path.clone()){
Ok(x) => x,
Err(_) => return Err(format!("default config not found ({})!", default_path)),
Err(_) => return Err(format!("default config not found ({default_path})!")),
};

let default: ConfigLoader = match ron::de::from_reader(default_file){
Ok(x) => {x},
Err(x) => return Err(format!("invalid default configuration ({})!", x)),
Err(x) => return Err(format!("invalid default configuration ({x})!")),
};

Ok(Self::new_from_loader(&sharedir, &default_config_folder, default, cfg))
Ok(Self::new_from_loader(sharedir, default_config_folder, default, cfg))
}
}
1 change: 0 additions & 1 deletion config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate serde;
extern crate serde_derive;
extern crate ron;

mod loader;
Expand Down
8 changes: 2 additions & 6 deletions config/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::config::*;
use serde_derive::Serialize;
use serde_derive::Deserialize;
use serde::{Deserialize, Serialize};
use std::time::Duration;

#[derive(Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -82,10 +81,7 @@ fn default_cow_primary_size() -> u64 {
}

fn default_ipt_filter() -> IptFilter {
IptFilter{
a: 0,
b: 0,
}
IptFilter { a: 0, b: 0 }
}

#[derive(Clone, Serialize, Deserialize)]
Expand Down
Loading