From 725d4450e850eb64d4c3fcda7ae567750f4c741f Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Fri, 31 May 2024 16:16:46 -0400 Subject: Add binaryninja::load_view --- rust/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'rust/src') diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 1c2dacd0..e24a3f78 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -269,6 +269,41 @@ pub fn load_with_options( } } +pub fn load_view( + bv: &BinaryView, + update_analysis_and_wait: bool, + options: Option, +) -> Option> { + let options_or_default = if let Some(opt) = options { + opt.get_json_string() + .ok()? + .into_bytes_with_nul() + .as_ref() + .to_vec() + } else { + Metadata::new_of_type(MetadataType::KeyValueDataType) + .get_json_string() + .ok()? + .as_ref() + .to_vec() + }; + + let handle = unsafe { + binaryninjacore_sys::BNLoadBinaryView( + bv.handle as *mut _, + update_analysis_and_wait, + options_or_default.as_ptr() as *mut core::ffi::c_char, + None, + ) + }; + + if handle.is_null() { + None + } else { + Some(unsafe { BinaryView::from_raw(handle) }) + } +} + pub fn install_directory() -> Result { let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetInstallDirectory() }; if s.is_null() { -- cgit v1.3.1