Implemented rand::Rng for libafl::Rand as feature flag (#174)
* implemented rand::Rng for libafl::Rand as feature flag * fixed build * renamed macro
This commit is contained in:
parent
b187157bef
commit
c2feddbe7c
@ -40,8 +40,9 @@ default = ["std", "anymap_debug", "derive", "llmp_compression"]
|
|||||||
std = ["serde_json"] # print, env, launcher ... support
|
std = ["serde_json"] # print, env, launcher ... support
|
||||||
anymap_debug = ["serde_json"] # uses serde_json to Debug the anymap trait. Disable for smaller footprint.
|
anymap_debug = ["serde_json"] # uses serde_json to Debug the anymap trait. Disable for smaller footprint.
|
||||||
derive = ["libafl_derive"] # provide derive(SerdeAny) macro.
|
derive = ["libafl_derive"] # provide derive(SerdeAny) macro.
|
||||||
|
rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng`
|
||||||
llmp_bind_public = [] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default.
|
llmp_bind_public = [] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default.
|
||||||
llmp_compression = [] # llmp compression using GZip
|
llmp_compression = ["miniz_oxide"] # llmp compression using GZip
|
||||||
llmp_debug = ["backtrace"] # Enables debug output for LLMP
|
llmp_debug = ["backtrace"] # Enables debug output for LLMP
|
||||||
llmp_small_maps = [] # reduces initial map size for llmp
|
llmp_small_maps = [] # reduces initial map size for llmp
|
||||||
introspection = [] # Include performance statistics of the fuzzing pipeline
|
introspection = [] # Include performance statistics of the fuzzing pipeline
|
||||||
@ -63,12 +64,14 @@ postcard = { version = "0.5.1", features = ["alloc"] } # no_std compatible serde
|
|||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
ctor = "0.1.20"
|
ctor = "0.1.20"
|
||||||
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
|
serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
|
||||||
miniz_oxide = "0.4.4"
|
miniz_oxide = { version = "0.4.4", optional = true}
|
||||||
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs" }
|
core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity_rs" }
|
||||||
num_enum = "0.5.1"
|
num_enum = "0.5.1" # compression/decomrpession lib
|
||||||
hostname = "^0.3" # Is there really no gethostname in the stdlib?
|
hostname = "^0.3" # Is there really no gethostname in the stdlib?
|
||||||
typed-builder = "0.9.0"
|
typed-builder = "0.9.0" # Implement the builder pattern at compiletime
|
||||||
ahash ="0.7"
|
ahash ="0.7" # The hash function already used in hashbrown
|
||||||
|
rand = { version = "0.8.1", optional = true } #
|
||||||
|
rand_core = { version = "0.6.2", optional = true } # This dependency allows us to export our RomuRand as rand::Rng.
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
backtrace = { version = "0.3", optional = true, default-features = false, features = ["std", "libbacktrace"] } # for llmp_debug
|
backtrace = { version = "0.3", optional = true, default-features = false, features = ["std", "libbacktrace"] } # for llmp_debug
|
||||||
|
@ -5,6 +5,9 @@ use xxhash_rust::xxh3::xxh3_64_with_seed;
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use crate::bolts::current_nanos;
|
use crate::bolts::current_nanos;
|
||||||
|
|
||||||
|
#[cfg(feature = "rand_trait")]
|
||||||
|
use rand_core::{self, impls::fill_bytes_via_next, RngCore};
|
||||||
|
|
||||||
const HASH_CONST: u64 = 0xa5b35705;
|
const HASH_CONST: u64 = 0xa5b35705;
|
||||||
|
|
||||||
/// The standard rand implementation for `LibAFL`.
|
/// The standard rand implementation for `LibAFL`.
|
||||||
@ -110,7 +113,7 @@ pub trait RandomSeed: Rand + Default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper macro to impl RandomSeed
|
// helper macro to impl RandomSeed
|
||||||
macro_rules! impl_randomseed {
|
macro_rules! impl_random {
|
||||||
($rand: ty) => {
|
($rand: ty) => {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl RandomSeed for $rand {
|
impl RandomSeed for $rand {
|
||||||
@ -119,14 +122,33 @@ macro_rules! impl_randomseed {
|
|||||||
Self::with_seed(current_nanos())
|
Self::with_seed(current_nanos())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "rand_trait")]
|
||||||
|
impl RngCore for $rand {
|
||||||
|
fn next_u32(&mut self) -> u32 {
|
||||||
|
self.next() as u32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_u64(&mut self) -> u64 {
|
||||||
|
self.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||||
|
fill_bytes_via_next(self, dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
|
||||||
|
Ok(self.fill_bytes(dest))
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_randomseed!(Xoshiro256StarRand);
|
impl_random!(Xoshiro256StarRand);
|
||||||
impl_randomseed!(XorShift64Rand);
|
impl_random!(XorShift64Rand);
|
||||||
impl_randomseed!(Lehmer64Rand);
|
impl_random!(Lehmer64Rand);
|
||||||
impl_randomseed!(RomuTrioRand);
|
impl_random!(RomuTrioRand);
|
||||||
impl_randomseed!(RomuDuoJrRand);
|
impl_random!(RomuDuoJrRand);
|
||||||
|
|
||||||
/// XXH3 Based, hopefully speedy, rnd implementation
|
/// XXH3 Based, hopefully speedy, rnd implementation
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||||
|
@ -205,9 +205,10 @@ impl Forkserver {
|
|||||||
{
|
{
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(Error::Forkserver(
|
return Err(Error::Forkserver(format!(
|
||||||
format!("Could not spawn the forkserver: {:#?}", err).into(),
|
"Could not spawn forkserver: {:#?}",
|
||||||
));
|
err
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ where
|
|||||||
Z: Evaluator<E, EM, I, S>,
|
Z: Evaluator<E, EM, I, S>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
fn perform(
|
fn perform(
|
||||||
&mut self,
|
&mut self,
|
||||||
fuzzer: &mut Z,
|
fuzzer: &mut Z,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user