summaryrefslogtreecommitdiff
path: root/rust/src/repository/manager.rs
diff options
context:
space:
mode:
author0cyn <kat@vector35.com>2026-04-14 15:45:28 -0400
committer0cyn <kat@vector35.com>2026-04-14 15:47:03 -0400
commit9fddd2a54eaa640888c656cdfb490690ec6f519b (patch)
treed2379dd29e8c17dd16dda72980273a30763c8b8a /rust/src/repository/manager.rs
parent544b7ee320dd8dd69f7b368a36ee72e3faf7e640 (diff)
Plugin Manifest V2 Support
Diffstat (limited to 'rust/src/repository/manager.rs')
-rw-r--r--rust/src/repository/manager.rs76
1 files changed, 16 insertions, 60 deletions
diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs
index cf0118ad..d20539c4 100644
--- a/rust/src/repository/manager.rs
+++ b/rust/src/repository/manager.rs
@@ -1,11 +1,10 @@
-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,
- BNRepositoryManagerAddRepository, BNRepositoryManagerCheckForUpdates,
- BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories,
+ BNRepositoryGetRepositoryByPath, BNRepositoryManagerAddRepository,
+ BNRepositoryManagerCheckForUpdates, BNRepositoryManagerGetDefaultRepository,
+ BNRepositoryManagerGetRepositories,
};
use std::fmt::Debug;
use std::path::Path;
@@ -13,38 +12,18 @@ 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>,
-}
+pub struct RepositoryManager;
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()) }
- }
-
/// Check for updates for all managed [`Repository`] objects
- pub fn check_for_updates(&self) -> bool {
- unsafe { BNRepositoryManagerCheckForUpdates(self.handle.as_ptr()) }
+ pub fn check_for_updates() -> bool {
+ unsafe { BNRepositoryManagerCheckForUpdates() }
}
/// List of [`Repository`] objects being managed
- pub fn repositories(&self) -> Array<Repository> {
+ pub fn repositories() -> Array<Repository> {
let mut count = 0;
- let result =
- unsafe { BNRepositoryManagerGetRepositories(self.handle.as_ptr(), &mut count) };
+ let result = unsafe { BNRepositoryManagerGetRepositories(&mut count) };
assert!(!result.is_null());
unsafe { Array::new(result, count, ()) }
}
@@ -60,24 +39,21 @@ impl RepositoryManager {
/// * `repository_path` - path to where the repository will be stored on disk locally
///
/// Returns true if the repository was successfully added, false otherwise.
- pub fn add_repository(&self, url: &str, repository_path: &Path) -> bool {
+ pub fn add_repository(url: &str, repository_path: &Path) -> bool {
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())
- }
+ unsafe { BNRepositoryManagerAddRepository(url.as_ptr(), repo_path.as_ptr()) }
}
- pub fn repository_by_path(&self, path: &Path) -> Option<Repository> {
+ pub fn repository_by_path(path: &Path) -> Option<Repository> {
let path = path.to_cstr();
- let result =
- unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) };
+ let result = 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()) };
+ pub fn default_repository() -> Ref<Repository> {
+ let result = unsafe { BNRepositoryManagerGetDefaultRepository() };
assert!(!result.is_null());
unsafe { Repository::ref_from_raw(NonNull::new(result).unwrap()) }
}
@@ -86,27 +62,7 @@ impl RepositoryManager {
impl Debug for RepositoryManager {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RepositoryManager")
- .field("repositories", &self.repositories().to_vec())
+ .field("repositories", &RepositoryManager::repositories().to_vec())
.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())
- }
-}