From d5bac712c9fa269aaeb016648116d3147edf3855 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 12 May 2025 12:06:22 -0400 Subject: [Rust] Misc cleanup --- rust/src/binary_view.rs | 2 +- rust/src/binary_view/reader.rs | 4 ++-- rust/src/custom_binary_view.rs | 4 ++-- rust/src/file_metadata.rs | 16 ++++++++-------- rust/src/settings.rs | 10 ++-------- 5 files changed, 15 insertions(+), 21 deletions(-) (limited to 'rust/src') diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index 1aa97891..4379e7f5 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -1163,7 +1163,7 @@ pub trait BinaryViewExt: BinaryViewBase { if settings_handle.is_null() { Err(()) } else { - Ok(unsafe { Settings::from_raw(settings_handle) }) + Ok(unsafe { Settings::ref_from_raw(settings_handle) }) } } diff --git a/rust/src/binary_view/reader.rs b/rust/src/binary_view/reader.rs index 7b49f28d..685914e2 100644 --- a/rust/src/binary_view/reader.rs +++ b/rust/src/binary_view/reader.rs @@ -68,12 +68,12 @@ impl BinaryReader { unsafe { BNSetBinaryReaderVirtualBase(self.handle, virtual_base_addr) } } - /// Prefer using [crate::reader::BinaryReader::seek] over this. + /// Prefer using [BinaryReader::seek] over this. pub fn seek_to_offset(&mut self, offset: u64) { unsafe { BNSeekBinaryReader(self.handle, offset) } } - /// Prefer using [crate::reader::BinaryReader::seek] over this. + /// Prefer using [BinaryReader::seek] over this. pub fn seek_to_relative_offset(&mut self, offset: i64) { unsafe { BNSeekBinaryReaderRelative(self.handle, offset) } } diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index f809f251..a0b1df21 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -200,7 +200,7 @@ pub trait BinaryViewTypeBase: AsRef { if settings_handle.is_null() { None } else { - unsafe { Some(Settings::from_raw(settings_handle)) } + unsafe { Some(Settings::ref_from_raw(settings_handle)) } } } @@ -388,7 +388,7 @@ impl BinaryViewTypeBase for BinaryViewType { if settings_handle.is_null() { None } else { - unsafe { Some(Settings::from_raw(settings_handle)) } + unsafe { Some(Settings::ref_from_raw(settings_handle)) } } } } diff --git a/rust/src/file_metadata.rs b/rust/src/file_metadata.rs index 56c8a9e9..ed859775 100644 --- a/rust/src/file_metadata.rs +++ b/rust/src/file_metadata.rs @@ -121,8 +121,8 @@ impl FileMetadata { /// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread /// and the thread executing this function, you can deadlock. You should also never call this function /// on multiple threads at a time. See the following issues: - /// - https://github.com/Vector35/binaryninja-api/issues/6289 - /// - https://github.com/Vector35/binaryninja-api/issues/6325 + /// - + /// - pub fn run_undoable_transaction Result, T, E>( &self, func: F, @@ -146,8 +146,8 @@ impl FileMetadata { /// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread /// and the thread executing this function, you can deadlock. You should also never call this function /// on multiple threads at a time. See the following issues: - /// - https://github.com/Vector35/binaryninja-api/issues/6289 - /// - https://github.com/Vector35/binaryninja-api/issues/6325 + /// - + /// - pub fn begin_undo_actions(&self, anonymous_allowed: bool) -> String { unsafe { BnString::into_string(BNBeginUndoActions(self.handle, anonymous_allowed)) } } @@ -157,8 +157,8 @@ impl FileMetadata { /// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread /// and the thread executing this function, you can deadlock. You should also never call this function /// on multiple threads at a time. See the following issues: - /// - https://github.com/Vector35/binaryninja-api/issues/6289 - /// - https://github.com/Vector35/binaryninja-api/issues/6325 + /// - + /// - pub fn commit_undo_actions(&self, id: &str) { let id = id.to_cstr(); unsafe { @@ -171,8 +171,8 @@ impl FileMetadata { /// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread /// and the thread executing this function, you can deadlock. You should also never call this function /// on multiple threads at a time. See the following issues: - /// - https://github.com/Vector35/binaryninja-api/issues/6289 - /// - https://github.com/Vector35/binaryninja-api/issues/6325 + /// - + /// - pub fn revert_undo_actions(&self, id: &str) { let id = id.to_cstr(); unsafe { diff --git a/rust/src/settings.rs b/rust/src/settings.rs index 0047f570..3882ce4d 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -35,7 +35,7 @@ pub struct Settings { } impl Settings { - pub(crate) unsafe fn from_raw(handle: *mut BNSettings) -> Ref { + pub(crate) unsafe fn ref_from_raw(handle: *mut BNSettings) -> Ref { debug_assert!(!handle.is_null()); Ref::new(Self { handle }) } @@ -46,11 +46,7 @@ impl Settings { pub fn new_with_id(instance_id: &str) -> Ref { let instance_id = instance_id.to_cstr(); - unsafe { - let handle = BNCreateSettings(instance_id.as_ptr()); - debug_assert!(!handle.is_null()); - Ref::new(Self { handle }) - } + unsafe { Self::ref_from_raw(BNCreateSettings(instance_id.as_ptr())) } } pub fn set_resource_id(&self, resource_id: &str) { @@ -84,8 +80,6 @@ impl Settings { unsafe { Array::new(result as *mut *mut c_char, count, ()) } } - // TODO Update the settings API to take an optional BinaryView or Function. Separate functions or...? - pub fn get_bool(&self, key: &str) -> bool { self.get_bool_with_opts(key, &mut QueryOptions::default()) } -- cgit v1.3.1