diff options
Diffstat (limited to 'rust')
62 files changed, 535 insertions, 524 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 62693800..c02fc717 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -27,7 +27,7 @@ use crate::{ platform::Platform, rc::*, relocation::CoreRelocationHandler, - string::AsCStr, + string::IntoCStr, string::*, types::{NameAndType, Type}, Endianness, @@ -1953,7 +1953,7 @@ macro_rules! cc_func { /// Contains helper methods for all types implementing 'Architecture' pub trait ArchitectureExt: Architecture { - fn register_by_name<S: AsCStr>(&self, name: S) -> Option<Self::Register> { + fn register_by_name<S: IntoCStr>(&self, name: S) -> Option<Self::Register> { let name = name.to_cstr(); match unsafe { BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ptr()) } { @@ -2031,7 +2031,7 @@ pub trait ArchitectureExt: Architecture { fn register_relocation_handler<S, R, F>(&self, name: S, func: F) where - S: AsCStr, + S: IntoCStr, R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send @@ -2054,7 +2054,7 @@ impl<T: Architecture> ArchitectureExt for T {} pub fn register_architecture<S, A, F>(name: S, func: F) -> &'static A where - S: AsCStr, + S: IntoCStr, A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync + Sized, F: FnOnce(CustomArchitectureHandle<A>, CoreArchitecture) -> A, { diff --git a/rust/src/background_task.rs b/rust/src/background_task.rs index 95bdda0b..b0537fa8 100644 --- a/rust/src/background_task.rs +++ b/rust/src/background_task.rs @@ -43,7 +43,7 @@ impl BackgroundTask { Self { handle } } - pub fn new<S: AsCStr>(initial_text: S, can_cancel: bool) -> Ref<Self> { + pub fn new<S: IntoCStr>(initial_text: S, can_cancel: bool) -> Ref<Self> { let text = initial_text.to_cstr(); let handle = unsafe { BNBeginBackgroundTask(text.as_ptr(), can_cancel) }; // We should always be returned a valid task. @@ -75,7 +75,7 @@ impl BackgroundTask { unsafe { BnString::into_string(BNGetBackgroundTaskProgressText(self.handle)) } } - pub fn set_progress_text<S: AsCStr>(&self, text: S) { + pub fn set_progress_text<S: IntoCStr>(&self, text: S) { let progress_text = text.to_cstr(); unsafe { BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ptr()) } } diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index a0fb9081..7259efbf 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -266,7 +266,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNGetEndOffset(self.as_ref().handle) } } - fn add_analysis_option(&self, name: impl AsCStr) { + fn add_analysis_option(&self, name: impl IntoCStr) { let name = name.to_cstr(); unsafe { BNAddAnalysisOption(self.as_ref().handle, name.as_ptr()) } } @@ -399,7 +399,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn symbol_by_raw_name<S: AsCStr>(&self, raw_name: S) -> Option<Ref<Symbol>> { + fn symbol_by_raw_name<S: IntoCStr>(&self, raw_name: S) -> Option<Ref<Symbol>> { let raw_name = raw_name.to_cstr(); unsafe { @@ -424,7 +424,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn symbols_by_name<S: AsCStr>(&self, name: S) -> Array<Symbol> { + fn symbols_by_name<S: IntoCStr>(&self, name: S) -> Array<Symbol> { let raw_name = name.to_cstr(); unsafe { @@ -585,7 +585,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn define_auto_type<T: Into<QualifiedName>, S: AsCStr>( + fn define_auto_type<T: Into<QualifiedName>, S: IntoCStr>( &self, name: T, source: S, @@ -602,7 +602,7 @@ pub trait BinaryViewExt: BinaryViewBase { QualifiedName::from_owned_raw(name_handle) } - fn define_auto_type_with_id<T: Into<QualifiedName>, S: AsCStr>( + fn define_auto_type_with_id<T: Into<QualifiedName>, S: IntoCStr>( &self, name: T, id: S, @@ -712,7 +712,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn undefine_auto_type<S: AsCStr>(&self, id: S) { + fn undefine_auto_type<S: IntoCStr>(&self, id: S) { let id_str = id.to_cstr(); unsafe { BNUndefineAnalysisType(self.as_ref().handle, id_str.as_ref().as_ptr() as *const _); @@ -763,7 +763,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn type_by_id<S: AsCStr>(&self, id: S) -> Option<Ref<Type>> { + fn type_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<Type>> { let id_str = id.to_cstr(); unsafe { let type_handle = BNGetAnalysisTypeById(self.as_ref().handle, id_str.as_ptr()); @@ -774,7 +774,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn type_name_by_id<S: AsCStr>(&self, id: S) -> Option<QualifiedName> { + fn type_name_by_id<S: IntoCStr>(&self, id: S) -> Option<QualifiedName> { let id_str = id.to_cstr(); unsafe { let name_handle = BNGetAnalysisTypeNameById(self.as_ref().handle, id_str.as_ptr()); @@ -871,7 +871,7 @@ pub trait BinaryViewExt: BinaryViewBase { section.create(self.as_ref()); } - fn remove_auto_section<S: AsCStr>(&self, name: S) { + fn remove_auto_section<S: IntoCStr>(&self, name: S) { let raw_name = name.to_cstr(); let raw_name_ptr = raw_name.as_ptr(); unsafe { @@ -879,7 +879,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn remove_user_section<S: AsCStr>(&self, name: S) { + fn remove_user_section<S: IntoCStr>(&self, name: S) { let raw_name = name.to_cstr(); let raw_name_ptr = raw_name.as_ptr(); unsafe { @@ -887,7 +887,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn section_by_name<S: AsCStr>(&self, name: S) -> Option<Ref<Section>> { + fn section_by_name<S: IntoCStr>(&self, name: S) -> Option<Ref<Section>> { unsafe { let raw_name = name.to_cstr(); let name_ptr = raw_name.as_ptr(); @@ -1103,14 +1103,14 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNApplyDebugInfo(self.as_ref().handle, debug_info.handle) } } - fn show_graph_report<S: AsCStr>(&self, raw_name: S, graph: &FlowGraph) { + fn show_graph_report<S: IntoCStr>(&self, raw_name: S, graph: &FlowGraph) { let raw_name = raw_name.to_cstr(); unsafe { BNShowGraphReport(self.as_ref().handle, raw_name.as_ptr(), graph.handle); } } - fn load_settings<S: AsCStr>(&self, view_type_name: S) -> Result<Ref<Settings>> { + fn load_settings<S: IntoCStr>(&self, view_type_name: S) -> Result<Ref<Settings>> { let view_type_name = view_type_name.to_cstr(); let settings_handle = unsafe { BNBinaryViewGetLoadSettings(self.as_ref().handle, view_type_name.as_ptr()) }; @@ -1122,7 +1122,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn set_load_settings<S: AsCStr>(&self, view_type_name: S, settings: &Settings) { + fn set_load_settings<S: IntoCStr>(&self, view_type_name: S, settings: &Settings) { let view_type_name = view_type_name.to_cstr(); unsafe { @@ -1139,7 +1139,7 @@ pub trait BinaryViewExt: BinaryViewBase { /// # Arguments /// * `name` - the name for the tag /// * `icon` - the icon (recommended 1 emoji or 2 chars) for the tag - fn create_tag_type<N: AsCStr, I: AsCStr>(&self, name: N, icon: I) -> Ref<TagType> { + fn create_tag_type<N: IntoCStr, I: IntoCStr>(&self, name: N, icon: I) -> Ref<TagType> { let tag_type = TagType::create(self.as_ref(), name, icon); unsafe { BNAddTagType(self.as_ref().handle, tag_type.handle); @@ -1153,7 +1153,7 @@ pub trait BinaryViewExt: BinaryViewBase { } /// Get a tag type by its name. - fn tag_type_by_name<S: AsCStr>(&self, name: S) -> Option<Ref<TagType>> { + fn tag_type_by_name<S: IntoCStr>(&self, name: S) -> Option<Ref<TagType>> { let name = name.to_cstr(); unsafe { let handle = BNGetTagType(self.as_ref().handle, name.as_ptr()); @@ -1167,7 +1167,7 @@ pub trait BinaryViewExt: BinaryViewBase { /// Get a tag by its id. /// /// Note this does not tell you anything about where it is used. - fn tag_by_id<S: AsCStr>(&self, id: S) -> Option<Ref<Tag>> { + fn tag_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<Tag>> { let id = id.to_cstr(); unsafe { let handle = BNGetTag(self.as_ref().handle, id.as_ptr()); @@ -1181,7 +1181,7 @@ pub trait BinaryViewExt: BinaryViewBase { /// Creates and adds a tag to an address /// /// User tag creations will be added to the undo buffer - fn add_tag<S: AsCStr>(&self, addr: u64, t: &TagType, data: S, user: bool) { + fn add_tag<S: IntoCStr>(&self, addr: u64, t: &TagType, data: S, user: bool) { let tag = Tag::new(t, data); unsafe { BNAddTag(self.as_ref().handle, tag.handle, user) } @@ -1218,7 +1218,7 @@ pub trait BinaryViewExt: BinaryViewBase { /// /// NOTE: This is different from setting a comment at the function-level. To set a comment in a /// function use [`Function::set_comment_at`] - fn set_comment_at(&self, addr: u64, comment: impl AsCStr) { + fn set_comment_at(&self, addr: u64, comment: impl IntoCStr) { let comment_raw = comment.to_cstr(); unsafe { BNSetGlobalCommentForAddress(self.as_ref().handle, addr, comment_raw.as_ptr()) } } @@ -1271,7 +1271,7 @@ pub trait BinaryViewExt: BinaryViewBase { result } - fn query_metadata<S: AsCStr>(&self, key: S) -> Option<Ref<Metadata>> { + fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Ref<Metadata>> { let key = key.to_cstr(); let value: *mut BNMetadata = unsafe { BNBinaryViewQueryMetadata(self.as_ref().handle, key.as_ptr()) }; @@ -1282,7 +1282,7 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn get_metadata<T, S: AsCStr>(&self, key: S) -> Option<Result<T>> + fn get_metadata<T, S: IntoCStr>(&self, key: S) -> Option<Result<T>> where T: for<'a> TryFrom<&'a Metadata>, { @@ -1290,7 +1290,7 @@ pub trait BinaryViewExt: BinaryViewBase { .map(|md| T::try_from(md.as_ref()).map_err(|_| ())) } - fn store_metadata<V, S: AsCStr>(&self, key: S, value: V, is_auto: bool) + fn store_metadata<V, S: IntoCStr>(&self, key: S, value: V, is_auto: bool) where V: Into<Ref<Metadata>>, { @@ -1306,7 +1306,7 @@ pub trait BinaryViewExt: BinaryViewBase { }; } - fn remove_metadata<S: AsCStr>(&self, key: S) { + fn remove_metadata<S: IntoCStr>(&self, key: S) { let key = key.to_cstr(); unsafe { BNBinaryViewRemoveMetadata(self.as_ref().handle, key.as_ptr()) }; } @@ -1432,7 +1432,7 @@ pub trait BinaryViewExt: BinaryViewBase { .collect() } - fn component_by_guid<S: AsCStr>(&self, guid: S) -> Option<Ref<Component>> { + fn component_by_guid<S: IntoCStr>(&self, guid: S) -> Option<Ref<Component>> { let name = guid.to_cstr(); let result = unsafe { BNGetComponentByGuid(self.as_ref().handle, name.as_ptr()) }; NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) }) @@ -1443,7 +1443,7 @@ pub trait BinaryViewExt: BinaryViewBase { NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) }) } - fn component_by_path<P: AsCStr>(&self, path: P) -> Option<Ref<Component>> { + fn component_by_path<P: IntoCStr>(&self, path: P) -> Option<Ref<Component>> { let path = path.to_cstr(); let result = unsafe { BNGetComponentByPath(self.as_ref().handle, path.as_ptr()) }; NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) }) @@ -1453,7 +1453,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNRemoveComponent(self.as_ref().handle, component.handle.as_ptr()) } } - fn remove_component_by_guid<P: AsCStr>(&self, guid: P) -> bool { + fn remove_component_by_guid<P: IntoCStr>(&self, guid: P) -> bool { let path = guid.to_cstr(); unsafe { BNRemoveComponentByGuid(self.as_ref().handle, path.as_ptr()) } } @@ -1476,7 +1476,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { Array::new(result, count, ()) } } - fn external_library<S: AsCStr>(&self, name: S) -> Option<Ref<ExternalLibrary>> { + fn external_library<S: IntoCStr>(&self, name: S) -> Option<Ref<ExternalLibrary>> { let name_ptr = name.to_cstr(); let result = unsafe { BNBinaryViewGetExternalLibrary(self.as_ref().handle, name_ptr.as_ptr()) }; @@ -1484,12 +1484,12 @@ pub trait BinaryViewExt: BinaryViewBase { Some(unsafe { ExternalLibrary::ref_from_raw(result_ptr) }) } - fn remove_external_library<S: AsCStr>(&self, name: S) { + fn remove_external_library<S: IntoCStr>(&self, name: S) { let name_ptr = name.to_cstr(); unsafe { BNBinaryViewRemoveExternalLibrary(self.as_ref().handle, name_ptr.as_ptr()) }; } - fn add_external_library<S: AsCStr>( + fn add_external_library<S: IntoCStr>( &self, name: S, backing_file: Option<&ProjectFile>, @@ -1531,7 +1531,7 @@ pub trait BinaryViewExt: BinaryViewBase { } // TODO: This is awful, rewrite this. - fn add_external_location<S: AsCStr>( + fn add_external_location<S: IntoCStr>( &self, symbol: &Symbol, library: &ExternalLibrary, @@ -1589,7 +1589,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { BNAddBinaryViewTypeLibrary(self.as_ref().handle, library.as_raw()) } } - fn type_library_by_name<S: AsCStr>(&self, name: S) -> Option<TypeLibrary> { + fn type_library_by_name<S: IntoCStr>(&self, name: S) -> Option<TypeLibrary> { let name = name.to_cstr(); let result = unsafe { BNGetBinaryViewTypeLibrary(self.as_ref().handle, name.as_ptr()) }; NonNull::new(result).map(|h| unsafe { TypeLibrary::from_raw(h) }) @@ -1682,7 +1682,7 @@ pub trait BinaryViewExt: BinaryViewBase { /// contain a metadata key called "type_guids" which is a map /// Dict[string_guid, string_type_name] or /// Dict[string_guid, Tuple[string_type_name, type_library_name]] - fn import_type_by_guid<S: AsCStr>(&self, guid: S) -> Option<Ref<Type>> { + fn import_type_by_guid<S: IntoCStr>(&self, guid: S) -> Option<Ref<Type>> { let guid = guid.to_cstr(); let result = unsafe { BNBinaryViewImportTypeLibraryTypeByGuid(self.as_ref().handle, guid.as_ptr()) }; diff --git a/rust/src/binary_view/memory_map.rs b/rust/src/binary_view/memory_map.rs index 6b6d3d20..ad7c8ea1 100644 --- a/rust/src/binary_view/memory_map.rs +++ b/rust/src/binary_view/memory_map.rs @@ -3,7 +3,7 @@ use crate::data_buffer::DataBuffer; use crate::file_accessor::FileAccessor; use crate::rc::Ref; use crate::segment::SegmentFlags; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; #[derive(PartialEq, Eq, Hash)] @@ -42,7 +42,7 @@ impl MemoryMap { pub fn add_binary_memory_region( &mut self, - name: impl AsCStr, + name: impl IntoCStr, start: u64, view: &BinaryView, segment_flags: Option<SegmentFlags>, @@ -61,7 +61,7 @@ impl MemoryMap { pub fn add_data_memory_region( &mut self, - name: impl AsCStr, + name: impl IntoCStr, start: u64, data: &DataBuffer, segment_flags: Option<SegmentFlags>, @@ -80,7 +80,7 @@ impl MemoryMap { pub fn add_remote_memory_region( &mut self, - name: impl AsCStr, + name: impl IntoCStr, start: u64, accessor: &mut FileAccessor, segment_flags: Option<SegmentFlags>, @@ -97,7 +97,7 @@ impl MemoryMap { } } - pub fn remove_memory_region(&mut self, name: impl AsCStr) -> bool { + pub fn remove_memory_region(&mut self, name: impl IntoCStr) -> bool { let name_raw = name.to_cstr(); unsafe { BNRemoveMemoryRegion(self.view.handle, name_raw.as_ptr()) } } @@ -109,44 +109,44 @@ impl MemoryMap { } } - pub fn memory_region_flags(&self, name: impl AsCStr) -> SegmentFlags { + pub fn memory_region_flags(&self, name: impl IntoCStr) -> SegmentFlags { let name_raw = name.to_cstr(); let flags_raw = unsafe { BNGetMemoryRegionFlags(self.view.handle, name_raw.as_ptr()) }; SegmentFlags::from_raw(flags_raw) } - pub fn set_memory_region_flags(&mut self, name: impl AsCStr, flags: SegmentFlags) -> bool { + pub fn set_memory_region_flags(&mut self, name: impl IntoCStr, flags: SegmentFlags) -> bool { let name_raw = name.to_cstr(); unsafe { BNSetMemoryRegionFlags(self.view.handle, name_raw.as_ptr(), flags.into_raw()) } } - pub fn is_memory_region_enabled(&self, name: impl AsCStr) -> bool { + pub fn is_memory_region_enabled(&self, name: impl IntoCStr) -> bool { let name_raw = name.to_cstr(); unsafe { BNIsMemoryRegionEnabled(self.view.handle, name_raw.as_ptr()) } } - pub fn set_memory_region_enabled(&mut self, name: impl AsCStr, enabled: bool) -> bool { + pub fn set_memory_region_enabled(&mut self, name: impl IntoCStr, enabled: bool) -> bool { let name_raw = name.to_cstr(); unsafe { BNSetMemoryRegionEnabled(self.view.handle, name_raw.as_ptr(), enabled) } } // TODO: Should we just call this is_memory_region_relocatable? - pub fn is_memory_region_rebaseable(&self, name: impl AsCStr) -> bool { + pub fn is_memory_region_rebaseable(&self, name: impl IntoCStr) -> bool { let name_raw = name.to_cstr(); unsafe { BNIsMemoryRegionRebaseable(self.view.handle, name_raw.as_ptr()) } } - pub fn set_memory_region_rebaseable(&mut self, name: impl AsCStr, enabled: bool) -> bool { + pub fn set_memory_region_rebaseable(&mut self, name: impl IntoCStr, enabled: bool) -> bool { let name_raw = name.to_cstr(); unsafe { BNSetMemoryRegionRebaseable(self.view.handle, name_raw.as_ptr(), enabled) } } - pub fn memory_region_fill(&self, name: impl AsCStr) -> u8 { + pub fn memory_region_fill(&self, name: impl IntoCStr) -> u8 { let name_raw = name.to_cstr(); unsafe { BNGetMemoryRegionFill(self.view.handle, name_raw.as_ptr()) } } - pub fn set_memory_region_fill(&mut self, name: impl AsCStr, fill: u8) -> bool { + pub fn set_memory_region_fill(&mut self, name: impl IntoCStr, fill: u8) -> bool { let name_raw = name.to_cstr(); unsafe { BNSetMemoryRegionFill(self.view.handle, name_raw.as_ptr(), fill) } } diff --git a/rust/src/calling_convention.rs b/rust/src/calling_convention.rs index 7db61d8a..90af3aa8 100644 --- a/rust/src/calling_convention.rs +++ b/rust/src/calling_convention.rs @@ -58,7 +58,7 @@ pub trait CallingConvention: Sync { pub fn register_calling_convention<A, N, C>(arch: &A, name: N, cc: C) -> Ref<CoreCallingConvention> where A: Architecture, - N: AsCStr, + N: IntoCStr, C: 'static + CallingConvention, { struct CustomCallingConventionContext<C> diff --git a/rust/src/collaboration.rs b/rust/src/collaboration.rs index 8a1774f2..9a97a0e8 100644 --- a/rust/src/collaboration.rs +++ b/rust/src/collaboration.rs @@ -30,7 +30,7 @@ pub use user::*; use binaryninjacore_sys::*; use crate::rc::{Array, Ref}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; // TODO: Should we pull metadata and information required to call a function? Or should we add documentation // TODO: on what functions need to have been called prior? I feel like we should make the user have to pull @@ -73,21 +73,21 @@ pub fn known_remotes() -> Array<Remote> { } /// Get Remote by unique `id` -pub fn get_remote_by_id<S: AsCStr>(id: S) -> Option<Ref<Remote>> { +pub fn get_remote_by_id<S: IntoCStr>(id: S) -> Option<Ref<Remote>> { let id = id.to_cstr(); let value = unsafe { BNCollaborationGetRemoteById(id.as_ptr()) }; NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) }) } /// Get Remote by `address` -pub fn get_remote_by_address<S: AsCStr>(address: S) -> Option<Ref<Remote>> { +pub fn get_remote_by_address<S: IntoCStr>(address: S) -> Option<Ref<Remote>> { let address = address.to_cstr(); let value = unsafe { BNCollaborationGetRemoteByAddress(address.as_ptr()) }; NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) }) } /// Get Remote by `name` -pub fn get_remote_by_name<S: AsCStr>(name: S) -> Option<Ref<Remote>> { +pub fn get_remote_by_name<S: IntoCStr>(name: S) -> Option<Ref<Remote>> { let name = name.to_cstr(); let value = unsafe { BNCollaborationGetRemoteByName(name.as_ptr()) }; NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) }) @@ -105,10 +105,10 @@ pub fn save_remotes() { pub fn store_data_in_keychain<K, I, DK, DV>(key: K, data: I) -> bool where - K: AsCStr, + K: IntoCStr, I: IntoIterator<Item = (DK, DV)>, - DK: AsCStr, - DV: AsCStr, + DK: IntoCStr, + DV: IntoCStr, { let key = key.to_cstr(); let (data_keys, data_values): (Vec<DK::Result>, Vec<DV::Result>) = data @@ -127,12 +127,12 @@ where } } -pub fn has_data_in_keychain<K: AsCStr>(key: K) -> bool { +pub fn has_data_in_keychain<K: IntoCStr>(key: K) -> bool { let key = key.to_cstr(); unsafe { BNCollaborationHasDataInKeychain(key.as_ptr()) } } -pub fn get_data_from_keychain<K: AsCStr>(key: K) -> Option<(Array<BnString>, Array<BnString>)> { +pub fn get_data_from_keychain<K: IntoCStr>(key: K) -> Option<(Array<BnString>, Array<BnString>)> { let key = key.to_cstr(); let mut keys = std::ptr::null_mut(); let mut values = std::ptr::null_mut(); @@ -142,7 +142,7 @@ pub fn get_data_from_keychain<K: AsCStr>(key: K) -> Option<(Array<BnString>, Arr keys.zip(values) } -pub fn delete_data_from_keychain<K: AsCStr>(key: K) -> bool { +pub fn delete_data_from_keychain<K: IntoCStr>(key: K) -> bool { let key = key.to_cstr(); unsafe { BNCollaborationDeleteDataFromKeychain(key.as_ptr()) } } diff --git a/rust/src/collaboration/changeset.rs b/rust/src/collaboration/changeset.rs index 0db384cb..b07f23de 100644 --- a/rust/src/collaboration/changeset.rs +++ b/rust/src/collaboration/changeset.rs @@ -6,7 +6,7 @@ use super::{RemoteFile, RemoteUser}; use crate::database::snapshot::SnapshotId; use crate::database::Database; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; /// A collection of snapshots in a local database #[repr(transparent)] @@ -65,7 +65,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 { + pub fn set_name<S: IntoCStr>(&self, value: S) -> bool { let value = value.to_cstr(); unsafe { BNCollaborationChangesetSetName(self.handle.as_ptr(), value.as_ptr()) } } diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs index 251b4f7d..699b34b8 100644 --- a/rust/src/collaboration/file.rs +++ b/rust/src/collaboration/file.rs @@ -16,7 +16,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback, SplitProgressBuilder}; use crate::project::file::ProjectFile; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub type RemoteFileType = BNRemoteFileType; @@ -94,7 +94,7 @@ impl RemoteFile { success.then_some(()).ok_or(()) } - pub fn set_metadata<S: AsCStr>(&self, folder: S) -> Result<(), ()> { + pub fn set_metadata<S: IntoCStr>(&self, folder: S) -> Result<(), ()> { let folder_raw = folder.to_cstr(); let success = unsafe { BNRemoteFileSetMetadata(self.handle.as_ptr(), folder_raw.as_ptr()) }; success.then_some(()).ok_or(()) @@ -185,7 +185,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<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteFileSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -199,7 +199,7 @@ 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<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteFileSetDescription(self.handle.as_ptr(), description.as_ptr()) }; @@ -249,7 +249,7 @@ impl RemoteFile { /// Get a specific Snapshot in the File by its id /// /// NOTE: If snapshots have not been pulled, they will be pulled upon calling this. - pub fn snapshot_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteSnapshot>>, ()> { + pub fn snapshot_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteSnapshot>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_snapshots() { self.pull_snapshots()?; @@ -295,9 +295,9 @@ impl RemoteFile { parent_ids: I, ) -> Result<Ref<RemoteSnapshot>, ()> where - S: AsCStr, + S: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { self.create_snapshot_with_progress( name, @@ -327,10 +327,10 @@ impl RemoteFile { mut progress: P, ) -> Result<Ref<RemoteSnapshot>, ()> where - S: AsCStr, + S: IntoCStr, P: ProgressCallback, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let name = name.to_cstr(); let parent_ids: Vec<_> = parent_ids.into_iter().map(|id| id.to_cstr()).collect(); @@ -405,7 +405,7 @@ impl RemoteFile { /// * `progress_function` - Function to call for progress updates pub fn download<S>(&self, db_path: S) -> Result<Ref<FileMetadata>, ()> where - S: AsCStr, + S: IntoCStr, { sync::download_file(self, db_path) } @@ -422,14 +422,14 @@ impl RemoteFile { progress_function: F, ) -> Result<Ref<FileMetadata>, ()> where - S: AsCStr, + S: IntoCStr, F: ProgressCallback, { sync::download_file_with_progress(self, db_path, progress_function) } /// Download a remote file and save it to a BNDB at the given `path`, returning the associated [`FileMetadata`]. - pub fn download_database<S: AsCStr>(&self, path: S) -> Result<Ref<FileMetadata>, ()> { + pub fn download_database<S: IntoCStr>(&self, path: S) -> Result<Ref<FileMetadata>, ()> { let file = self.download(path)?; let database = file.database().ok_or(())?; self.sync(&database, DatabaseConflictHandlerFail, NoNameChangeset)?; @@ -439,7 +439,7 @@ impl RemoteFile { // TODO: This might be a bad helper... maybe remove... // TODO: AsRef<Path> /// Download a remote file and save it to a BNDB at the given `path`. - pub fn download_database_with_progress<S: AsCStr>( + pub fn download_database_with_progress<S: IntoCStr>( &self, path: S, progress: impl ProgressCallback, diff --git a/rust/src/collaboration/folder.rs b/rust/src/collaboration/folder.rs index b5fde3b4..35ff0788 100644 --- a/rust/src/collaboration/folder.rs +++ b/rust/src/collaboration/folder.rs @@ -4,7 +4,7 @@ use std::ptr::NonNull; use crate::project::folder::ProjectFolder; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteFolder { @@ -103,7 +103,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<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteFolderSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -117,7 +117,7 @@ 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<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteFolderSetDescription(self.handle.as_ptr(), description.as_ptr()) }; diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index b8b32c7a..08efa079 100644 --- a/rust/src/collaboration/group.rs +++ b/rust/src/collaboration/group.rs @@ -1,6 +1,6 @@ use super::Remote; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; use std::fmt; use std::fmt::{Display, Formatter}; @@ -49,7 +49,7 @@ impl RemoteGroup { /// Set group name /// You will need to push the group to update the Remote. - pub fn set_name<U: AsCStr>(&self, name: U) { + pub fn set_name<U: IntoCStr>(&self, name: U) { let name = name.to_cstr(); unsafe { BNCollaborationGroupSetName(self.handle.as_ptr(), name.as_ptr()) } } @@ -84,7 +84,7 @@ impl RemoteGroup { pub fn set_users<I>(&self, usernames: I) -> Result<(), ()> where I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let usernames: Vec<_> = usernames.into_iter().map(|u| u.to_cstr()).collect(); let mut usernames_raw: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect(); @@ -102,7 +102,7 @@ impl RemoteGroup { } /// Test if a group has a user with the given username - pub fn contains_user<U: AsCStr>(&self, username: U) -> bool { + pub fn contains_user<U: IntoCStr>(&self, username: U) -> bool { let username = username.to_cstr(); unsafe { BNCollaborationGroupContainsUser(self.handle.as_ptr(), username.as_ptr()) } } diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs index 2fb5b3de..9ebf4cda 100644 --- a/rust/src/collaboration/merge.rs +++ b/rust/src/collaboration/merge.rs @@ -4,7 +4,7 @@ use std::ptr::NonNull; use crate::database::{snapshot::Snapshot, Database}; use crate::file_metadata::FileMetadata; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub type MergeConflictDataType = BNMergeConflictDataType; @@ -48,7 +48,7 @@ impl MergeConflict { NonNull::new(result).map(|handle| unsafe { Snapshot::from_raw(handle) }) } - pub fn path_item_string<S: AsCStr>(&self, path: S) -> Result<BnString, ()> { + pub fn path_item_string<S: IntoCStr>(&self, path: S) -> Result<BnString, ()> { let path = path.to_cstr(); let result = unsafe { BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path.as_ptr()) @@ -119,7 +119,7 @@ impl MergeConflict { } /// Call this when you've resolved the conflict to save the result - pub fn success<S: AsCStr>(&self, value: S) -> Result<(), ()> { + pub fn success<S: IntoCStr>(&self, value: S) -> Result<(), ()> { let value = value.to_cstr(); let success = unsafe { BNAnalysisMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) }; @@ -127,7 +127,7 @@ impl MergeConflict { } // 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> { + pub unsafe fn get_path_item_number<S: IntoCStr>(&self, path_key: S) -> Option<u64> { let path_key = path_key.to_cstr(); let value = unsafe { BNAnalysisMergeConflictGetPathItem(self.handle.as_ptr(), path_key.as_ptr()) }; @@ -138,7 +138,7 @@ impl MergeConflict { } } - pub unsafe fn get_path_item_string<S: AsCStr>(&self, path_key: S) -> Option<BnString> { + pub unsafe fn get_path_item_string<S: IntoCStr>(&self, path_key: S) -> Option<BnString> { let path_key = path_key.to_cstr(); let value = unsafe { BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path_key.as_ptr()) diff --git a/rust/src/collaboration/project.rs b/rust/src/collaboration/project.rs index fce2a5f6..3d34da9e 100644 --- a/rust/src/collaboration/project.rs +++ b/rust/src/collaboration/project.rs @@ -15,7 +15,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::Project; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteProject { @@ -136,7 +136,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<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteProjectSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -150,7 +150,7 @@ 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<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteProjectSetDescription(self.handle.as_ptr(), description.as_ptr()) }; @@ -221,7 +221,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If files have not been pulled, they will be pulled upon calling this. - pub fn get_file_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteFile>>, ()> { + pub fn get_file_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFile>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_files() { self.pull_files()?; @@ -235,7 +235,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If files have not been pulled, they will be pulled upon calling this. - pub fn get_file_by_name<S: AsCStr>(&self, name: S) -> Result<Option<Ref<RemoteFile>>, ()> { + pub fn get_file_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteFile>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_files() { self.pull_files()?; @@ -292,9 +292,9 @@ impl RemoteProject { file_type: RemoteFileType, ) -> Result<Ref<RemoteFile>, ()> where - F: AsCStr, - N: AsCStr, - D: AsCStr, + F: IntoCStr, + N: IntoCStr, + D: IntoCStr, { self.create_file_with_progress( filename, @@ -329,9 +329,9 @@ impl RemoteProject { mut progress: P, ) -> Result<Ref<RemoteFile>, ()> where - F: AsCStr, - N: AsCStr, - D: AsCStr, + F: IntoCStr, + N: IntoCStr, + D: IntoCStr, P: ProgressCallback, { // TODO: This sync should be removed? @@ -367,8 +367,8 @@ impl RemoteProject { pub fn push_file<I, K, V>(&self, file: &RemoteFile, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { // TODO: This sync should be removed? self.open()?; @@ -421,7 +421,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If folders have not been pulled, they will be pulled upon calling this. - pub fn get_folder_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteFolder>>, ()> { + pub fn get_folder_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFolder>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_folders() { self.pull_folders()?; @@ -472,8 +472,8 @@ impl RemoteProject { parent_folder: Option<&RemoteFolder>, ) -> Result<Ref<RemoteFolder>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, { self.create_folder_with_progress(name, description, parent_folder, NoProgressCallback) } @@ -494,8 +494,8 @@ impl RemoteProject { mut progress: P, ) -> Result<Ref<RemoteFolder>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, P: ProgressCallback, { // TODO: This sync should be removed? @@ -529,8 +529,8 @@ impl RemoteProject { pub fn push_folder<I, K, V>(&self, folder: &RemoteFolder, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { // TODO: This sync should be removed? self.open()?; @@ -598,7 +598,7 @@ impl RemoteProject { /// Get a specific permission in the Project by its id. /// /// NOTE: If group or user permissions have not been pulled, they will be pulled upon calling this. - pub fn get_permission_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<Permission>>, ()> { + pub fn get_permission_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<Permission>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_user_permissions() { self.pull_user_permissions()?; @@ -703,7 +703,7 @@ impl RemoteProject { /// /// * `user_id` - User id /// * `level` - Permission level - pub fn create_user_permission<S: AsCStr>( + pub fn create_user_permission<S: IntoCStr>( &self, user_id: S, level: CollaborationPermissionLevel, @@ -718,7 +718,7 @@ impl RemoteProject { /// * `user_id` - User id /// * `level` - Permission level /// * `progress` - The progress callback to call - pub fn create_user_permission_with_progress<S: AsCStr, F: ProgressCallback>( + pub fn create_user_permission_with_progress<S: IntoCStr, F: ProgressCallback>( &self, user_id: S, level: CollaborationPermissionLevel, @@ -753,8 +753,8 @@ impl RemoteProject { ) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -788,7 +788,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_view<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_view<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), username.as_ptr()) } } @@ -798,7 +798,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_edit<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_edit<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), username.as_ptr()) } } @@ -808,7 +808,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_admin<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_admin<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), username.as_ptr()) } } diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs index 4d69873a..baeba412 100644 --- a/rust/src/collaboration/remote.rs +++ b/rust/src/collaboration/remote.rs @@ -10,7 +10,7 @@ use crate::enterprise; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::Project; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct Remote { @@ -27,7 +27,7 @@ impl Remote { } /// Create a Remote and add it to the list of known remotes (saved to Settings) - pub fn new<N: AsCStr, A: AsCStr>(name: N, address: A) -> Ref<Self> { + pub fn new<N: IntoCStr, A: IntoCStr>(name: N, address: A) -> Ref<Self> { let name = name.to_cstr(); let address = address.to_cstr(); let result = unsafe { BNCollaborationCreateRemote(name.as_ptr(), address.as_ptr()) }; @@ -163,7 +163,7 @@ impl Remote { } /// Requests an authentication token using a username and password. - pub fn request_authentication_token<U: AsCStr, P: AsCStr>( + pub fn request_authentication_token<U: IntoCStr, P: IntoCStr>( &self, username: U, password: P, @@ -275,7 +275,7 @@ impl Remote { /// Gets a specific project in the Remote by its id. /// /// NOTE: If projects have not been pulled, they will be pulled upon calling this. - pub fn get_project_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteProject>>, ()> { + pub fn get_project_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteProject>>, ()> { if !self.has_pulled_projects() { self.pull_projects()?; } @@ -288,7 +288,7 @@ impl Remote { /// Gets a specific project in the Remote by its name. /// /// NOTE: If projects have not been pulled, they will be pulled upon calling this. - pub fn get_project_by_name<S: AsCStr>( + pub fn get_project_by_name<S: IntoCStr>( &self, name: S, ) -> Result<Option<Ref<RemoteProject>>, ()> { @@ -331,7 +331,7 @@ impl Remote { /// /// * `name` - Project name /// * `description` - Project description - pub fn create_project<N: AsCStr, D: AsCStr>( + pub fn create_project<N: IntoCStr, D: IntoCStr>( &self, name: N, description: D, @@ -383,8 +383,8 @@ impl Remote { pub fn push_project<I, K, V>(&self, project: &RemoteProject, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -446,7 +446,7 @@ impl Remote { /// /// If groups have not been pulled, they will be pulled upon calling this. /// This function is only available to accounts with admin status on the Remote. - pub fn get_group_by_name<S: AsCStr>(&self, name: S) -> Result<Option<Ref<RemoteGroup>>, ()> { + pub fn get_group_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteGroup>>, ()> { if !self.has_pulled_groups() { self.pull_groups()?; } @@ -462,7 +462,7 @@ impl Remote { /// # Arguments /// /// * `prefix` - Prefix of name for groups - pub fn search_groups<S: AsCStr>( + pub fn search_groups<S: IntoCStr>( &self, prefix: S, ) -> Result<(Array<GroupId>, Array<BnString>), ()> { @@ -526,9 +526,9 @@ impl Remote { /// * `usernames` - List of usernames of users in the group pub fn create_group<N, I>(&self, name: N, usernames: I) -> Result<Ref<RemoteGroup>, ()> where - N: AsCStr, + N: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let name = name.to_cstr(); let usernames: Vec<_> = usernames.into_iter().map(|s| s.to_cstr()).collect(); @@ -557,8 +557,8 @@ impl Remote { pub fn push_group<I, K, V>(&self, group: &RemoteGroup, extra_fields: I) -> Result<(), ()> where I: IntoIterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -617,7 +617,7 @@ impl Remote { /// # Arguments /// /// * `id` - The identifier of the user to retrieve. - pub fn get_user_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteUser>>, ()> { + pub fn get_user_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteUser>>, ()> { if !self.has_pulled_users() { self.pull_users()?; } @@ -635,7 +635,7 @@ impl Remote { /// # Arguments /// /// * `username` - The username of the user to retrieve. - pub fn get_user_by_username<S: AsCStr>( + pub fn get_user_by_username<S: IntoCStr>( &self, username: S, ) -> Result<Option<Ref<RemoteUser>>, ()> { @@ -665,7 +665,7 @@ impl Remote { /// # Arguments /// /// * `prefix` - The prefix to search for in usernames. - pub fn search_users<S: AsCStr>( + pub fn search_users<S: IntoCStr>( &self, prefix: S, ) -> Result<(Array<BnString>, Array<BnString>), ()> { @@ -730,7 +730,7 @@ impl Remote { /// # Arguments /// /// * Various details about the new user to be created. - pub fn create_user<U: AsCStr, E: AsCStr, P: AsCStr>( + pub fn create_user<U: IntoCStr, E: IntoCStr, P: IntoCStr>( &self, username: U, email: E, @@ -772,8 +772,8 @@ impl Remote { pub fn push_user<I, K, V>(&self, user: &RemoteUser, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() diff --git a/rust/src/collaboration/snapshot.rs b/rust/src/collaboration/snapshot.rs index 6e1dfb89..c8256608 100644 --- a/rust/src/collaboration/snapshot.rs +++ b/rust/src/collaboration/snapshot.rs @@ -8,7 +8,7 @@ use crate::collaboration::undo::{RemoteUndoEntry, RemoteUndoEntryId}; use crate::database::snapshot::Snapshot; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; // TODO: RemoteSnapshotId ? @@ -226,7 +226,7 @@ impl RemoteSnapshot { } /// Create a new Undo Entry in this snapshot. - pub fn create_undo_entry<S: AsCStr>( + pub fn create_undo_entry<S: IntoCStr>( &self, parent: Option<u64>, data: S, diff --git a/rust/src/collaboration/sync.rs b/rust/src/collaboration/sync.rs index 5afb8923..b1b26982 100644 --- a/rust/src/collaboration/sync.rs +++ b/rust/src/collaboration/sync.rs @@ -11,7 +11,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::file::ProjectFile; use crate::rc::Ref; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_archive::{TypeArchive, TypeArchiveMergeConflict}; // TODO: PathBuf @@ -43,7 +43,7 @@ pub fn default_file_path(file: &RemoteFile) -> Result<BnString, ()> { /// /// * `file` - Remote File to download and open /// * `db_path` - File path for saved database -pub fn download_file<S: AsCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<FileMetadata>, ()> { +pub fn download_file<S: IntoCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<FileMetadata>, ()> { download_file_with_progress(file, db_path, NoProgressCallback) } @@ -54,7 +54,7 @@ pub fn download_file<S: AsCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<Fil /// * `file` - Remote File to download and open /// * `db_path` - File path for saved database /// * `progress` - Function to call for progress updates -pub fn download_file_with_progress<S: AsCStr, F: ProgressCallback>( +pub fn download_file_with_progress<S: IntoCStr, F: ProgressCallback>( file: &RemoteFile, db_path: S, mut progress: F, @@ -220,7 +220,7 @@ pub fn get_local_snapshot_for_remote( pub fn download_database<S>(file: &RemoteFile, location: S, force: bool) -> Result<(), ()> where - S: AsCStr, + S: IntoCStr, { download_database_with_progress(file, location, force, NoProgressCallback) } @@ -232,7 +232,7 @@ pub fn download_database_with_progress<S, F>( mut progress: F, ) -> Result<(), ()> where - S: AsCStr, + S: IntoCStr, F: ProgressCallback, { let db_path = location.to_cstr(); @@ -475,7 +475,7 @@ pub fn get_snapshot_author( /// * `database` - Parent database /// * `snapshot` - Snapshot to edit /// * `author` - Target author -pub fn set_snapshot_author<S: AsCStr>( +pub fn set_snapshot_author<S: IntoCStr>( database: &Database, snapshot: &Snapshot, author: S, @@ -650,7 +650,7 @@ pub fn get_remote_file_for_local_type_archive(database: &TypeArchive) -> Option< } /// Get the remote snapshot associated with a local snapshot (if it exists) in a Type Archive -pub fn get_remote_snapshot_from_local_type_archive<S: AsCStr>( +pub fn get_remote_snapshot_from_local_type_archive<S: IntoCStr>( type_archive: &TypeArchive, snapshot_id: S, ) -> Option<Ref<RemoteSnapshot>> { @@ -679,7 +679,7 @@ pub fn get_local_snapshot_from_remote_type_archive( } /// Test if a snapshot is ignored from the archive -pub fn is_type_archive_snapshot_ignored<S: AsCStr>( +pub fn is_type_archive_snapshot_ignored<S: IntoCStr>( type_archive: &TypeArchive, snapshot_id: S, ) -> bool { @@ -694,7 +694,7 @@ pub fn is_type_archive_snapshot_ignored<S: AsCStr>( /// Download a type archive from its remote, saving all snapshots to an archive in the /// specified `location`. Returns a [`TypeArchive`] for using later. -pub fn download_type_archive<S: AsCStr>( +pub fn download_type_archive<S: IntoCStr>( file: &RemoteFile, location: S, ) -> Result<Option<Ref<TypeArchive>>, ()> { @@ -703,7 +703,7 @@ pub fn download_type_archive<S: AsCStr>( /// Download a type archive from its remote, saving all snapshots to an archive in the /// specified `location`. Returns a [`TypeArchive`] for using later. -pub fn download_type_archive_with_progress<S: AsCStr, F: ProgressCallback>( +pub fn download_type_archive_with_progress<S: IntoCStr, F: ProgressCallback>( file: &RemoteFile, location: S, mut progress: F, diff --git a/rust/src/collaboration/user.rs b/rust/src/collaboration/user.rs index d4aea2c5..6b490942 100644 --- a/rust/src/collaboration/user.rs +++ b/rust/src/collaboration/user.rs @@ -3,7 +3,7 @@ use binaryninjacore_sys::*; use std::ptr::NonNull; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteUser { @@ -48,7 +48,7 @@ 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<(), ()> { + pub fn set_username<U: IntoCStr>(&self, username: U) -> Result<(), ()> { let username = username.to_cstr(); let result = unsafe { BNCollaborationUserSetUsername(self.handle.as_ptr(), username.as_ptr()) }; @@ -67,7 +67,7 @@ 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<(), ()> { + pub fn set_email<U: IntoCStr>(&self, email: U) -> Result<(), ()> { let username = email.to_cstr(); let result = unsafe { BNCollaborationUserSetEmail(self.handle.as_ptr(), username.as_ptr()) }; diff --git a/rust/src/command.rs b/rust/src/command.rs index 721f9170..099eafa8 100644 --- a/rust/src/command.rs +++ b/rust/src/command.rs @@ -42,7 +42,7 @@ use std::os::raw::c_void; use crate::binary_view::BinaryView; use crate::function::Function; -use crate::string::AsCStr; +use crate::string::IntoCStr; /// The trait required for generic commands. See [register_command] for example usage. pub trait Command: 'static + Sync { @@ -95,7 +95,7 @@ where /// ``` pub fn register_command<S, C>(name: S, desc: S, command: C) where - S: AsCStr, + S: IntoCStr, C: Command, { extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView) @@ -196,7 +196,7 @@ where /// ``` pub fn register_command_for_address<S, C>(name: S, desc: S, command: C) where - S: AsCStr, + S: IntoCStr, C: AddressCommand, { extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64) @@ -298,7 +298,7 @@ where /// ``` pub fn register_command_for_range<S, C>(name: S, desc: S, command: C) where - S: AsCStr, + S: IntoCStr, C: RangeCommand, { extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64, len: u64) @@ -405,7 +405,7 @@ where /// ``` pub fn register_command_for_function<S, C>(name: S, desc: S, command: C) where - S: AsCStr, + S: IntoCStr, C: FunctionCommand, { extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, func: *mut BNFunction) diff --git a/rust/src/component.rs b/rust/src/component.rs index 48c8b110..ae5fd55e 100644 --- a/rust/src/component.rs +++ b/rust/src/component.rs @@ -1,7 +1,7 @@ use crate::binary_view::{BinaryView, BinaryViewExt}; use crate::function::Function; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::types::ComponentReferencedType; use std::ffi::c_char; use std::fmt::Debug; @@ -164,7 +164,7 @@ impl Component { unsafe { BnString::into_string(result) } } - pub fn set_name<S: AsCStr>(&self, name: S) { + pub fn set_name<S: IntoCStr>(&self, name: S) { let name = name.to_cstr(); unsafe { BNComponentSetName(self.handle.as_ptr(), name.as_ptr()) } } diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index ee32a67f..7e5c0a24 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -41,7 +41,7 @@ use crate::Endianness; /// implementation of the `CustomBinaryViewType` must return. pub fn register_view_type<S, T, F>(name: S, long_name: S, constructor: F) -> &'static T where - S: AsCStr, + S: IntoCStr, T: CustomBinaryViewType, F: FnOnce(BinaryViewType) -> T, { @@ -359,7 +359,7 @@ impl BinaryViewType { } /// Looks up a BinaryViewType by its short name - pub fn by_name<N: AsCStr>(name: N) -> Result<Self> { + pub fn by_name<N: IntoCStr>(name: N) -> Result<Self> { let bytes = name.to_cstr(); let handle = unsafe { BNGetBinaryViewTypeByName(bytes.as_ref().as_ptr() as *const _) }; match handle.is_null() { diff --git a/rust/src/data_buffer.rs b/rust/src/data_buffer.rs index a163d346..bfffc33f 100644 --- a/rust/src/data_buffer.rs +++ b/rust/src/data_buffer.rs @@ -19,7 +19,7 @@ use binaryninjacore_sys::*; use std::ffi::c_void; use std::slice; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub struct DataBuffer(*mut BNDataBuffer); diff --git a/rust/src/database.rs b/rust/src/database.rs index 61d6f608..1746b405 100644 --- a/rust/src/database.rs +++ b/rust/src/database.rs @@ -15,7 +15,7 @@ use crate::database::snapshot::{Snapshot, SnapshotId}; use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::rc::{Array, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub struct Database { pub(crate) handle: NonNull<BNDatabase>, @@ -62,7 +62,7 @@ impl Database { unsafe { BNSetDatabaseCurrentSnapshot(self.handle.as_ptr(), id.0) } } - pub fn write_snapshot_data<N: AsCStr>( + pub fn write_snapshot_data<N: IntoCStr>( &self, parents: &[SnapshotId], file: &BinaryView, @@ -90,7 +90,7 @@ impl Database { mut progress: P, ) -> SnapshotId where - N: AsCStr, + N: IntoCStr, P: ProgressCallback, { let name_raw = name.to_cstr(); @@ -133,7 +133,7 @@ impl Database { Err(()) } } - pub fn has_global<S: AsCStr>(&self, key: S) -> bool { + pub fn has_global<S: IntoCStr>(&self, key: S) -> bool { let key_raw = key.to_cstr(); unsafe { BNDatabaseHasGlobal(self.handle.as_ptr(), key_raw.as_ptr()) != 0 } } @@ -155,28 +155,28 @@ impl Database { } /// Get a specific global by key - pub fn read_global<S: AsCStr>(&self, key: S) -> Option<BnString> { + pub fn read_global<S: IntoCStr>(&self, key: S) -> Option<BnString> { let key_raw = key.to_cstr(); let result = unsafe { BNReadDatabaseGlobal(self.handle.as_ptr(), key_raw.as_ptr()) }; unsafe { NonNull::new(result).map(|_| BnString::from_raw(result)) } } /// Write a global into the database - pub fn write_global<K: AsCStr, V: AsCStr>(&self, key: K, value: V) -> bool { + pub fn write_global<K: IntoCStr, V: IntoCStr>(&self, key: K, value: V) -> bool { let key_raw = key.to_cstr(); let value_raw = value.to_cstr(); unsafe { BNWriteDatabaseGlobal(self.handle.as_ptr(), key_raw.as_ptr(), value_raw.as_ptr()) } } /// Get a specific global by key, as a binary buffer - pub fn read_global_data<S: AsCStr>(&self, key: S) -> Option<DataBuffer> { + pub fn read_global_data<S: IntoCStr>(&self, key: S) -> Option<DataBuffer> { let key_raw = key.to_cstr(); let result = unsafe { BNReadDatabaseGlobalData(self.handle.as_ptr(), key_raw.as_ptr()) }; NonNull::new(result).map(|_| DataBuffer::from_raw(result)) } /// Write a binary buffer into a global in the database - pub fn write_global_data<K: AsCStr>(&self, key: K, value: &DataBuffer) -> bool { + pub fn write_global_data<K: IntoCStr>(&self, key: K, value: &DataBuffer) -> bool { let key_raw = key.to_cstr(); unsafe { BNWriteDatabaseGlobalData(self.handle.as_ptr(), key_raw.as_ptr(), value.as_raw()) } } diff --git a/rust/src/database/kvs.rs b/rust/src/database/kvs.rs index e84da7f3..5b7cbbe8 100644 --- a/rust/src/database/kvs.rs +++ b/rust/src/database/kvs.rs @@ -1,6 +1,6 @@ use crate::data_buffer::DataBuffer; use crate::rc::{Array, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::{ BNBeginKeyValueStoreNamespace, BNEndKeyValueStoreNamespace, BNFreeKeyValueStore, BNGetKeyValueStoreBuffer, BNGetKeyValueStoreDataSize, BNGetKeyValueStoreKeys, @@ -41,7 +41,7 @@ impl KeyValueStore { } /// Get the value for a single key - pub fn value<S: AsCStr>(&self, key: S) -> Option<DataBuffer> { + pub fn value<S: IntoCStr>(&self, key: S) -> Option<DataBuffer> { let key_raw = key.to_cstr(); let key_ptr = key_raw.as_ptr(); let result = unsafe { BNGetKeyValueStoreBuffer(self.handle.as_ptr(), key_ptr) }; @@ -49,7 +49,7 @@ impl KeyValueStore { } /// Set the value for a single key - pub fn set_value<S: AsCStr>(&self, key: S, value: &DataBuffer) -> bool { + pub fn set_value<S: IntoCStr>(&self, key: S, value: &DataBuffer) -> bool { let key_raw = key.to_cstr(); let key_ptr = key_raw.as_ptr(); unsafe { BNSetKeyValueStoreBuffer(self.handle.as_ptr(), key_ptr, value.as_raw()) } @@ -63,7 +63,7 @@ impl KeyValueStore { } /// Begin storing new keys into a namespace - pub fn begin_namespace<S: AsCStr>(&self, name: S) { + pub fn begin_namespace<S: IntoCStr>(&self, name: S) { let name_raw = name.to_cstr(); let name_ptr = name_raw.as_ptr(); unsafe { BNBeginKeyValueStoreNamespace(self.handle.as_ptr(), name_ptr) } diff --git a/rust/src/database/snapshot.rs b/rust/src/database/snapshot.rs index 599a749a..d9ff030a 100644 --- a/rust/src/database/snapshot.rs +++ b/rust/src/database/snapshot.rs @@ -4,7 +4,7 @@ use crate::database::undo::UndoEntry; use crate::database::Database; use crate::progress::ProgressCallback; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::{ BNCollaborationFreeSnapshotIdList, BNFreeSnapshot, BNFreeSnapshotList, BNGetSnapshotChildren, BNGetSnapshotDatabase, BNGetSnapshotFileContents, BNGetSnapshotFileContentsHash, @@ -50,7 +50,7 @@ impl Snapshot { } /// Set the displayed snapshot name - pub fn set_name<S: AsCStr>(&self, value: S) { + pub fn set_name<S: IntoCStr>(&self, value: S) { let value_raw = value.to_cstr(); let value_ptr = value_raw.as_ptr(); unsafe { BNSetSnapshotName(self.handle.as_ptr(), value_ptr) } diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index 92c0170d..248726f3 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -83,7 +83,7 @@ use crate::{ binary_view::BinaryView, platform::Platform, rc::*, - string::{raw_to_string, AsCStr, BnString}, + string::{raw_to_string, BnString, IntoCStr}, types::{NameAndType, Type}, }; @@ -115,7 +115,7 @@ impl DebugInfoParser { } /// Returns debug info parser of the given name, if it exists - pub fn from_name<S: AsCStr>(name: S) -> Result<Ref<Self>, ()> { + pub fn from_name<S: IntoCStr>(name: S) -> Result<Ref<Self>, ()> { let name = name.to_cstr(); let parser = unsafe { BNGetDebugInfoParserByName(name.as_ptr()) }; @@ -209,7 +209,7 @@ impl DebugInfoParser { // Registers a DebugInfoParser. See `binaryninja::debuginfo::DebugInfoParser` for more details. pub fn register<S, C>(name: S, parser_callbacks: C) -> Ref<Self> where - S: AsCStr, + S: IntoCStr, C: CustomDebugInfoParser, { extern "C" fn cb_is_valid<C>(ctxt: *mut c_void, view: *mut BNBinaryView) -> bool @@ -418,7 +418,7 @@ impl DebugInfo { } /// Returns all types within the parser - pub fn types_by_name<S: AsCStr>(&self, parser_name: S) -> Vec<NameAndType> { + pub fn types_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<NameAndType> { let parser_name = parser_name.to_cstr(); let mut count: usize = 0; @@ -451,7 +451,7 @@ impl DebugInfo { } /// Returns all functions within the parser - pub fn functions_by_name<S: AsCStr>(&self, parser_name: S) -> Vec<DebugFunctionInfo> { + pub fn functions_by_name<S: IntoCStr>(&self, parser_name: S) -> Vec<DebugFunctionInfo> { let parser_name = parser_name.to_cstr(); let mut count: usize = 0; @@ -486,7 +486,7 @@ impl DebugInfo { } /// Returns all data variables within the parser - pub fn data_variables_by_name<S: AsCStr>( + pub fn data_variables_by_name<S: IntoCStr>( &self, parser_name: S, ) -> Vec<NamedDataVariableWithType> { @@ -523,7 +523,7 @@ impl DebugInfo { result } - pub fn type_by_name<S: AsCStr>(&self, parser_name: S, name: S) -> Option<Ref<Type>> { + pub fn type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> Option<Ref<Type>> { let parser_name = parser_name.to_cstr(); let name = name.to_cstr(); @@ -536,7 +536,7 @@ impl DebugInfo { } } - pub fn get_data_variable_by_name<S: AsCStr>( + pub fn get_data_variable_by_name<S: IntoCStr>( &self, parser_name: S, name: S, @@ -558,7 +558,7 @@ impl DebugInfo { } } - pub fn get_data_variable_by_address<S: AsCStr>( + pub fn get_data_variable_by_address<S: IntoCStr>( &self, parser_name: S, address: u64, @@ -576,7 +576,7 @@ impl DebugInfo { } /// Returns a list of [`NameAndType`] where the `name` is the parser the type originates from. - pub fn get_types_by_name<S: AsCStr>(&self, name: S) -> Vec<NameAndType> { + pub fn get_types_by_name<S: IntoCStr>(&self, name: S) -> Vec<NameAndType> { let mut count: usize = 0; let name = name.to_cstr(); let raw_names_and_types_ptr = @@ -595,7 +595,10 @@ impl DebugInfo { } // The tuple is (DebugInfoParserName, address, type) - pub fn get_data_variables_by_name<S: AsCStr>(&self, name: S) -> Vec<(String, u64, Ref<Type>)> { + pub fn get_data_variables_by_name<S: IntoCStr>( + &self, + name: S, + ) -> Vec<(String, u64, Ref<Type>)> { let name = name.to_cstr(); let mut count: usize = 0; @@ -646,51 +649,55 @@ impl DebugInfo { result } - pub fn remove_parser_info<S: AsCStr>(&self, parser_name: S) -> bool { + pub fn remove_parser_info<S: IntoCStr>(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserInfo(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_types<S: AsCStr>(&self, parser_name: S) -> bool { + pub fn remove_parser_types<S: IntoCStr>(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserTypes(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_functions<S: AsCStr>(&self, parser_name: S) -> bool { + pub fn remove_parser_functions<S: IntoCStr>(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserFunctions(self.handle, parser_name.as_ptr()) } } - pub fn remove_parser_data_variables<S: AsCStr>(&self, parser_name: S) -> bool { + pub fn remove_parser_data_variables<S: IntoCStr>(&self, parser_name: S) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugParserDataVariables(self.handle, parser_name.as_ptr()) } } - pub fn remove_type_by_name<S: AsCStr>(&self, parser_name: S, name: S) -> bool { + pub fn remove_type_by_name<S: IntoCStr>(&self, parser_name: S, name: S) -> bool { let parser_name = parser_name.to_cstr(); let name = name.to_cstr(); unsafe { BNRemoveDebugTypeByName(self.handle, parser_name.as_ptr(), name.as_ptr()) } } - pub fn remove_function_by_index<S: AsCStr>(&self, parser_name: S, index: usize) -> bool { + pub fn remove_function_by_index<S: IntoCStr>(&self, parser_name: S, index: usize) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugFunctionByIndex(self.handle, parser_name.as_ptr(), index) } } - pub fn remove_data_variable_by_address<S: AsCStr>(&self, parser_name: S, address: u64) -> bool { + pub fn remove_data_variable_by_address<S: IntoCStr>( + &self, + parser_name: S, + address: u64, + ) -> bool { let parser_name = parser_name.to_cstr(); unsafe { BNRemoveDebugDataVariableByAddress(self.handle, parser_name.as_ptr(), address) } } /// Adds a type scoped under the current parser's name to the debug info - pub fn add_type<S: AsCStr>(&self, name: S, new_type: &Type, components: &[&str]) -> bool { + pub fn add_type<S: IntoCStr>(&self, name: S, new_type: &Type, components: &[&str]) -> bool { // SAFETY: Lifetime of `components` will live long enough, so passing as_ptr is safe. let raw_components: Vec<_> = components.iter().map(|&c| c.as_ptr()).collect(); @@ -772,7 +779,7 @@ impl DebugInfo { } /// Adds a data variable scoped under the current parser's name to the debug info - pub fn add_data_variable<S: AsCStr>( + pub fn add_data_variable<S: IntoCStr>( &self, address: u64, t: &Type, diff --git a/rust/src/demangle.rs b/rust/src/demangle.rs index a883dc82..68b349ca 100644 --- a/rust/src/demangle.rs +++ b/rust/src/demangle.rs @@ -19,14 +19,14 @@ use std::ffi::{c_char, c_void}; use crate::architecture::CoreArchitecture; use crate::binary_view::BinaryView; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::types::{QualifiedName, Type}; use crate::rc::*; pub type Result<R> = std::result::Result<R, ()>; -pub fn demangle_generic<S: AsCStr>( +pub fn demangle_generic<S: IntoCStr>( arch: &CoreArchitecture, mangled_name: S, view: Option<&BinaryView>, @@ -57,7 +57,7 @@ pub fn demangle_generic<S: AsCStr>( } } -pub fn demangle_llvm<S: AsCStr>(mangled_name: S, simplify: bool) -> Option<QualifiedName> { +pub fn demangle_llvm<S: IntoCStr>(mangled_name: S, simplify: bool) -> Option<QualifiedName> { let mangled_name = mangled_name.to_cstr(); let mut out_name: *mut *mut std::os::raw::c_char = std::ptr::null_mut(); let mut out_size: usize = 0; @@ -85,7 +85,7 @@ pub fn demangle_llvm<S: AsCStr>(mangled_name: S, simplify: bool) -> Option<Quali } } -pub fn demangle_gnu3<S: AsCStr>( +pub fn demangle_gnu3<S: IntoCStr>( arch: &CoreArchitecture, mangled_name: S, simplify: bool, @@ -125,7 +125,7 @@ pub fn demangle_gnu3<S: AsCStr>( } } -pub fn demangle_ms<S: AsCStr>( +pub fn demangle_ms<S: IntoCStr>( arch: &CoreArchitecture, mangled_name: S, simplify: bool, @@ -182,12 +182,12 @@ impl Demangler { unsafe { Array::<Demangler>::new(demanglers, count, ()) } } - pub fn is_mangled_string<S: AsCStr>(&self, name: S) -> bool { + pub fn is_mangled_string<S: IntoCStr>(&self, name: S) -> bool { let bytes = name.to_cstr(); unsafe { BNIsDemanglerMangledName(self.handle, bytes.as_ref().as_ptr() as *const _) } } - pub fn demangle<S: AsCStr>( + pub fn demangle<S: IntoCStr>( &self, arch: &CoreArchitecture, name: S, @@ -231,7 +231,7 @@ impl Demangler { unsafe { BnString::into_string(BNGetDemanglerName(self.handle)) } } - pub fn from_name<S: AsCStr>(name: S) -> Option<Self> { + pub fn from_name<S: IntoCStr>(name: S) -> Option<Self> { let name_bytes = name.to_cstr(); let demangler = unsafe { BNGetDemanglerByName(name_bytes.as_ref().as_ptr() as *const _) }; if demangler.is_null() { @@ -243,7 +243,7 @@ impl Demangler { pub fn register<S, C>(name: S, demangler: C) -> Self where - S: AsCStr, + S: IntoCStr, C: CustomDemangler, { extern "C" fn cb_is_mangled_string<C>(ctxt: *mut c_void, name: *const c_char) -> bool diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index 5964324d..396bcfcc 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -22,7 +22,7 @@ use crate::function::{Location, NativeBlock}; use crate::high_level_il as hlil; use crate::low_level_il as llil; use crate::medium_level_il as mlil; -use crate::string::AsCStr; +use crate::string::IntoCStr; use crate::string::{raw_to_string, strings_to_string_list, BnString}; use crate::rc::*; @@ -1242,7 +1242,7 @@ impl DisassemblyTextRenderer { unsafe { Array::new(tokens, count, ()) } } - pub fn wrap_comment<S1: AsCStr, S2: AsCStr, S3: AsCStr>( + pub fn wrap_comment<S1: IntoCStr, S2: IntoCStr, S3: IntoCStr>( &self, cur_line: DisassemblyTextLine, comment: S1, diff --git a/rust/src/download_provider.rs b/rust/src/download_provider.rs index 7d28058f..e74274f4 100644 --- a/rust/src/download_provider.rs +++ b/rust/src/download_provider.rs @@ -1,6 +1,6 @@ use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::settings::Settings; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; use std::collections::HashMap; use std::ffi::{c_void, CStr}; @@ -13,7 +13,7 @@ pub struct DownloadProvider { } impl DownloadProvider { - pub fn get<S: AsCStr>(name: S) -> Option<DownloadProvider> { + pub fn get<S: IntoCStr>(name: S) -> Option<DownloadProvider> { let name = name.to_cstr(); let result = unsafe { BNGetDownloadProviderByName(name.as_ptr()) }; if result.is_null() { @@ -131,7 +131,7 @@ impl DownloadInstance { } } - pub fn perform_request<S: AsCStr>( + pub fn perform_request<S: IntoCStr>( &mut self, url: S, callbacks: DownloadInstanceOutputCallbacks, @@ -202,11 +202,11 @@ impl DownloadInstance { } pub fn perform_custom_request< - M: AsCStr, - U: AsCStr, - HK: AsCStr, - HV: AsCStr, - I: IntoIterator<Item = (HK, HV)>, + M: IntoCStr, + U: IntoCStr, + HK: IntoCStr, + HV: IntoCStr, + I: Iterator<Item = (HK, HV)>, >( &mut self, method: M, diff --git a/rust/src/enterprise.rs b/rust/src/enterprise.rs index 74389d45..7c2aad19 100644 --- a/rust/src/enterprise.rs +++ b/rust/src/enterprise.rs @@ -1,5 +1,5 @@ use crate::rc::Array; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use std::ffi::c_void; use std::marker::PhantomData; use std::time::{Duration, SystemTime, UNIX_EPOCH}; @@ -120,7 +120,7 @@ pub fn server_url() -> String { unsafe { BnString::into_string(binaryninjacore_sys::BNGetEnterpriseServerUrl()) } } -pub fn set_server_url<S: AsCStr>(url: S) -> Result<(), ()> { +pub fn set_server_url<S: IntoCStr>(url: S) -> Result<(), ()> { let url = url.to_cstr(); let result = unsafe { binaryninjacore_sys::BNSetEnterpriseServerUrl( @@ -185,8 +185,8 @@ pub fn is_server_license_still_activated() -> bool { pub fn authenticate_server_with_credentials<U, P>(username: U, password: P, remember: bool) -> bool where - U: AsCStr, - P: AsCStr, + U: IntoCStr, + P: IntoCStr, { let username = username.to_cstr(); let password = password.to_cstr(); @@ -199,7 +199,7 @@ where } } -pub fn authenticate_server_with_method<S: AsCStr>(method: S, remember: bool) -> bool { +pub fn authenticate_server_with_method<S: IntoCStr>(method: S, remember: bool) -> bool { let method = method.to_cstr(); unsafe { binaryninjacore_sys::BNAuthenticateEnterpriseServerWithMethod( diff --git a/rust/src/external_library.rs b/rust/src/external_library.rs index 57848a7a..4f6e0e84 100644 --- a/rust/src/external_library.rs +++ b/rust/src/external_library.rs @@ -1,6 +1,6 @@ use crate::project::file::ProjectFile; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::symbol::Symbol; use binaryninjacore_sys::*; use std::fmt::Debug; @@ -166,7 +166,7 @@ impl ExternalLocation { /// Set the symbol pointed to by this ExternalLocation. /// ExternalLocations must have a valid target address and/or symbol set. - pub fn set_target_symbol<S: AsCStr>(&self, symbol: Option<S>) -> bool { + pub fn set_target_symbol<S: IntoCStr>(&self, symbol: Option<S>) -> bool { match symbol { Some(sym) => { let raw_sym = sym.to_cstr(); diff --git a/rust/src/file_metadata.rs b/rust/src/file_metadata.rs index 100f255b..deec36f0 100644 --- a/rust/src/file_metadata.rs +++ b/rust/src/file_metadata.rs @@ -52,7 +52,7 @@ impl FileMetadata { Self::ref_from_raw(unsafe { BNCreateFileMetadata() }) } - pub fn with_filename<S: AsCStr>(name: S) -> Ref<Self> { + pub fn with_filename<S: IntoCStr>(name: S) -> Ref<Self> { let ret = FileMetadata::new(); ret.set_filename(name); ret @@ -75,7 +75,7 @@ impl FileMetadata { } } - pub fn set_filename<S: AsCStr>(&self, name: S) { + pub fn set_filename<S: IntoCStr>(&self, name: S) { let name = name.to_cstr(); unsafe { @@ -107,7 +107,7 @@ impl FileMetadata { self.is_database_backed_for_view_type("") } - pub fn is_database_backed_for_view_type<S: AsCStr>(&self, view_type: S) -> bool { + pub fn is_database_backed_for_view_type<S: IntoCStr>(&self, view_type: S) -> bool { let view_type = view_type.to_cstr(); unsafe { BNIsBackedByDatabase(self.handle, view_type.as_ref().as_ptr() as *const _) } @@ -135,14 +135,14 @@ impl FileMetadata { unsafe { BnString::into_string(BNBeginUndoActions(self.handle, anonymous_allowed)) } } - pub fn commit_undo_actions<S: AsCStr>(&self, id: S) { + pub fn commit_undo_actions<S: IntoCStr>(&self, id: S) { let id = id.to_cstr(); unsafe { BNCommitUndoActions(self.handle, id.as_ref().as_ptr() as *const _); } } - pub fn revert_undo_actions<S: AsCStr>(&self, id: S) { + pub fn revert_undo_actions<S: IntoCStr>(&self, id: S) { let id = id.to_cstr(); unsafe { BNRevertUndoActions(self.handle, id.as_ref().as_ptr() as *const _); @@ -169,7 +169,7 @@ impl FileMetadata { unsafe { BNGetCurrentOffset(self.handle) } } - pub fn navigate_to<S: AsCStr>(&self, view: S, offset: u64) -> Result<(), ()> { + pub fn navigate_to<S: IntoCStr>(&self, view: S, offset: u64) -> Result<(), ()> { let view = view.to_cstr(); unsafe { @@ -181,7 +181,7 @@ impl FileMetadata { } } - pub fn view_of_type<S: AsCStr>(&self, view: S) -> Option<Ref<BinaryView>> { + pub fn view_of_type<S: IntoCStr>(&self, view: S) -> Option<Ref<BinaryView>> { let view = view.to_cstr(); unsafe { @@ -226,7 +226,7 @@ impl FileMetadata { } // TODO: Pass settings? - pub fn create_database_with_progress<S: AsCStr, P: ProgressCallback>( + pub fn create_database_with_progress<S: IntoCStr, P: ProgressCallback>( &self, file_path: impl AsRef<Path>, mut progress: P, @@ -256,7 +256,7 @@ impl FileMetadata { unsafe { BNSaveAutoSnapshot(raw_view.handle, ptr::null_mut() as *mut _) } } - pub fn open_database_for_configuration<S: AsCStr>( + pub fn open_database_for_configuration<S: IntoCStr>( &self, filename: S, ) -> Result<Ref<BinaryView>, ()> { @@ -273,7 +273,7 @@ impl FileMetadata { } } - pub fn open_database<S: AsCStr>(&self, filename: S) -> Result<Ref<BinaryView>, ()> { + pub fn open_database<S: IntoCStr>(&self, filename: S) -> Result<Ref<BinaryView>, ()> { let filename = filename.to_cstr(); let filename_ptr = filename.as_ptr(); @@ -286,7 +286,7 @@ impl FileMetadata { } } - pub fn open_database_with_progress<S: AsCStr, P: ProgressCallback>( + pub fn open_database_with_progress<S: IntoCStr, P: ProgressCallback>( &self, filename: S, mut progress: P, diff --git a/rust/src/function.rs b/rust/src/function.rs index 36bd1d56..5ebb84f6 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -372,7 +372,7 @@ impl Function { unsafe { BnString::into_string(BNGetFunctionComment(self.handle)) } } - pub fn set_comment<S: AsCStr>(&self, comment: S) { + pub fn set_comment<S: IntoCStr>(&self, comment: S) { let raw = comment.to_cstr(); unsafe { @@ -394,7 +394,7 @@ impl Function { unsafe { BnString::into_string(BNGetCommentForAddress(self.handle, addr)) } } - pub fn set_comment_at<S: AsCStr>(&self, addr: u64, comment: S) { + pub fn set_comment_at<S: IntoCStr>(&self, addr: u64, comment: S) { let raw = comment.to_cstr(); unsafe { @@ -1103,7 +1103,7 @@ impl Function { /// let crash = bv.create_tag_type("Crashes", "🎯"); /// fun.add_tag(&crash, "Nullpointer dereference", Some(0x1337), false, None); /// ``` - pub fn add_tag<S: AsCStr>( + pub fn add_tag<S: IntoCStr>( &self, tag_type: &TagType, data: S, @@ -1707,10 +1707,10 @@ impl Function { operand: usize, display_type: IntegerDisplayType, arch: Option<CoreArchitecture>, - enum_display_typeid: Option<impl AsCStr>, + enum_display_typeid: Option<impl IntoCStr>, ) { let arch = arch.unwrap_or_else(|| self.arch()); - let enum_display_typeid = enum_display_typeid.map(AsCStr::to_cstr); + let enum_display_typeid = enum_display_typeid.map(IntoCStr::to_cstr); let enum_display_typeid_ptr = enum_display_typeid .map(|x| x.as_ptr()) .unwrap_or(std::ptr::null()); diff --git a/rust/src/high_level_il/operation.rs b/rust/src/high_level_il/operation.rs index 302a6d73..8f7e9d81 100644 --- a/rust/src/high_level_il/operation.rs +++ b/rust/src/high_level_il/operation.rs @@ -6,7 +6,7 @@ use super::HighLevelILLiftedInstruction; use crate::architecture::CoreIntrinsic; use crate::function::Function; use crate::rc::Ref; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::variable::{ConstantData, SSAVariable, Variable}; #[derive(Clone, PartialEq, Eq)] @@ -20,7 +20,7 @@ impl GotoLabel { unsafe { BnString::into_string(BNGetGotoLabelName(self.function.handle, self.target)) } } - fn set_name<S: AsCStr>(&self, name: S) { + fn set_name<S: IntoCStr>(&self, name: S) { let raw = name.to_cstr(); unsafe { BNSetUserGotoLabelName( @@ -327,7 +327,7 @@ impl LiftedLabel { self.target.name() } - pub fn set_name<S: AsCStr>(&self, name: S) { + pub fn set_name<S: IntoCStr>(&self, name: S) { self.target.set_name(name) } } diff --git a/rust/src/interaction.rs b/rust/src/interaction.rs index 9994608f..fad207d1 100644 --- a/rust/src/interaction.rs +++ b/rust/src/interaction.rs @@ -21,7 +21,7 @@ use std::path::PathBuf; use crate::binary_view::BinaryView; use crate::rc::Ref; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub type MessageBoxButtonSet = BNMessageBoxButtonSet; pub type MessageBoxIcon = BNMessageBoxIcon; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 08abc349..8d8fae13 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -102,8 +102,8 @@ use std::cmp; use std::collections::HashMap; use std::ffi::{c_char, c_void, CStr}; use std::path::{Path, PathBuf}; -use string::AsCStr; use string::BnString; +use string::IntoCStr; use string::IntoJson; use crate::progress::{NoProgressCallback, ProgressCallback}; @@ -470,7 +470,7 @@ impl VersionInfo { unsafe { BnString::free_raw(value.channel) }; } - pub fn from_string<S: AsCStr>(string: S) -> Self { + pub fn from_string<S: IntoCStr>(string: S) -> Self { let string = string.to_cstr(); let result = unsafe { BNParseVersionString(string.as_ptr()) }; Self::from_owned_raw(result) @@ -529,13 +529,13 @@ pub fn license_count() -> i32 { /// 1. Check the BN_LICENSE environment variable /// 2. Check the Binary Ninja user directory for license.dat #[cfg(not(feature = "demo"))] -pub fn set_license<S: AsCStr + Default>(license: Option<S>) { +pub fn set_license<S: IntoCStr + Default>(license: Option<S>) { let license = license.unwrap_or_default().to_cstr(); unsafe { BNSetLicense(license.as_ptr()) } } #[cfg(feature = "demo")] -pub fn set_license<S: AsCStr + Default>(_license: Option<S>) {} +pub fn set_license<S: IntoCStr + Default>(_license: Option<S>) {} pub fn product() -> String { unsafe { BnString::into_string(BNGetProduct()) } @@ -554,7 +554,7 @@ pub fn is_ui_enabled() -> bool { unsafe { BNIsUIEnabled() } } -pub fn is_database<S: AsCStr>(filename: S) -> bool { +pub fn is_database<S: IntoCStr>(filename: S) -> bool { let filename = filename.to_cstr(); unsafe { BNIsDatabase(filename.as_ptr()) } } @@ -583,12 +583,12 @@ pub fn plugin_ui_abi_minimum_version() -> u32 { BN_MINIMUM_UI_ABI_VERSION } -pub fn add_required_plugin_dependency<S: AsCStr>(name: S) { +pub fn add_required_plugin_dependency<S: IntoCStr>(name: S) { let raw_name = name.to_cstr(); unsafe { BNAddRequiredPluginDependency(raw_name.as_ptr()) }; } -pub fn add_optional_plugin_dependency<S: AsCStr>(name: S) { +pub fn add_optional_plugin_dependency<S: IntoCStr>(name: S) { let raw_name = name.to_cstr(); unsafe { BNAddOptionalPluginDependency(raw_name.as_ptr()) }; } diff --git a/rust/src/logger.rs b/rust/src/logger.rs index 5f14af69..ad6bd9d1 100644 --- a/rust/src/logger.rs +++ b/rust/src/logger.rs @@ -35,7 +35,7 @@ use binaryninjacore_sys::{ }; use crate::rc::{Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use log; use log::LevelFilter; use std::ffi::{CStr, CString}; diff --git a/rust/src/medium_level_il/function.rs b/rust/src/medium_level_il/function.rs index 75ccad82..0b88c166 100644 --- a/rust/src/medium_level_il/function.rs +++ b/rust/src/medium_level_il/function.rs @@ -10,7 +10,7 @@ use crate::disassembly::DisassemblySettings; use crate::flowgraph::FlowGraph; use crate::function::{Function, Location}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref, RefCountable}; -use crate::string::AsCStr; +use crate::string::IntoCStr; use crate::types::Type; use crate::variable::{PossibleValueSet, RegisterValue, SSAVariable, UserVariableValue, Variable}; @@ -121,7 +121,7 @@ impl MediumLevelILFunction { unsafe { Array::new(raw_instr_idxs, count, self.to_owned()) } } - pub fn create_user_stack_var<'a, S: AsCStr, C: Into<Conf<&'a Type>>>( + pub fn create_user_stack_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>( self, offset: i64, var_type: C, @@ -143,7 +143,7 @@ impl MediumLevelILFunction { unsafe { BNDeleteUserStackVariable(self.function().handle, offset) } } - pub fn create_user_var<'a, S: AsCStr, C: Into<Conf<&'a Type>>>( + pub fn create_user_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>( &self, var: &Variable, var_type: C, @@ -273,7 +273,7 @@ impl MediumLevelILFunction { Ok(()) } - pub fn create_auto_stack_var<'a, T: Into<Conf<&'a Type>>, S: AsCStr>( + pub fn create_auto_stack_var<'a, T: Into<Conf<&'a Type>>, S: IntoCStr>( &self, offset: i64, var_type: T, @@ -295,7 +295,7 @@ impl MediumLevelILFunction { unsafe { BNDeleteAutoStackVariable(self.function().handle, offset) } } - pub fn create_auto_var<'a, S: AsCStr, C: Into<Conf<&'a Type>>>( + pub fn create_auto_var<'a, S: IntoCStr, C: Into<Conf<&'a Type>>>( &self, var: &Variable, var_type: C, diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs index b6b3ce61..2ccd9d52 100644 --- a/rust/src/metadata.rs +++ b/rust/src/metadata.rs @@ -1,5 +1,5 @@ use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString, IntoJson}; +use crate::string::{BnString, IntoCStr, IntoJson}; use binaryninjacore_sys::*; use std::collections::HashMap; use std::os::raw::c_char; @@ -267,7 +267,7 @@ impl Metadata { Ok(Some(unsafe { Self::ref_from_raw(ptr) })) } - pub fn get<S: AsCStr>(&self, key: S) -> Result<Option<Ref<Metadata>>, ()> { + pub fn get<S: IntoCStr>(&self, key: S) -> Result<Option<Ref<Metadata>>, ()> { if self.get_type() != MetadataType::KeyValueDataType { return Err(()); } @@ -287,7 +287,7 @@ impl Metadata { Ok(()) } - pub fn insert<S: AsCStr>(&self, key: S, value: &Metadata) -> Result<(), ()> { + pub fn insert<S: IntoCStr>(&self, key: S, value: &Metadata) -> Result<(), ()> { if self.get_type() != MetadataType::KeyValueDataType { return Err(()); } @@ -305,7 +305,7 @@ impl Metadata { Ok(()) } - pub fn remove_key<S: AsCStr>(&self, key: S) -> Result<(), ()> { + pub fn remove_key<S: IntoCStr>(&self, key: S) -> Result<(), ()> { if self.get_type() != MetadataType::KeyValueDataType { return Err(()); } @@ -424,7 +424,7 @@ impl From<&Array<Metadata>> for Ref<Metadata> { } } -impl<S: AsCStr> From<HashMap<S, Ref<Metadata>>> for Ref<Metadata> { +impl<S: IntoCStr> From<HashMap<S, Ref<Metadata>>> for Ref<Metadata> { fn from(value: HashMap<S, Ref<Metadata>>) -> Self { let data: Vec<(S::Result, Ref<Metadata>)> = value.into_iter().map(|(k, v)| (k.to_cstr(), v)).collect(); @@ -443,7 +443,7 @@ impl<S: AsCStr> From<HashMap<S, Ref<Metadata>>> for Ref<Metadata> { impl<S, T> From<&[(S, T)]> for Ref<Metadata> where - S: AsCStr + Copy, + S: IntoCStr + Copy, for<'a> &'a T: Into<Ref<Metadata>>, { fn from(value: &[(S, T)]) -> Self { @@ -464,7 +464,7 @@ where impl<S, T, const N: usize> From<[(S, T); N]> for Ref<Metadata> where - S: AsCStr + Copy, + S: IntoCStr + Copy, for<'a> &'a T: Into<Ref<Metadata>>, { fn from(value: [(S, T); N]) -> Self { @@ -518,7 +518,7 @@ impl From<&Vec<f64>> for Ref<Metadata> { } } -impl<S: AsCStr> From<Vec<S>> for Ref<Metadata> { +impl<S: IntoCStr> From<Vec<S>> for Ref<Metadata> { fn from(value: Vec<S>) -> Self { let mut refs = vec![]; for v in value { diff --git a/rust/src/platform.rs b/rust/src/platform.rs index b51ad61d..d7d3b990 100644 --- a/rust/src/platform.rs +++ b/rust/src/platform.rs @@ -82,7 +82,7 @@ impl Platform { Ref::new(Self { handle }) } - pub fn by_name<S: AsCStr>(name: S) -> Option<Ref<Self>> { + pub fn by_name<S: IntoCStr>(name: S) -> Option<Ref<Self>> { let raw_name = name.to_cstr(); unsafe { let res = BNGetPlatformByName(raw_name.as_ptr()); @@ -113,7 +113,7 @@ impl Platform { } } - pub fn list_by_os<S: AsCStr>(name: S) -> Array<Platform> { + pub fn list_by_os<S: IntoCStr>(name: S) -> Array<Platform> { let raw_name = name.to_cstr(); unsafe { @@ -124,7 +124,7 @@ impl Platform { } } - pub fn list_by_os_and_arch<S: AsCStr>(name: S, arch: &CoreArchitecture) -> Array<Platform> { + pub fn list_by_os_and_arch<S: IntoCStr>(name: S, arch: &CoreArchitecture) -> Array<Platform> { let raw_name = name.to_cstr(); unsafe { @@ -145,7 +145,7 @@ impl Platform { } } - pub fn new<A: Architecture, S: AsCStr>(arch: &A, name: S) -> Ref<Self> { + pub fn new<A: Architecture, S: IntoCStr>(arch: &A, name: S) -> Ref<Self> { let name = name.to_cstr(); unsafe { let handle = BNCreatePlatform(arch.as_ref().handle, name.as_ptr()); @@ -173,7 +173,7 @@ impl Platform { unsafe { TypeContainer::from_raw(type_container_ptr.unwrap()) } } - pub fn get_type_libraries_by_name<T: AsCStr>(&self, name: T) -> Array<TypeLibrary> { + pub fn get_type_libraries_by_name<T: IntoCStr>(&self, name: T) -> Array<TypeLibrary> { let mut count = 0; let name = name.to_cstr(); let result = @@ -182,7 +182,7 @@ impl Platform { unsafe { Array::new(result, count, ()) } } - pub fn register_os<S: AsCStr>(&self, os: S) { + pub fn register_os<S: IntoCStr>(&self, os: S) { let os = os.to_cstr(); unsafe { diff --git a/rust/src/project.rs b/rust/src/project.rs index 351b6e3f..7b6a263e 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -13,7 +13,7 @@ use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::file::ProjectFile; use crate::project::folder::ProjectFolder; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub struct Project { pub(crate) handle: NonNull<BNProject>, @@ -39,7 +39,7 @@ impl Project { /// /// * `path` - Path to the project directory (.bnpr) /// * `name` - Name of the new project - pub fn create<P: AsCStr, S: AsCStr>(path: P, name: S) -> Option<Ref<Self>> { + pub fn create<P: IntoCStr, S: IntoCStr>(path: P, name: S) -> Option<Ref<Self>> { let path_raw = path.to_cstr(); let name_raw = name.to_cstr(); let handle = unsafe { BNCreateProject(path_raw.as_ptr(), name_raw.as_ptr()) }; @@ -49,7 +49,7 @@ impl Project { /// Open an existing project /// /// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm) - pub fn open_project<P: AsCStr>(path: P) -> Option<Ref<Self>> { + pub fn open_project<P: IntoCStr>(path: P) -> Option<Ref<Self>> { let path_raw = path.to_cstr(); let handle = unsafe { BNOpenProject(path_raw.as_ptr()) }; NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) }) @@ -94,7 +94,7 @@ impl Project { } /// Set the name of the project - pub fn set_name<S: AsCStr>(&self, value: S) { + pub fn set_name<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNProjectSetName(self.handle.as_ptr(), value.as_ptr()) } } @@ -105,13 +105,13 @@ impl Project { } /// Set the description of the project - pub fn set_description<S: AsCStr>(&self, value: S) { + pub fn set_description<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNProjectSetDescription(self.handle.as_ptr(), value.as_ptr()) } } /// Retrieves metadata stored under a key from the project - pub fn query_metadata<S: AsCStr>(&self, key: S) -> Ref<Metadata> { + pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Ref<Metadata> { let key = key.to_cstr(); let result = unsafe { BNProjectQueryMetadata(self.handle.as_ptr(), key.as_ptr()) }; unsafe { Metadata::ref_from_raw(result) } @@ -121,13 +121,13 @@ impl Project { /// /// * `key` - Key under which to store the Metadata object /// * `value` - Object to store - pub fn store_metadata<S: AsCStr>(&self, key: S, value: &Metadata) -> bool { + pub fn store_metadata<S: IntoCStr>(&self, key: S, value: &Metadata) -> bool { let key_raw = key.to_cstr(); unsafe { BNProjectStoreMetadata(self.handle.as_ptr(), key_raw.as_ptr(), value.handle) } } /// Removes the metadata associated with this `key` from the project - pub fn remove_metadata<S: AsCStr>(&self, key: S) { + pub fn remove_metadata<S: IntoCStr>(&self, key: S) { let key_raw = key.to_cstr(); unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) } } @@ -148,8 +148,8 @@ impl Project { description: D, ) -> Result<Ref<ProjectFolder>, ()> where - P: AsCStr, - D: AsCStr, + P: IntoCStr, + D: IntoCStr, { self.create_folder_from_path_with_progress(path, parent, description, NoProgressCallback) } @@ -168,8 +168,8 @@ impl Project { mut progress: PC, ) -> Result<Ref<ProjectFolder>, ()> where - P: AsCStr, - D: AsCStr, + P: IntoCStr, + D: IntoCStr, PC: ProgressCallback, { let path_raw = path.to_cstr(); @@ -201,8 +201,8 @@ impl Project { description: D, ) -> Result<Ref<ProjectFolder>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, { let name_raw = name.to_cstr(); let description_raw = description.to_cstr(); @@ -232,9 +232,9 @@ impl Project { id: I, ) -> Result<Ref<ProjectFolder>, ()> where - N: AsCStr, - D: AsCStr, - I: AsCStr, + N: IntoCStr, + D: IntoCStr, + I: IntoCStr, { let name_raw = name.to_cstr(); let description_raw = description.to_cstr(); @@ -264,7 +264,7 @@ impl Project { } /// Retrieve a folder in the project by unique folder `id` - pub fn folder_by_id<S: AsCStr>(&self, id: S) -> Option<Ref<ProjectFolder>> { + pub fn folder_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<ProjectFolder>> { let raw_id = id.to_cstr(); let result = unsafe { BNProjectGetFolderById(self.handle.as_ptr(), raw_id.as_ptr()) }; let handle = NonNull::new(result)?; @@ -321,9 +321,9 @@ impl Project { description: D, ) -> Result<Ref<ProjectFile>, ()> where - P: AsCStr, - N: AsCStr, - D: AsCStr, + P: IntoCStr, + N: IntoCStr, + D: IntoCStr, { self.create_file_from_path_with_progress( path, @@ -350,9 +350,9 @@ impl Project { mut progress: PC, ) -> Result<Ref<ProjectFile>, ()> where - P: AsCStr, - N: AsCStr, - D: AsCStr, + P: IntoCStr, + N: IntoCStr, + D: IntoCStr, PC: ProgressCallback, { let path_raw = path.to_cstr(); @@ -392,10 +392,10 @@ impl Project { creation_time: SystemTime, ) -> Result<Ref<ProjectFile>, ()> where - P: AsCStr, - N: AsCStr, - D: AsCStr, - I: AsCStr, + P: IntoCStr, + N: IntoCStr, + D: IntoCStr, + I: IntoCStr, { self.create_file_from_path_unsafe_with_progress( path, @@ -429,10 +429,10 @@ impl Project { mut progress: PC, ) -> Result<Ref<ProjectFile>, ()> where - P: AsCStr, - N: AsCStr, - D: AsCStr, - I: AsCStr, + P: IntoCStr, + N: IntoCStr, + D: IntoCStr, + I: IntoCStr, PC: ProgressCallback, { let path_raw = path.to_cstr(); @@ -471,8 +471,8 @@ impl Project { description: D, ) -> Result<Ref<ProjectFile>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, { self.create_file_with_progress(contents, folder, name, description, NoProgressCallback) } @@ -493,8 +493,8 @@ impl Project { mut progress: P, ) -> Result<Ref<ProjectFile>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, P: ProgressCallback, { let name_raw = name.to_cstr(); @@ -534,9 +534,9 @@ impl Project { creation_time: SystemTime, ) -> Result<Ref<ProjectFile>, ()> where - N: AsCStr, - D: AsCStr, - I: AsCStr, + N: IntoCStr, + D: IntoCStr, + I: IntoCStr, { self.create_file_unsafe_with_progress( contents, @@ -570,9 +570,9 @@ impl Project { mut progress: P, ) -> Result<Ref<ProjectFile>, ()> where - N: AsCStr, - D: AsCStr, - I: AsCStr, + N: IntoCStr, + D: IntoCStr, + I: IntoCStr, P: ProgressCallback, { let name_raw = name.to_cstr(); @@ -606,7 +606,7 @@ impl Project { } /// Retrieve a file in the project by unique `id` - pub fn file_by_id<S: AsCStr>(&self, id: S) -> Option<Ref<ProjectFile>> { + pub fn file_by_id<S: IntoCStr>(&self, id: S) -> Option<Ref<ProjectFile>> { let raw_id = id.to_cstr(); let result = unsafe { BNProjectGetFileById(self.handle.as_ptr(), raw_id.as_ptr()) }; let handle = NonNull::new(result)?; @@ -614,7 +614,7 @@ impl Project { } /// Retrieve a file in the project by the `path` on disk - pub fn file_by_path<S: AsCStr>(&self, path: S) -> Option<Ref<ProjectFile>> { + pub fn file_by_path<S: IntoCStr>(&self, path: S) -> Option<Ref<ProjectFile>> { let path_raw = path.to_cstr(); let result = unsafe { BNProjectGetFileByPathOnDisk(self.handle.as_ptr(), path_raw.as_ptr()) }; diff --git a/rust/src/project/file.rs b/rust/src/project/file.rs index bc486ed9..4a1d6fec 100644 --- a/rust/src/project/file.rs +++ b/rust/src/project/file.rs @@ -1,6 +1,6 @@ use crate::project::{systime_from_bntime, Project, ProjectFolder}; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::{ BNFreeProjectFile, BNFreeProjectFileList, BNNewProjectFileReference, BNProjectFile, BNProjectFileExistsOnDisk, BNProjectFileExport, BNProjectFileGetCreationTimestamp, @@ -56,7 +56,7 @@ impl ProjectFile { } /// Set the name of this file - pub fn set_name<S: AsCStr>(&self, value: S) -> bool { + pub fn set_name<S: IntoCStr>(&self, value: S) -> bool { let value_raw = value.to_cstr(); unsafe { BNProjectFileSetName(self.handle.as_ptr(), value_raw.as_ptr()) } } @@ -67,7 +67,7 @@ impl ProjectFile { } /// Set the description of this file - pub fn set_description<S: AsCStr>(&self, value: S) -> bool { + pub fn set_description<S: IntoCStr>(&self, value: S) -> bool { let value_raw = value.to_cstr(); unsafe { BNProjectFileSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) } } @@ -93,7 +93,7 @@ impl ProjectFile { /// Export this file to disk, `true' if the export succeeded /// /// * `dest` - Destination path for the exported contents - pub fn export<S: AsCStr>(&self, dest: S) -> bool { + pub fn export<S: IntoCStr>(&self, dest: S) -> bool { let dest_raw = dest.to_cstr(); unsafe { BNProjectFileExport(self.handle.as_ptr(), dest_raw.as_ptr()) } } diff --git a/rust/src/project/folder.rs b/rust/src/project/folder.rs index c7ec82e4..acb663fb 100644 --- a/rust/src/project/folder.rs +++ b/rust/src/project/folder.rs @@ -1,7 +1,7 @@ use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::Project; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::{ BNFreeProjectFolder, BNFreeProjectFolderList, BNNewProjectFolderReference, BNProjectFolder, BNProjectFolderExport, BNProjectFolderGetDescription, BNProjectFolderGetId, @@ -46,7 +46,7 @@ impl ProjectFolder { } /// Set the name of this folder - pub fn set_name<S: AsCStr>(&self, value: S) -> bool { + pub fn set_name<S: IntoCStr>(&self, value: S) -> bool { let value_raw = value.to_cstr(); unsafe { BNProjectFolderSetName(self.handle.as_ptr(), value_raw.as_ptr()) } } @@ -57,7 +57,7 @@ impl ProjectFolder { } /// Set the description of this folder - pub fn set_description<S: AsCStr>(&self, value: S) -> bool { + pub fn set_description<S: IntoCStr>(&self, value: S) -> bool { let value_raw = value.to_cstr(); unsafe { BNProjectFolderSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) } } @@ -78,7 +78,7 @@ impl ProjectFolder { /// Recursively export this folder to disk, returns `true' if the export succeeded /// /// * `dest` - Destination path for the exported contents - pub fn export<S: AsCStr>(&self, dest: S) -> bool { + pub fn export<S: IntoCStr>(&self, dest: S) -> bool { self.export_with_progress(dest, NoProgressCallback) } @@ -89,7 +89,7 @@ impl ProjectFolder { /// * `progress` - [`ProgressCallback`] that will be called as contents are exporting pub fn export_with_progress<S, P>(&self, dest: S, mut progress: P) -> bool where - S: AsCStr, + S: IntoCStr, P: ProgressCallback, { let dest_raw = dest.to_cstr(); diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs index b794f698..756c76bf 100644 --- a/rust/src/relocation.rs +++ b/rust/src/relocation.rs @@ -1,6 +1,6 @@ use crate::low_level_il::RegularLowLevelILFunction; use crate::rc::Guard; -use crate::string::AsCStr; +use crate::string::IntoCStr; use crate::{ architecture::CoreArchitecture, binary_view::BinaryView, @@ -404,7 +404,7 @@ unsafe impl RefCountable for CoreRelocationHandler { pub(crate) fn register_relocation_handler<S, R, F>(arch: &CoreArchitecture, name: S, func: F) where - S: AsCStr, + S: IntoCStr, R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync + Sized, F: FnOnce(CustomRelocationHandlerHandle<R>, CoreRelocationHandler) -> R, { diff --git a/rust/src/render_layer.rs b/rust/src/render_layer.rs index 7d792491..3fd94a3a 100644 --- a/rust/src/render_layer.rs +++ b/rust/src/render_layer.rs @@ -6,7 +6,7 @@ use crate::flowgraph::FlowGraph; use crate::function::{Function, NativeBlock}; use crate::linear_view::{LinearDisassemblyLine, LinearDisassemblyLineType, LinearViewObject}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner}; -use crate::string::AsCStr; +use crate::string::IntoCStr; use binaryninjacore_sys::*; use std::ffi::c_void; use std::ptr::NonNull; @@ -61,7 +61,7 @@ impl Default for RenderLayerDefaultState { } /// Register a [`RenderLayer`] with the API. -pub fn register_render_layer<S: AsCStr, T: RenderLayer>( +pub fn register_render_layer<S: IntoCStr, T: RenderLayer>( name: S, render_layer: T, default_state: RenderLayerDefaultState, @@ -299,7 +299,7 @@ impl CoreRenderLayer { unsafe { Array::new(result, count, ()) } } - pub fn render_layer_by_name<S: AsCStr>(name: S) -> Option<CoreRenderLayer> { + pub fn render_layer_by_name<S: IntoCStr>(name: S) -> Option<CoreRenderLayer> { let name_raw = name.to_cstr(); let result = unsafe { BNGetRenderLayerByName(name_raw.as_ptr()) }; NonNull::new(result).map(Self::from_raw) diff --git a/rust/src/repository.rs b/rust/src/repository.rs index 27825b96..8d9a8f40 100644 --- a/rust/src/repository.rs +++ b/rust/src/repository.rs @@ -9,7 +9,7 @@ use binaryninjacore_sys::*; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::repository::plugin::RepositoryPlugin; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub use manager::RepositoryManager; @@ -52,7 +52,7 @@ impl Repository { unsafe { Array::new(result, count, ()) } } - pub fn plugin_by_path<S: AsCStr>(&self, path: S) -> Option<Ref<RepositoryPlugin>> { + pub fn plugin_by_path<S: IntoCStr>(&self, path: S) -> Option<Ref<RepositoryPlugin>> { let path = path.to_cstr(); let result = unsafe { BNRepositoryGetPluginByPath(self.handle.as_ptr(), path.as_ptr()) }; NonNull::new(result).map(|h| unsafe { RepositoryPlugin::ref_from_raw(h) }) diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs index 29c73605..42d8aa42 100644 --- a/rust/src/repository/manager.rs +++ b/rust/src/repository/manager.rs @@ -1,6 +1,6 @@ use crate::rc::{Array, Ref, RefCountable}; use crate::repository::Repository; -use crate::string::AsCStr; +use crate::string::IntoCStr; use binaryninjacore_sys::{ BNCreateRepositoryManager, BNFreeRepositoryManager, BNGetRepositoryManager, BNNewRepositoryManagerReference, BNRepositoryGetRepositoryByPath, BNRepositoryManager, @@ -28,7 +28,7 @@ impl RepositoryManager { Ref::new(Self { handle }) } - pub fn new<S: AsCStr>(plugins_path: S) -> Ref<Self> { + pub fn new<S: IntoCStr>(plugins_path: S) -> 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 +59,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: AsCStr, P: AsCStr>(&self, url: U, repository_path: P) -> bool { + pub fn add_repository<U: IntoCStr, P: IntoCStr>(&self, url: U, repository_path: P) -> bool { let url = url.to_cstr(); let repo_path = repository_path.to_cstr(); unsafe { @@ -67,7 +67,7 @@ impl RepositoryManager { } } - pub fn repository_by_path<P: AsCStr>(&self, path: P) -> Option<Repository> { + pub fn repository_by_path<P: IntoCStr>(&self, path: P) -> Option<Repository> { let path = path.to_cstr(); let result = unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) }; diff --git a/rust/src/secrets_provider.rs b/rust/src/secrets_provider.rs index fcb20644..5924b9fb 100644 --- a/rust/src/secrets_provider.rs +++ b/rust/src/secrets_provider.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use std::ptr::NonNull; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub trait SecretsProvider { fn has_data(&mut self, key: &str) -> bool; @@ -49,7 +49,7 @@ impl CoreSecretsProvider { } /// Retrieve a provider by name - pub fn by_name<S: AsCStr>(name: S) -> Option<CoreSecretsProvider> { + pub fn by_name<S: IntoCStr>(name: S) -> Option<CoreSecretsProvider> { let name = name.to_cstr(); let result = unsafe { BNGetSecretsProviderByName(name.as_ptr()) }; NonNull::new(result).map(|h| unsafe { Self::from_raw(h) }) @@ -62,27 +62,27 @@ impl CoreSecretsProvider { } /// Check if data for a specific key exists, but do not retrieve it - pub fn has_data<S: AsCStr>(&self, key: S) -> bool { + pub fn has_data<S: IntoCStr>(&self, key: S) -> bool { let key = key.to_cstr(); unsafe { BNSecretsProviderHasData(self.handle.as_ptr(), key.as_ptr()) } } /// Retrieve data for the given key, if it exists - pub fn get_data<S: AsCStr>(&self, key: S) -> String { + pub fn get_data<S: IntoCStr>(&self, key: S) -> String { let key = key.to_cstr(); let result = unsafe { BNGetSecretsProviderData(self.handle.as_ptr(), key.as_ptr()) }; unsafe { BnString::into_string(result) } } /// Store data with the given key - pub fn store_data<K: AsCStr, V: AsCStr>(&self, key: K, value: V) -> bool { + pub fn store_data<K: IntoCStr, V: IntoCStr>(&self, key: K, value: V) -> bool { let key = key.to_cstr(); let value = value.to_cstr(); unsafe { BNStoreSecretsProviderData(self.handle.as_ptr(), key.as_ptr(), value.as_ptr()) } } /// Delete stored data with the given key - pub fn delete_data<S: AsCStr>(&self, key: S) -> bool { + pub fn delete_data<S: IntoCStr>(&self, key: S) -> bool { let key = key.to_cstr(); unsafe { BNDeleteSecretsProviderData(self.handle.as_ptr(), key.as_ptr()) } } diff --git a/rust/src/settings.rs b/rust/src/settings.rs index be2fd955..35f7b7a0 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -20,7 +20,7 @@ use std::fmt::Debug; use crate::binary_view::BinaryView; use crate::rc::*; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::function::Function; @@ -44,7 +44,7 @@ impl Settings { Self::new_with_id(GLOBAL_INSTANCE_ID) } - pub fn new_with_id<S: AsCStr>(instance_id: S) -> Ref<Self> { + pub fn new_with_id<S: IntoCStr>(instance_id: S) -> Ref<Self> { let instance_id = instance_id.to_cstr(); unsafe { let handle = BNCreateSettings(instance_id.as_ptr()); @@ -53,7 +53,7 @@ impl Settings { } } - pub fn set_resource_id<S: AsCStr>(&self, resource_id: S) { + pub fn set_resource_id<S: IntoCStr>(&self, resource_id: S) { let resource_id = resource_id.to_cstr(); unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ptr()) }; } @@ -62,11 +62,11 @@ impl Settings { unsafe { BnString::into_string(BNSettingsSerializeSchema(self.handle)) } } - pub fn deserialize_schema<S: AsCStr>(&self, schema: S) -> bool { + pub fn deserialize_schema<S: IntoCStr>(&self, schema: S) -> bool { self.deserialize_schema_with_scope(schema, SettingsScope::SettingsAutoScope) } - pub fn deserialize_schema_with_scope<S: AsCStr>( + pub fn deserialize_schema_with_scope<S: IntoCStr>( &self, schema: S, scope: SettingsScope, @@ -75,7 +75,7 @@ impl Settings { unsafe { BNSettingsDeserializeSchema(self.handle, schema.as_ptr(), scope, true) } } - pub fn contains<S: AsCStr>(&self, key: S) -> bool { + pub fn contains<S: IntoCStr>(&self, key: S) -> bool { let key = key.to_cstr(); unsafe { BNSettingsContains(self.handle, key.as_ptr()) } @@ -90,11 +90,11 @@ impl Settings { // TODO Update the settings API to take an optional BinaryView or Function. Separate functions or...? - pub fn get_bool<S: AsCStr>(&self, key: S) -> bool { + pub fn get_bool<S: IntoCStr>(&self, key: S) -> bool { self.get_bool_with_opts(key, &mut QueryOptions::default()) } - pub fn get_bool_with_opts<S: AsCStr>(&self, key: S, options: &mut QueryOptions) -> bool { + pub fn get_bool_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> bool { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -115,11 +115,11 @@ impl Settings { } } - pub fn get_double<S: AsCStr>(&self, key: S) -> f64 { + pub fn get_double<S: IntoCStr>(&self, key: S) -> f64 { self.get_double_with_opts(key, &mut QueryOptions::default()) } - pub fn get_double_with_opts<S: AsCStr>(&self, key: S, options: &mut QueryOptions) -> f64 { + pub fn get_double_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> f64 { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -140,11 +140,11 @@ impl Settings { } } - pub fn get_integer<S: AsCStr>(&self, key: S) -> u64 { + pub fn get_integer<S: IntoCStr>(&self, key: S) -> u64 { self.get_integer_with_opts(key, &mut QueryOptions::default()) } - pub fn get_integer_with_opts<S: AsCStr>(&self, key: S, options: &mut QueryOptions) -> u64 { + pub fn get_integer_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> u64 { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -165,11 +165,11 @@ impl Settings { } } - pub fn get_string<S: AsCStr>(&self, key: S) -> String { + pub fn get_string<S: IntoCStr>(&self, key: S) -> String { self.get_string_with_opts(key, &mut QueryOptions::default()) } - pub fn get_string_with_opts<S: AsCStr>(&self, key: S, options: &mut QueryOptions) -> String { + pub fn get_string_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> String { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -190,11 +190,11 @@ impl Settings { } } - pub fn get_string_list<S: AsCStr>(&self, key: S) -> Array<BnString> { + pub fn get_string_list<S: IntoCStr>(&self, key: S) -> Array<BnString> { self.get_string_list_with_opts(key, &mut QueryOptions::default()) } - pub fn get_string_list_with_opts<S: AsCStr>( + pub fn get_string_list_with_opts<S: IntoCStr>( &self, key: S, options: &mut QueryOptions, @@ -225,11 +225,11 @@ impl Settings { } } - pub fn get_json<S: AsCStr>(&self, key: S) -> String { + pub fn get_json<S: IntoCStr>(&self, key: S) -> String { self.get_json_with_opts(key, &mut QueryOptions::default()) } - pub fn get_json_with_opts<S: AsCStr>(&self, key: S, options: &mut QueryOptions) -> String { + pub fn get_json_with_opts<S: IntoCStr>(&self, key: S, options: &mut QueryOptions) -> String { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -250,11 +250,11 @@ impl Settings { } } - pub fn set_bool<S: AsCStr>(&self, key: S, value: bool) { + pub fn set_bool<S: IntoCStr>(&self, key: S, value: bool) { self.set_bool_with_opts(key, value, &QueryOptions::default()) } - pub fn set_bool_with_opts<S: AsCStr>(&self, key: S, value: bool, options: &QueryOptions) { + pub fn set_bool_with_opts<S: IntoCStr>(&self, key: S, value: bool, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -276,10 +276,10 @@ impl Settings { } } - pub fn set_double<S: AsCStr>(&self, key: S, value: f64) { + pub fn set_double<S: IntoCStr>(&self, key: S, value: f64) { self.set_double_with_opts(key, value, &QueryOptions::default()) } - pub fn set_double_with_opts<S: AsCStr>(&self, key: S, value: f64, options: &QueryOptions) { + pub fn set_double_with_opts<S: IntoCStr>(&self, key: S, value: f64, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -301,11 +301,11 @@ impl Settings { } } - pub fn set_integer<S: AsCStr>(&self, key: S, value: u64) { + pub fn set_integer<S: IntoCStr>(&self, key: S, value: u64) { self.set_integer_with_opts(key, value, &QueryOptions::default()) } - pub fn set_integer_with_opts<S: AsCStr>(&self, key: S, value: u64, options: &QueryOptions) { + pub fn set_integer_with_opts<S: IntoCStr>(&self, key: S, value: u64, options: &QueryOptions) { let key = key.to_cstr(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -327,11 +327,11 @@ impl Settings { } } - pub fn set_string<S1: AsCStr, S2: AsCStr>(&self, key: S1, value: S2) { + pub fn set_string<S1: IntoCStr, S2: IntoCStr>(&self, key: S1, value: S2) { self.set_string_with_opts(key, value, &QueryOptions::default()) } - pub fn set_string_with_opts<S1: AsCStr, S2: AsCStr>( + pub fn set_string_with_opts<S1: IntoCStr, S2: IntoCStr>( &self, key: S1, value: S2, @@ -359,7 +359,7 @@ impl Settings { } } - pub fn set_string_list<S1: AsCStr, S2: AsCStr, I: Iterator<Item = S2>>( + pub fn set_string_list<S1: IntoCStr, S2: IntoCStr, I: Iterator<Item = S2>>( &self, key: S1, value: I, @@ -367,7 +367,7 @@ impl Settings { self.set_string_list_with_opts(key, value, &QueryOptions::default()) } - pub fn set_string_list_with_opts<S1: AsCStr, S2: AsCStr, I: Iterator<Item = S2>>( + pub fn set_string_list_with_opts<S1: IntoCStr, S2: IntoCStr, I: Iterator<Item = S2>>( &self, key: S1, value: I, @@ -398,11 +398,11 @@ impl Settings { } } - pub fn set_json<S1: AsCStr, S2: AsCStr>(&self, key: S1, value: S2) -> bool { + pub fn set_json<S1: IntoCStr, S2: IntoCStr>(&self, key: S1, value: S2) -> bool { self.set_json_with_opts(key, value, &QueryOptions::default()) } - pub fn set_json_with_opts<S1: AsCStr, S2: AsCStr>( + pub fn set_json_with_opts<S1: IntoCStr, S2: IntoCStr>( &self, key: S1, value: S2, @@ -430,7 +430,7 @@ impl Settings { } } - pub fn get_property_string<S: AsCStr>(&self, key: S, property: S) -> String { + pub fn get_property_string<S: IntoCStr>(&self, key: S, property: S) -> String { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -442,7 +442,7 @@ impl Settings { } } - pub fn get_property_string_list<S: AsCStr>(&self, key: S, property: S) -> Array<BnString> { + pub fn get_property_string_list<S: IntoCStr>(&self, key: S, property: S) -> Array<BnString> { let key = key.to_cstr(); let property = property.to_cstr(); let mut size: usize = 0; @@ -460,7 +460,7 @@ impl Settings { } } - pub fn update_bool_property<S: AsCStr>(&self, key: S, property: S, value: bool) { + pub fn update_bool_property<S: IntoCStr>(&self, key: S, property: S, value: bool) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -468,7 +468,7 @@ impl Settings { } } - pub fn update_integer_property<S: AsCStr>(&self, key: S, property: S, value: u64) { + pub fn update_integer_property<S: IntoCStr>(&self, key: S, property: S, value: u64) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -476,7 +476,7 @@ impl Settings { } } - pub fn update_double_property<S: AsCStr>(&self, key: S, property: S, value: f64) { + pub fn update_double_property<S: IntoCStr>(&self, key: S, property: S, value: f64) { let key = key.to_cstr(); let property = property.to_cstr(); unsafe { @@ -484,7 +484,7 @@ impl Settings { } } - pub fn update_string_property<S: AsCStr>(&self, key: S, property: S, value: S) { + pub fn update_string_property<S: IntoCStr>(&self, key: S, property: S, value: S) { let key = key.to_cstr(); let property = property.to_cstr(); let value = value.to_cstr(); @@ -498,7 +498,7 @@ impl Settings { } } - pub fn update_string_list_property<S: AsCStr, I: Iterator<Item = S>>( + pub fn update_string_list_property<S: IntoCStr, I: Iterator<Item = S>>( &self, key: S, property: S, @@ -520,14 +520,18 @@ impl Settings { } } - pub fn register_group<S1: AsCStr, S2: AsCStr>(&self, group: S1, title: S2) -> bool { + pub fn register_group<S1: IntoCStr, S2: IntoCStr>(&self, group: S1, title: S2) -> bool { let group = group.to_cstr(); let title = title.to_cstr(); unsafe { BNSettingsRegisterGroup(self.handle, group.as_ptr(), title.as_ptr()) } } - pub fn register_setting_json<S1: AsCStr, S2: AsCStr>(&self, group: S1, properties: S2) -> bool { + pub fn register_setting_json<S1: IntoCStr, S2: IntoCStr>( + &self, + group: S1, + properties: S2, + ) -> bool { let group = group.to_cstr(); let properties = properties.to_cstr(); diff --git a/rust/src/string.rs b/rust/src/string.rs index 820418d0..a670320b 100644 --- a/rust/src/string.rs +++ b/rust/src/string.rs @@ -62,7 +62,7 @@ pub struct BnString { } impl BnString { - pub fn new<S: AsCStr>(s: S) -> Self { + pub fn new<S: IntoCStr>(s: S) -> Self { use binaryninjacore_sys::BNAllocString; let raw = s.to_cstr(); unsafe { Self::from_raw(BNAllocString(raw.as_ptr())) } @@ -183,13 +183,13 @@ unsafe impl CoreArrayProviderInner for BnString { } } -pub unsafe trait AsCStr { +pub unsafe trait IntoCStr { type Result: Deref<Target = CStr>; fn to_cstr(self) -> Self::Result; } -unsafe impl AsCStr for &CStr { +unsafe impl IntoCStr for &CStr { type Result = Self; fn to_cstr(self) -> Self::Result { @@ -197,7 +197,7 @@ unsafe impl AsCStr for &CStr { } } -unsafe impl AsCStr for BnString { +unsafe impl IntoCStr for BnString { type Result = Self; fn to_cstr(self) -> Self::Result { @@ -205,7 +205,7 @@ unsafe impl AsCStr for BnString { } } -unsafe impl AsCStr for &BnString { +unsafe impl IntoCStr for &BnString { type Result = BnString; fn to_cstr(self) -> Self::Result { @@ -213,7 +213,7 @@ unsafe impl AsCStr for &BnString { } } -unsafe impl AsCStr for CString { +unsafe impl IntoCStr for CString { type Result = Self; fn to_cstr(self) -> Self::Result { @@ -221,7 +221,7 @@ unsafe impl AsCStr for CString { } } -unsafe impl AsCStr for &str { +unsafe impl IntoCStr for &str { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -229,7 +229,7 @@ unsafe impl AsCStr for &str { } } -unsafe impl AsCStr for String { +unsafe impl IntoCStr for String { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -237,7 +237,7 @@ unsafe impl AsCStr for String { } } -unsafe impl AsCStr for &String { +unsafe impl IntoCStr for &String { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -245,7 +245,7 @@ unsafe impl AsCStr for &String { } } -unsafe impl<'a> AsCStr for &'a Cow<'a, str> { +unsafe impl<'a> IntoCStr for &'a Cow<'a, str> { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -253,7 +253,7 @@ unsafe impl<'a> AsCStr for &'a Cow<'a, str> { } } -unsafe impl AsCStr for Cow<'_, str> { +unsafe impl IntoCStr for Cow<'_, str> { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -261,7 +261,7 @@ unsafe impl AsCStr for Cow<'_, str> { } } -unsafe impl AsCStr for &QualifiedName { +unsafe impl IntoCStr for &QualifiedName { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -269,7 +269,7 @@ unsafe impl AsCStr for &QualifiedName { } } -unsafe impl AsCStr for PathBuf { +unsafe impl IntoCStr for PathBuf { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -277,7 +277,7 @@ unsafe impl AsCStr for PathBuf { } } -unsafe impl AsCStr for &Path { +unsafe impl IntoCStr for &Path { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -286,7 +286,7 @@ unsafe impl AsCStr for &Path { } } -unsafe impl AsCStr for TypeArchiveSnapshotId { +unsafe impl IntoCStr for TypeArchiveSnapshotId { type Result = CString; fn to_cstr(self) -> Self::Result { @@ -295,12 +295,12 @@ unsafe impl AsCStr for TypeArchiveSnapshotId { } pub trait IntoJson { - type Output: AsCStr; + type Output: IntoCStr; fn get_json_string(self) -> Result<Self::Output, ()>; } -impl<S: AsCStr> IntoJson for S { +impl<S: IntoCStr> IntoJson for S { type Output = S; fn get_json_string(self) -> Result<Self::Output, ()> { diff --git a/rust/src/tags.rs b/rust/src/tags.rs index 72cae705..e7a2d44d 100644 --- a/rust/src/tags.rs +++ b/rust/src/tags.rs @@ -42,7 +42,7 @@ impl Tag { Ref::new(Self { handle }) } - pub fn new<S: AsCStr>(t: &TagType, data: S) -> Ref<Self> { + pub fn new<S: IntoCStr>(t: &TagType, data: S) -> Ref<Self> { let data = data.to_cstr(); unsafe { Self::ref_from_raw(BNCreateTag(t.handle, data.as_ptr())) } } @@ -59,7 +59,7 @@ impl Tag { unsafe { TagType::ref_from_raw(BNTagGetType(self.handle)) } } - pub fn set_data<S: AsCStr>(&self, data: S) { + pub fn set_data<S: IntoCStr>(&self, data: S) { let data = data.to_cstr(); unsafe { BNTagSetData(self.handle, data.as_ptr()); @@ -134,7 +134,7 @@ impl TagType { Ref::new(Self { handle }) } - pub fn create<N: AsCStr, I: AsCStr>(view: &BinaryView, name: N, icon: I) -> Ref<Self> { + pub fn create<N: IntoCStr, I: IntoCStr>(view: &BinaryView, name: N, icon: I) -> Ref<Self> { let tag_type = unsafe { Self::ref_from_raw(BNCreateTagType(view.handle)) }; tag_type.set_name(name); tag_type.set_icon(icon); @@ -149,7 +149,7 @@ impl TagType { unsafe { BnString::into_string(BNTagTypeGetIcon(self.handle)) } } - pub fn set_icon<S: AsCStr>(&self, icon: S) { + pub fn set_icon<S: IntoCStr>(&self, icon: S) { let icon = icon.to_cstr(); unsafe { BNTagTypeSetIcon(self.handle, icon.as_ptr()); @@ -160,7 +160,7 @@ impl TagType { unsafe { BnString::into_string(BNTagTypeGetName(self.handle)) } } - pub fn set_name<S: AsCStr>(&self, name: S) { + pub fn set_name<S: IntoCStr>(&self, name: S) { let name = name.to_cstr(); unsafe { BNTagTypeSetName(self.handle, name.as_ptr()); @@ -179,7 +179,7 @@ impl TagType { unsafe { BNTagTypeGetType(self.handle) } } - pub fn set_type<S: AsCStr>(&self, t: S) { + pub fn set_type<S: IntoCStr>(&self, t: S) { let t = t.to_cstr(); unsafe { BNTagTypeSetName(self.handle, t.as_ptr()); diff --git a/rust/src/template_simplifier.rs b/rust/src/template_simplifier.rs index c9e54e72..81f8deb4 100644 --- a/rust/src/template_simplifier.rs +++ b/rust/src/template_simplifier.rs @@ -1,15 +1,15 @@ use crate::{ - string::{AsCStr, BnString}, + string::{BnString, IntoCStr}, types::QualifiedName, }; use binaryninjacore_sys::{BNRustSimplifyStrToFQN, BNRustSimplifyStrToStr}; -pub fn simplify_str_to_str<S: AsCStr>(input: S) -> BnString { +pub fn simplify_str_to_str<S: IntoCStr>(input: S) -> BnString { let name = input.to_cstr(); unsafe { BnString::from_raw(BNRustSimplifyStrToStr(name.as_ptr())) } } -pub fn simplify_str_to_fqn<S: AsCStr>(input: S, simplify: bool) -> QualifiedName { +pub fn simplify_str_to_fqn<S: IntoCStr>(input: S, simplify: bool) -> QualifiedName { let name = input.to_cstr(); unsafe { QualifiedName::from_owned_raw(BNRustSimplifyStrToFQN(name.as_ptr(), simplify)) } } diff --git a/rust/src/type_archive.rs b/rust/src/type_archive.rs index 8d9dd670..84e9fdee 100644 --- a/rust/src/type_archive.rs +++ b/rust/src/type_archive.rs @@ -10,7 +10,7 @@ use crate::data_buffer::DataBuffer; use crate::metadata::Metadata; use crate::platform::Platform; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_container::TypeContainer; use crate::types::{QualifiedName, QualifiedNameAndType, QualifiedNameTypeAndId, Type}; @@ -82,7 +82,7 @@ impl TypeArchive { /// Create a Type Archive at the given path and id, returning None if it could not be created. /// /// If the file has already been created and is not a valid type archive this will return `None`. - pub fn create_with_id<I: AsCStr>( + pub fn create_with_id<I: IntoCStr>( path: impl AsRef<Path>, id: I, platform: &Platform, @@ -95,7 +95,7 @@ impl TypeArchive { } /// Get a reference to the Type Archive with the known id, if one exists. - pub fn lookup_by_id<S: AsCStr>(id: S) -> Option<Ref<TypeArchive>> { + pub fn lookup_by_id<S: IntoCStr>(id: S) -> Option<Ref<TypeArchive>> { let id = id.to_cstr(); let handle = unsafe { BNLookupTypeArchiveById(id.as_ptr()) }; NonNull::new(handle).map(|handle| unsafe { TypeArchive::ref_from_raw(handle) }) @@ -150,7 +150,7 @@ impl TypeArchive { } /// Get the ids of the parents to the given snapshot - pub fn get_snapshot_parent_ids<S: AsCStr>( + pub fn get_snapshot_parent_ids<S: IntoCStr>( &self, snapshot: &TypeArchiveSnapshotId, ) -> Option<Array<BnString>> { @@ -166,7 +166,7 @@ impl TypeArchive { } /// Get the ids of the children to the given snapshot - pub fn get_snapshot_child_ids<S: AsCStr>( + pub fn get_snapshot_child_ids<S: IntoCStr>( &self, snapshot: &TypeArchiveSnapshotId, ) -> Option<Array<BnString>> { @@ -229,7 +229,7 @@ impl TypeArchive { /// /// * `id` - Old id of type in archive /// * `new_name` - New type name - pub fn rename_type_by_id<S: AsCStr>(&self, id: S, new_name: QualifiedName) -> bool { + pub fn rename_type_by_id<S: IntoCStr>(&self, id: S, new_name: QualifiedName) -> bool { let id = id.to_cstr(); let raw_name = QualifiedName::into_raw(new_name); let result = @@ -248,7 +248,7 @@ impl TypeArchive { } /// Delete an existing type in the type archive. - pub fn delete_type_by_id<S: AsCStr>(&self, id: S) -> bool { + pub fn delete_type_by_id<S: IntoCStr>(&self, id: S) -> bool { let id = id.to_cstr(); unsafe { BNDeleteTypeArchiveType(self.handle.as_ptr(), id.as_ptr()) } } @@ -256,7 +256,7 @@ impl TypeArchive { /// Retrieve a stored type in the archive /// /// * `name` - Type name - pub fn get_type_by_name<S: AsCStr>(&self, name: QualifiedName) -> Option<Ref<Type>> { + pub fn get_type_by_name<S: IntoCStr>(&self, name: QualifiedName) -> Option<Ref<Type>> { self.get_type_by_name_from_snapshot(name, &TypeArchiveSnapshotId::unset()) } @@ -284,7 +284,7 @@ impl TypeArchive { /// Retrieve a stored type in the archive by id /// /// * `id` - Type id - pub fn get_type_by_id<I: AsCStr>(&self, id: I) -> Option<Ref<Type>> { + pub fn get_type_by_id<I: IntoCStr>(&self, id: I) -> Option<Ref<Type>> { self.get_type_by_id_from_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -292,7 +292,7 @@ impl TypeArchive { /// /// * `id` - Type id /// * `snapshot` - Snapshot id to search for types - pub fn get_type_by_id_from_snapshot<I: AsCStr>( + pub fn get_type_by_id_from_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -311,7 +311,7 @@ impl TypeArchive { /// Retrieve a type's name by its id /// /// * `id` - Type id - pub fn get_type_name_by_id<I: AsCStr>(&self, id: I) -> QualifiedName { + pub fn get_type_name_by_id<I: IntoCStr>(&self, id: I) -> QualifiedName { self.get_type_name_by_id_from_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -319,7 +319,7 @@ impl TypeArchive { /// /// * `id` - Type id /// * `snapshot` - Snapshot id to search for types - pub fn get_type_name_by_id_from_snapshot<I: AsCStr>( + pub fn get_type_name_by_id_from_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -465,7 +465,7 @@ impl TypeArchive { /// Get all types a given type references directly /// /// * `id` - Source type id - pub fn get_outgoing_direct_references<I: AsCStr>(&self, id: I) -> Array<BnString> { + pub fn get_outgoing_direct_references<I: IntoCStr>(&self, id: I) -> Array<BnString> { self.get_outgoing_direct_references_from_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -473,7 +473,7 @@ impl TypeArchive { /// /// * `id` - Source type id /// * `snapshot` - Snapshot id to search for types - pub fn get_outgoing_direct_references_from_snapshot<I: AsCStr>( + pub fn get_outgoing_direct_references_from_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -495,7 +495,7 @@ impl TypeArchive { /// Get all types a given type references, and any types that the referenced types reference /// /// * `id` - Source type id - pub fn get_outgoing_recursive_references<I: AsCStr>(&self, id: I) -> Array<BnString> { + pub fn get_outgoing_recursive_references<I: IntoCStr>(&self, id: I) -> Array<BnString> { self.get_outgoing_recursive_references_from_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -503,7 +503,7 @@ impl TypeArchive { /// /// * `id` - Source type id /// * `snapshot` - Snapshot id to search for types - pub fn get_outgoing_recursive_references_from_snapshot<I: AsCStr>( + pub fn get_outgoing_recursive_references_from_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -525,7 +525,7 @@ impl TypeArchive { /// Get all types that reference a given type /// /// * `id` - Target type id - pub fn get_incoming_direct_references<I: AsCStr>(&self, id: I) -> Array<BnString> { + pub fn get_incoming_direct_references<I: IntoCStr>(&self, id: I) -> Array<BnString> { self.get_incoming_direct_references_with_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -533,7 +533,7 @@ impl TypeArchive { /// /// * `id` - Target type id /// * `snapshot` - Snapshot id to search for types - pub fn get_incoming_direct_references_with_snapshot<I: AsCStr>( + pub fn get_incoming_direct_references_with_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -555,7 +555,7 @@ impl TypeArchive { /// Get all types that reference a given type, and all types that reference them, recursively /// /// * `id` - Target type id - pub fn get_incoming_recursive_references<I: AsCStr>(&self, id: I) -> Array<BnString> { + pub fn get_incoming_recursive_references<I: IntoCStr>(&self, id: I) -> Array<BnString> { self.get_incoming_recursive_references_with_snapshot(id, &TypeArchiveSnapshotId::unset()) } @@ -563,7 +563,7 @@ impl TypeArchive { /// /// * `id` - Target type id /// * `snapshot` - Snapshot id to search for types, or empty string to search the latest snapshot - pub fn get_incoming_recursive_references_with_snapshot<I: AsCStr>( + pub fn get_incoming_recursive_references_with_snapshot<I: IntoCStr>( &self, id: I, snapshot: &TypeArchiveSnapshotId, @@ -583,7 +583,7 @@ impl TypeArchive { } /// Look up a metadata entry in the archive - pub fn query_metadata<S: AsCStr>(&self, key: S) -> Option<Ref<Metadata>> { + pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Ref<Metadata>> { let key = key.to_cstr(); let result = unsafe { BNTypeArchiveQueryMetadata(self.handle.as_ptr(), key.as_ptr()) }; (!result.is_null()).then(|| unsafe { Metadata::ref_from_raw(result) }) @@ -593,7 +593,7 @@ impl TypeArchive { /// /// * `key` - key value to associate the Metadata object with /// * `md` - object to store. - pub fn store_metadata<S: AsCStr>(&self, key: S, md: &Metadata) { + pub fn store_metadata<S: IntoCStr>(&self, key: S, md: &Metadata) { let key = key.to_cstr(); let result = unsafe { BNTypeArchiveStoreMetadata(self.handle.as_ptr(), key.as_ptr(), md.handle) }; @@ -601,13 +601,13 @@ impl TypeArchive { } /// Delete a given metadata entry in the archive from the `key` - pub fn remove_metadata<S: AsCStr>(&self, key: S) -> bool { + pub fn remove_metadata<S: IntoCStr>(&self, key: S) -> bool { let key = key.to_cstr(); unsafe { BNTypeArchiveRemoveMetadata(self.handle.as_ptr(), key.as_ptr()) } } /// Turn a given `snapshot` id into a data stream - pub fn serialize_snapshot<S: AsCStr>(&self, snapshot: &TypeArchiveSnapshotId) -> DataBuffer { + pub fn serialize_snapshot<S: IntoCStr>(&self, snapshot: &TypeArchiveSnapshotId) -> DataBuffer { let result = unsafe { BNTypeArchiveSerializeSnapshot( self.handle.as_ptr(), @@ -680,7 +680,7 @@ impl TypeArchive { // TODO: Make this AsRef<Path>? /// Determine if `file` is a Type Archive - pub fn is_type_archive<P: AsCStr>(file: P) -> bool { + pub fn is_type_archive<P: IntoCStr>(file: P) -> bool { let file = file.to_cstr(); unsafe { BNIsTypeArchive(file.as_ptr()) } } @@ -705,7 +705,7 @@ impl TypeArchive { parents: &[TypeArchiveSnapshotId], ) -> TypeArchiveSnapshotId where - P: AsCStr, + P: IntoCStr, F: FnMut(&TypeArchiveSnapshotId) -> bool, { unsafe extern "C" fn cb_callback<F: FnMut(&TypeArchiveSnapshotId) -> bool>( @@ -752,12 +752,12 @@ impl TypeArchive { merge_conflicts: M, ) -> Result<BnString, Array<BnString>> where - B: AsCStr, - F: AsCStr, - S: AsCStr, + B: IntoCStr, + F: IntoCStr, + S: IntoCStr, M: IntoIterator<Item = (MI, MK)>, - MI: AsCStr, - MK: AsCStr, + MI: IntoCStr, + MK: IntoCStr, { self.merge_snapshots_with_progress( base_snapshot, @@ -787,12 +787,12 @@ impl TypeArchive { mut progress: P, ) -> Result<BnString, Array<BnString>> where - B: AsCStr, - F: AsCStr, - S: AsCStr, + B: IntoCStr, + F: IntoCStr, + S: IntoCStr, M: IntoIterator<Item = (MI, MK)>, - MI: AsCStr, - MK: AsCStr, + MI: IntoCStr, + MK: IntoCStr, P: ProgressCallback, { let base_snapshot = base_snapshot.to_cstr(); @@ -1141,7 +1141,7 @@ impl TypeArchiveMergeConflict { } // TODO: This needs documentation! - pub fn success<S: AsCStr>(&self, value: S) -> bool { + pub fn success<S: IntoCStr>(&self, value: S) -> bool { let value = value.to_cstr(); unsafe { BNTypeArchiveMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) } } diff --git a/rust/src/type_container.rs b/rust/src/type_container.rs index 90b2ebc9..2257a297 100644 --- a/rust/src/type_container.rs +++ b/rust/src/type_container.rs @@ -11,7 +11,7 @@ use crate::platform::Platform; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::rc::{Array, Ref}; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_parser::{TypeParserError, TypeParserResult}; use crate::types::{QualifiedName, QualifiedNameAndType, Type}; use binaryninjacore_sys::*; @@ -137,7 +137,7 @@ impl TypeContainer { /// (by id) to use the new name. /// /// Returns true if the type was renamed. - pub fn rename_type<T: Into<QualifiedName>, S: AsCStr>(&self, name: T, type_id: S) -> bool { + pub fn rename_type<T: Into<QualifiedName>, S: IntoCStr>(&self, name: T, type_id: S) -> bool { let type_id = type_id.to_cstr(); let raw_name = QualifiedName::into_raw(name.into()); let success = @@ -150,7 +150,7 @@ impl TypeContainer { /// not specified and you may end up with broken references if any still exist. /// /// Returns true if the type was deleted. - pub fn delete_type<S: AsCStr>(&self, type_id: S) -> bool { + pub fn delete_type<S: IntoCStr>(&self, type_id: S) -> bool { let type_id = type_id.to_cstr(); unsafe { BNTypeContainerDeleteType(self.handle.as_ptr(), type_id.as_ptr()) } } @@ -170,7 +170,7 @@ impl TypeContainer { /// Get the unique name of the type in the Type Container with the given id. /// /// If no type with that id exists, returns None. - pub fn type_name<S: AsCStr>(&self, type_id: S) -> Option<QualifiedName> { + pub fn type_name<S: IntoCStr>(&self, type_id: S) -> Option<QualifiedName> { let type_id = type_id.to_cstr(); let mut result = BNQualifiedName::default(); let success = unsafe { @@ -182,7 +182,7 @@ impl TypeContainer { /// Get the definition of the type in the Type Container with the given id. /// /// If no type with that id exists, returns None. - pub fn type_by_id<S: AsCStr>(&self, type_id: S) -> Option<Ref<Type>> { + pub fn type_by_id<S: IntoCStr>(&self, type_id: S) -> Option<Ref<Type>> { let type_id = type_id.to_cstr(); let mut result = std::ptr::null_mut(); let success = unsafe { @@ -283,7 +283,7 @@ impl TypeContainer { /// /// * `source` - Source code to parse /// * `import_dependencies` - If Type Library / Type Archive types should be imported during parsing - pub fn parse_type_string<S: AsCStr>( + pub fn parse_type_string<S: IntoCStr>( &self, source: S, import_dependencies: bool, @@ -329,13 +329,13 @@ impl TypeContainer { import_dependencies: bool, ) -> Result<TypeParserResult, Array<TypeParserError>> where - S: AsCStr, - F: AsCStr, + S: IntoCStr, + F: IntoCStr, O: IntoIterator, - O::Item: AsCStr, + O::Item: IntoCStr, D: IntoIterator, - D::Item: AsCStr, - A: AsCStr, + D::Item: IntoCStr, + A: IntoCStr, { let source = source.to_cstr(); let filename = filename.to_cstr(); diff --git a/rust/src/type_library.rs b/rust/src/type_library.rs index 91e86c61..29634c38 100644 --- a/rust/src/type_library.rs +++ b/rust/src/type_library.rs @@ -7,7 +7,7 @@ use crate::{ metadata::Metadata, platform::Platform, rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref}, - string::{AsCStr, BnString}, + string::{BnString, IntoCStr}, types::{QualifiedName, QualifiedNameAndType, Type}, }; @@ -42,7 +42,7 @@ impl TypeLibrary { } /// Creates an empty type library object with a random GUID and the provided name. - pub fn new<S: AsCStr>(arch: CoreArchitecture, name: S) -> TypeLibrary { + pub fn new<S: IntoCStr>(arch: CoreArchitecture, name: S) -> TypeLibrary { let name = name.to_cstr(); let new_lib = unsafe { BNNewTypeLibrary(arch.handle, name.as_ref().as_ptr() as *const ffi::c_char) }; @@ -57,7 +57,7 @@ impl TypeLibrary { } /// Decompresses a type library file to a file on disk. - pub fn decompress_to_file<P: AsCStr, O: AsCStr>(path: P, output: O) -> bool { + pub fn decompress_to_file<P: IntoCStr, O: IntoCStr>(path: P, output: O) -> bool { let path = path.to_cstr(); let output = output.to_cstr(); unsafe { @@ -69,7 +69,7 @@ impl TypeLibrary { } /// Loads a finalized type library instance from file - pub fn load_from_file<S: AsCStr>(path: S) -> Option<TypeLibrary> { + pub fn load_from_file<S: IntoCStr>(path: S) -> Option<TypeLibrary> { let path = path.to_cstr(); let handle = unsafe { BNLoadTypeLibraryFromFile(path.as_ref().as_ptr() as *const ffi::c_char) }; @@ -77,7 +77,7 @@ impl TypeLibrary { } /// Saves a finalized type library instance to file - pub fn write_to_file<S: AsCStr>(&self, path: S) -> bool { + pub fn write_to_file<S: IntoCStr>(&self, path: S) -> bool { let path = path.to_cstr(); unsafe { BNWriteTypeLibraryToFile(self.as_raw(), path.as_ref().as_ptr() as *const ffi::c_char) @@ -86,7 +86,7 @@ impl TypeLibrary { /// Looks up the first type library found with a matching name. Keep in mind that names are not /// necessarily unique. - pub fn from_name<S: AsCStr>(arch: CoreArchitecture, name: S) -> Option<TypeLibrary> { + pub fn from_name<S: IntoCStr>(arch: CoreArchitecture, name: S) -> Option<TypeLibrary> { let name = name.to_cstr(); let handle = unsafe { BNLookupTypeLibraryByName(arch.handle, name.as_ref().as_ptr() as *const ffi::c_char) @@ -95,7 +95,7 @@ impl TypeLibrary { } /// Attempts to grab a type library associated with the provided Architecture and GUID pair - pub fn from_guid<S: AsCStr>(arch: CoreArchitecture, guid: S) -> Option<TypeLibrary> { + pub fn from_guid<S: IntoCStr>(arch: CoreArchitecture, guid: S) -> Option<TypeLibrary> { let guid = guid.to_cstr(); let handle = unsafe { BNLookupTypeLibraryByGuid(arch.handle, guid.as_ref().as_ptr() as *const ffi::c_char) @@ -117,7 +117,7 @@ impl TypeLibrary { } /// Sets the name of a type library instance that has not been finalized - pub fn set_name<S: AsCStr>(&self, value: S) { + pub fn set_name<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNSetTypeLibraryName(self.as_raw(), value.as_ref().as_ptr() as *const ffi::c_char) @@ -135,7 +135,7 @@ impl TypeLibrary { } /// Sets the dependency name of a type library instance that has not been finalized - pub fn set_dependency_name<S: AsCStr>(&self, value: S) { + pub fn set_dependency_name<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNSetTypeLibraryDependencyName( @@ -152,7 +152,7 @@ impl TypeLibrary { } /// Sets the GUID of a type library instance that has not been finalized - pub fn set_guid<S: AsCStr>(&self, value: S) { + pub fn set_guid<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNSetTypeLibraryGuid(self.as_raw(), value.as_ref().as_ptr() as *const ffi::c_char) @@ -168,7 +168,7 @@ impl TypeLibrary { } /// Adds an extra name to this type library used during library lookups and dependency resolution - pub fn add_alternate_name<S: AsCStr>(&self, value: S) { + pub fn add_alternate_name<S: IntoCStr>(&self, value: S) { let value = value.to_cstr(); unsafe { BNAddTypeLibraryAlternateName( @@ -212,7 +212,7 @@ impl TypeLibrary { } /// Retrieves a metadata associated with the given key stored in the type library - pub fn query_metadata<S: AsCStr>(&self, key: S) -> Option<Metadata> { + pub fn query_metadata<S: IntoCStr>(&self, key: S) -> Option<Metadata> { let key = key.to_cstr(); let result = unsafe { BNTypeLibraryQueryMetadata(self.as_raw(), key.as_ref().as_ptr() as *const ffi::c_char) @@ -231,7 +231,7 @@ impl TypeLibrary { /// /// * `key` - key value to associate the Metadata object with /// * `md` - object to store. - pub fn store_metadata<S: AsCStr>(&self, key: S, md: &Metadata) { + pub fn store_metadata<S: IntoCStr>(&self, key: S, md: &Metadata) { let key = key.to_cstr(); unsafe { BNTypeLibraryStoreMetadata( @@ -243,7 +243,7 @@ impl TypeLibrary { } /// Removes the metadata associated with key from the current type library. - pub fn remove_metadata<S: AsCStr>(&self, key: S) { + pub fn remove_metadata<S: IntoCStr>(&self, key: S) { let key = key.to_cstr(); unsafe { BNTypeLibraryRemoveMetadata(self.as_raw(), key.as_ref().as_ptr() as *const ffi::c_char) @@ -299,7 +299,7 @@ impl TypeLibrary { /// Use this api with extreme caution. /// /// </div> - pub fn add_type_source<S: AsCStr>(&self, name: QualifiedName, source: S) { + pub fn add_type_source<S: IntoCStr>(&self, name: QualifiedName, source: S) { let source = source.to_cstr(); let mut raw_name = QualifiedName::into_raw(name); unsafe { diff --git a/rust/src/type_parser.rs b/rust/src/type_parser.rs index 53827e65..e2134b2b 100644 --- a/rust/src/type_parser.rs +++ b/rust/src/type_parser.rs @@ -6,7 +6,7 @@ use std::ptr::NonNull; use crate::platform::Platform; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref}; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_container::TypeContainer; use crate::types::{QualifiedName, QualifiedNameAndType, Type}; @@ -14,7 +14,7 @@ pub type TypeParserErrorSeverity = BNTypeParserErrorSeverity; pub type TypeParserOption = BNTypeParserOption; /// Register a custom parser with the API -pub fn register_type_parser<S: AsCStr, T: TypeParser>( +pub fn register_type_parser<S: IntoCStr, T: TypeParser>( name: S, parser: T, ) -> (&'static mut T, CoreTypeParser) { @@ -51,7 +51,7 @@ impl CoreTypeParser { unsafe { Array::new(result, count, ()) } } - pub fn parser_by_name<S: AsCStr>(name: S) -> Option<CoreTypeParser> { + pub fn parser_by_name<S: IntoCStr>(name: S) -> Option<CoreTypeParser> { let name_raw = name.to_cstr(); let result = unsafe { BNGetTypeParserByName(name_raw.as_ptr()) }; NonNull::new(result).map(|x| unsafe { Self::from_raw(x) }) diff --git a/rust/src/type_printer.rs b/rust/src/type_printer.rs index 278e486a..206478a2 100644 --- a/rust/src/type_printer.rs +++ b/rust/src/type_printer.rs @@ -4,7 +4,7 @@ use crate::binary_view::BinaryView; use crate::disassembly::InstructionTextToken; use crate::platform::Platform; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref}; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_container::TypeContainer; use crate::types::{NamedTypeReference, QualifiedName, QualifiedNameAndType, Type}; use binaryninjacore_sys::*; @@ -15,7 +15,7 @@ pub type TokenEscapingType = BNTokenEscapingType; pub type TypeDefinitionLineType = BNTypeDefinitionLineType; /// Register a custom parser with the API -pub fn register_type_printer<S: AsCStr, T: TypePrinter>( +pub fn register_type_printer<S: IntoCStr, T: TypePrinter>( name: S, parser: T, ) -> (&'static mut T, CoreTypePrinter) { @@ -57,7 +57,7 @@ impl CoreTypePrinter { unsafe { Array::new(result, count, ()) } } - pub fn printer_by_name<S: AsCStr>(name: S) -> Option<CoreTypePrinter> { + pub fn printer_by_name<S: IntoCStr>(name: S) -> Option<CoreTypePrinter> { let name_raw = name.to_cstr(); let result = unsafe { BNGetTypePrinterByName(name_raw.as_ptr()) }; NonNull::new(result).map(|x| unsafe { Self::from_raw(x) }) diff --git a/rust/src/types.rs b/rust/src/types.rs index 42c1f8d2..33972965 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -24,7 +24,7 @@ use crate::{ binary_view::{BinaryView, BinaryViewExt}, calling_convention::CoreCallingConvention, rc::*, - string::{AsCStr, BnString}, + string::{BnString, IntoCStr}, }; use crate::confidence::{Conf, MAX_CONFIDENCE, MIN_CONFIDENCE}; @@ -258,7 +258,7 @@ impl TypeBuilder { } } - pub fn named_int<S: AsCStr>(width: usize, is_signed: bool, alt_name: S) -> Self { + pub fn named_int<S: IntoCStr>(width: usize, is_signed: bool, alt_name: S) -> Self { let mut is_signed = Conf::new(is_signed, MAX_CONFIDENCE).into(); // let alt_name = BnString::new(alt_name); let alt_name = alt_name.to_cstr(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data @@ -281,7 +281,7 @@ impl TypeBuilder { } } - pub fn named_float<S: AsCStr>(width: usize, alt_name: S) -> Self { + pub fn named_float<S: IntoCStr>(width: usize, alt_name: S) -> Self { // let alt_name = BnString::new(alt_name); let alt_name = alt_name.to_cstr(); // See same line in `named_int` above @@ -649,7 +649,7 @@ impl Type { } } - pub fn named_int<S: AsCStr>(width: usize, is_signed: bool, alt_name: S) -> Ref<Self> { + pub fn named_int<S: IntoCStr>(width: usize, is_signed: bool, alt_name: S) -> Ref<Self> { let mut is_signed = Conf::new(is_signed, MAX_CONFIDENCE).into(); // let alt_name = BnString::new(alt_name); let alt_name = alt_name.to_cstr(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data @@ -672,7 +672,7 @@ impl Type { } } - pub fn named_float<S: AsCStr>(width: usize, alt_name: S) -> Ref<Self> { + pub fn named_float<S: IntoCStr>(width: usize, alt_name: S) -> Ref<Self> { // let alt_name = BnString::new(alt_name); let alt_name = alt_name.to_cstr(); // See same line in `named_int` above @@ -1217,7 +1217,7 @@ impl EnumerationBuilder { unsafe { Enumeration::ref_from_raw(BNFinalizeEnumerationBuilder(self.handle)) } } - pub fn append<S: AsCStr>(&mut self, name: S) -> &mut Self { + pub fn append<S: IntoCStr>(&mut self, name: S) -> &mut Self { let name = name.to_cstr(); unsafe { BNAddEnumerationBuilderMember(self.handle, name.as_ref().as_ptr() as _); @@ -1225,7 +1225,7 @@ impl EnumerationBuilder { self } - pub fn insert<S: AsCStr>(&mut self, name: S, value: u64) -> &mut Self { + pub fn insert<S: IntoCStr>(&mut self, name: S, value: u64) -> &mut Self { let name = name.to_cstr(); unsafe { BNAddEnumerationBuilderMemberWithValue(self.handle, name.as_ref().as_ptr() as _, value); @@ -1233,7 +1233,7 @@ impl EnumerationBuilder { self } - pub fn replace<S: AsCStr>(&mut self, id: usize, name: S, value: u64) -> &mut Self { + pub fn replace<S: IntoCStr>(&mut self, id: usize, name: S, value: u64) -> &mut Self { let name = name.to_cstr(); unsafe { BNReplaceEnumerationBuilderMember(self.handle, id, name.as_ref().as_ptr() as _, value); @@ -1476,7 +1476,7 @@ impl StructureBuilder { self } - pub fn append<'a, S: AsCStr, T: Into<Conf<&'a Type>>>( + pub fn append<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: S, @@ -1513,7 +1513,7 @@ impl StructureBuilder { self } - pub fn insert<'a, S: AsCStr, T: Into<Conf<&'a Type>>>( + pub fn insert<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>( &mut self, ty: T, name: S, @@ -1538,7 +1538,7 @@ impl StructureBuilder { self } - pub fn replace<'a, S: AsCStr, T: Into<Conf<&'a Type>>>( + pub fn replace<'a, S: IntoCStr, T: Into<Conf<&'a Type>>>( &mut self, index: usize, ty: T, @@ -1870,7 +1870,7 @@ impl NamedTypeReference { /// You should not assign type ids yourself: if you use this to reference a type you are going /// to create but have not yet created, you may run into problems when giving your types to /// a BinaryView. - pub fn new_with_id<T: Into<QualifiedName>, S: AsCStr>( + pub fn new_with_id<T: Into<QualifiedName>, S: IntoCStr>( type_class: NamedTypeReferenceClass, type_id: S, name: T, diff --git a/rust/src/update.rs b/rust/src/update.rs index be85c93e..48d841fb 100644 --- a/rust/src/update.rs +++ b/rust/src/update.rs @@ -4,7 +4,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner}; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use binaryninjacore_sys::*; pub type UpdateResult = BNUpdateResult; diff --git a/rust/src/websocket/client.rs b/rust/src/websocket/client.rs index 8e2c6db0..aa69c381 100644 --- a/rust/src/websocket/client.rs +++ b/rust/src/websocket/client.rs @@ -1,5 +1,5 @@ use crate::rc::{Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; use std::ffi::{c_char, c_void, CStr}; use std::ptr::NonNull; @@ -21,8 +21,8 @@ pub trait WebsocketClient: Sync + Send { fn connect<I, K, V>(&self, host: &str, headers: I) -> bool where I: IntoIterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr; + K: IntoCStr, + V: IntoCStr; fn write(&self, data: &[u8]) -> bool; @@ -77,8 +77,8 @@ impl CoreWebsocketClient { ) -> bool where I: IntoIterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, C: WebsocketClientCallback, { let url = host.to_cstr(); diff --git a/rust/src/websocket/provider.rs b/rust/src/websocket/provider.rs index 9cc1de84..40235c2b 100644 --- a/rust/src/websocket/provider.rs +++ b/rust/src/websocket/provider.rs @@ -1,5 +1,5 @@ use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Ref}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use crate::websocket::client; use crate::websocket::client::{CoreWebsocketClient, WebsocketClient}; use binaryninjacore_sys::*; @@ -80,7 +80,7 @@ impl CoreWebsocketProvider { unsafe { Array::new(result, count, ()) } } - pub fn by_name<S: AsCStr>(name: S) -> Option<CoreWebsocketProvider> { + pub fn by_name<S: IntoCStr>(name: S) -> Option<CoreWebsocketProvider> { let name = name.to_cstr(); let result = unsafe { BNGetWebsocketProviderByName(name.as_ptr()) }; NonNull::new(result).map(|h| unsafe { Self::from_raw(h) }) diff --git a/rust/src/worker_thread.rs b/rust/src/worker_thread.rs index e0d7b0db..8fbfb8ef 100644 --- a/rust/src/worker_thread.rs +++ b/rust/src/worker_thread.rs @@ -1,4 +1,4 @@ -use crate::string::AsCStr; +use crate::string::IntoCStr; use binaryninjacore_sys::*; use std::ffi::c_void; @@ -17,7 +17,7 @@ impl WorkerThreadActionExecutor { } } -pub fn execute_on_worker_thread<F: Fn() + 'static, S: AsCStr>(name: S, f: F) { +pub fn execute_on_worker_thread<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) { let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) }); let raw_executor = Box::into_raw(boxed_executor); let name = name.to_cstr(); @@ -30,7 +30,7 @@ pub fn execute_on_worker_thread<F: Fn() + 'static, S: AsCStr>(name: S, f: F) { } } -pub fn execute_on_worker_thread_priority<F: Fn() + 'static, S: AsCStr>(name: S, f: F) { +pub fn execute_on_worker_thread_priority<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) { let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) }); let raw_executor = Box::into_raw(boxed_executor); let name = name.to_cstr(); @@ -43,7 +43,7 @@ pub fn execute_on_worker_thread_priority<F: Fn() + 'static, S: AsCStr>(name: S, } } -pub fn execute_on_worker_thread_interactive<F: Fn() + 'static, S: AsCStr>(name: S, f: F) { +pub fn execute_on_worker_thread_interactive<F: Fn() + 'static, S: IntoCStr>(name: S, f: F) { let boxed_executor = Box::new(WorkerThreadActionExecutor { func: Box::new(f) }); let raw_executor = Box::into_raw(boxed_executor); let name = name.to_cstr(); diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs index 9bbc0b31..5b908ddd 100644 --- a/rust/src/workflow.rs +++ b/rust/src/workflow.rs @@ -9,7 +9,7 @@ use crate::low_level_il::function::{LowLevelILFunction, Mutable, NonSSA, NonSSAV use crate::low_level_il::MutableLiftedILFunction; use crate::medium_level_il::MediumLevelILFunction; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use std::ffi::{c_char, c_void}; use std::ptr::NonNull; @@ -108,7 +108,7 @@ impl AnalysisContext { } } - pub fn inform<S: AsCStr>(&self, request: S) -> bool { + pub fn inform<S: IntoCStr>(&self, request: S) -> bool { let request = request.to_cstr(); unsafe { BNAnalysisContextInform(self.handle.as_ptr(), request.as_ptr()) } } @@ -161,7 +161,7 @@ impl Activity { Ref::new(Self { handle }) } - pub fn new<S: AsCStr>(config: S) -> Ref<Self> { + pub fn new<S: IntoCStr>(config: S) -> Ref<Self> { unsafe extern "C" fn cb_action_nop(_: *mut c_void, _: *mut BNAnalysisContext) {} let config = config.to_cstr(); let result = @@ -171,7 +171,7 @@ impl Activity { pub fn new_with_action<S, F>(config: S, mut action: F) -> Ref<Self> where - S: AsCStr, + S: IntoCStr, F: FnMut(&AnalysisContext), { unsafe extern "C" fn cb_action<F: FnMut(&AnalysisContext)>( @@ -240,7 +240,7 @@ impl Workflow { /// Create a new unregistered [Workflow] with no activities. /// /// To get a copy of an existing registered [Workflow] use [Workflow::clone_to]. - pub fn new<S: AsCStr>(name: S) -> Ref<Self> { + pub fn new<S: IntoCStr>(name: S) -> Ref<Self> { let name = name.to_cstr(); let result = unsafe { BNCreateWorkflow(name.as_ptr()) }; unsafe { Workflow::ref_from_raw(NonNull::new(result).unwrap()) } @@ -250,7 +250,7 @@ impl Workflow { /// /// * `name` - the name for the new [Workflow] #[must_use] - pub fn clone_to<S: AsCStr + Clone>(&self, name: S) -> Ref<Workflow> { + pub fn clone_to<S: IntoCStr + Clone>(&self, name: S) -> Ref<Workflow> { self.clone_to_with_root(name, "") } @@ -259,7 +259,7 @@ impl Workflow { /// * `name` - the name for the new [Workflow] /// * `root_activity` - perform the clone operation with this activity as the root #[must_use] - pub fn clone_to_with_root<S: AsCStr, A: AsCStr>( + pub fn clone_to_with_root<S: IntoCStr, A: IntoCStr>( &self, name: S, root_activity: A, @@ -278,7 +278,7 @@ impl Workflow { } } - pub fn instance<S: AsCStr>(name: S) -> Ref<Workflow> { + pub fn instance<S: IntoCStr>(name: S) -> Ref<Workflow> { let name = name.to_cstr(); let result = unsafe { BNWorkflowInstance(name.as_ptr()) }; unsafe { Workflow::ref_from_raw(NonNull::new(result).unwrap()) } @@ -306,7 +306,7 @@ impl Workflow { /// Register this [Workflow], making it immutable and available for use. /// /// * `configuration` - a JSON representation of the workflow configuration - pub fn register_with_config<S: AsCStr>(&self, config: S) -> Result<(), ()> { + pub fn register_with_config<S: IntoCStr>(&self, config: S) -> Result<(), ()> { let config = config.to_cstr(); if unsafe { BNRegisterWorkflow(self.handle.as_ptr(), config.as_ptr()) } { Ok(()) @@ -333,7 +333,7 @@ impl Workflow { ) -> Result<Ref<Activity>, ()> where I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let subactivities_raw: Vec<_> = subactivities.into_iter().map(|x| x.to_cstr()).collect(); let mut subactivities_ptr: Vec<*const _> = @@ -351,7 +351,7 @@ impl Workflow { } /// Determine if an Activity exists in this [Workflow]. - pub fn contains<A: AsCStr>(&self, activity: A) -> bool { + pub fn contains<A: IntoCStr>(&self, activity: A) -> bool { let activity = activity.to_cstr(); unsafe { BNWorkflowContains(self.handle.as_ptr(), activity.as_ptr()) } } @@ -365,7 +365,7 @@ impl Workflow { /// [Workflow], just for the given `activity`. /// /// `activity` - return the configuration for the `activity` - pub fn configuration_with_activity<A: AsCStr>(&self, activity: A) -> String { + pub fn configuration_with_activity<A: IntoCStr>(&self, activity: A) -> String { let activity = activity.to_cstr(); let result = unsafe { BNWorkflowGetConfiguration(self.handle.as_ptr(), activity.as_ptr()) }; assert!(!result.is_null()); @@ -382,7 +382,7 @@ impl Workflow { } /// Retrieve the Activity object for the specified `name`. - pub fn activity<A: AsCStr>(&self, name: A) -> Option<Ref<Activity>> { + pub fn activity<A: IntoCStr>(&self, name: A) -> Option<Ref<Activity>> { let name = name.to_cstr(); let result = unsafe { BNWorkflowGetActivity(self.handle.as_ptr(), name.as_ptr()) }; NonNull::new(result).map(|a| unsafe { Activity::ref_from_raw(a) }) @@ -392,7 +392,7 @@ impl Workflow { /// specified just for the given `activity`. /// /// * `activity` - if specified, return the roots for the `activity` - pub fn activity_roots<A: AsCStr>(&self, activity: A) -> Array<BnString> { + pub fn activity_roots<A: IntoCStr>(&self, activity: A) -> Array<BnString> { let activity = activity.to_cstr(); let mut count = 0; let result = unsafe { @@ -406,7 +406,7 @@ impl Workflow { /// /// * `activity` - if specified, return the direct children and optionally the descendants of the `activity` (includes `activity`) /// * `immediate` - whether to include only direct children of `activity` or all descendants - pub fn subactivities<A: AsCStr>(&self, activity: A, immediate: bool) -> Array<BnString> { + pub fn subactivities<A: IntoCStr>(&self, activity: A, immediate: bool) -> Array<BnString> { let activity = activity.to_cstr(); let mut count = 0; let result = unsafe { @@ -427,9 +427,9 @@ impl Workflow { /// * `activities` - the list of Activities to assign pub fn assign_subactivities<A, I>(&self, activity: A, activities: I) -> bool where - A: AsCStr, + A: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let activity = activity.to_cstr(); let input_list: Vec<_> = activities.into_iter().map(|a| a.to_cstr()).collect(); @@ -455,9 +455,9 @@ impl Workflow { /// * `activities` - the list of Activities to insert pub fn insert<A, I>(&self, activity: A, activities: I) -> bool where - A: AsCStr, + A: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let activity = activity.to_cstr(); let input_list: Vec<_> = activities.into_iter().map(|a| a.to_cstr()).collect(); @@ -478,9 +478,9 @@ impl Workflow { /// * `activities` - the list of Activities to insert pub fn insert_after<A, I>(&self, activity: A, activities: I) -> bool where - A: AsCStr, + A: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let activity = activity.to_cstr(); let input_list: Vec<_> = activities.into_iter().map(|a| a.to_cstr()).collect(); @@ -496,7 +496,7 @@ impl Workflow { } /// Remove the specified `activity` - pub fn remove<A: AsCStr>(&self, activity: A) -> bool { + pub fn remove<A: IntoCStr>(&self, activity: A) -> bool { let activity = activity.to_cstr(); unsafe { BNWorkflowRemove(self.handle.as_ptr(), activity.as_ptr()) } } @@ -505,7 +505,7 @@ impl Workflow { /// /// * `activity` - the Activity to replace /// * `new_activity` - the replacement Activity - pub fn replace<A: AsCStr, N: AsCStr>(&self, activity: A, new_activity: N) -> bool { + pub fn replace<A: IntoCStr, N: IntoCStr>(&self, activity: A, new_activity: N) -> bool { let activity = activity.to_cstr(); let new_activity = new_activity.to_cstr(); unsafe { @@ -521,7 +521,7 @@ impl Workflow { /// /// * `activity` - if specified, generate the Flowgraph using `activity` as the root /// * `sequential` - whether to generate a **Composite** or **Sequential** style graph - pub fn graph<A: AsCStr>( + pub fn graph<A: IntoCStr>( &self, activity: A, sequential: Option<bool>, diff --git a/rust/tests/websocket.rs b/rust/tests/websocket.rs index 01d2d791..c5cf6be4 100644 --- a/rust/tests/websocket.rs +++ b/rust/tests/websocket.rs @@ -1,6 +1,6 @@ use binaryninja::headless::Session; use binaryninja::rc::Ref; -use binaryninja::string::AsCStr; +use binaryninja::string::IntoCStr; use binaryninja::websocket::{ register_websocket_provider, CoreWebsocketClient, CoreWebsocketProvider, WebsocketClient, WebsocketClientCallback, WebsocketProvider, @@ -34,8 +34,8 @@ impl WebsocketClient for MyWebsocketClient { fn connect<I, K, V>(&self, host: &str, _headers: I) -> bool where I: IntoIterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { assert_eq!(host, "url"); true |
