summaryrefslogtreecommitdiff
path: root/rust/src/string.rs
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-07-11 17:59:07 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:21 -0400
commit90a3729620e85f66b8fa5d385ead21ac581a1cc5 (patch)
treeaf798477ab9b8165e966b9ef5f249de011a9aaf2 /rust/src/string.rs
parent642d32f688d735decccf2b844d113c436982f5e0 (diff)
[Rust API] Helpers and Structure::members/insert_member
Diffstat (limited to 'rust/src/string.rs')
-rw-r--r--rust/src/string.rs26
1 files changed, 26 insertions, 0 deletions
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<String> {
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<u8>;
+
+ fn as_bytes_with_nul(self) -> Self::Result {
+ self.string().as_bytes_with_nul()
+ }
+}