From 90a3729620e85f66b8fa5d385ead21ac581a1cc5 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 11 Jul 2022 17:59:07 -0400 Subject: [Rust API] Helpers and Structure::members/insert_member --- rust/src/string.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'rust/src/string.rs') diff --git a/rust/src/string.rs b/rust/src/string.rs index c4419b5e..e6de576b 100644 --- a/rust/src/string.rs +++ b/rust/src/string.rs @@ -22,6 +22,7 @@ use std::ops::Deref; use std::os::raw; use crate::rc::*; +use crate::types::QualifiedName; pub(crate) fn raw_to_string(ptr: *const raw::c_char) -> Option { if ptr.is_null() { @@ -137,6 +138,17 @@ impl Drop for BnString { } } +impl Clone for BnString { + fn clone(&self) -> Self { + use binaryninjacore_sys::BNAllocString; + unsafe { + Self { + raw: BNAllocString(self.raw), + } + } + } +} + impl Deref for BnString { type Target = BnStr; @@ -157,6 +169,12 @@ impl fmt::Display for BnString { } } +impl fmt::Debug for BnString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.as_cstr().to_string_lossy()) + } +} + impl CoreArrayProvider for BnString { type Raw = *mut raw::c_char; type Context = (); @@ -239,3 +257,11 @@ unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> { self.as_ref().as_bytes() } } + +unsafe impl BnStrCompatible for &QualifiedName { + type Result = Vec; + + fn as_bytes_with_nul(self) -> Self::Result { + self.string().as_bytes_with_nul() + } +} -- cgit v1.3.1