summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/src/headless.rs6
-rw-r--r--rust/src/repository.rs8
-rw-r--r--rust/src/repository/manager.rs76
-rw-r--r--rust/src/repository/plugin.rs65
4 files changed, 40 insertions, 115 deletions
diff --git a/rust/src/headless.rs b/rust/src/headless.rs
index 73bc2396..b134c8fe 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.rs b/rust/src/repository.rs
index b7d61cac..2f1ab267 100644
--- a/rust/src/repository.rs
+++ b/rust/src/repository.rs
@@ -11,7 +11,7 @@ use std::ptr::NonNull;
use binaryninjacore_sys::*;
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
-use crate::repository::plugin::RepositoryPlugin;
+use crate::repository::plugin::Extension;
use crate::string::{BnString, IntoCStr};
pub use manager::RepositoryManager;
@@ -49,17 +49,17 @@ impl Repository {
}
/// List of RepoPlugin objects contained within this repository
- pub fn plugins(&self) -> Array<RepositoryPlugin> {
+ pub fn plugins(&self) -> Array<Extension> {
let mut count = 0;
let result = unsafe { BNRepositoryGetPlugins(self.handle.as_ptr(), &mut count) };
assert!(!result.is_null());
unsafe { Array::new(result, count, ()) }
}
- pub fn plugin_by_path(&self, path: &Path) -> Option<Ref<RepositoryPlugin>> {
+ pub fn plugin_by_path(&self, path: &Path) -> Option<Ref<Extension>> {
let path = path.to_cstr();
let result = unsafe { BNRepositoryGetPluginByPath(self.handle.as_ptr(), path.as_ptr()) };
- NonNull::new(result).map(|h| unsafe { RepositoryPlugin::ref_from_raw(h) })
+ NonNull::new(result).map(|h| unsafe { Extension::ref_from_raw(h) })
}
/// String full path the repository
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())
- }
-}
diff --git a/rust/src/repository/plugin.rs b/rust/src/repository/plugin.rs
index e0ab9679..ba95c29c 100644
--- a/rust/src/repository/plugin.rs
+++ b/rust/src/repository/plugin.rs
@@ -1,25 +1,24 @@
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
use crate::repository::{PluginStatus, PluginType};
-use crate::string::BnString;
+use crate::string::{BnString, IntoCStr};
use crate::VersionInfo;
use binaryninjacore_sys::*;
use std::ffi::c_char;
use std::fmt::Debug;
use std::path::PathBuf;
use std::ptr::NonNull;
-use std::time::{Duration, SystemTime, UNIX_EPOCH};
#[repr(transparent)]
-pub struct RepositoryPlugin {
- handle: NonNull<BNRepoPlugin>,
+pub struct Extension {
+ handle: NonNull<BNPlugin>,
}
-impl RepositoryPlugin {
- pub(crate) unsafe fn from_raw(handle: NonNull<BNRepoPlugin>) -> Self {
+impl Extension {
+ 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 })
}
@@ -45,20 +44,6 @@ impl RepositoryPlugin {
unsafe { BnString::into_string(result as *mut c_char) }
}
- /// String complete license text for the given plugin
- pub fn license_text(&self) -> String {
- let result = unsafe { BNPluginGetLicenseText(self.handle.as_ptr()) };
- assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
- }
-
- /// String long description of the plugin
- pub fn long_description(&self) -> String {
- let result = unsafe { BNPluginGetLongdescription(self.handle.as_ptr()) };
- assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
- }
-
/// Minimum version info the plugin was tested on
pub fn minimum_version_info(&self) -> VersionInfo {
let result = unsafe { BNPluginGetMinimumVersionInfo(self.handle.as_ptr()) };
@@ -98,12 +83,6 @@ impl RepositoryPlugin {
assert!(!result.is_null());
unsafe { BnString::into_string(result as *mut c_char) }
}
- /// String version of the plugin
- pub fn version(&self) -> String {
- let result = unsafe { BNPluginGetVersion(self.handle.as_ptr()) };
- assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
- }
/// String of the commit of this plugin git repository
pub fn commit(&self) -> String {
@@ -168,8 +147,9 @@ impl RepositoryPlugin {
}
/// Attempt to install the given plugin
- pub fn install(&self) -> bool {
- unsafe { BNPluginInstall(self.handle.as_ptr()) }
+ pub fn install(&self, version_id: &str) -> bool {
+ let version_id_raw = version_id.to_cstr();
+ unsafe { BNPluginInstall(self.handle.as_ptr(), version_id_raw.as_ptr()) }
}
pub fn install_dependencies(&self) -> bool {
@@ -181,8 +161,9 @@ impl RepositoryPlugin {
unsafe { BNPluginUninstall(self.handle.as_ptr()) }
}
- pub fn updated(&self) -> bool {
- unsafe { BNPluginUpdate(self.handle.as_ptr()) }
+ pub fn updated(&self, version_id: &str) -> bool {
+ let version_id_raw = version_id.to_cstr();
+ unsafe { BNPluginUpdate(self.handle.as_ptr(), version_id_raw.as_ptr()) }
}
/// List of platforms this plugin can execute on
@@ -245,30 +226,22 @@ impl RepositoryPlugin {
assert!(!result.is_null());
unsafe { BnString::into_string(result) }
}
-
- /// Returns a datetime object representing the plugins last update
- pub fn last_update(&self) -> SystemTime {
- let result = unsafe { BNPluginGetLastUpdate(self.handle.as_ptr()) };
- UNIX_EPOCH + Duration::from_secs(result)
- }
}
-impl Debug for RepositoryPlugin {
+impl Debug for Extension {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("RepositoryPlugin")
+ f.debug_struct("Extension")
.field("name", &self.name())
- .field("version", &self.version())
.field("author", &self.author())
.field("description", &self.description())
.field("minimum_version_info", &self.minimum_version_info())
.field("maximum_version_info", &self.maximum_version_info())
- .field("last_update", &self.last_update())
.field("status", &self.status())
.finish()
}
}
-impl ToOwned for RepositoryPlugin {
+impl ToOwned for Extension {
type Owned = Ref<Self>;
fn to_owned(&self) -> Self::Owned {
@@ -276,7 +249,7 @@ impl ToOwned for RepositoryPlugin {
}
}
-unsafe impl RefCountable for RepositoryPlugin {
+unsafe impl RefCountable for Extension {
unsafe fn inc_ref(handle: &Self) -> Ref<Self> {
Self::ref_from_raw(NonNull::new(BNNewPluginReference(handle.handle.as_ptr())).unwrap())
}
@@ -286,13 +259,13 @@ unsafe impl RefCountable for RepositoryPlugin {
}
}
-impl CoreArrayProvider for RepositoryPlugin {
- type Raw = *mut BNRepoPlugin;
+impl CoreArrayProvider for Extension {
+ type Raw = *mut BNPlugin;
type Context = ();
type Wrapped<'a> = Guard<'a, Self>;
}
-unsafe impl CoreArrayProviderInner for RepositoryPlugin {
+unsafe impl CoreArrayProviderInner for Extension {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeRepositoryPluginList(raw)
}