diff options
| author | Mason Reed <mason@vector35.com> | 2025-08-20 13:42:19 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-08-20 13:42:19 -0400 |
| commit | 2ba29fd5fc09a78dd5e16a8706bbb8aa6468eb1d (patch) | |
| tree | fff9d0278c348d3b19c3f928b5bac66e7fa570a3 | |
| parent | ff72f3be107e94a0be41a1e7ba113000a4e95089 (diff) | |
[Rust] Add project path file retrieval related functions
| -rw-r--r-- | rust/src/project.rs | 12 | ||||
| -rw-r--r-- | rust/src/project/file.rs | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/rust/src/project.rs b/rust/src/project.rs index b2617cae..d276e532 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -575,6 +575,18 @@ impl Project { Some(unsafe { ProjectFile::ref_from_raw(handle) }) } + /// Retrieve a list of files in the project by the `path` inside the project. + /// + /// Because a [`ProjectFile`] name is not unique, this returns a list instead of a single [`ProjectFile`]. + pub fn files_by_path_in_project(&self, path: &Path) -> Array<ProjectFile> { + let path_raw = path.to_cstr(); + let mut count = 0; + let result = unsafe { + BNProjectGetFilesByPathInProject(self.handle.as_ptr(), path_raw.as_ptr(), &mut count) + }; + unsafe { Array::new(result, count, ()) } + } + /// Delete a file from the project pub fn delete_file(&self, file: &ProjectFile) -> bool { unsafe { BNProjectDeleteFile(self.handle.as_ptr(), file.handle.as_ptr()) } diff --git a/rust/src/project/file.rs b/rust/src/project/file.rs index 2d75cb24..ae23365a 100644 --- a/rust/src/project/file.rs +++ b/rust/src/project/file.rs @@ -5,8 +5,8 @@ use binaryninjacore_sys::{ BNFreeProjectFile, BNFreeProjectFileList, BNNewProjectFileReference, BNProjectFile, BNProjectFileExistsOnDisk, BNProjectFileExport, BNProjectFileGetCreationTimestamp, BNProjectFileGetDescription, BNProjectFileGetFolder, BNProjectFileGetId, BNProjectFileGetName, - BNProjectFileGetPathOnDisk, BNProjectFileGetProject, BNProjectFileSetDescription, - BNProjectFileSetFolder, BNProjectFileSetName, + BNProjectFileGetPathInProject, BNProjectFileGetPathOnDisk, BNProjectFileGetProject, + BNProjectFileSetDescription, BNProjectFileSetFolder, BNProjectFileSetName, }; use std::fmt::Debug; use std::path::{Path, PathBuf}; @@ -46,6 +46,13 @@ impl ProjectFile { Some(PathBuf::from(path_str)) } + /// Get the path in the project to this file's contents + pub fn path_in_project(&self) -> Option<PathBuf> { + let path_str = + unsafe { BnString::into_string(BNProjectFileGetPathInProject(self.handle.as_ptr())) }; + Some(PathBuf::from(path_str)) + } + /// Check if this file's contents exist on disk pub fn exists_on_disk(&self) -> bool { unsafe { BNProjectFileExistsOnDisk(self.handle.as_ptr()) } |
