summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-02-17 20:17:37 -0800
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-02-23 00:09:44 -0800
commit5872ea35017892cd15e3bd1adb500eb9cd02c3c5 (patch)
treed40785836da81f1f6d77c634b96258bb00f70e10
parent271fff5e07edd7abcbbc8afbbd5e7e3fd85d69e4 (diff)
[Rust] Add `load_project_file` and `load_project_file_with_progress`
Use these when you intend to query through the `FileMetadata::project_file`, if you do not use these then you will be in a detached binary view from the originating project
-rw-r--r--rust/src/lib.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 084d8a96..254dd2f8 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -108,6 +108,7 @@ use string::BnString;
use string::IntoCStr;
use string::IntoJson;
+use crate::project::file::ProjectFile;
pub use binaryninjacore_sys::BNDataFlowQueryOption as DataFlowQueryOption;
pub use binaryninjacore_sys::BNEndianness as Endianness;
pub use binaryninjacore_sys::BNILBranchDependence as ILBranchDependence;
@@ -271,6 +272,54 @@ where
}
}
+pub fn load_project_file<O>(
+ file: &ProjectFile,
+ update_analysis_and_wait: bool,
+ options: Option<O>,
+) -> Option<Ref<BinaryView>>
+where
+ O: IntoJson,
+{
+ load_project_file_with_progress(file, update_analysis_and_wait, options, NoProgressCallback)
+}
+
+/// Equivalent to [`load_project_file`] but with a progress callback.
+pub fn load_project_file_with_progress<O, P>(
+ file: &ProjectFile,
+ update_analysis_and_wait: bool,
+ options: Option<O>,
+ mut progress: P,
+) -> Option<Ref<BinaryView>>
+where
+ O: IntoJson,
+ P: ProgressCallback,
+{
+ let options_or_default = if let Some(opt) = options {
+ opt.get_json_string()
+ .ok()?
+ .to_cstr()
+ .to_bytes_with_nul()
+ .to_vec()
+ } else {
+ "{}".to_cstr().to_bytes_with_nul().to_vec()
+ };
+ let handle = unsafe {
+ BNLoadProjectFile(
+ file.handle.as_ptr(),
+ update_analysis_and_wait,
+ options_or_default.as_ptr() as *mut c_char,
+ Some(P::cb_progress_callback),
+ &mut progress as *mut P as *mut c_void,
+ )
+ };
+
+ if handle.is_null() {
+ None
+ } else {
+ Some(unsafe { BinaryView::ref_from_raw(handle) })
+ }
+}
+
pub fn install_directory() -> PathBuf {
let install_dir_ptr: *mut c_char = unsafe { BNGetInstallDirectory() };
assert!(!install_dir_ptr.is_null());