summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
author0cyn <kat@vector35.com>2025-10-22 02:37:05 -0400
committer0cyn <kat@vector35.com>2025-10-29 07:50:20 -0400
commit72fcf44f3731ade3cf1310da55f633f1cb9069ce (patch)
tree8b110d6951080ee3bf3a1a742c2c72dbb497c517 /rust
parent5d9fa6553036f9d0e5216948585f4e7dcde3fcb7 (diff)
Refactor Plugin Load/Management to support upcoming changes
Diffstat (limited to 'rust')
-rw-r--r--rust/src/headless.rs6
-rw-r--r--rust/src/repository/manager.rs54
-rw-r--r--rust/src/repository/plugin.rs10
3 files changed, 15 insertions, 55 deletions
diff --git a/rust/src/headless.rs b/rust/src/headless.rs
index 5910cd85..40ff25b8 100644
--- a/rust/src/headless.rs
+++ b/rust/src/headless.rs
@@ -26,7 +26,7 @@ use crate::enterprise::EnterpriseCheckoutStatus;
use crate::main_thread::{MainThreadAction, MainThreadHandler};
use crate::progress::ProgressCallback;
use crate::rc::Ref;
-use binaryninjacore_sys::{BNInitPlugins, BNInitRepoPlugins};
+use binaryninjacore_sys::{BNInitPlugins};
use std::sync::mpsc::Sender;
use std::sync::Mutex;
use std::thread::JoinHandle;
@@ -221,10 +221,6 @@ pub fn init_with_opts(options: InitializationOptions) -> Result<(), Initializati
unsafe {
BNInitPlugins(options.user_plugins);
- if options.repo_plugins {
- // We are allowed to initialize repo plugins, so do it!
- BNInitRepoPlugins();
- }
}
if !is_license_validated() {
diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs
index cf0118ad..f65adc43 100644
--- a/rust/src/repository/manager.rs
+++ b/rust/src/repository/manager.rs
@@ -1,9 +1,7 @@
-use crate::rc::{Array, Ref, RefCountable};
+use crate::rc::{Array, Ref};
use crate::repository::Repository;
use crate::string::IntoCStr;
-use binaryninjacore_sys::{
- BNCreateRepositoryManager, BNFreeRepositoryManager, BNGetRepositoryManager,
- BNNewRepositoryManagerReference, BNRepositoryGetRepositoryByPath, BNRepositoryManager,
+use binaryninjacore_sys::{BNRepositoryGetRepositoryByPath,
BNRepositoryManagerAddRepository, BNRepositoryManagerCheckForUpdates,
BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories,
};
@@ -13,38 +11,24 @@ use std::ptr::NonNull;
/// Keeps track of all the repositories and keeps the `enabled_plugins.json`
/// file coherent with the plugins that are installed/uninstalled enabled/disabled
-#[repr(transparent)]
pub struct RepositoryManager {
- handle: NonNull<BNRepositoryManager>,
}
impl RepositoryManager {
- #[allow(clippy::should_implement_trait)]
- pub fn default() -> Ref<Self> {
- let result = unsafe { BNGetRepositoryManager() };
- unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) }
- }
-
- pub(crate) unsafe fn ref_from_raw(handle: NonNull<BNRepositoryManager>) -> Ref<Self> {
- Ref::new(Self { handle })
- }
-
- pub fn new(plugins_path: &str) -> Ref<Self> {
- let plugins_path = plugins_path.to_cstr();
- let result = unsafe { BNCreateRepositoryManager(plugins_path.as_ptr()) };
- unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) }
+ pub fn new() -> Self {
+ Self {}
}
/// Check for updates for all managed [`Repository`] objects
pub fn check_for_updates(&self) -> bool {
- unsafe { BNRepositoryManagerCheckForUpdates(self.handle.as_ptr()) }
+ unsafe { BNRepositoryManagerCheckForUpdates() }
}
/// List of [`Repository`] objects being managed
pub fn repositories(&self) -> Array<Repository> {
let mut count = 0;
let result =
- unsafe { BNRepositoryManagerGetRepositories(self.handle.as_ptr(), &mut count) };
+ unsafe { BNRepositoryManagerGetRepositories(&mut count) };
assert!(!result.is_null());
unsafe { Array::new(result, count, ()) }
}
@@ -64,20 +48,20 @@ impl RepositoryManager {
let url = url.to_cstr();
let repo_path = repository_path.to_cstr();
unsafe {
- BNRepositoryManagerAddRepository(self.handle.as_ptr(), url.as_ptr(), repo_path.as_ptr())
+ BNRepositoryManagerAddRepository(url.as_ptr(), repo_path.as_ptr())
}
}
pub fn repository_by_path(&self, path: &Path) -> Option<Repository> {
let path = path.to_cstr();
let result =
- unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) };
+ unsafe { BNRepositoryGetRepositoryByPath(path.as_ptr()) };
NonNull::new(result).map(|raw| unsafe { Repository::from_raw(raw) })
}
/// Gets the default [`Repository`]
pub fn default_repository(&self) -> Ref<Repository> {
- let result = unsafe { BNRepositoryManagerGetDefaultRepository(self.handle.as_ptr()) };
+ let result = unsafe { BNRepositoryManagerGetDefaultRepository() };
assert!(!result.is_null());
unsafe { Repository::ref_from_raw(NonNull::new(result).unwrap()) }
}
@@ -90,23 +74,3 @@ impl Debug for RepositoryManager {
.finish()
}
}
-
-impl ToOwned for RepositoryManager {
- type Owned = Ref<Self>;
-
- fn to_owned(&self) -> Self::Owned {
- unsafe { RefCountable::inc_ref(self) }
- }
-}
-
-unsafe impl RefCountable for RepositoryManager {
- unsafe fn inc_ref(handle: &Self) -> Ref<Self> {
- Self::ref_from_raw(
- NonNull::new(BNNewRepositoryManagerReference(handle.handle.as_ptr())).unwrap(),
- )
- }
-
- unsafe fn dec_ref(handle: &Self) {
- BNFreeRepositoryManager(handle.handle.as_ptr())
- }
-}
diff --git a/rust/src/repository/plugin.rs b/rust/src/repository/plugin.rs
index e0ab9679..45d0e684 100644
--- a/rust/src/repository/plugin.rs
+++ b/rust/src/repository/plugin.rs
@@ -11,15 +11,15 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
#[repr(transparent)]
pub struct RepositoryPlugin {
- handle: NonNull<BNRepoPlugin>,
+ handle: NonNull<BNPlugin>,
}
impl RepositoryPlugin {
- pub(crate) unsafe fn from_raw(handle: NonNull<BNRepoPlugin>) -> Self {
+ pub(crate) unsafe fn from_raw(handle: NonNull<BNPlugin>) -> Self {
Self { handle }
}
- pub(crate) unsafe fn ref_from_raw(handle: NonNull<BNRepoPlugin>) -> Ref<Self> {
+ pub(crate) unsafe fn ref_from_raw(handle: NonNull<BNPlugin>) -> Ref<Self> {
Ref::new(Self { handle })
}
@@ -33,7 +33,7 @@ impl RepositoryPlugin {
/// String of the plugin author
pub fn author(&self) -> String {
- let result = unsafe { BNPluginGetAuthor(self.handle.as_ptr()) };
+ let result = unsafe { BNPluginGetAuthorUrl(self.handle.as_ptr()) };
assert!(!result.is_null());
unsafe { BnString::into_string(result as *mut c_char) }
}
@@ -287,7 +287,7 @@ unsafe impl RefCountable for RepositoryPlugin {
}
impl CoreArrayProvider for RepositoryPlugin {
- type Raw = *mut BNRepoPlugin;
+ type Raw = *mut BNPlugin;
type Context = ();
type Wrapped<'a> = Guard<'a, Self>;
}