summaryrefslogtreecommitdiff
path: root/rust/src/headless.rs
diff options
context:
space:
mode:
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();
+}