diff --git a/src/ext/search.rs b/src/ext/search.rs index 55a94fb..b42641b 100644 --- a/src/ext/search.rs +++ b/src/ext/search.rs @@ -26,7 +26,11 @@ pub trait SearchExt { fn search_i8(&self, value: i8, byte_order: Option) -> SearchExtResult>; fn search_i16(&self, value: i16, byte_order: Option) -> SearchExtResult>; fn search_i32(&self, value: i32, byte_order: Option) -> SearchExtResult>; + #[cfg(target_pointer_width = "64")] fn search_i64(&self, value: i64, byte_order: Option) -> SearchExtResult>; + fn search_f32(&self, value: f32, byte_order: Option) -> SearchExtResult>; + #[cfg(target_pointer_width = "64")] + fn search_f64(&self, value: f64, byte_order: Option) -> SearchExtResult>; } #[cfg(target_os = "linux")] @@ -220,6 +224,27 @@ impl SearchExt for crate::prelude::Process { }), ) } + + fn search_f32(&self, value: f32, byte_order: Option) -> SearchExtResult> { + self.search_bytes( + &(match byte_order { + Some(ByteOrder::BigEndian) => value.to_be_bytes(), + Some(ByteOrder::LittleEndian) => value.to_le_bytes(), + None => value.to_ne_bytes(), + }), + ) + } + + #[cfg(target_pointer_width = "64")] + fn search_f64(&self, value: f64, byte_order: Option) -> SearchExtResult> { + self.search_bytes( + &(match byte_order { + Some(ByteOrder::BigEndian) => value.to_be_bytes(), + Some(ByteOrder::LittleEndian) => value.to_le_bytes(), + None => value.to_ne_bytes(), + }), + ) + } } #[derive(Debug, Error)] @@ -468,6 +493,7 @@ mod linux_tests { assert_contains!(addresses, &target_address); } + #[cfg(target_pointer_width = "64")] #[rstest] fn test_search_i64(dummy_process: DummyProcess) { let process = @@ -489,4 +515,49 @@ mod linux_tests { assert_contains!(addresses, &target_address); } + + #[rstest] + fn test_search_f32(dummy_process: DummyProcess) { + let process = + Process::try_new(dummy_process.pid).expect("Could not get dummy process with id."); + let addresses = process + .search_f32(1.5, None) + .expect("Could not search f32 value."); + + let target_address: usize = { + let response = + reqwest::blocking::get(format!("{}/f32val/address", dummy_process.base_url)) + .expect("Could not request f32val address."); + response + .text() + .expect("Could not decode the charset of f32val address.") + .parse() + } + .expect("Could not parse address usize."); + + assert_contains!(addresses, &target_address); + } + + #[cfg(target_pointer_width = "64")] + #[rstest] + fn test_search_f64(dummy_process: DummyProcess) { + let process = + Process::try_new(dummy_process.pid).expect("Could not get dummy process with id."); + let addresses = process + .search_f64(2.5, None) + .expect("Could not search f64 value."); + + let target_address: usize = { + let response = + reqwest::blocking::get(format!("{}/f64val/address", dummy_process.base_url)) + .expect("Could not request f64val address."); + response + .text() + .expect("Could not decode the charset of f64val address.") + .parse() + } + .expect("Could not parse address usize."); + + assert_contains!(addresses, &target_address); + } }