summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2024-08-29 19:08:59 -0400
committerMason Reed <mason@vector35.com>2024-08-29 19:10:30 -0400
commitc19bd82b7dfe4dd695048dda81707de4da651313 (patch)
tree4625c3b3f016d065f2e3443ae4a8c48d2080dd91 /rust/src
parentc558b0c44bc80edaaf016e899c391f39dddebeef (diff)
Update load setting properties from rust plugin
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/settings.rs90
1 files changed, 81 insertions, 9 deletions
diff --git a/rust/src/settings.rs b/rust/src/settings.rs
index ff959cfc..f37a5a34 100644
--- a/rust/src/settings.rs
+++ b/rust/src/settings.rs
@@ -16,7 +16,6 @@
pub use binaryninjacore_sys::BNSettingsScope as SettingsScope;
use binaryninjacore_sys::*;
-use std::iter::FromIterator;
use std::os::raw::c_char;
use crate::binaryview::BinaryView;
@@ -363,12 +362,9 @@ impl Settings {
scope: Option<SettingsScope>,
) -> bool {
let key = key.into_bytes_with_nul();
- let v = Vec::from_iter(value);
-
- let mut value = vec![];
- for item in v {
- value.push(item.into_bytes_with_nul().as_ref().as_ptr() as *const c_char);
- }
+ let mut list: Vec<_> = value
+ .map(|s| s.into_bytes_with_nul().as_ref().as_ptr() as *const c_char)
+ .collect();
let view_handle = match view {
Some(view) => view.handle,
@@ -387,8 +383,8 @@ impl Settings {
std::ptr::null_mut(),
scope,
key.as_ref().as_ptr() as *mut _,
- value.as_mut_ptr(),
- value.len(),
+ list.as_mut_ptr(),
+ list.len(),
)
}
}
@@ -425,6 +421,82 @@ impl Settings {
}
}
+ pub fn update_bool_property<S: BnStrCompatible>(&self, key: S, property: S, value: bool) {
+ let key = key.into_bytes_with_nul();
+ let property = property.into_bytes_with_nul();
+ unsafe {
+ BNSettingsUpdateBoolProperty(
+ self.handle,
+ key.as_ref().as_ptr() as *mut _,
+ property.as_ref().as_ptr() as *mut _,
+ value,
+ );
+ }
+ }
+
+ pub fn update_integer_property<S: BnStrCompatible>(&self, key: S, property: S, value: u64) {
+ let key = key.into_bytes_with_nul();
+ let property = property.into_bytes_with_nul();
+ unsafe {
+ BNSettingsUpdateUInt64Property(
+ self.handle,
+ key.as_ref().as_ptr() as *mut _,
+ property.as_ref().as_ptr() as *mut _,
+ value,
+ );
+ }
+ }
+
+ pub fn update_double_property<S: BnStrCompatible>(&self, key: S, property: S, value: f64) {
+ let key = key.into_bytes_with_nul();
+ let property = property.into_bytes_with_nul();
+ unsafe {
+ BNSettingsUpdateDoubleProperty(
+ self.handle,
+ key.as_ref().as_ptr() as *mut _,
+ property.as_ref().as_ptr() as *mut _,
+ value,
+ );
+ }
+ }
+
+ pub fn update_string_property<S: BnStrCompatible>(&self, key: S, property: S, value: S) {
+ let key = key.into_bytes_with_nul();
+ let property = property.into_bytes_with_nul();
+ let value = value.into_bytes_with_nul();
+ unsafe {
+ BNSettingsUpdateStringProperty(
+ self.handle,
+ key.as_ref().as_ptr() as *mut _,
+ property.as_ref().as_ptr() as *mut _,
+ value.as_ref().as_ptr() as *mut _,
+ );
+ }
+ }
+
+ pub fn update_string_list_property<S: BnStrCompatible, I: Iterator<Item = S>>(
+ &self,
+ key: S,
+ property: S,
+ value: I,
+ ) {
+ let key = key.into_bytes_with_nul();
+ let property = property.into_bytes_with_nul();
+ let mut list: Vec<_> = value
+ .map(|s| s.into_bytes_with_nul().as_ref().as_ptr() as *const c_char)
+ .collect();
+
+ unsafe {
+ BNSettingsUpdateStringListProperty(
+ self.handle,
+ key.as_ref().as_ptr() as *mut _,
+ property.as_ref().as_ptr() as *mut _,
+ list.as_mut_ptr(),
+ list.len(),
+ );
+ }
+ }
+
pub fn register_group<S1: BnStrCompatible, S2: BnStrCompatible>(
&self,
group: S1,