diff --git a/afl/Cargo.toml b/afl/Cargo.toml index 7900609236..5d10ec95bd 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -13,6 +13,8 @@ fxhash = "0.2.1" # yet another hash xxhash-rust = { version = "0.8.0", features = ["const_xxh3", "xxh3"] } # xxh3 hashing for rust serde_json = "1.0.60" +num_cpus = "1.0" # cpu count, for llmp example + [[bench]] name = "rand_speeds" harness = false @@ -30,6 +32,10 @@ debug = true default = ["std"] std = [] +[[example]] +name = "llmp_test" +path = "./examples/llmp_test/main.rs" + [dependencies] tuple_list = "0.1.2" hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible diff --git a/afl/llmp_test/src/main.rs b/afl/examples/llmp_test/main.rs similarity index 70% rename from afl/llmp_test/src/main.rs rename to afl/examples/llmp_test/main.rs index 88eaa358d5..18f08e42bb 100644 --- a/afl/llmp_test/src/main.rs +++ b/afl/examples/llmp_test/main.rs @@ -6,18 +6,20 @@ use std::thread; use std::time; use afl::events::llmp; +use afl::events::shmem::AflShmem; +use afl::AflError; const TAG_SIMPLE_U32_V1: u32 = 0x51300321; const TAG_MATH_RESULT_V1: u32 = 0x77474331; fn adder_loop(port: u16) -> ! { - let mut client = llmp::LlmpClient::create_attach_to_tcp(port).unwrap(); + let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); let mut last_result: u32 = 0; let mut current_result: u32 = 0; loop { let mut msg_counter = 0; loop { - let (tag, buf) = match client.recv_buf().unwrap() { + let (_sender, tag, buf) = match client.recv_buf().unwrap() { None => break, Some(msg) => msg, }; @@ -47,29 +49,30 @@ fn adder_loop(port: u16) -> ! { } } -unsafe fn broker_message_hook( +fn broker_message_hook( client_id: u32, - message: *mut llmp::LlmpMsg, -) -> llmp::LlmpMsgHookResult { - match (*message).tag { + tag: llmp::Tag, + message: &[u8], +) -> Result { + match tag { TAG_SIMPLE_U32_V1 => { println!( "Client {:?} sent message: {:?}", client_id, - u32::from_le_bytes((*message).as_slice_unsafe().try_into().unwrap()) + u32::from_le_bytes(message.try_into().unwrap()) ); - llmp::LlmpMsgHookResult::ForwardToClients + Ok(llmp::LlmpMsgHookResult::ForwardToClients) } TAG_MATH_RESULT_V1 => { println!( "Adder Client has this current result: {:?}", - u32::from_le_bytes((*message).as_slice_unsafe().try_into().unwrap()) + u32::from_le_bytes(message.try_into().unwrap()) ); - llmp::LlmpMsgHookResult::Handled + Ok(llmp::LlmpMsgHookResult::Handled) } _ => { println!("Unknwon message id received!"); - llmp::LlmpMsgHookResult::ForwardToClients + Ok(llmp::LlmpMsgHookResult::ForwardToClients) } } } @@ -89,13 +92,16 @@ fn main() { match mode.as_str() { "broker" => { - let mut broker: llmp::LlmpBroker = llmp::LlmpBroker::new().unwrap(); - broker.launch_tcp_listener(port).unwrap(); - broker.add_message_hook(broker_message_hook); - broker.loop_forever(Some(Duration::from_millis(5))) + let mut broker = llmp::LlmpBroker::::new().unwrap(); + broker + .launch_tcp_listener( + std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(), + ) + .unwrap(); + broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5))) } "ctr" => { - let mut client = llmp::LlmpClient::create_attach_to_tcp(port).unwrap(); + let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); let mut counter: u32 = 0; loop { counter = counter.wrapping_add(1); diff --git a/afl/llmp_test/Cargo.toml b/afl/llmp_test/Cargo.toml deleted file mode 100644 index 5ce6bfad10..0000000000 --- a/afl/llmp_test/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "llmp_test" -version = "0.1.0" -authors = ["Dominik Maier "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -num_cpus = "1.0" -afl = { path = "../" } \ No newline at end of file diff --git a/afl/src/observers/mod.rs b/afl/src/observers/mod.rs index 545f1373c7..7bb9fd94b3 100644 --- a/afl/src/observers/mod.rs +++ b/afl/src/observers/mod.rs @@ -313,22 +313,21 @@ where } } -/* #[cfg(feature = "std")] #[cfg(test)] mod tests { - use crate::observers::{Observer, StdMapObserver}; + use crate::observers::StdMapObserver; + use crate::tuples::Named; + static mut MAP: [u32; 4] = [0; 4]; #[test] fn test_observer_serde() { - let o: Box = - Box::new(StdMapObserver::::new("test", unsafe { &mut MAP })); - let s = serde_json::to_string(&o).unwrap(); - println!("{}", s); - let d: Box = serde_json::from_str(&s).unwrap(); - assert_eq!(d.name(), o.name()); + let obv = StdMapObserver::new("test", unsafe { &mut MAP }); + let vec = postcard::to_allocvec(&obv).unwrap(); + println!("{:?}", vec); + let obv2: StdMapObserver = postcard::from_bytes(&vec).unwrap(); + assert_eq!(obv.name(), obv2.name()); } } -*/ diff --git a/afl_derives/Cargo.toml b/afl_derives/Cargo.toml deleted file mode 100644 index 014c3dc43d..0000000000 --- a/afl_derives/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "afl_derives" -version = "0.1.0" -authors = ["Andrea Fioraldi "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -syn = "0.15" -quote = "0.6" - -[lib] -proc-macro = true \ No newline at end of file diff --git a/afl_derives/src/lib.rs b/afl_derives/src/lib.rs deleted file mode 100644 index 219717834b..0000000000 --- a/afl_derives/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -#[macro_use] -extern crate quote; -#[macro_use] -extern crate syn; - -extern crate proc_macro; - -use proc_macro::TokenStream; -use syn::DeriveInput; - -#[proc_macro_derive(MyMacro)] -pub fn my_macro(input: TokenStream) -> TokenStream { - // Parse the input tokens into a syntax tree - let input = parse_macro_input!(input as DeriveInput); - - // Build the output, possibly using quasi-quotation - let expanded = quote! { - // ... - }; - - // Hand the output tokens back to the compiler - TokenStream::from(expanded) -}