diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-04 19:47:55 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 788a8b7091bbdde77817030e0836d7a7a786fd99 (patch) | |
| tree | 40e8f8d3c870788259a5acb5d14995cdc1656979 /rust/src/collaboration | |
| parent | a826c589dfc10c542deba7ca3343a462e02d6bde (diff) | |
[Rust] Simplify usage surrounding c strings
`cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()`
`cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()`
`cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()`
With a few fixes for cstrings that might be dropped prematurely.
Diffstat (limited to 'rust/src/collaboration')
| -rw-r--r-- | rust/src/collaboration/changeset.rs | 8 | ||||
| -rw-r--r-- | rust/src/collaboration/file.rs | 35 | ||||
| -rw-r--r-- | rust/src/collaboration/folder.rs | 16 | ||||
| -rw-r--r-- | rust/src/collaboration/group.rs | 20 | ||||
| -rw-r--r-- | rust/src/collaboration/merge.rs | 27 | ||||
| -rw-r--r-- | rust/src/collaboration/project.rs | 98 | ||||
| -rw-r--r-- | rust/src/collaboration/remote.rs | 99 | ||||
| -rw-r--r-- | rust/src/collaboration/snapshot.rs | 4 | ||||
| -rw-r--r-- | rust/src/collaboration/sync.rs | 12 | ||||
| -rw-r--r-- | rust/src/collaboration/user.rs | 17 |
10 files changed, 79 insertions, 257 deletions
diff --git a/rust/src/collaboration/changeset.rs b/rust/src/collaboration/changeset.rs index 1cc30d76..0db384cb 100644 --- a/rust/src/collaboration/changeset.rs +++ b/rust/src/collaboration/changeset.rs @@ -1,5 +1,4 @@ use binaryninjacore_sys::*; -use std::ffi::c_char; use std::ptr::NonNull; use super::{RemoteFile, RemoteUser}; @@ -68,12 +67,7 @@ impl Changeset { /// Set the name of the changeset, e.g. in a name changeset function. pub fn set_name<S: AsCStr>(&self, value: S) -> bool { let value = value.to_cstr(); - unsafe { - BNCollaborationChangesetSetName( - self.handle.as_ptr(), - value.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNCollaborationChangesetSetName(self.handle.as_ptr(), value.as_ptr()) } } } diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs index 2089fbb7..251b4f7d 100644 --- a/rust/src/collaboration/file.rs +++ b/rust/src/collaboration/file.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, c_void}; +use std::ffi::c_void; use std::fmt::{Debug, Formatter}; use std::ptr::NonNull; use std::time::SystemTime; @@ -96,12 +96,7 @@ impl RemoteFile { pub fn set_metadata<S: AsCStr>(&self, folder: S) -> Result<(), ()> { let folder_raw = folder.to_cstr(); - let success = unsafe { - BNRemoteFileSetMetadata( - self.handle.as_ptr(), - folder_raw.as_ref().as_ptr() as *const c_char, - ) - }; + let success = unsafe { BNRemoteFileSetMetadata(self.handle.as_ptr(), folder_raw.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -192,12 +187,7 @@ impl RemoteFile { /// Set the description of the file. You will need to push the file to update the remote version. pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); - let success = unsafe { - BNRemoteFileSetName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - }; + let success = unsafe { BNRemoteFileSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -211,12 +201,8 @@ impl RemoteFile { /// Set the description of the file. You will need to push the file to update the remote version. pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); - let success = unsafe { - BNRemoteFileSetDescription( - self.handle.as_ptr(), - description.as_ref().as_ptr() as *const c_char, - ) - }; + let success = + unsafe { BNRemoteFileSetDescription(self.handle.as_ptr(), description.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -269,9 +255,7 @@ impl RemoteFile { self.pull_snapshots()?; } let id = id.to_cstr(); - let result = unsafe { - BNRemoteFileGetSnapshotById(self.handle.as_ptr(), id.as_ref().as_ptr() as *const c_char) - }; + let result = unsafe { BNRemoteFileGetSnapshotById(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(result).map(|handle| unsafe { RemoteSnapshot::ref_from_raw(handle) })) } @@ -350,14 +334,11 @@ impl RemoteFile { { let name = name.to_cstr(); let parent_ids: Vec<_> = parent_ids.into_iter().map(|id| id.to_cstr()).collect(); - let mut parent_ids_raw: Vec<_> = parent_ids - .iter() - .map(|x| x.as_ref().as_ptr() as *const c_char) - .collect(); + let mut parent_ids_raw: Vec<_> = parent_ids.iter().map(|x| x.as_ptr()).collect(); let result = unsafe { BNRemoteFileCreateSnapshot( self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, + name.as_ptr(), contents.as_mut_ptr(), contents.len(), analysis_cache_contexts.as_mut_ptr(), diff --git a/rust/src/collaboration/folder.rs b/rust/src/collaboration/folder.rs index 0fd2bf87..b5fde3b4 100644 --- a/rust/src/collaboration/folder.rs +++ b/rust/src/collaboration/folder.rs @@ -1,6 +1,5 @@ use super::{Remote, RemoteProject}; use binaryninjacore_sys::*; -use std::ffi::c_char; use std::ptr::NonNull; use crate::project::folder::ProjectFolder; @@ -106,12 +105,7 @@ impl RemoteFolder { /// Set the display name of the folder. You will need to push the folder to update the remote version. pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); - let success = unsafe { - BNRemoteFolderSetName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - }; + let success = unsafe { BNRemoteFolderSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -125,12 +119,8 @@ impl RemoteFolder { /// Set the description of the folder. You will need to push the folder to update the remote version. pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); - let success = unsafe { - BNRemoteFolderSetDescription( - self.handle.as_ptr(), - description.as_ref().as_ptr() as *const c_char, - ) - }; + let success = + unsafe { BNRemoteFolderSetDescription(self.handle.as_ptr(), description.as_ptr()) }; success.then_some(()).ok_or(()) } } diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index 94253519..b8b32c7a 100644 --- a/rust/src/collaboration/group.rs +++ b/rust/src/collaboration/group.rs @@ -2,7 +2,6 @@ use super::Remote; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::string::{AsCStr, BnString}; use binaryninjacore_sys::*; -use std::ffi::c_char; use std::fmt; use std::fmt::{Display, Formatter}; use std::ptr::NonNull; @@ -52,12 +51,7 @@ impl RemoteGroup { /// You will need to push the group to update the Remote. pub fn set_name<U: AsCStr>(&self, name: U) { let name = name.to_cstr(); - unsafe { - BNCollaborationGroupSetName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNCollaborationGroupSetName(self.handle.as_ptr(), name.as_ptr()) } } /// Get list of users in the group @@ -93,10 +87,7 @@ impl RemoteGroup { I::Item: AsCStr, { let usernames: Vec<_> = usernames.into_iter().map(|u| u.to_cstr()).collect(); - let mut usernames_raw: Vec<_> = usernames - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); + let mut usernames_raw: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect(); // TODO: This should only fail if collaboration is not supported. // TODO: Because you should not have a RemoteGroup at that point we can ignore? // TODO: Do you need any permissions to do this? @@ -113,12 +104,7 @@ impl RemoteGroup { /// Test if a group has a user with the given username pub fn contains_user<U: AsCStr>(&self, username: U) -> bool { let username = username.to_cstr(); - unsafe { - BNCollaborationGroupContainsUser( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNCollaborationGroupContainsUser(self.handle.as_ptr(), username.as_ptr()) } } } diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs index 84aa6192..2fb5b3de 100644 --- a/rust/src/collaboration/merge.rs +++ b/rust/src/collaboration/merge.rs @@ -1,5 +1,4 @@ use binaryninjacore_sys::*; -use std::ffi::c_char; use std::ptr::NonNull; use crate::database::{snapshot::Snapshot, Database}; @@ -52,10 +51,7 @@ impl MergeConflict { pub fn path_item_string<S: AsCStr>(&self, path: S) -> Result<BnString, ()> { let path = path.to_cstr(); let result = unsafe { - BNAnalysisMergeConflictGetPathItemString( - self.handle.as_ptr(), - path.as_ref().as_ptr() as *const c_char, - ) + BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path.as_ptr()) }; (!result.is_null()) .then(|| unsafe { BnString::from_raw(result) }) @@ -125,24 +121,16 @@ impl MergeConflict { /// Call this when you've resolved the conflict to save the result pub fn success<S: AsCStr>(&self, value: S) -> Result<(), ()> { let value = value.to_cstr(); - let success = unsafe { - BNAnalysisMergeConflictSuccess( - self.handle.as_ptr(), - value.as_ref().as_ptr() as *const c_char, - ) - }; + let success = + unsafe { BNAnalysisMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) }; success.then_some(()).ok_or(()) } // TODO: Make a safe version of this that checks the path and if it holds a number pub unsafe fn get_path_item_number<S: AsCStr>(&self, path_key: S) -> Option<u64> { let path_key = path_key.to_cstr(); - let value = unsafe { - BNAnalysisMergeConflictGetPathItem( - self.handle.as_ptr(), - path_key.as_ref().as_ptr() as *const c_char, - ) - }; + let value = + unsafe { BNAnalysisMergeConflictGetPathItem(self.handle.as_ptr(), path_key.as_ptr()) }; match value.is_null() { // SAFETY: The path must be a number. false => Some(value as u64), @@ -153,10 +141,7 @@ impl MergeConflict { pub unsafe fn get_path_item_string<S: AsCStr>(&self, path_key: S) -> Option<BnString> { let path_key = path_key.to_cstr(); let value = unsafe { - BNAnalysisMergeConflictGetPathItemString( - self.handle.as_ptr(), - path_key.as_ref().as_ptr() as *const c_char, - ) + BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path_key.as_ptr()) }; match value.is_null() { false => Some(unsafe { BnString::from_raw(value) }), diff --git a/rust/src/collaboration/project.rs b/rust/src/collaboration/project.rs index 8c04080b..fce2a5f6 100644 --- a/rust/src/collaboration/project.rs +++ b/rust/src/collaboration/project.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, c_void}; +use std::ffi::c_void; use std::ptr::NonNull; use std::time::SystemTime; @@ -138,12 +138,7 @@ impl RemoteProject { /// Set the description of the file. You will need to push the file to update the remote version. pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); - let success = unsafe { - BNRemoteProjectSetName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - }; + let success = unsafe { BNRemoteProjectSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -157,12 +152,8 @@ impl RemoteProject { /// Set the description of the file. You will need to push the file to update the remote version. pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); - let success = unsafe { - BNRemoteProjectSetDescription( - self.handle.as_ptr(), - description.as_ref().as_ptr() as *const c_char, - ) - }; + let success = + unsafe { BNRemoteProjectSetDescription(self.handle.as_ptr(), description.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -236,9 +227,7 @@ impl RemoteProject { self.pull_files()?; } let id = id.to_cstr(); - let result = unsafe { - BNRemoteProjectGetFileById(self.handle.as_ptr(), id.as_ref().as_ptr() as *const c_char) - }; + let result = unsafe { BNRemoteProjectGetFileById(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(result).map(|handle| unsafe { RemoteFile::ref_from_raw(handle) })) } @@ -252,12 +241,7 @@ impl RemoteProject { self.pull_files()?; } let id = name.to_cstr(); - let result = unsafe { - BNRemoteProjectGetFileByName( - self.handle.as_ptr(), - id.as_ref().as_ptr() as *const c_char, - ) - }; + let result = unsafe { BNRemoteProjectGetFileByName(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(result).map(|handle| unsafe { RemoteFile::ref_from_raw(handle) })) } @@ -360,11 +344,11 @@ impl RemoteProject { let file_ptr = unsafe { BNRemoteProjectCreateFile( self.handle.as_ptr(), - filename.as_ref().as_ptr() as *const c_char, + filename.as_ptr(), contents.as_ptr() as *mut _, contents.len(), - name.as_ref().as_ptr() as *const c_char, - description.as_ref().as_ptr() as *const c_char, + name.as_ptr(), + description.as_ptr(), folder_handle, file_type, Some(P::cb_progress_callback), @@ -393,14 +377,8 @@ impl RemoteProject { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); - let mut values_raw = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); + let mut keys_raw = keys.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); + let mut values_raw = values.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); let success = unsafe { BNRemoteProjectPushFile( self.handle.as_ptr(), @@ -449,12 +427,7 @@ impl RemoteProject { self.pull_folders()?; } let id = id.to_cstr(); - let result = unsafe { - BNRemoteProjectGetFolderById( - self.handle.as_ptr(), - id.as_ref().as_ptr() as *const c_char, - ) - }; + let result = unsafe { BNRemoteProjectGetFolderById(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(result).map(|handle| unsafe { RemoteFolder::ref_from_raw(handle) })) } @@ -534,8 +507,8 @@ impl RemoteProject { let file_ptr = unsafe { BNRemoteProjectCreateFolder( self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - description.as_ref().as_ptr() as *const c_char, + name.as_ptr(), + description.as_ptr(), folder_handle, Some(P::cb_progress_callback), &mut progress as *mut P as *mut c_void, @@ -566,14 +539,8 @@ impl RemoteProject { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); - let mut values_raw = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); + let mut keys_raw = keys.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); + let mut values_raw = values.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); let success = unsafe { BNRemoteProjectPushFolder( self.handle.as_ptr(), @@ -761,7 +728,7 @@ impl RemoteProject { let value = unsafe { BNRemoteProjectCreateUserPermission( self.handle.as_ptr(), - user_id.as_ref().as_ptr() as *const c_char, + user_id.as_ptr(), level, Some(F::cb_progress_callback), &mut progress as *mut F as *mut c_void, @@ -793,14 +760,8 @@ impl RemoteProject { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); - let mut values_raw = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); + let mut keys_raw = keys.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); + let mut values_raw = values.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); let success = unsafe { BNRemoteProjectPushPermission( @@ -829,12 +790,7 @@ impl RemoteProject { /// * `username` - Username of user to check pub fn can_user_view<S: AsCStr>(&self, username: S) -> bool { let username = username.to_cstr(); - unsafe { - BNRemoteProjectCanUserView( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), username.as_ptr()) } } /// Determine if a user is in any of the edit/admin groups. @@ -844,12 +800,7 @@ impl RemoteProject { /// * `username` - Username of user to check pub fn can_user_edit<S: AsCStr>(&self, username: S) -> bool { let username = username.to_cstr(); - unsafe { - BNRemoteProjectCanUserEdit( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), username.as_ptr()) } } /// Determine if a user is in the admin group. @@ -859,12 +810,7 @@ impl RemoteProject { /// * `username` - Username of user to check pub fn can_user_admin<S: AsCStr>(&self, username: S) -> bool { let username = username.to_cstr(); - unsafe { - BNRemoteProjectCanUserAdmin( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), username.as_ptr()) } } /// Get the default directory path for a remote Project. This is based off diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs index 3a1f021c..ee37e9fb 100644 --- a/rust/src/collaboration/remote.rs +++ b/rust/src/collaboration/remote.rs @@ -1,5 +1,5 @@ use binaryninjacore_sys::*; -use std::ffi::{c_char, c_void}; +use std::ffi::c_void; use std::ptr::NonNull; use super::{sync, GroupId, RemoteGroup, RemoteProject, RemoteUser}; @@ -30,12 +30,7 @@ impl Remote { pub fn new<N: AsCStr, A: AsCStr>(name: N, address: A) -> Ref<Self> { let name = name.to_cstr(); let address = address.to_cstr(); - let result = unsafe { - BNCollaborationCreateRemote( - name.as_ref().as_ptr() as *const c_char, - address.as_ref().as_ptr() as *const c_char, - ) - }; + let result = unsafe { BNCollaborationCreateRemote(name.as_ptr(), address.as_ptr()) }; unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) } } @@ -178,8 +173,8 @@ impl Remote { let token = unsafe { BNRemoteRequestAuthenticationToken( self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - password.as_ref().as_ptr() as *const c_char, + username.as_ptr(), + password.as_ptr(), ) }; if token.is_null() { @@ -230,10 +225,8 @@ impl Remote { } }; let username = options.username.to_cstr(); - let username_ptr = username.as_ptr() as *const c_char; let token = token.to_cstr(); - let token_ptr = token.as_ptr() as *const c_char; - let success = unsafe { BNRemoteConnect(self.handle.as_ptr(), username_ptr, token_ptr) }; + let success = unsafe { BNRemoteConnect(self.handle.as_ptr(), username.as_ptr(), token.as_ptr()) }; success.then_some(()).ok_or(()) } @@ -287,9 +280,7 @@ impl Remote { } let id = id.to_cstr(); - let value = unsafe { - BNRemoteGetProjectById(self.handle.as_ptr(), id.as_ref().as_ptr() as *const c_char) - }; + let value = unsafe { BNRemoteGetProjectById(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(value).map(|handle| unsafe { RemoteProject::ref_from_raw(handle) })) } @@ -305,12 +296,7 @@ impl Remote { } let name = name.to_cstr(); - let value = unsafe { - BNRemoteGetProjectByName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - }; + let value = unsafe { BNRemoteGetProjectByName(self.handle.as_ptr(), name.as_ptr()) }; Ok(NonNull::new(value).map(|handle| unsafe { RemoteProject::ref_from_raw(handle) })) } @@ -358,11 +344,7 @@ impl Remote { let name = name.to_cstr(); let description = description.to_cstr(); let value = unsafe { - BNRemoteCreateProject( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - description.as_ref().as_ptr() as *const c_char, - ) + BNRemoteCreateProject(self.handle.as_ptr(), name.as_ptr(), description.as_ptr()) }; NonNull::new(value) .map(|handle| unsafe { RemoteProject::ref_from_raw(handle) }) @@ -407,14 +389,8 @@ impl Remote { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); - let mut values_raw = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect::<Vec<_>>(); + let mut keys_raw = keys.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); + let mut values_raw = values.iter().map(|s| s.as_ptr()).collect::<Vec<_>>(); let success = unsafe { BNRemotePushProject( @@ -475,12 +451,7 @@ impl Remote { } let name = name.to_cstr(); - let value = unsafe { - BNRemoteGetGroupByName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - }; + let value = unsafe { BNRemoteGetGroupByName(self.handle.as_ptr(), name.as_ptr()) }; Ok(NonNull::new(value).map(|handle| unsafe { RemoteGroup::ref_from_raw(handle) })) } @@ -502,7 +473,7 @@ impl Remote { let success = unsafe { BNRemoteSearchGroups( self.handle.as_ptr(), - prefix.as_ref().as_ptr() as *const c_char, + prefix.as_ptr(), &mut group_ids, &mut group_names, &mut count, @@ -560,15 +531,12 @@ impl Remote { { let name = name.to_cstr(); let usernames: Vec<_> = usernames.into_iter().map(|s| s.to_cstr()).collect(); - let mut username_ptrs: Vec<_> = usernames - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); + let mut username_ptrs: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect(); let value = unsafe { BNRemoteCreateGroup( self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, + name.as_ptr(), username_ptrs.as_mut_ptr(), username_ptrs.len(), ) @@ -595,14 +563,8 @@ impl Remote { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw: Vec<_> = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); - let mut values_raw: Vec<_> = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); + let mut keys_raw: Vec<_> = keys.iter().map(|s| s.as_ptr()).collect(); + let mut values_raw: Vec<_> = values.iter().map(|s| s.as_ptr()).collect(); let success = unsafe { BNRemotePushGroup( @@ -659,9 +621,7 @@ impl Remote { self.pull_users()?; } let id = id.to_cstr(); - let value = unsafe { - BNRemoteGetUserById(self.handle.as_ptr(), id.as_ref().as_ptr() as *const c_char) - }; + let value = unsafe { BNRemoteGetUserById(self.handle.as_ptr(), id.as_ptr()) }; Ok(NonNull::new(value).map(|handle| unsafe { RemoteUser::ref_from_raw(handle) })) } @@ -682,12 +642,7 @@ impl Remote { self.pull_users()?; } let username = username.to_cstr(); - let value = unsafe { - BNRemoteGetUserByUsername( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - }; + let value = unsafe { BNRemoteGetUserByUsername(self.handle.as_ptr(), username.as_ptr()) }; Ok(NonNull::new(value).map(|handle| unsafe { RemoteUser::ref_from_raw(handle) })) } @@ -720,7 +675,7 @@ impl Remote { let success = unsafe { BNRemoteSearchUsers( self.handle.as_ptr(), - prefix.as_ref().as_ptr() as *const c_char, + prefix.as_ptr(), &mut user_ids, &mut usernames, &mut count, @@ -790,10 +745,10 @@ impl Remote { let value = unsafe { BNRemoteCreateUser( self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - email.as_ref().as_ptr() as *const c_char, + username.as_ptr(), + email.as_ptr(), is_active, - password.as_ref().as_ptr() as *const c_char, + password.as_ptr(), group_ids.as_ptr(), group_ids.len(), user_permission_ids.as_ptr(), @@ -823,14 +778,8 @@ impl Remote { .into_iter() .map(|(k, v)| (k.to_cstr(), v.to_cstr())) .unzip(); - let mut keys_raw: Vec<_> = keys - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); - let mut values_raw: Vec<_> = values - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); + let mut keys_raw: Vec<_> = keys.iter().map(|s| s.as_ptr()).collect(); + let mut values_raw: Vec<_> = values.iter().map(|s| s.as_ptr()).collect(); let success = unsafe { BNRemotePushUser( self.handle.as_ptr(), diff --git a/rust/src/collaboration/snapshot.rs b/rust/src/collaboration/snapshot.rs index 465ae46a..6e1dfb89 100644 --- a/rust/src/collaboration/snapshot.rs +++ b/rust/src/collaboration/snapshot.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, c_void}; +use std::ffi::c_void; use std::ptr::NonNull; use std::time::SystemTime; @@ -237,7 +237,7 @@ impl RemoteSnapshot { self.handle.as_ptr(), parent.is_some(), parent.unwrap_or(0), - data.as_ref().as_ptr() as *const c_char, + data.as_ptr(), ) }; let handle = NonNull::new(value).ok_or(())?; diff --git a/rust/src/collaboration/sync.rs b/rust/src/collaboration/sync.rs index 4c112336..5afb8923 100644 --- a/rust/src/collaboration/sync.rs +++ b/rust/src/collaboration/sync.rs @@ -63,7 +63,7 @@ pub fn download_file_with_progress<S: AsCStr, F: ProgressCallback>( let result = unsafe { BNCollaborationDownloadFile( file.handle.as_ptr(), - db_path.as_ref().as_ptr() as *const c_char, + db_path.as_ptr(), Some(F::cb_progress_callback), &mut progress as *mut F as *mut c_void, ) @@ -239,7 +239,7 @@ where let success = unsafe { BNCollaborationDownloadDatabaseForFile( file.handle.as_ptr(), - db_path.as_ref().as_ptr() as *const c_char, + db_path.as_ptr(), force, Some(F::cb_progress_callback), &mut progress as *mut _ as *mut c_void, @@ -485,7 +485,7 @@ pub fn set_snapshot_author<S: AsCStr>( BNCollaborationSetSnapshotAuthor( database.handle.as_ptr(), snapshot.handle.as_ptr(), - author.as_ref().as_ptr() as *const c_char, + author.as_ptr(), ) }; success.then_some(()).ok_or(()) @@ -658,7 +658,7 @@ pub fn get_remote_snapshot_from_local_type_archive<S: AsCStr>( let value = unsafe { BNCollaborationGetRemoteSnapshotFromLocalTypeArchive( type_archive.handle.as_ptr(), - snapshot_id.as_ref().as_ptr() as *const c_char, + snapshot_id.as_ptr(), ) }; NonNull::new(value).map(|handle| unsafe { RemoteSnapshot::ref_from_raw(handle) }) @@ -687,7 +687,7 @@ pub fn is_type_archive_snapshot_ignored<S: AsCStr>( unsafe { BNCollaborationIsTypeArchiveSnapshotIgnored( type_archive.handle.as_ptr(), - snapshot_id.as_ref().as_ptr() as *const c_char, + snapshot_id.as_ptr(), ) } } @@ -713,7 +713,7 @@ pub fn download_type_archive_with_progress<S: AsCStr, F: ProgressCallback>( let success = unsafe { BNCollaborationDownloadTypeArchive( file.handle.as_ptr(), - db_path.as_ref().as_ptr() as *const c_char, + db_path.as_ptr(), Some(F::cb_progress_callback), &mut progress as *mut F as *mut c_void, &mut value, diff --git a/rust/src/collaboration/user.rs b/rust/src/collaboration/user.rs index 43b4e854..d4aea2c5 100644 --- a/rust/src/collaboration/user.rs +++ b/rust/src/collaboration/user.rs @@ -1,6 +1,5 @@ use super::Remote; use binaryninjacore_sys::*; -use std::ffi::c_char; use std::ptr::NonNull; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; @@ -51,12 +50,8 @@ impl RemoteUser { /// Set user's username. You will need to push the user to update the Remote pub fn set_username<U: AsCStr>(&self, username: U) -> Result<(), ()> { let username = username.to_cstr(); - let result = unsafe { - BNCollaborationUserSetUsername( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - }; + let result = + unsafe { BNCollaborationUserSetUsername(self.handle.as_ptr(), username.as_ptr()) }; if result { Ok(()) } else { @@ -74,12 +69,8 @@ impl RemoteUser { /// Set user's email. You will need to push the user to update the Remote pub fn set_email<U: AsCStr>(&self, email: U) -> Result<(), ()> { let username = email.to_cstr(); - let result = unsafe { - BNCollaborationUserSetEmail( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - }; + let result = + unsafe { BNCollaborationUserSetEmail(self.handle.as_ptr(), username.as_ptr()) }; if result { Ok(()) } else { |
