summaryrefslogtreecommitdiff
path: root/rust/src/types.rs
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-06-29 17:28:31 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:20 -0400
commit642d32f688d735decccf2b844d113c436982f5e0 (patch)
tree0148b8474bd154345c121c623b2fa23159e0c755 /rust/src/types.rs
parent207925956bb8ca0174d40523fda70bfb5bc7bd38 (diff)
[Rust API] Make more types convertible to BN types
Diffstat (limited to 'rust/src/types.rs')
-rw-r--r--rust/src/types.rs42
1 files changed, 42 insertions, 0 deletions
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 {