diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-12-05 13:05:44 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-12-05 13:05:44 -0500 |
| commit | ae144062dbdb047b924c2071a37a8154864cb07b (patch) | |
| tree | bd4237b33e29dde60ae49ea60cef3e7d4a4abe54 /rust/examples | |
| parent | b02b6584f7da7d22c82f7d9839f55ea38e51de95 (diff) | |
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.
Diffstat (limited to 'rust/examples')
| -rw-r--r-- | rust/examples/basic_script/src/main.rs | 9 | ||||
| -rw-r--r-- | rust/examples/mlil_lifter/src/main.rs | 5 | ||||
| -rw-r--r-- | rust/examples/mlil_visitor/src/main.rs | 5 | ||||
| -rw-r--r-- | rust/examples/template/src/main.rs | 9 |
4 files changed, 10 insertions, 18 deletions
diff --git a/rust/examples/basic_script/src/main.rs b/rust/examples/basic_script/src/main.rs index 85187747..b979c156 100644 --- a/rust/examples/basic_script/src/main.rs +++ b/rust/examples/basic_script/src/main.rs @@ -3,10 +3,12 @@ use binaryninja::binaryview::{BinaryViewBase, BinaryViewExt}; fn main() { println!("Loading plugins..."); // This loads all the core architecture, platform, etc plugins - 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`"); println!("Filename: `{}`", bv.file().filename()); println!("File size: `{:#x}`", bv.len()); @@ -32,7 +34,4 @@ fn main() { } } } - - // Important! You need to call shutdown or your script will hang forever - binaryninja::headless::shutdown(); } diff --git a/rust/examples/mlil_lifter/src/main.rs b/rust/examples/mlil_lifter/src/main.rs index 3ba25630..b827e0cb 100644 --- a/rust/examples/mlil_lifter/src/main.rs +++ b/rust/examples/mlil_lifter/src/main.rs @@ -14,7 +14,7 @@ fn main() { // This loads all the core architecture, platform, etc plugins // Standalone executables probably need to call this, but plugins do not println!("Loading plugins..."); - binaryninja::headless::init(); + let _headless_session = binaryninja::headless::Session::new(); // Your code here... println!("Loading binary..."); @@ -46,7 +46,4 @@ fn main() { } println!(); } - - // Important! Standalone executables need to call shutdown or they will hang forever - binaryninja::headless::shutdown(); } diff --git a/rust/examples/mlil_visitor/src/main.rs b/rust/examples/mlil_visitor/src/main.rs index 3f75708c..f83a7eac 100644 --- a/rust/examples/mlil_visitor/src/main.rs +++ b/rust/examples/mlil_visitor/src/main.rs @@ -235,7 +235,7 @@ fn main() { // This loads all the core architecture, platform, etc plugins // Standalone executables probably need to call this, but plugins do not println!("Loading plugins..."); - binaryninja::headless::init(); + let _headless_session = binaryninja::headless::Session::new(); // Your code here... println!("Loading binary..."); @@ -261,7 +261,4 @@ fn main() { } println!(); } - - // Important! Standalone executables need to call shutdown or they will hang forever - binaryninja::headless::shutdown(); } diff --git a/rust/examples/template/src/main.rs b/rust/examples/template/src/main.rs index 20e082f2..5b21efb3 100644 --- a/rust/examples/template/src/main.rs +++ b/rust/examples/template/src/main.rs @@ -7,11 +7,13 @@ fn main() { // This loads all the core architecture, platform, etc plugins // Standalone executables probably need to call this, but plugins do not println!("Loading plugins..."); - binaryninja::headless::init(); + let headless_session = binaryninja::headless::Session::new(); // Your code here... 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`"); println!("Filename: `{}`", bv.file().filename()); println!("File size: `{:#x}`", bv.len()); @@ -37,7 +39,4 @@ fn main() { } } } - - // Important! Standalone executables need to call shutdown or they will hang forever - binaryninja::headless::shutdown(); } |
