Skip to content

Commit

Permalink
Cargo Format/Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ntrash committed Jan 10, 2025
1 parent bce3474 commit 8019b96
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 86 deletions.
2 changes: 1 addition & 1 deletion fuzzers/full_system/nyx_launcher/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Client<'a> {
options: &'a FuzzerOptions,
}

impl<'a> Client<'a> {
impl Client<'_> {
pub fn new(options: &FuzzerOptions) -> Client {
Client { options }
}
Expand Down
17 changes: 9 additions & 8 deletions fuzzers/full_system/nyx_launcher/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ use std::{
};

use clap::Parser;

use libafl::events::{
ClientDescription, EventConfig, Launcher, LlmpEventManager, LlmpRestartingEventManager,
MonitorTypedEventManager,
};
use libafl::{
events::{
ClientDescription, EventConfig, Launcher, LlmpEventManager, LlmpRestartingEventManager,
MonitorTypedEventManager,
},
monitors::{tui::TuiMonitor, Monitor, MultiMonitor},
Error,
};

use libafl_bolts::shmem::{ShMemProvider, StdShMemProvider};
use libafl_bolts::{
core_affinity::CoreId, current_time, llmp::LlmpBroker, staterestore::StateRestorer,
core_affinity::CoreId,
current_time,
llmp::LlmpBroker,
shmem::{ShMemProvider, StdShMemProvider},
staterestore::StateRestorer,
tuples::tuple_list,
};
#[cfg(unix)]
Expand Down
30 changes: 16 additions & 14 deletions fuzzers/full_system/nyx_launcher/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
use std::{marker::PhantomData, process};

use libafl::events::{
ClientDescription, LlmpRestartingEventManager, MonitorTypedEventManager, NopEventManager,
};
use libafl::executors::ShadowExecutor;
use libafl::mutators::I2SRandReplace;
use libafl::stages::CalibrationStage;
use libafl::{
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::EventRestarter,
executors::Executor,
events::{
ClientDescription, EventRestarter, LlmpRestartingEventManager, MonitorTypedEventManager,
NopEventManager,
},
executors::{Executor, ShadowExecutor},
feedback_and_fast, feedback_or, feedback_or_fast,
feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback},
fuzzer::{Evaluator, Fuzzer, StdFuzzer},
inputs::BytesInput,
monitors::Monitor,
mutators::{havoc_mutations, StdMOptMutator, StdScheduledMutator},
mutators::{tokens_mutations, Tokens},
mutators::{
havoc_mutations, tokens_mutations, I2SRandReplace, StdMOptMutator, StdScheduledMutator,
Tokens,
},
observers::{CanTrack, HitcountsMapObserver, StdMapObserver, TimeObserver},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, PowerQueueScheduler,
},
stages::{power::StdPowerMutationalStage, ShadowTracingStage, StagesTuple, StdMutationalStage},
stages::{
power::StdPowerMutationalStage, CalibrationStage, ShadowTracingStage, StagesTuple,
StdMutationalStage,
},
state::{HasCorpus, HasMaxSize, StdState, UsesState},
Error, HasMetadata, NopFuzzer,
};
use libafl_bolts::shmem::StdShMemProvider;
use libafl_bolts::{
current_nanos,
rands::StdRand,
shmem::StdShMemProvider,
tuples::{tuple_list, Merge},
};
use libafl_nyx::{
Expand All @@ -54,7 +56,7 @@ pub struct Instance<'a, M: Monitor> {
phantom: PhantomData<M>,
}

