summaryrefslogtreecommitdiff
path: root/rust/src/repository
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 19:22:21 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit2f214f6c9935e8ce8df4732cde44a540a003258c (patch)
tree6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/repository
parentb4cf0be8816182c9efca037e27e9439482f8bf36 (diff)
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids. Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type. This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type. Special consideration must be made for symbols or other possible non utf-8 objects. This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'rust/src/repository')
-rw-r--r--rust/src/repository/manager.rs7
-rw-r--r--rust/src/repository/plugin.rs11
2 files changed, 11 insertions, 7 deletions
diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs
index 42d8aa42..cf0118ad 100644
--- a/rust/src/repository/manager.rs
+++ b/rust/src/repository/manager.rs
@@ -8,6 +8,7 @@ use binaryninjacore_sys::{
BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories,
};
use std::fmt::Debug;
+use std::path::Path;
use std::ptr::NonNull;
/// Keeps track of all the repositories and keeps the `enabled_plugins.json`
@@ -28,7 +29,7 @@ impl RepositoryManager {
Ref::new(Self { handle })
}
- pub fn new<S: IntoCStr>(plugins_path: S) -> Ref<Self> {
+ 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()) }
@@ -59,7 +60,7 @@ 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<U: IntoCStr, P: IntoCStr>(&self, url: U, repository_path: P) -> bool {
+ pub fn add_repository(&self, url: &str, repository_path: &Path) -> bool {
let url = url.to_cstr();
let repo_path = repository_path.to_cstr();
unsafe {
@@ -67,7 +68,7 @@ impl RepositoryManager {
}
}
- pub fn repository_by_path<P: IntoCStr>(&self, path: P) -> Option<Repository> {
+ 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()) };
diff --git a/rust/src/repository/plugin.rs b/rust/src/repository/plugin.rs
index 82309e79..e0ab9679 100644
--- a/rust/src/repository/plugin.rs
+++ b/rust/src/repository/plugin.rs
@@ -5,6 +5,7 @@ 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};
@@ -112,17 +113,19 @@ impl RepositoryPlugin {
}
/// Relative path from the base of the repository to the actual plugin
- pub fn path(&self) -> String {
+ pub fn path(&self) -> PathBuf {
let result = unsafe { BNPluginGetPath(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
/// Optional sub-directory the plugin code lives in as a relative path from the plugin root
- pub fn subdir(&self) -> String {
+ pub fn subdir(&self) -> PathBuf {
let result = unsafe { BNPluginGetSubdir(self.handle.as_ptr()) };
assert!(!result.is_null());
- unsafe { BnString::into_string(result as *mut c_char) }
+ let result_str = unsafe { BnString::into_string(result as *mut c_char) };
+ PathBuf::from(result_str)
}
/// Dependencies required for installing this plugin