From ae144062dbdb047b924c2071a37a8154864cb07b Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Tue, 5 Dec 2023 13:05:44 -0500 Subject: Resolves #3714: Adds core initialization/shutdown wrapper object (to the Rust API) that you can initialize at the top of your script and it'll auto-cleanup at the end of your script. Also some misc doc fixes. --- rust/src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'rust/src/lib.rs') diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 3eff5ea1..d6161d53 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -72,20 +72,17 @@ //! The most up-to-date version of the suggested [`build.rs` is here]. //! //! ### `main.rs` -//! All standalone binaries need to call [`headless::init()`] at start and [`headless::shutdown()`] at shutdown. +//! Standalone binaries need to initialize Binary Ninja before they can work. You can do this through [`headless::Session`], [`headless::script_helper`], or [`headless::init()`] at start and [`headless::shutdown()`] at shutdown. //! ```rust //! fn main() { //! // This loads all the core architecture, platform, etc plugins //! // Standalone executables need to call this, but plugins do not -//! binaryninja::headless::init(); +//! let headless_session = binaryninja::headless::Session::new(); //! //! println!("Loading binary..."); -//! let bv = binaryninja::load("/bin/cat").expect("Couldn't open `/bin/cat`"); +//! let bv = headless_session.load("/bin/cat").expect("Couldn't open `/bin/cat`"); //! //! // Your code here... -//! -//! // Important! Standalone executables need to call shutdown or they will hang forever -//! binaryninja::headless::shutdown(); //! } //! ``` //! @@ -123,7 +120,6 @@ extern crate rayon; // cc possible values // bv reorg // core fileaccessor (for bv saving) -// headless wrapper for shutdown // platform cc #[macro_use] @@ -196,6 +192,7 @@ use string::BnStrCompatible; const BN_FULL_CONFIDENCE: u8 = 255; const BN_INVALID_EXPR: usize = usize::MAX; +/// The main way to open and load files into Binary Ninja. Make sure you've properly initialized the core before calling this function. See [`crate::headless::init()`] pub fn load(filename: S) -> Option> { let filename = filename.into_bytes_with_nul(); let metadata = Metadata::new_of_type(MetadataType::KeyValueDataType); @@ -216,6 +213,8 @@ pub fn load(filename: S) -> Option