summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-03-16 11:48:46 -0700
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-03-24 18:46:48 -0700
commitd7c91093e808731bbe4fafd67daccb8776d5710e (patch)
treecf6e2ffd9a1d742bdb630e259811b1e38e4ca159 /rust
parent8738e69ab2713abbeb349aa1ea990165913f18cd (diff)
[Rust] Misc project module cleanup
Diffstat (limited to 'rust')
-rw-r--r--rust/src/project.rs21
-rw-r--r--rust/tests/project.rs2
2 files changed, 14 insertions, 9 deletions
diff --git a/rust/src/project.rs b/rust/src/project.rs
index fc750bcb..7188ed59 100644
--- a/rust/src/project.rs
+++ b/rust/src/project.rs
@@ -1,5 +1,4 @@
-pub mod file;
-pub mod folder;
+//! Represents a collection of files and folders within Binary Ninja.
use std::ffi::c_void;
use std::fmt::Debug;
@@ -17,6 +16,9 @@ use crate::project::folder::ProjectFolder;
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
use crate::string::{BnString, IntoCStr};
+pub mod file;
+pub mod folder;
+
pub struct Project {
pub(crate) handle: NonNull<BNProject>,
}
@@ -30,6 +32,7 @@ impl Project {
Ref::new(Self { handle })
}
+ /// All of the open [`Project`]s
pub fn all_open() -> Array<Project> {
let mut count = 0;
let result = unsafe { BNGetOpenProjects(&mut count) };
@@ -37,7 +40,6 @@ impl Project {
unsafe { Array::new(result, count, ()) }
}
- // TODO: Path here is actually local path?
/// Create a new project
///
/// * `path` - Path to the project directory (.bnpr)
@@ -49,7 +51,6 @@ impl Project {
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
}
- // TODO: Path here is actually local path?
/// Open an existing project
///
/// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm)
@@ -73,7 +74,7 @@ impl Project {
}
}
- /// Close a open project
+ /// Close an open project
pub fn close(&self) -> Result<(), ()> {
if unsafe { BNProjectClose(self.handle.as_ptr()) } {
Ok(())
@@ -87,9 +88,10 @@ impl Project {
unsafe { BnString::into_string(BNProjectGetId(self.handle.as_ptr())) }
}
- /// Get the path of the project
- pub fn path(&self) -> String {
- unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) }
+ /// Get the path on disk for the project
+ pub fn path(&self) -> PathBuf {
+ let path_str = unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) };
+ PathBuf::from(path_str)
}
/// Get the name of the project
@@ -136,6 +138,7 @@ impl Project {
unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) }
}
+ /// Call this after updating the [`ProjectFolder`] to have the changes reflected in the database.
pub fn push_folder(&self, file: &ProjectFolder) -> bool {
unsafe { BNProjectPushFolder(self.handle.as_ptr(), file.handle.as_ptr()) }
}
@@ -212,6 +215,7 @@ impl Project {
}
}
+ // TODO: Rename create_folder_with_id and comment about the id being unique
/// Recursively create files and folders in the project from a path on disk
///
/// * `parent` - Parent folder in the project that will contain the new folder
@@ -289,6 +293,7 @@ impl Project {
}
}
+ /// Call this after updating the [`ProjectFile`] to have the changes reflected in the database.
pub fn push_file(&self, file: &ProjectFile) -> bool {
unsafe { BNProjectPushFile(self.handle.as_ptr(), file.handle.as_ptr()) }
}
diff --git a/rust/tests/project.rs b/rust/tests/project.rs
index 18676b2e..263dea7a 100644
--- a/rust/tests/project.rs
+++ b/rust/tests/project.rs
@@ -26,7 +26,7 @@ fn create_delete_empty() {
let project_path_received = project.path();
assert_eq!(
canonicalize(&project_path).unwrap(),
- canonicalize(project_path_received.to_string()).unwrap()
+ canonicalize(project_path_received).unwrap()
);
let project_name_received = project.name();
assert_eq!(project_name, project_name_received.as_str());