summaryrefslogtreecommitdiff
path: root/rust/src/headless.rs
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-05-03 18:45:19 -0400
committerKyleMiles <krm504@nyu.edu>2021-05-11 16:49:24 -0400
commiteb7a52bf4bd3b19c22f2eadda444ab045c674fe3 (patch)
tree2395d577d410908b5d0291682660dac2017c7e97 /rust/src/headless.rs
parent5731e612900bed0d542421e00e64324dbac9367e (diff)
Rust API : Better headless support; Introducing `binaryninja::open_view` and `binaryninja::open_view_with_options`, updated init/shutdown, script example, more setting support, and misc fixes
Diffstat (limited to 'rust/src/headless.rs')
-rw-r--r--rust/src/headless.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/rust/src/headless.rs b/rust/src/headless.rs
index f7b9f16d..39711f94 100644
--- a/rust/src/headless.rs
+++ b/rust/src/headless.rs
@@ -63,9 +63,7 @@ fn binja_path() -> PathBuf {
PathBuf::from(env::var("PROGRAMFILES").unwrap()).join("Vector35\\BinaryNinja\\")
}
-use binaryninjacore_sys::{
- BNInitCorePlugins, BNInitRepoPlugins, BNInitUserPlugins, BNSetBundledPluginDirectory,
-};
+use binaryninjacore_sys::{BNInitPlugins, BNInitRepoPlugins, BNSetBundledPluginDirectory};
pub fn init() {
unsafe {
@@ -73,8 +71,32 @@ pub fn init() {
let path = CString::new(path.into_string().unwrap()).unwrap();
BNSetBundledPluginDirectory(path.as_ptr());
- BNInitCorePlugins();
- BNInitUserPlugins();
+ BNInitPlugins(true);
BNInitRepoPlugins();
}
}
+
+pub fn shutdown() {
+ //! Unloads plugins, stops all worker threads, and closes open logs
+ //! Important! : Must be called at the end of scripts
+
+ unsafe { binaryninjacore_sys::BNShutdown() };
+}
+
+pub fn script_helper(func: fn()) {
+ //! Prelued-postlued helper function:
+ //! ```
+ //! fn main() {
+ //! binaryninja::headless::script_helper(|| {
+ //! binaryninja::open_view("/bin/cat")
+ //! .expect("Couldn't open `/bin/cat`")
+ //! .iter()
+ //! .for_each(|func| println!(" `{}`", func.symbol().full_name()));
+ //! });
+ //! }
+ //! ```
+
+ init();
+ func();
+ shutdown();
+}