diff --git a/Cargo.lock b/Cargo.lock index 46746ef..8075bde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,31 @@ dependencies = [ "libloading", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "either" version = "1.11.0" @@ -108,6 +133,7 @@ name = "il-tests" version = "0.1.0" dependencies = [ "hex-slice", + "rayon", "rizin-rs", ] @@ -216,6 +242,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "regex" version = "1.10.4" diff --git a/il-tests/Cargo.toml b/il-tests/Cargo.toml index 05d4796..c1e31bf 100644 --- a/il-tests/Cargo.toml +++ b/il-tests/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] hex-slice = "0.1.4" +rayon = "1.10.0" [dependencies.rizin-rs] path = ".." diff --git a/il-tests/src/main.rs b/il-tests/src/main.rs index c187458..cfb08d2 100644 --- a/il-tests/src/main.rs +++ b/il-tests/src/main.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; use std::fmt::{Display, Formatter}; +use std::sync::Mutex; use hex_slice::AsHex; +use rayon::prelude::*; use rizin_rs::wrapper::Core; struct Instruction { @@ -46,17 +48,23 @@ impl Display for Instruction { } fn main() -> Result<(), ()> { - let core = Core::new(); - core.set("analysis.arch", "pic")?; - core.set("analysis.cpu", "pic18")?; let addrs = vec![0, 0xff00]; - let mut insts = HashMap::::new(); + let insts = Mutex::new(HashMap::::new()); const INST_LIMIT: usize = 0x8_usize; - for x in 0x1000_u32..0xffff_u32 { + let core = Mutex::new(Core::new()); + { + let co = core.lock().unwrap(); + co.set("analysis.arch", "pic").unwrap(); + co.set("analysis.cpu", "pic18").unwrap(); + } + + (0x1000_u32..u32::MAX).into_par_iter().for_each(|x| { + let core = core.lock().unwrap(); let b: [u8; 4] = x.to_le_bytes(); for addr in addrs.clone() { if let Ok(inst) = Instruction::from_bytes(&core, &b, addr) { + let mut insts = insts.lock().unwrap(); match insts.get_mut(&inst.inst) { Some(k) if *k > INST_LIMIT => continue, Some(k) => { @@ -70,6 +78,7 @@ fn main() -> Result<(), ()> { } } } - } + }); + Ok(()) } diff --git a/src/wrapper.rs b/src/wrapper.rs index 1c0078f..6c97444 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -9,6 +9,9 @@ use crate::*; pub struct Core(pub Box); +unsafe impl Sync for Core {} +unsafe impl Send for Core {} + impl Drop for Core { fn drop(&mut self) { let ptr = Box::into_raw(self.0.clone());