diff options
| author | Mason Reed <mason@vector35.com> | 2024-08-29 19:08:59 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2024-08-29 19:10:30 -0400 |
| commit | c19bd82b7dfe4dd695048dda81707de4da651313 (patch) | |
| tree | 4625c3b3f016d065f2e3443ae4a8c48d2080dd91 | |
| parent | c558b0c44bc80edaaf016e899c391f39dddebeef (diff) | |
Update load setting properties from rust plugin
| -rw-r--r-- | rust/src/settings.rs | 90 | ||||
| -rw-r--r-- | view/bintxt/src/ihex.rs | 21 |
2 files changed, 101 insertions, 10 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, diff --git a/view/bintxt/src/ihex.rs b/view/bintxt/src/ihex.rs index 5b210ff4..bb694941 100644 --- a/view/bintxt/src/ihex.rs +++ b/view/bintxt/src/ihex.rs @@ -3,7 +3,8 @@ use binaryninja::custombinaryview::*; use binaryninja::rc::Ref; use binaryninja::segment::SegmentBuilder; use ihex::Record; - +use binaryninja::platform::Platform; +use binaryninja::settings::Settings; use crate::segment_after_address; use crate::segment_from_address; use crate::sort_and_merge_segments; @@ -150,6 +151,15 @@ impl BinaryViewTypeBase for IHexViewConstructor { fn is_deprecated(&self) -> bool { false } + + fn load_settings_for_data(&self, data: &BinaryView) -> Option<Ref<Settings>> { + self.default_load_settings_for_data(&data).map(|s| { + s.update_bool_property("loader.platform", "readOnly", false); + s.update_bool_property("loader.imageBase", "readOnly", false); + s.update_bool_property("loader.segments", "readOnly", false); + s + }) + } } pub struct IHexView { @@ -206,6 +216,15 @@ unsafe impl CustomBinaryView for IHexView { .contains_code(true), ); } + + // TODO: Because we detached from the raw view this setting will never be set. + let _ = self.core.load_settings(self.type_name()).map(|s| { + let platform_name = s.get_string("loader.platform", Some(&self.core), None); + if let Some(platform) = Platform::by_name(platform_name) { + self.set_default_platform(&platform); + } + }); + Ok(()) } } |
