summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/platform.rs2
-rw-r--r--rust/src/rc.rs13
-rw-r--r--rust/src/string.rs10
-rw-r--r--rust/src/types.rs42
4 files changed, 65 insertions, 2 deletions
diff --git a/rust/src/platform.rs b/rust/src/platform.rs
index d0cc9282..6bdf8c9f 100644
--- a/rust/src/platform.rs
+++ b/rust/src/platform.rs
@@ -281,7 +281,7 @@ impl TypeParser for Platform {
let mut include_dirs = vec![];
for dir in include_directories.iter() {
- let d = dir.as_ref().to_string_lossy().as_bytes_with_nul();
+ let d = dir.as_ref().to_string_lossy().to_string().as_bytes_with_nul();
include_dirs.push(d.as_ptr() as _);
}
diff --git a/rust/src/rc.rs b/rust/src/rc.rs
index f8507d0c..b21b7b94 100644
--- a/rust/src/rc.rs
+++ b/rust/src/rc.rs
@@ -15,6 +15,7 @@
//! Reference counting for core Binary Ninja objects.
use std::borrow::Borrow;
+use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
@@ -99,6 +100,18 @@ impl<T: RefCountable> Clone for Ref<T> {
}
}
+impl<T: RefCountable + Display> Display for Ref<T> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ self.contents.fmt(f)
+ }
+}
+
+impl<T: RefCountable + Debug> Debug for Ref<T> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ self.contents.fmt(f)
+ }
+}
+
// Guard provides access to a core-allocated resource whose
// reference is held indirectly (e.g. a core-allocated array
// of raw `*mut BNRawT`).
diff --git a/rust/src/string.rs b/rust/src/string.rs
index c1ca88d8..c4419b5e 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -14,7 +14,7 @@
//! String wrappers for core-owned strings and strings being passed to the core
-use std::borrow::Borrow;
+use std::borrow::{Borrow, Cow};
use std::ffi::{CStr, CString};
use std::fmt;
use std::mem;
@@ -231,3 +231,11 @@ unsafe impl BnStrCompatible for String {
ret.into_bytes_with_nul()
}
}
+
+unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
+ type Result = &'a [u8];
+
+ fn as_bytes_with_nul(self) -> Self::Result {
+ self.as_ref().as_bytes()
+ }
+}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 09b1b97d..c1f24c59 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -17,6 +17,7 @@
// TODO : Test the get_enumeration and get_structure methods
use binaryninjacore_sys::*;
+use std::iter::IntoIterator;
use std::{fmt, mem, ptr, result, slice};
use crate::architecture::{Architecture, CoreArchitecture};
@@ -724,6 +725,15 @@ impl Type {
Self::int(1, true)
}
+ pub fn wide_char(width: usize) -> Ref<Self> {
+ unsafe {
+ Self::ref_from_raw(BNCreateWideCharType(
+ width,
+ BnString::new("").as_ptr() as *mut _,
+ ))
+ }
+ }
+
pub fn int(width: usize, is_signed: bool) -> Ref<Self> {
let mut is_signed = Conf::new(is_signed, max_confidence()).into();
unsafe {
@@ -1041,6 +1051,18 @@ impl fmt::Display for Type {
}
}
+impl fmt::Debug for Type {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", unsafe {
+ BnString::from_raw(BNGetTypeString(
+ self.handle,
+ ptr::null_mut(),
+ BNTokenEscapingType::NoTokenEscapingType,
+ ))
+ })
+ }
+}
+
unsafe impl Send for Type {}
unsafe impl Sync for Type {}
@@ -1625,6 +1647,26 @@ impl<S: BnStrCompatible> From<S> for QualifiedName {
}
}
+impl<S: BnStrCompatible> From<Vec<S>> for QualifiedName {
+ fn from(names: Vec<S>) -> Self {
+ let join = BnString::new("::");
+ let names = names
+ .into_iter()
+ .map(|n| n.as_bytes_with_nul())
+ .collect::<Vec<_>>();
+ let mut list = names
+ .iter()
+ .map(|n| n.as_ref().as_ptr() as *const _)
+ .collect::<Vec<_>>();
+
+ QualifiedName(BNQualifiedName {
+ name: unsafe { BNAllocStringList(list.as_mut_ptr(), list.len()) },
+ join: join.into_raw(),
+ nameCount: list.len(),
+ })
+ }
+}
+
impl Drop for QualifiedName {
fn drop(&mut self) {
unsafe {