Skip to content

Commit f8e79b4

Browse files
committed
[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
1 parent 03e8399 commit f8e79b4

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

rust/src/lib.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ use string::BnString;
108108
use string::IntoCStr;
109109
use string::IntoJson;
110110

111+
use crate::project::file::ProjectFile;
111112
pub use binaryninjacore_sys::BNDataFlowQueryOption as DataFlowQueryOption;
112113
pub use binaryninjacore_sys::BNEndianness as Endianness;
113114
pub use binaryninjacore_sys::BNILBranchDependence as ILBranchDependence;
@@ -271,6 +272,54 @@ where
271272
}
272273
}
273274

275+
pub fn load_project_file<O>(
276+
file: &ProjectFile,
277+
update_analysis_and_wait: bool,
278+
options: Option<O>,
279+
) -> Option<Ref<BinaryView>>
280+
where
281+
O: IntoJson,
282+
{
283+
load_project_file_with_progress(file, update_analysis_and_wait, options, NoProgressCallback)
284+
}
285+
286+
/// Equivalent to [`load_project_file`] but with a progress callback.
287+
pub fn load_project_file_with_progress<O, P>(
288+
file: &ProjectFile,
289+
update_analysis_and_wait: bool,
290+
options: Option<O>,
291+
mut progress: P,
292+
) -> Option<Ref<BinaryView>>
293+
where
294+
O: IntoJson,
295+
P: ProgressCallback,
296+
{
297+
let options_or_default = if let Some(opt) = options {
298+
opt.get_json_string()
299+
.ok()?
300+
.to_cstr()
301+
.to_bytes_with_nul()
302+
.to_vec()
303+
} else {
304+
"{}".to_cstr().to_bytes_with_nul().to_vec()
305+
};
306+
let handle = unsafe {
307+
BNLoadProjectFile(
308+
file.handle.as_ptr(),
309+
update_analysis_and_wait,
310+
options_or_default.as_ptr() as *mut c_char,
311+
Some(P::cb_progress_callback),
312+
&mut progress as *mut P as *mut c_void,
313+
)
314+
};
315+
316+
if handle.is_null() {
317+
None
318+
} else {
319+
Some(unsafe { BinaryView::ref_from_raw(handle) })
320+
}
321+
}
322+
274323
pub fn install_directory() -> PathBuf {
275324
let install_dir_ptr: *mut c_char = unsafe { BNGetInstallDirectory() };
276325
assert!(!install_dir_ptr.is_null());

0 commit comments

Comments
 (0)