impl<'a, M: Monitor> Instance<'a, M> {
impl<M: Monitor> Instance<'_, M> {
pub fn run(mut self, state: Option<ClientState>) -> Result<(), Error> {
let parent_cpu_id = self
.options
Expand All @@ -65,7 +67,7 @@ impl<'a, M: Monitor> Instance<'a, M> {

let settings = NyxSettings::builder()
.cpu_id(self.client_description.core_id().0)
.parent_cpu_id(Some(parent_cpu_id.0 as usize))
.parent_cpu_id(Some(parent_cpu_id.0))
.input_buffer_size(self.options.buffer_size)
.timeout_secs(0)
.timeout_micro_secs(self.options.timeout)
Expand Down
120 changes: 59 additions & 61 deletions libafl_nyx/src/cmplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ pub enum RedqueenBPType {
impl RedqueenBPType {
fn new(data: &str) -> Result<RedqueenBPType, String> {
match data {
"STR" => return Ok(Self::Str),
"CMP" => return Ok(Self::Cmp),
"SUB" => return Ok(Self::Sub),
"STR" => Ok(Self::Str),
"CMP" => Ok(Self::Cmp),
"SUB" => Ok(Self::Sub),
_ => Err("Unknown redqueen type".to_string()),
}
}
Expand All @@ -116,26 +116,26 @@ impl RedqueenEvent {

let captures = RE
.captures(line)
.ok_or_else(|| format!("Failed to parse Redqueen line: '{}'", line))?;
.ok_or_else(|| format!("Failed to parse Redqueen line: '{line}'"))?;

let addr_s = captures.get(1).ok_or("Missing address field")?.as_str();
let type_s = captures.get(2).ok_or("Missing type field")?.as_str();
let size_s = captures.get(3).ok_or("Missing size field")?.as_str();
let lhs_s = captures.get(4).ok_or("Missing LHS field")?.as_str();
let rhs_s = captures.get(5).ok_or("Missing RHS field")?.as_str();
let imm = captures.get(6).map(|_x| true).unwrap_or(false);
let imm = captures.get(6).is_some_and(|_x| true);

let addr = u64::from_str_radix(addr_s, 16)
.map_err(|_| format!("Invalid address: '{}'", addr_s))?;
let addr =
u64::from_str_radix(addr_s, 16).map_err(|_| format!("Invalid address: '{addr_s}'"))?;
let bp_type = RedqueenBPType::new(type_s)
.map_err(|e| format!("Invalid redqueen type: '{}' - {}", type_s, e))?;
.map_err(|e| format!("Invalid redqueen type: '{type_s}' - {e}"))?;
let size = size_s
.parse::<usize>()
.map_err(|_| format!("Invalid size: '{}'", size_s))?;
.map_err(|_| format!("Invalid size: '{size_s}'"))?;
let lhs =
hex::decode(lhs_s).map_err(|e| format!("Failed to decode LHS: '{}' - {}", lhs_s, e))?;
hex::decode(lhs_s).map_err(|e| format!("Failed to decode LHS: '{lhs_s}' - {e}"))?;
let rhs =
hex::decode(rhs_s).map_err(|e| format!("Failed to decode RHS: '{}' - {}", rhs_s, e))?;
hex::decode(rhs_s).map_err(|e| format!("Failed to decode RHS: '{rhs_s}' - {e}"))?;

Ok(Self {
addr,
Expand All @@ -158,63 +158,61 @@ fn parse_redqueen_data(data: &str) -> RedqueenInfo {
.lines()
.filter_map(|line| RedqueenEvent::new(line).ok())
.collect::<Vec<_>>();
return RedqueenInfo { bps };
RedqueenInfo { bps }
}

impl TryInto<CmpValues> for RedqueenEvent {
type Error = String;

fn try_into(self) -> Result<CmpValues, Self::Error> {
match self.bp_type {
RedqueenBPType::Cmp => {
return match self.size {
8 => Ok(CmpValues::U8((
*self.rhs.first().ok_or("Invalid RHS length for U8")?,
*self.lhs.first().ok_or("Invalid LHS length for U8")?,
self.imm,
))),
16 => Ok(CmpValues::U16((
u16::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U16")?,
),
u16::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U16")?,
),
self.imm,
))),
32 => Ok(CmpValues::U32((
u32::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U32")?,
),
u32::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U32")?,
),
self.imm,
))),
64 => Ok(CmpValues::U64((
u64::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U64")?,
),
u64::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U64")?,
),
self.imm,
))),
_ => Err("Invalid size".to_string()),
}
}
RedqueenBPType::Cmp => match self.size {
8 => Ok(CmpValues::U8((
*self.rhs.first().ok_or("Invalid RHS length for U8")?,
*self.lhs.first().ok_or("Invalid LHS length for U8")?,
self.imm,
))),
16 => Ok(CmpValues::U16((
u16::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U16")?,
),
u16::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U16")?,
),
self.imm,
))),
32 => Ok(CmpValues::U32((
u32::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U32")?,
),
u32::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U32")?,
),
self.imm,
))),
64 => Ok(CmpValues::U64((
u64::from_be_bytes(
self.rhs
.try_into()
.map_err(|_| "Invalid RHS length for U64")?,
),
u64::from_be_bytes(
self.lhs
.try_into()
.map_err(|_| "Invalid LHS length for U64")?,
),
self.imm,
))),
_ => Err("Invalid size".to_string()),
},
// TODO: Add encoding for `STR` and `SUB`
_ => Err("Redqueen type not implemented".to_string()),
}
Expand Down
4 changes: 2 additions & 2 deletions libafl_nyx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(target_os = "linux")]
pub mod cmplog;
#[cfg(target_os = "linux")]
pub mod executor;
#[cfg(target_os = "linux")]
pub mod helper;
#[cfg(target_os = "linux")]
pub mod settings;
#[cfg(target_os = "linux")]
pub mod cmplog;

0 comments on commit 8019b96

Please sign in to comment.