diff options
| author | Glenn Smith <glenn@vector35.com> | 2022-08-04 19:19:21 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2022-09-29 21:02:22 -0400 |
| commit | 9fd6ed156fb926c64420c1b38b4e27f0e5c17d0a (patch) | |
| tree | 801dfb15ba40dc3882c86111f2092ca096fcf86f /rust/src | |
| parent | 56404139af933b7a559c9023c81b849acaf6f0f4 (diff) | |
[Rust API] Various path getters
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/lib.rs | 121 |
1 files changed, 120 insertions, 1 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c13d2b22..275816fe 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -161,7 +161,7 @@ pub mod types; use std::collections::HashMap; use std::fs::File; use std::io::Read; -use std::path::Path; +use std::path::{Path, PathBuf}; pub use binaryninjacore_sys::BNBranchType as BranchType; pub use binaryninjacore_sys::BNEndianness as Endianness; @@ -566,6 +566,125 @@ pub fn open_view_with_options<F: AsRef<Path>>( } } +pub fn install_directory() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetInstallDirectory() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn bundled_plugin_directory() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = + unsafe { binaryninjacore_sys::BNGetBundledPluginDirectory() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn set_bundled_plugin_directory<S: string::BnStrCompatible>(new_dir: S) { + unsafe { + binaryninjacore_sys::BNSetBundledPluginDirectory( + new_dir.into_bytes_with_nul().as_ref().as_ptr() as *const std::os::raw::c_char, + ) + }; +} + +pub fn user_directory() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetUserDirectory() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn user_plugin_directory() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetUserPluginDirectory() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn repositories_directory() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetRepositoriesDirectory() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn settings_file_name() -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { binaryninjacore_sys::BNGetSettingsFileName() }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn save_last_run() { + unsafe { binaryninjacore_sys::BNSaveLastRun() }; +} + +pub fn path_relative_to_bundled_plugin_directory<S: string::BnStrCompatible>( + path: S, +) -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { + binaryninjacore_sys::BNGetPathRelativeToBundledPluginDirectory( + path.into_bytes_with_nul().as_ref().as_ptr() as *const std::os::raw::c_char, + ) + }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn path_relative_to_user_plugin_directory<S: string::BnStrCompatible>( + path: S, +) -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { + binaryninjacore_sys::BNGetPathRelativeToUserPluginDirectory( + path.into_bytes_with_nul().as_ref().as_ptr() as *const std::os::raw::c_char, + ) + }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + +pub fn path_relative_to_user_directory<S: string::BnStrCompatible>(path: S) -> Result<PathBuf, ()> { + let s: *mut std::os::raw::c_char = unsafe { + binaryninjacore_sys::BNGetPathRelativeToUserDirectory( + path.into_bytes_with_nul().as_ref().as_ptr() as *const std::os::raw::c_char, + ) + }; + if s.is_null() { + return Err(()); + } + Ok(PathBuf::from( + unsafe { string::BnString::from_raw(s) }.to_string(), + )) +} + pub fn version() -> string::BnString { unsafe { string::BnString::from_raw(binaryninjacore_sys::BNGetVersionString()) } } |
