summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2024-04-06 16:32:00 -0300
committerKyle Martin <krm504@nyu.edu>2024-04-09 13:39:49 -0400
commit193dea95daedde471e6f1fbcbeaf1932c6fbd50c (patch)
tree99be67d81a899543ed5e4636eea3d589583e48a5 /rust/src
parenta6b48153b64a227c3492d77a96e679b8c469034c (diff)
replace BStr with str
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/binaryview.rs2
-rw-r--r--rust/src/callingconvention.rs16
-rw-r--r--rust/src/custombinaryview.rs4
-rw-r--r--rust/src/demangle.rs2
-rw-r--r--rust/src/disassembly.rs25
-rw-r--r--rust/src/downloadprovider.rs8
-rw-r--r--rust/src/interaction.rs8
-rw-r--r--rust/src/logger.rs9
-rw-r--r--rust/src/string.rs102
-rw-r--r--rust/src/symbol.rs9
-rw-r--r--rust/src/types.rs74
11 files changed, 107 insertions, 152 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs
index e188b650..52d688b8 100644
--- a/rust/src/binaryview.rs
+++ b/rust/src/binaryview.rs
@@ -674,7 +674,7 @@ pub trait BinaryViewExt: BinaryViewBase {
let name_array = unsafe { Array::<QualifiedName>::new(result_names, result_count, ()) };
for (id, name) in id_array.iter().zip(name_array.iter()) {
- result.insert(id.as_str().to_owned(), name.clone());
+ result.insert(id.to_owned(), name.clone());
}
result
diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs
index 56755b37..815f4d42 100644
--- a/rust/src/callingconvention.rs
+++ b/rust/src/callingconvention.rs
@@ -448,24 +448,21 @@ impl<A: Architecture> CallingConvention<A> {
unsafe { BnString::from_raw(BNGetCallingConventionName(self.handle)) }
}
- pub fn variables_for_parameters<S: Clone + BnStrCompatible>(
+ pub fn variables_for_parameters(
&self,
- params: &[FunctionParameter<S>],
+ params: &[FunctionParameter],
permitted_registers: Option<&[A::Register]>,
) -> Vec<Variable> {
let mut bn_params: Vec<BNFunctionParameter> = vec![];
- let mut name_strings = vec![];
+ let name_strings = params.iter().map(|parameter| &parameter.name);
- for parameter in params.iter() {
- name_strings.push(parameter.name.clone().into_bytes_with_nul());
- }
- for (parameter, raw_name) in params.iter().zip(name_strings.iter_mut()) {
+ for (parameter, raw_name) in params.iter().zip(name_strings) {
let location = match &parameter.location {
Some(location) => location.raw(),
None => unsafe { mem::zeroed() },
};
bn_params.push(BNFunctionParameter {
- name: raw_name.as_ref().as_ptr() as *mut _,
+ name: BnString::new(raw_name).into_raw(),
type_: parameter.t.contents.handle,
typeConfidence: parameter.t.confidence,
defaultLocation: parameter.location.is_none(),
@@ -501,9 +498,6 @@ impl<A: Architecture> CallingConvention<A> {
}
};
- // Gotta keep this around so the pointers are valid during the call
- drop(name_strings);
-
let vars_slice = unsafe { slice::from_raw_parts(vars, count) };
let mut result = vec![];
for var in vars_slice {
diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs
index 21b63c91..956be9bd 100644
--- a/rust/src/custombinaryview.rs
+++ b/rust/src/custombinaryview.rs
@@ -388,7 +388,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> {
let view_name = view_type.name();
- if let Ok(bv) = file.get_view_of_type(view_name.as_cstr()) {
+ if let Ok(bv) = file.get_view_of_type(view_name.as_str()) {
// while it seems to work most of the time, you can get really unlucky
// if the a free of the existing view of the same type kicks off while
// BNCreateBinaryViewOfType is still running. the freeObject callback
@@ -772,7 +772,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> {
unsafe {
let res = BNCreateCustomBinaryView(
- view_name.as_cstr().as_ptr(),
+ view_name.as_ptr(),
file.handle,
parent.handle,
&mut bn_obj,
diff --git a/rust/src/demangle.rs b/rust/src/demangle.rs
index 2efa0ca4..19eb085c 100644
--- a/rust/src/demangle.rs
+++ b/rust/src/demangle.rs
@@ -73,7 +73,7 @@ pub fn demangle_gnu3<S: BnStrCompatible>(
let names = unsafe { ArrayGuard::<BnString>::new(out_name, out_size, ()) }
.iter()
- .map(|name| name.to_string())
+ .map(str::to_string)
.collect();
unsafe { BNFreeDemangledName(&mut out_name, out_size) };
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs
index 1d0dfb8b..f213fa0e 100644
--- a/rust/src/disassembly.rs
+++ b/rust/src/disassembly.rs
@@ -16,12 +16,13 @@
use binaryninjacore_sys::*;
-use crate::string::{BnStr, BnString};
+use crate::string::BnString;
use crate::{BN_FULL_CONFIDENCE, BN_INVALID_EXPR};
use crate::rc::*;
use std::convert::From;
+use std::ffi::CStr;
use std::mem;
use std::ptr;
@@ -102,7 +103,7 @@ impl InstructionTextToken {
Self(*raw)
}
- pub fn new(text: BnString, contents: InstructionTextTokenContents) -> Self {
+ pub fn new(text: &str, contents: InstructionTextTokenContents) -> Self {
let (value, address) = match contents {
InstructionTextTokenContents::Integer(v) => (v, 0),
InstructionTextTokenContents::PossibleAddress(v)
@@ -149,7 +150,7 @@ impl InstructionTextToken {
InstructionTextToken(BNInstructionTextToken {
type_,
- text: text.into_raw(),
+ text: BnString::new(text).into_raw(),
value,
width,
size: 0,
@@ -159,7 +160,7 @@ impl InstructionTextToken {
address,
typeNames: ptr::null_mut(),
namesCount: 0,
- exprIndex: BN_INVALID_EXPR
+ exprIndex: BN_INVALID_EXPR,
})
}
@@ -171,8 +172,8 @@ impl InstructionTextToken {
self.0.context = context;
}
- pub fn text(&self) -> &BnStr {
- unsafe { BnStr::from_raw(self.0.text) }
+ pub fn text(&self) -> &str {
+ unsafe { CStr::from_ptr(self.0.text) }.to_str().unwrap()
}
pub fn contents(&self) -> InstructionTextTokenContents {
@@ -229,7 +230,7 @@ impl Default for InstructionTextToken {
address: 0,
typeNames: ptr::null_mut(),
namesCount: 0,
- exprIndex: BN_INVALID_EXPR
+ exprIndex: BN_INVALID_EXPR,
})
}
}
@@ -248,7 +249,7 @@ impl Clone for InstructionTextToken {
confidence: 0xff,
typeNames: ptr::null_mut(),
namesCount: 0,
- exprIndex: self.0.exprIndex
+ exprIndex: self.0.exprIndex,
})
}
}
@@ -345,9 +346,11 @@ impl From<Vec<InstructionTextToken>> for DisassemblyTextLine {
impl From<&Vec<&str>> for DisassemblyTextLine {
fn from(string_tokens: &Vec<&str>) -> Self {
let mut tokens: Vec<BNInstructionTextToken> = Vec::with_capacity(string_tokens.len());
- tokens.extend(string_tokens.iter().map(|&token| {
- InstructionTextToken::new(BnString::new(token), InstructionTextTokenContents::Text).0
- }));
+ tokens.extend(
+ string_tokens.iter().map(|&token| {
+ InstructionTextToken::new(token, InstructionTextTokenContents::Text).0
+ }),
+ );
assert!(tokens.len() == tokens.capacity());
// let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nighly feature
diff --git a/rust/src/downloadprovider.rs b/rust/src/downloadprovider.rs
index 4ba07dbe..97ebbdbc 100644
--- a/rust/src/downloadprovider.rs
+++ b/rust/src/downloadprovider.rs
@@ -2,10 +2,10 @@ use crate::rc::{
Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable,
};
use crate::settings::Settings;
-use crate::string::{BnStr, BnStrCompatible, BnString};
+use crate::string::{BnStrCompatible, BnString};
use binaryninjacore_sys::*;
use std::collections::HashMap;
-use std::ffi::c_void;
+use std::ffi::{c_void, CStr};
use std::os::raw::c_char;
use std::ptr::null_mut;
use std::slice;
@@ -270,8 +270,8 @@ impl DownloadInstance {
.zip(response_header_values.iter())
{
response_headers.insert(
- BnStr::from_raw(*key).to_string(),
- BnStr::from_raw(*value).to_string(),
+ CStr::from_ptr(*key).to_str().unwrap().to_owned(),
+ CStr::from_ptr(*value).to_str().unwrap().to_owned(),
);
}
}
diff --git a/rust/src/interaction.rs b/rust/src/interaction.rs
index 7e549253..ccb5c81a 100644
--- a/rust/src/interaction.rs
+++ b/rust/src/interaction.rs
@@ -16,12 +16,13 @@
use binaryninjacore_sys::*;
+use std::ffi::CStr;
use std::os::raw::{c_char, c_void};
use std::path::PathBuf;
use crate::binaryview::BinaryView;
use crate::rc::Ref;
-use crate::string::{BnStr, BnStrCompatible, BnString};
+use crate::string::{BnStrCompatible, BnString};
pub fn get_text_line_input(prompt: &str, title: &str) -> Option<String> {
let mut value: *mut libc::c_char = std::ptr::null_mut();
@@ -499,7 +500,10 @@ impl FormInputBuilder {
| BNFormInputFieldType::SaveFileNameFormField
| BNFormInputFieldType::DirectoryNameFormField => {
FormResponses::String(unsafe {
- BnStr::from_raw(form_field.stringResult).to_string()
+ CStr::from_ptr(form_field.stringResult)
+ .to_str()
+ .unwrap()
+ .to_owned()
})
}
diff --git a/rust/src/logger.rs b/rust/src/logger.rs
index 8651eec3..43423900 100644
--- a/rust/src/logger.rs
+++ b/rust/src/logger.rs
@@ -29,12 +29,11 @@
//! ```
//!
-use crate::string::BnStr;
-
pub use binaryninjacore_sys::BNLogLevel as Level;
use binaryninjacore_sys::{BNLogListener, BNUpdateLogListeners};
use log;
+use std::ffi::CStr;
use std::os::raw::{c_char, c_void};
struct Logger;
@@ -84,7 +83,7 @@ pub fn init(filter: log::LevelFilter) -> Result<(), log::SetLoggerError> {
}
pub trait LogListener: 'static + Sync {
- fn log(&self, session: usize, level: Level, msg: &BnStr, logger_name: &BnStr, tid: usize);
+ fn log(&self, session: usize, level: Level, msg: &CStr, logger_name: &CStr, tid: usize);
fn level(&self) -> Level;
fn close(&self) {}
}
@@ -147,8 +146,8 @@ extern "C" fn cb_log<L>(
listener.log(
session,
level,
- BnStr::from_raw(msg),
- BnStr::from_raw(logger_name),
+ CStr::from_ptr(msg),
+ CStr::from_ptr(logger_name),
tid,
);
})
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 55521f09..1011ca49 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, Cow};
+use std::borrow::Cow;
use std::ffi::{CStr, CString};
use std::fmt;
use std::hash::{Hash, Hasher};
@@ -33,61 +33,9 @@ pub(crate) fn raw_to_string(ptr: *const raw::c_char) -> Option<String> {
}
}
-/// These are strings that the core will both allocate and free.
-/// We just have a reference to these strings and want to be able use them, but aren't responsible for cleanup
-#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
-#[repr(C)]
-pub struct BnStr {
- raw: [u8],
-}
-
-impl BnStr {
- pub(crate) unsafe fn from_raw<'a>(ptr: *const raw::c_char) -> &'a Self {
- mem::transmute(CStr::from_ptr(ptr).to_bytes_with_nul())
- }
-
- pub fn as_str(&self) -> &str {
- self.as_cstr().to_str().unwrap()
- }
-
- pub fn as_cstr(&self) -> &CStr {
- unsafe { CStr::from_bytes_with_nul_unchecked(&self.raw) }
- }
-}
-
-impl Deref for BnStr {
- type Target = str;
-
- fn deref(&self) -> &str {
- self.as_str()
- }
-}
-
-impl AsRef<[u8]> for BnStr {
- fn as_ref(&self) -> &[u8] {
- &self.raw
- }
-}
-
-impl AsRef<str> for BnStr {
- fn as_ref(&self) -> &str {
- self.as_str()
- }
-}
-
-impl Borrow<str> for BnStr {
- fn borrow(&self) -> &str {
- self.as_str()
- }
-}
-
-impl fmt::Display for BnStr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.as_cstr().to_string_lossy())
- }
-}
-
-#[repr(C)]
+/// Is the quivalent of `core::ffi::CString` but using the allocation and free
+/// functions provided by binaryninja_sys.
+#[repr(transparent)]
pub struct BnString {
raw: *mut raw::c_char,
}
@@ -132,7 +80,19 @@ impl BnString {
}
pub fn as_str(&self) -> &str {
- unsafe { BnStr::from_raw(self.raw).as_str() }
+ unsafe { CStr::from_ptr(self.raw).to_str().unwrap() }
+ }
+
+ pub fn as_bytes(&self) -> &[u8] {
+ self.as_str().as_bytes()
+ }
+
+ pub fn as_bytes_with_null(&self) -> &[u8] {
+ self.deref().to_bytes()
+ }
+
+ pub fn len(&self) -> usize {
+ self.as_ref().len()
}
}
@@ -158,16 +118,16 @@ impl Clone for BnString {
}
impl Deref for BnString {
- type Target = BnStr;
+ type Target = CStr;
- fn deref(&self) -> &BnStr {
- unsafe { BnStr::from_raw(self.raw) }
+ fn deref(&self) -> &CStr {
+ unsafe { CStr::from_ptr(self.raw) }
}
}
impl AsRef<[u8]> for BnString {
fn as_ref(&self) -> &[u8] {
- self.as_cstr().to_bytes_with_nul()
+ self.to_bytes_with_nul()
}
}
@@ -187,13 +147,13 @@ impl Eq for BnString {}
impl fmt::Display for BnString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.as_cstr().to_string_lossy())
+ write!(f, "{}", self.to_string_lossy())
}
}
impl fmt::Debug for BnString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.as_cstr().to_string_lossy())
+ write!(f, "{}", self.to_string_lossy())
}
}
@@ -210,10 +170,10 @@ unsafe impl CoreOwnedArrayProvider for BnString {
}
unsafe impl<'a> CoreArrayWrapper<'a> for BnString {
- type Wrapped = &'a BnStr;
+ type Wrapped = &'a str;
unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped {
- BnStr::from_raw(*raw)
+ CStr::from_ptr(*raw).to_str().unwrap()
}
}
@@ -222,11 +182,11 @@ pub unsafe trait BnStrCompatible {
fn into_bytes_with_nul(self) -> Self::Result;
}
-unsafe impl<'a> BnStrCompatible for &'a BnStr {
+unsafe impl<'a> BnStrCompatible for &'a CStr {
type Result = &'a [u8];
fn into_bytes_with_nul(self) -> Self::Result {
- self.as_cstr().to_bytes_with_nul()
+ self.to_bytes_with_nul()
}
}
@@ -238,14 +198,6 @@ unsafe impl BnStrCompatible for BnString {
}
}
-unsafe impl<'a> BnStrCompatible for &'a CStr {
- type Result = &'a [u8];
-
- fn into_bytes_with_nul(self) -> Self::Result {
- self.to_bytes_with_nul()
- }
-}
-
unsafe impl BnStrCompatible for CString {
type Result = Vec<u8>;
diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs
index 25801eee..cf4c3b10 100644
--- a/rust/src/symbol.rs
+++ b/rust/src/symbol.rs
@@ -14,6 +14,7 @@
//! Interfaces for the various kinds of symbols in a binary.
+use std::ffi::CStr;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::ptr;
@@ -252,17 +253,17 @@ impl Symbol {
}
}
- pub fn short_name(&self) -> BnString {
+ pub fn short_name(&self) -> &str {
unsafe {
let name = BNGetSymbolShortName(self.handle);
- BnString::from_raw(name)
+ CStr::from_ptr(name).to_str().unwrap()
}
}
- pub fn raw_name(&self) -> BnString {
+ pub fn raw_name(&self) -> &str {
unsafe {
let name = BNGetSymbolRawName(self.handle);
- BnString::from_raw(name)
+ CStr::from_ptr(name).to_str().unwrap()
}
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 5463ce39..2a2a50d4 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -25,7 +25,7 @@ use crate::{
filemetadata::FileMetadata,
function::Function,
rc::*,
- string::{raw_to_string, BnStr, BnStrCompatible, BnString},
+ string::{raw_to_string, BnStrCompatible, BnString},
symbol::Symbol,
};
@@ -420,7 +420,7 @@ impl TypeBuilder {
}
}
- pub fn parameters(&self) -> Result<Vec<FunctionParameter<BnString>>> {
+ pub fn parameters(&self) -> Result<Vec<FunctionParameter>> {
unsafe {
let mut count: usize = mem::zeroed();
let parameters_raw = BNGetTypeBuilderParameters(self.handle, &mut count);
@@ -791,7 +791,7 @@ impl Type {
}
}
- pub fn parameters(&self) -> Result<Vec<FunctionParameter<BnString>>> {
+ pub fn parameters(&self) -> Result<Vec<FunctionParameter>> {
unsafe {
let mut count: usize = mem::zeroed();
let parameters_raw: *mut BNFunctionParameter =
@@ -992,9 +992,9 @@ impl Type {
}
}
- pub fn function<'a, S: BnStrCompatible + Clone, T: Into<Conf<&'a Type>>>(
+ pub fn function<'a, T: Into<Conf<&'a Type>>>(
return_type: T,
- parameters: &[FunctionParameter<S>],
+ parameters: &[FunctionParameter],
variable_arguments: bool,
) -> Ref<Self> {
let mut return_type = return_type.into().into();
@@ -1012,14 +1012,14 @@ impl Type {
let mut raw_parameters = Vec::<BNFunctionParameter>::with_capacity(parameters.len());
let mut parameter_name_references = Vec::with_capacity(parameters.len());
for parameter in parameters {
- let raw_name = parameter.name.clone().into_bytes_with_nul();
+ let raw_name = parameter.name.as_str().into_bytes_with_nul();
let location = match &parameter.location {
Some(location) => location.raw(),
None => unsafe { mem::zeroed() },
};
raw_parameters.push(BNFunctionParameter {
- name: raw_name.as_ref().as_ptr() as *mut _,
+ name: raw_name.as_slice().as_ptr() as *mut _,
type_: parameter.t.contents.handle,
typeConfidence: parameter.t.confidence,
defaultLocation: parameter.location.is_none(),
@@ -1058,12 +1058,11 @@ impl Type {
pub fn function_with_options<
'a,
A: Architecture,
- S: BnStrCompatible + Clone,
T: Into<Conf<&'a Type>>,
C: Into<Conf<&'a CallingConvention<A>>>,
>(
return_type: T,
- parameters: &[FunctionParameter<S>],
+ parameters: &[FunctionParameter],
variable_arguments: bool,
calling_convention: C,
stack_adjust: Conf<i64>,
@@ -1084,14 +1083,14 @@ impl Type {
}
for (name, parameter) in zip(name_ptrs, parameters) {
- let raw_name = name.into_bytes_with_nul();
+ let raw_name = name.as_str().into_bytes_with_nul();
let location = match &parameter.location {
Some(location) => location.raw(),
None => unsafe { mem::zeroed() },
};
raw_parameters.push(BNFunctionParameter {
- name: raw_name.as_ref().as_ptr() as *mut _,
+ name: raw_name.as_slice().as_ptr() as *mut _,
type_: parameter.t.contents.handle,
typeConfidence: parameter.t.confidence,
defaultLocation: parameter.location.is_none(),
@@ -1200,9 +1199,11 @@ impl Type {
}
}
- pub fn generate_auto_demangled_type_id<'a, S: BnStrCompatible>(name: S) -> &'a BnStr {
+ pub fn generate_auto_demangled_type_id<'a, S: BnStrCompatible>(name: S) -> &'a str {
let mut name = QualifiedName::from(name);
- unsafe { BnStr::from_raw(BNGenerateAutoDemangledTypeId(&mut name.0)) }
+ unsafe { CStr::from_ptr(BNGenerateAutoDemangledTypeId(&mut name.0)) }
+ .to_str()
+ .unwrap()
}
}
@@ -1315,34 +1316,35 @@ impl ToOwned for Type {
// FunctionParameter
#[derive(Clone, Debug)]
-pub struct FunctionParameter<S: BnStrCompatible> {
+pub struct FunctionParameter {
pub t: Conf<Ref<Type>>,
- pub name: S,
+ pub name: String,
pub location: Option<Variable>,
}
-impl<S: BnStrCompatible> FunctionParameter<S> {
- pub fn new<T: Into<Conf<Ref<Type>>>>(t: T, name: S, location: Option<Variable>) -> Self {
+impl FunctionParameter {
+ pub fn new<T: Into<Conf<Ref<Type>>>>(t: T, name: String, location: Option<Variable>) -> Self {
Self {
t: t.into(),
name,
location,
}
}
-}
-impl FunctionParameter<BnString> {
pub(crate) fn from_raw(member: BNFunctionParameter) -> Self {
- let name: BnString = if member.name.is_null() {
+ let name = if member.name.is_null() {
if member.location.type_ == BNVariableSourceType::RegisterVariableSourceType {
- BnString::new(format!("reg_{}", member.location.storage))
+ format!("reg_{}", member.location.storage)
} else if member.location.type_ == BNVariableSourceType::StackVariableSourceType {
- BnString::new(format!("arg_{}", member.location.storage))
+ format!("arg_{}", member.location.storage)
} else {
- BnString::new("")
+ String::new()
}
} else {
- BnString::new(unsafe { BnStr::from_raw(member.name) })
+ unsafe { CStr::from_ptr(member.name) }
+ .to_str()
+ .unwrap()
+ .to_owned()
};
Self {
@@ -1420,7 +1422,7 @@ pub struct NamedTypedVariable {
impl NamedTypedVariable {
pub fn name(&self) -> &str {
- unsafe { BnStr::from_raw(self.name).as_str() }
+ unsafe { CStr::from_ptr(self.name).to_str().unwrap() }
}
pub fn var(&self) -> Variable {
@@ -1470,15 +1472,15 @@ unsafe impl<'a> CoreArrayWrapper<'a> for NamedTypedVariable {
#[derive(Debug, Clone)]
pub struct EnumerationMember {
- pub name: BnString,
+ pub name: String,
pub value: u64,
pub is_default: bool,
}
impl EnumerationMember {
- pub fn new<S: BnStrCompatible>(name: S, value: u64, is_default: bool) -> Self {
+ pub fn new(name: String, value: u64, is_default: bool) -> Self {
Self {
- name: BnString::new(name),
+ name,
value,
is_default,
}
@@ -1486,7 +1488,7 @@ impl EnumerationMember {
pub(crate) unsafe fn from_raw(member: BNEnumerationMember) -> Self {
Self {
- name: BnString::new(raw_to_string(member.name).unwrap()),
+ name: raw_to_string(member.name).unwrap(),
value: member.value,
is_default: member.isDefault,
}
@@ -2010,23 +2012,23 @@ impl ToOwned for Structure {
#[derive(Debug, Clone)]
pub struct StructureMember {
pub ty: Conf<Ref<Type>>,
- pub name: BnString,
+ pub name: String,
pub offset: u64,
pub access: MemberAccess,
pub scope: MemberScope,
}
impl StructureMember {
- pub fn new<T: BnStrCompatible>(
+ pub fn new(
ty: Conf<Ref<Type>>,
- name: T,
+ name: String,
offset: u64,
access: MemberAccess,
scope: MemberScope,
) -> Self {
Self {
ty,
- name: BnString::new(name),
+ name,
offset,
access,
scope,
@@ -2039,7 +2041,7 @@ impl StructureMember {
RefCountable::inc_ref(&Type::from_raw(handle.type_)),
handle.typeConfidence,
),
- name: BnString::new(BnStr::from_raw(handle.name)),
+ name: CStr::from_ptr(handle.name).to_string_lossy().to_string(),
offset: handle.offset,
access: handle.access,
scope: handle.scope,
@@ -2407,8 +2409,8 @@ impl QualifiedNameTypeAndId {
unsafe { mem::transmute(&self.0.name) }
}
- pub fn id(&self) -> &BnStr {
- unsafe { BnStr::from_raw(self.0.id) }
+ pub fn id(&self) -> &str {
+ unsafe { CStr::from_ptr(self.0.id).to_str().unwrap() }
}
pub fn type_object(&self) -> Guard<Type> {