summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/architecture.rs4
-rw-r--r--rust/src/backgroundtask.rs4
-rw-r--r--rust/src/binaryview.rs28
-rw-r--r--rust/src/callingconvention.rs36
-rw-r--r--rust/src/command.rs16
-rw-r--r--rust/src/custombinaryview.rs6
-rw-r--r--rust/src/debuginfo.rs52
-rw-r--r--rust/src/demangle.rs4
-rw-r--r--rust/src/filemetadata.rs18
-rw-r--r--rust/src/function.rs4
-rw-r--r--rust/src/metadata.rs12
-rw-r--r--rust/src/platform.rs31
-rw-r--r--rust/src/rc.rs9
-rw-r--r--rust/src/section.rs8
-rw-r--r--rust/src/settings.rs38
-rw-r--r--rust/src/string.rs23
-rw-r--r--rust/src/symbol.rs6
-rw-r--r--rust/src/tags.rs10
-rw-r--r--rust/src/types.rs50
19 files changed, 214 insertions, 145 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs
index 878b2c5e..f1cdead0 100644
--- a/rust/src/architecture.rs
+++ b/rust/src/architecture.rs
@@ -1048,7 +1048,7 @@ macro_rules! cc_func {
/// Contains helper methods for all types implementing 'Architecture'
pub trait ArchitectureExt: Architecture {
fn register_by_name<S: BnStrCompatible>(&self, name: S) -> Option<Self::Register> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
match unsafe {
BNGetArchitectureRegisterByName(self.as_ref().0, name.as_ref().as_ptr() as *mut _)
@@ -1906,7 +1906,7 @@ where
false
}
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let uninit_arch = ArchitectureBuilder {
arch: unsafe { zeroed() },
diff --git a/rust/src/backgroundtask.rs b/rust/src/backgroundtask.rs
index 234bc623..e3bd407d 100644
--- a/rust/src/backgroundtask.rs
+++ b/rust/src/backgroundtask.rs
@@ -36,7 +36,7 @@ impl BackgroundTask {
}
pub fn new<S: BnStrCompatible>(initial_text: S, can_cancel: bool) -> Result<Ref<Self>> {
- let text = initial_text.as_bytes_with_nul();
+ let text = initial_text.into_bytes_with_nul();
let handle = unsafe { BNBeginBackgroundTask(text.as_ref().as_ptr() as *mut _, can_cancel) };
@@ -72,7 +72,7 @@ impl BackgroundTask {
}
pub fn set_progress_text<S: BnStrCompatible>(&self, text: S) {
- let progress_text = text.as_bytes_with_nul();
+ let progress_text = text.into_bytes_with_nul();
unsafe {
BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ref().as_ptr() as *mut _)
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs
index 43eb1dfc..ff556d54 100644
--- a/rust/src/binaryview.rs
+++ b/rust/src/binaryview.rs
@@ -299,7 +299,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn symbol_by_raw_name<S: BnStrCompatible>(&self, raw_name: S) -> Result<Ref<Symbol>> {
- let raw_name = raw_name.as_bytes_with_nul();
+ let raw_name = raw_name.into_bytes_with_nul();
unsafe {
let raw_sym = BNGetSymbolByRawName(
@@ -326,7 +326,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn symbols_by_name<S: BnStrCompatible>(&self, name: S) -> Array<Symbol> {
- let raw_name = name.as_bytes_with_nul();
+ let raw_name = name.into_bytes_with_nul();
unsafe {
let mut count = 0;
@@ -481,7 +481,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn remove_auto_section<S: BnStrCompatible>(&self, name: S) {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
unsafe {
@@ -490,7 +490,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn remove_user_section<S: BnStrCompatible>(&self, name: S) {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
unsafe {
@@ -500,7 +500,7 @@ pub trait BinaryViewExt: BinaryViewBase {
fn section_by_name<S: BnStrCompatible>(&self, name: S) -> Result<Section> {
unsafe {
- let raw_name = name.as_bytes_with_nul();
+ let raw_name = name.into_bytes_with_nul();
let name_ptr = raw_name.as_ref().as_ptr() as *mut _;
let raw_section = BNGetSectionByName(self.as_ref().handle, name_ptr);
@@ -646,7 +646,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn show_graph_report<S: BnStrCompatible>(&self, raw_name: S, graph: FlowGraph) {
- let raw_name = raw_name.as_bytes_with_nul();
+ let raw_name = raw_name.into_bytes_with_nul();
unsafe {
BNShowGraphReport(
self.as_ref().handle,
@@ -657,7 +657,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn load_settings<S: BnStrCompatible>(&self, view_type_name: S) -> Result<Ref<Settings>> {
- let view_type_name = view_type_name.as_bytes_with_nul();
+ let view_type_name = view_type_name.into_bytes_with_nul();
let settings_handle = unsafe {
BNBinaryViewGetLoadSettings(
self.as_ref().handle,
@@ -673,7 +673,7 @@ pub trait BinaryViewExt: BinaryViewBase {
}
fn set_load_settings<S: BnStrCompatible>(&self, view_type_name: S, settings: &Settings) {
- let view_type_name = view_type_name.as_bytes_with_nul();
+ let view_type_name = view_type_name.into_bytes_with_nul();
unsafe {
BNBinaryViewSetLoadSettings(
@@ -715,7 +715,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Get a tag type by its name
fn get_tag_type_by_name<S: BnStrCompatible>(&self, name: S) -> Option<Ref<TagType>> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
let handle = BNGetTagType(self.as_ref().handle, name.as_ref().as_ptr() as *mut _);
@@ -728,7 +728,7 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Get a tag type by its id
fn get_tag_type_by_id<S: BnStrCompatible>(&self, id: S) -> Option<Ref<TagType>> {
- let id = id.as_bytes_with_nul();
+ let id = id.into_bytes_with_nul();
unsafe {
let handle = BNGetTagTypeById(self.as_ref().handle, id.as_ref().as_ptr() as *mut _);
@@ -757,7 +757,7 @@ pub trait BinaryViewExt: BinaryViewBase {
///
/// Note this does not tell you anything about where it is used.
fn get_tag<S: BnStrCompatible>(&self, id: S) -> Option<Ref<Tag>> {
- let id = id.as_bytes_with_nul();
+ let id = id.into_bytes_with_nul();
unsafe {
let handle = BNGetTag(self.as_ref().handle, id.as_ref().as_ptr() as *mut _);
if handle.is_null() {
@@ -842,7 +842,7 @@ pub trait BinaryViewExt: BinaryViewBase {
let value: *mut BNMetadata = unsafe {
BNBinaryViewQueryMetadata(
self.as_ref().handle,
- key.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ key.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
)
};
if value.is_null() {
@@ -864,7 +864,7 @@ pub trait BinaryViewExt: BinaryViewBase {
unsafe {
BNBinaryViewRemoveMetadata(
self.as_ref().handle,
- key.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ key.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
)
};
}
@@ -888,7 +888,7 @@ impl BinaryView {
meta: &mut FileMetadata,
filename: S,
) -> Result<Ref<Self>> {
- let file = filename.as_bytes_with_nul();
+ let file = filename.into_bytes_with_nul();
let handle = unsafe {
BNCreateBinaryDataViewFromFilename(meta.handle, file.as_ref().as_ptr() as *mut _)
diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs
index 8e29a0b0..672b2c1b 100644
--- a/rust/src/callingconvention.rs
+++ b/rust/src/callingconvention.rs
@@ -24,7 +24,9 @@ use std::slice;
use binaryninjacore_sys::*;
use crate::architecture::{Architecture, ArchitectureExt, Register};
-use crate::rc::{Ref, RefCountable};
+use crate::rc::{
+ CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable,
+};
use crate::string::*;
// TODO
@@ -365,7 +367,7 @@ where
)
}
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let raw = Box::into_raw(Box::new(CustomCallingConventionContext {
raw_handle: ptr::null_mut(),
cc: cc,
@@ -438,6 +440,10 @@ impl<A: Architecture> CallingConvention<A> {
_arch: PhantomData,
})
}
+
+ pub fn name(&self) -> BnString {
+ unsafe { BnString::from_raw(BNGetCallingConventionName(self.handle)) }
+ }
}
impl<A: Architecture> Eq for CallingConvention<A> {}
@@ -580,6 +586,32 @@ unsafe impl<A: Architecture> RefCountable for CallingConvention<A> {
}
}
+impl<A: Architecture> CoreArrayProvider for CallingConvention<A> {
+ type Raw = *mut BNCallingConvention;
+ type Context = A::Handle;
+}
+
+unsafe impl<A: Architecture> CoreOwnedArrayProvider for CallingConvention<A> {
+ unsafe fn free(raw: *mut *mut BNCallingConvention, count: usize, _content: &Self::Context) {
+ BNFreeCallingConventionList(raw, count);
+ }
+}
+
+unsafe impl<'a, A: Architecture> CoreArrayWrapper<'a> for CallingConvention<A> {
+ type Wrapped = Guard<'a, CallingConvention<A>>;
+
+ unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped {
+ Guard::new(
+ CallingConvention {
+ handle: *raw,
+ arch_handle: context.clone(),
+ _arch: Default::default(),
+ },
+ context,
+ )
+ }
+}
+
pub struct ConventionBuilder<A: Architecture> {
caller_saved_registers: Vec<A::Register>,
_callee_saved_registers: Vec<A::Register>,
diff --git a/rust/src/command.rs b/rust/src/command.rs
index 4763fee2..53ec9771 100644
--- a/rust/src/command.rs
+++ b/rust/src/command.rs
@@ -119,8 +119,8 @@ where
})
}
- let name = name.as_bytes_with_nul();
- let desc = desc.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
+ let desc = desc.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -217,8 +217,8 @@ where
})
}
- let name = name.as_bytes_with_nul();
- let desc = desc.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
+ let desc = desc.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -320,8 +320,8 @@ where
})
}
- let name = name.as_bytes_with_nul();
- let desc = desc.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
+ let desc = desc.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -428,8 +428,8 @@ where
})
}
- let name = name.as_bytes_with_nul();
- let desc = desc.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
+ let desc = desc.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs
index 13470517..443d6384 100644
--- a/rust/src/custombinaryview.rs
+++ b/rust/src/custombinaryview.rs
@@ -115,10 +115,10 @@ where
})
}
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
- let long_name = long_name.as_bytes_with_nul();
+ let long_name = long_name.into_bytes_with_nul();
let long_name_ptr = long_name.as_ref().as_ptr() as *mut _;
let ctxt = Box::new(unsafe { mem::zeroed() });
@@ -232,7 +232,7 @@ impl BinaryViewType {
/// Looks up a BinaryViewType by its short name
pub fn by_name<N: BnStrCompatible>(name: N) -> Result<Self> {
- let bytes = name.as_bytes_with_nul();
+ let bytes = name.into_bytes_with_nul();
let res = unsafe { BNGetBinaryViewTypeByName(bytes.as_ref().as_ptr() as *const _) };
diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs
index f780973c..08453b2d 100644
--- a/rust/src/debuginfo.rs
+++ b/rust/src/debuginfo.rs
@@ -97,7 +97,7 @@ impl DebugInfoParser {
/// Returns debug info parser of the given name, if it exists
pub fn from_name<S: BnStrCompatible>(name: S) -> Result<Ref<Self>, ()> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let parser = unsafe { BNGetDebugInfoParserByName(name.as_ref().as_ptr() as *mut _) };
if parser.is_null() {
@@ -185,7 +185,7 @@ impl DebugInfoParser {
})
}
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let ctxt = Box::into_raw(Box::new(parser_callbacks));
@@ -370,7 +370,7 @@ impl DebugInfo {
/// Returns a generator of all types provided by a named DebugInfoParser
pub fn types_by_name<S: BnStrCompatible>(&self, parser_name: S) -> Vec<NameAndType<String>> {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
let mut count: usize = 0;
let debug_types_ptr = unsafe {
@@ -411,7 +411,7 @@ impl DebugInfo {
&self,
parser_name: S,
) -> Vec<DebugFunctionInfo<CoreArchitecture, String, String>> {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
let mut count: usize = 0;
let functions_ptr = unsafe {
@@ -455,7 +455,7 @@ impl DebugInfo {
&self,
parser_name: S,
) -> Vec<DataVariableAndName<String>> {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
let mut count: usize = 0;
let data_variables_ptr = unsafe {
@@ -496,8 +496,8 @@ impl DebugInfo {
/// May return nullptr
pub fn type_by_name<S: BnStrCompatible>(&self, parser_name: S, name: S) -> Option<Ref<Type>> {
- let parser_name = parser_name.as_bytes_with_nul();
- let name = name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let result = unsafe {
BNGetDebugTypeByName(
@@ -518,8 +518,8 @@ impl DebugInfo {
parser_name: S,
name: S,
) -> Option<(u64, Ref<Type>)> {
- let parser_name = parser_name.as_bytes_with_nul();
- let name = name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let result = unsafe {
BNGetDebugDataVariableByName(
@@ -542,7 +542,7 @@ impl DebugInfo {
parser_name: S,
address: u64,
) -> Option<(String, Ref<Type>)> {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
let name_and_var = unsafe {
BNGetDebugDataVariableByAddress(
self.handle,
@@ -567,7 +567,7 @@ impl DebugInfo {
// The tuple is (DebugInfoParserName, type)
pub fn get_types_by_name<S: BnStrCompatible>(&self, name: S) -> Vec<(String, Ref<Type>)> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let mut count: usize = 0;
let raw_names_and_types = unsafe {
@@ -596,7 +596,7 @@ impl DebugInfo {
&self,
name: S,
) -> Vec<(String, u64, Ref<Type>)> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let mut count: usize = 0;
let raw_variables_and_names = unsafe {
@@ -646,19 +646,19 @@ impl DebugInfo {
}
pub fn remove_parser_info<S: BnStrCompatible>(&self, parser_name: S) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe { BNRemoveDebugParserInfo(self.handle, parser_name.as_ref().as_ptr() as *mut _) }
}
pub fn remove_parser_types<S: BnStrCompatible>(&self, parser_name: S) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe { BNRemoveDebugParserTypes(self.handle, parser_name.as_ref().as_ptr() as *mut _) }
}
pub fn remove_parser_functions<S: BnStrCompatible>(&self, parser_name: S) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe {
BNRemoveDebugParserFunctions(self.handle, parser_name.as_ref().as_ptr() as *mut _)
@@ -666,7 +666,7 @@ impl DebugInfo {
}
pub fn remove_parser_data_variables<S: BnStrCompatible>(&self, parser_name: S) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe {
BNRemoveDebugParserDataVariables(self.handle, parser_name.as_ref().as_ptr() as *mut _)
@@ -674,8 +674,8 @@ impl DebugInfo {
}
pub fn remove_type_by_name<S: BnStrCompatible>(&self, parser_name: S, name: S) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
- let name = name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNRemoveDebugTypeByName(
@@ -691,7 +691,7 @@ impl DebugInfo {
parser_name: S,
index: usize,
) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe {
BNRemoveDebugFunctionByIndex(
@@ -707,7 +707,7 @@ impl DebugInfo {
parser_name: S,
address: u64,
) -> bool {
- let parser_name = parser_name.as_bytes_with_nul();
+ let parser_name = parser_name.into_bytes_with_nul();
unsafe {
BNRemoveDebugDataVariableByAddress(
@@ -720,7 +720,7 @@ impl DebugInfo {
/// Adds a type scoped under the current parser's name to the debug info
pub fn add_type<S: BnStrCompatible>(&mut self, name: S, new_type: &Type) -> bool {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddDebugType(
self.handle,
@@ -737,19 +737,19 @@ impl DebugInfo {
) -> bool {
let parameter_count: usize = new_func.parameters.len();
- let short_name_bytes = new_func.short_name.map(|name| name.as_bytes_with_nul());
+ let short_name_bytes = new_func.short_name.map(|name| name.into_bytes_with_nul());
let short_name = short_name_bytes
.as_ref()
.map_or(ptr::null_mut() as *mut _, |name| {
name.as_ref().as_ptr() as *mut _
});
- let full_name_bytes = new_func.full_name.map(|name| name.as_bytes_with_nul());
+ let full_name_bytes = new_func.full_name.map(|name| name.into_bytes_with_nul());
let full_name = full_name_bytes
.as_ref()
.map_or(ptr::null_mut() as *mut _, |name| {
name.as_ref().as_ptr() as *mut _
});
- let raw_name_bytes = new_func.raw_name.map(|name| name.as_bytes_with_nul());
+ let raw_name_bytes = new_func.raw_name.map(|name| name.into_bytes_with_nul());
let raw_name = raw_name_bytes
.as_ref()
.map_or(ptr::null_mut() as *mut _, |name| {
@@ -767,7 +767,7 @@ impl DebugInfo {
Vec::with_capacity(parameter_count),
),
|(mut parameter_names, mut parameter_types, mut name_refs), (n, t)| {
- let name_ref = n.as_bytes_with_nul();
+ let name_ref = n.into_bytes_with_nul();
parameter_names.push(name_ref.as_ref().as_ptr() as *mut _);
name_refs.push(name_ref);
parameter_types.push(t.handle);
@@ -819,7 +819,7 @@ impl DebugInfo {
) -> bool {
match name {
Some(name) => {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddDebugDataVariable(
self.handle,
diff --git a/rust/src/demangle.rs b/rust/src/demangle.rs
index 2a1bff0d..8987a7bb 100644
--- a/rust/src/demangle.rs
+++ b/rust/src/demangle.rs
@@ -30,7 +30,7 @@ pub fn demangle_gnu3<S: BnStrCompatible>(
mangled_name: S,
simplify: bool,
) -> Result<(Option<Ref<Type>>, Vec<String>)> {
- let mangled_name_bwn = mangled_name.as_bytes_with_nul();
+ let mangled_name_bwn = mangled_name.into_bytes_with_nul();
let mangled_name_ptr = mangled_name_bwn.as_ref();
let mut out_type: *mut BNType = unsafe { std::mem::zeroed() };
let mut out_name: *mut *mut std::os::raw::c_char = unsafe { std::mem::zeroed() };
@@ -85,7 +85,7 @@ pub fn demangle_ms<S: BnStrCompatible>(
mangled_name: S,
simplify: bool,
) -> Result<(Option<Ref<Type>>, Vec<String>)> {
- let mangled_name_bwn = mangled_name.as_bytes_with_nul();
+ let mangled_name_bwn = mangled_name.into_bytes_with_nul();
let mangled_name_ptr = mangled_name_bwn.as_ref();
let mut out_type: *mut BNType = unsafe { std::mem::zeroed() };
diff --git a/rust/src/filemetadata.rs b/rust/src/filemetadata.rs
index 5745e857..b3ea655d 100644
--- a/rust/src/filemetadata.rs
+++ b/rust/src/filemetadata.rs
@@ -91,7 +91,7 @@ impl FileMetadata {
}
pub fn set_filename<S: BnStrCompatible>(&self, name: S) {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNSetFilename(self.handle, name.as_ref().as_ptr() as *mut _);
@@ -119,7 +119,7 @@ impl FileMetadata {
}
pub fn is_database_backed<S: BnStrCompatible>(&self, view_type: S) -> bool {
- let view_type = view_type.as_bytes_with_nul();
+ let view_type = view_type.into_bytes_with_nul();
unsafe { BNIsBackedByDatabase(self.handle, view_type.as_ref().as_ptr() as *const _) }
}
@@ -157,7 +157,7 @@ impl FileMetadata {
}
pub fn navigate_to<S: BnStrCompatible>(&self, view: S, offset: u64) -> Result<(), ()> {
- let view = view.as_bytes_with_nul();
+ let view = view.into_bytes_with_nul();
unsafe {
if BNNavigate(self.handle, view.as_ref().as_ptr() as *const _, offset) {
@@ -169,7 +169,7 @@ impl FileMetadata {
}
pub fn get_view_of_type<S: BnStrCompatible>(&self, view: S) -> Result<Ref<BinaryView>, ()> {
- let view = view.as_bytes_with_nul();
+ let view = view.into_bytes_with_nul();
unsafe {
let res = BNGetFileViewOfType(self.handle, view.as_ref().as_ptr() as *const _);
@@ -183,8 +183,8 @@ impl FileMetadata {
}
pub fn create_database<S: BnStrCompatible>(&self, filename: S) -> bool {
- let filename = filename.as_bytes_with_nul();
- let raw = "Raw".as_bytes_with_nul();
+ let filename = filename.into_bytes_with_nul();
+ let raw = "Raw".into_bytes_with_nul();
unsafe {
BNCreateDatabase(
@@ -196,7 +196,7 @@ impl FileMetadata {
}
pub fn save_auto_snapshot(&self) -> bool {
- let raw = "Raw".as_bytes_with_nul();
+ let raw = "Raw".into_bytes_with_nul();
unsafe {
BNSaveAutoSnapshot(
BNGetFileViewOfType(self.handle, raw.as_ptr() as *mut _),
@@ -209,7 +209,7 @@ impl FileMetadata {
&self,
filename: S,
) -> Result<Ref<BinaryView>, ()> {
- let filename = filename.as_bytes_with_nul();
+ let filename = filename.into_bytes_with_nul();
unsafe {
let bv =
BNOpenDatabaseForConfiguration(self.handle, filename.as_ref().as_ptr() as *const _);
@@ -223,7 +223,7 @@ impl FileMetadata {
}
pub fn open_database<S: BnStrCompatible>(&self, filename: S) -> Result<Ref<BinaryView>, ()> {
- let filename = filename.as_bytes_with_nul();
+ let filename = filename.into_bytes_with_nul();
let filename_ptr = filename.as_ref().as_ptr() as *mut _;
let view = unsafe { BNOpenExistingDatabase(self.handle, filename_ptr) };
diff --git a/rust/src/function.rs b/rust/src/function.rs
index 079d0ae5..16debf18 100644
--- a/rust/src/function.rs
+++ b/rust/src/function.rs
@@ -164,7 +164,7 @@ impl Function {
}
pub fn set_comment<S: BnStrCompatible>(&self, comment: S) {
- let raw = comment.as_bytes_with_nul();
+ let raw = comment.into_bytes_with_nul();
unsafe {
BNSetFunctionComment(self.handle, raw.as_ref().as_ptr() as *mut _);
@@ -176,7 +176,7 @@ impl Function {
}
pub fn set_comment_at<S: BnStrCompatible>(&self, addr: u64, comment: S) {
- let raw = comment.as_bytes_with_nul();
+ let raw = comment.into_bytes_with_nul();
unsafe {
BNSetCommentForAddress(self.handle, addr, raw.as_ref().as_ptr() as *mut _);
diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs
index f7d5e45e..acc77a14 100644
--- a/rust/src/metadata.rs
+++ b/rust/src/metadata.rs
@@ -257,7 +257,7 @@ impl Metadata {
let ptr: *mut BNMetadata = unsafe {
BNMetadataGetForKey(
self.handle,
- key.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ key.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
)
};
if ptr.is_null() {
@@ -282,7 +282,7 @@ impl Metadata {
unsafe {
BNMetadataSetValueForKey(
self.handle,
- key.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ key.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
value.handle,
)
};
@@ -306,7 +306,7 @@ impl Metadata {
unsafe {
BNMetadataRemoveKey(
self.handle,
- key.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ key.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
)
};
Ok(())
@@ -389,7 +389,7 @@ impl<S: BnStrCompatible> From<S> for Ref<Metadata> {
fn from(value: S) -> Self {
unsafe {
Metadata::ref_from_raw(BNCreateMetadataStringData(
- value.as_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ value.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
))
}
}
@@ -431,7 +431,7 @@ impl<S: BnStrCompatible> From<HashMap<S, Ref<Metadata>>> for Ref<Metadata> {
let mut keys: Vec<*const c_char> = vec![];
let mut values: Vec<*mut BNMetadata> = vec![];
for (k, v) in value.into_iter() {
- key_refs.push(k.as_bytes_with_nul());
+ key_refs.push(k.into_bytes_with_nul());
values.push(v.as_ref().handle);
}
for k in &key_refs {
@@ -496,7 +496,7 @@ impl<S: BnStrCompatible> From<Vec<S>> for Ref<Metadata> {
fn from(value: Vec<S>) -> Self {
let mut refs = vec![];
for v in value {
- refs.push(v.as_bytes_with_nul());
+ refs.push(v.into_bytes_with_nul());
}
let mut pointers = vec![];
for r in &refs {
diff --git a/rust/src/platform.rs b/rust/src/platform.rs
index 6bdf8c9f..3f33a056 100644
--- a/rust/src/platform.rs
+++ b/rust/src/platform.rs
@@ -73,7 +73,7 @@ impl Platform {
}
pub fn by_name<S: BnStrCompatible>(name: S) -> Option<Ref<Self>> {
- let raw_name = name.as_bytes_with_nul();
+ let raw_name = name.into_bytes_with_nul();
unsafe {
let res = BNGetPlatformByName(raw_name.as_ref().as_ptr() as *mut _);
@@ -104,7 +104,7 @@ impl Platform {
}
pub fn list_by_os<S: BnStrCompatible>(name: S) -> Array<Platform> {
- let raw_name = name.as_bytes_with_nul();
+ let raw_name = name.into_bytes_with_nul();
unsafe {
let mut count = 0;
@@ -118,7 +118,7 @@ impl Platform {
name: S,
arch: &CoreArchitecture,
) -> Array<Platform> {
- let raw_name = name.as_bytes_with_nul();
+ let raw_name = name.into_bytes_with_nul();
unsafe {
let mut count = 0;
@@ -142,7 +142,7 @@ impl Platform {
}
pub fn new<A: Architecture, S: BnStrCompatible>(arch: &A, name: S) -> Ref<Self> {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
let handle = BNCreatePlatform(arch.as_ref().0, name.as_ref().as_ptr() as *mut _);
@@ -164,7 +164,7 @@ impl Platform {
}
pub fn register_os<S: BnStrCompatible>(&self, os: S) {
- let os = os.as_bytes_with_nul();
+ let os = os.into_bytes_with_nul();
unsafe {
BNRegisterPlatform(os.as_ref().as_ptr() as *mut _, self.handle);
@@ -206,6 +206,15 @@ impl Platform {
BNSetPlatformSystemCallConvention
);
+ pub fn calling_conventions(&self) -> Array<CallingConvention<CoreArchitecture>> {
+ unsafe {
+ let mut count = 0;
+ let handles = BNGetPlatformCallingConventions(self.handle, &mut count);
+
+ Array::new(handles, count, self.arch())
+ }
+ }
+
pub fn types(&self) -> Array<QualifiedNameAndType> {
unsafe {
let mut count = 0;
@@ -274,14 +283,18 @@ impl TypeParser for Platform {
let mut error_string: *mut raw::c_char = ptr::null_mut();
- let src = source.as_bytes_with_nul();
- let filename = filename.as_bytes_with_nul();
- let auto_type_source = auto_type_source.as_bytes_with_nul();
+ let src = source.into_bytes_with_nul();
+ let filename = filename.into_bytes_with_nul();
+ let auto_type_source = auto_type_source.into_bytes_with_nul();
let mut include_dirs = vec![];
for dir in include_directories.iter() {
- let d = dir.as_ref().to_string_lossy().to_string().as_bytes_with_nul();
+ let d = dir
+ .as_ref()
+ .to_string_lossy()
+ .to_string()
+ .into_bytes_with_nul();
include_dirs.push(d.as_ptr() as _);
}
diff --git a/rust/src/rc.rs b/rust/src/rc.rs
index b21b7b94..a65403e2 100644
--- a/rust/src/rc.rs
+++ b/rust/src/rc.rs
@@ -135,6 +135,15 @@ impl<'a, T> Guard<'a, T> {
}
}
+impl<'a, T> Guard<'a, T>
+where
+ T: RefCountable,
+{
+ pub fn clone(&self) -> Ref<T> {
+ unsafe { <T as RefCountable>::inc_ref(&self.contents) }
+ }
+}
+
impl<'a, T> AsRef<T> for Guard<'a, T> {
fn as_ref(&self) -> &T {
&self.contents
diff --git a/rust/src/section.rs b/rust/src/section.rs
index 9790801c..da43763d 100644
--- a/rust/src/section.rs
+++ b/rust/src/section.rs
@@ -245,10 +245,10 @@ impl<S: BnStrCompatible> SectionBuilder<S> {
}
pub(crate) fn create(self, view: &BinaryView) {
- let name = self.name.as_bytes_with_nul();
- let ty = self._ty.map(|s| s.as_bytes_with_nul());
- let linked_section = self.linked_section.map(|s| s.as_bytes_with_nul());
- let info_section = self.info_section.map(|s| s.as_bytes_with_nul());
+ let name = self.name.into_bytes_with_nul();
+ let ty = self._ty.map(|s| s.into_bytes_with_nul());
+ let linked_section = self.linked_section.map(|s| s.into_bytes_with_nul());
+ let info_section = self.info_section.map(|s| s.into_bytes_with_nul());
let start = self.range.start;
let len = self.range.end.wrapping_sub(start);
diff --git a/rust/src/settings.rs b/rust/src/settings.rs
index 83aa2df0..ba84acb7 100644
--- a/rust/src/settings.rs
+++ b/rust/src/settings.rs
@@ -41,7 +41,7 @@ impl Settings {
}
pub fn new<S: BnStrCompatible>(instance_id: S) -> Ref<Self> {
- let instance_id = instance_id.as_bytes_with_nul();
+ let instance_id = instance_id.into_bytes_with_nul();
unsafe {
let handle = BNCreateSettings(instance_id.as_ref().as_ptr() as *mut _);
@@ -52,7 +52,7 @@ impl Settings {
}
pub fn set_resource_id<S: BnStrCompatible>(&self, resource_id: S) {
- let resource_id = resource_id.as_bytes_with_nul();
+ let resource_id = resource_id.into_bytes_with_nul();
unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ref().as_ptr() as *mut _) };
}
@@ -61,7 +61,7 @@ impl Settings {
}
pub fn deserialize_schema<S: BnStrCompatible>(&self, schema: S) -> bool {
- let schema = schema.as_bytes_with_nul();
+ let schema = schema.into_bytes_with_nul();
unsafe {
BNSettingsDeserializeSchema(
self.handle,
@@ -73,7 +73,7 @@ impl Settings {
}
pub fn contains<S: BnStrCompatible>(&self, key: S) -> bool {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
unsafe { BNSettingsContains(self.handle, key.as_ref().as_ptr() as *mut _) }
}
@@ -84,7 +84,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> bool {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -109,7 +109,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> f64 {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -134,7 +134,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> u64 {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -159,7 +159,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> BnString {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -184,7 +184,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> Array<BnString> {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -215,7 +215,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<Box<SettingsScope>>,
) -> BnString {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -241,7 +241,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -268,7 +268,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -295,7 +295,7 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -322,8 +322,8 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) {
- let key = key.as_bytes_with_nul();
- let value = value.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
+ let value = value.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
_ => ptr::null_mut() as *mut _,
@@ -350,12 +350,12 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) -> bool {
- let key = key.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
let v = Vec::from_iter(value);
let mut value = vec![];
for item in v {
- value.push(item.as_bytes_with_nul().as_ref().as_ptr() as *const c_char);
+ value.push(item.into_bytes_with_nul().as_ref().as_ptr() as *const c_char);
}
let view_handle = match view {
@@ -387,8 +387,8 @@ impl Settings {
view: Option<&BinaryView>,
scope: Option<SettingsScope>,
) -> bool {
- let key = key.as_bytes_with_nul();
- let value = value.as_bytes_with_nul();
+ let key = key.into_bytes_with_nul();
+ let value = value.into_bytes_with_nul();
let view_handle = match view {
Some(view) => view.handle,
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 42ff4fdc..965d21f3 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -99,7 +99,7 @@ impl BnString {
pub fn new<S: BnStrCompatible>(s: S) -> Self {
use binaryninjacore_sys::BNAllocString;
- let raw = s.as_bytes_with_nul();
+ let raw = s.into_bytes_with_nul();
unsafe {
let ptr = raw.as_ref().as_ptr() as *mut _;
@@ -110,6 +110,7 @@ impl BnString {
}
}
+ /// Construct a BnString from an owned const char* allocated by BNAllocString
pub(crate) unsafe fn from_raw(raw: *mut raw::c_char) -> Self {
Self { raw }
}
@@ -212,13 +213,13 @@ unsafe impl<'a> CoreArrayWrapper<'a> for BnString {
pub unsafe trait BnStrCompatible {
type Result: AsRef<[u8]>;
- fn as_bytes_with_nul(self) -> Self::Result;
+ fn into_bytes_with_nul(self) -> Self::Result;
}
unsafe impl<'a> BnStrCompatible for &'a BnStr {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.as_cstr().to_bytes_with_nul()
}
}
@@ -226,7 +227,7 @@ unsafe impl<'a> BnStrCompatible for &'a BnStr {
unsafe impl BnStrCompatible for BnString {
type Result = Self;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self
}
}
@@ -234,7 +235,7 @@ unsafe impl BnStrCompatible for BnString {
unsafe impl<'a> BnStrCompatible for &'a CStr {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.to_bytes_with_nul()
}
}
@@ -242,7 +243,7 @@ unsafe impl<'a> BnStrCompatible for &'a CStr {
unsafe impl BnStrCompatible for CString {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.into_bytes_with_nul()
}
}
@@ -250,7 +251,7 @@ unsafe impl BnStrCompatible for CString {
unsafe impl<'a> BnStrCompatible for &'a str {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
let ret = CString::new(self).expect("can't pass strings with internal nul bytes to core!");
ret.into_bytes_with_nul()
}
@@ -259,7 +260,7 @@ unsafe impl<'a> BnStrCompatible for &'a str {
unsafe impl BnStrCompatible for String {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
let ret = CString::new(self).expect("can't pass strings with internal nul bytes to core!");
ret.into_bytes_with_nul()
}
@@ -268,7 +269,7 @@ unsafe impl BnStrCompatible for String {
unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.as_ref().as_bytes()
}
}
@@ -276,7 +277,7 @@ unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
unsafe impl BnStrCompatible for &QualifiedName {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
- self.string().as_bytes_with_nul()
+ fn into_bytes_with_nul(self) -> Self::Result {
+ self.string().into_bytes_with_nul()
}
}
diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs
index 27e701dc..21ae440e 100644
--- a/rust/src/symbol.rs
+++ b/rust/src/symbol.rs
@@ -134,9 +134,9 @@ impl<S: BnStrCompatible> SymbolBuilder<S> {
}
pub fn create(self) -> Ref<Symbol> {
- let raw_name = self.raw_name.as_bytes_with_nul();
- let short_name = self.short_name.map(|s| s.as_bytes_with_nul());
- let full_name = self.full_name.map(|s| s.as_bytes_with_nul());
+ let raw_name = self.raw_name.into_bytes_with_nul();
+ let short_name = self.short_name.map(|s| s.into_bytes_with_nul());
+ let full_name = self.full_name.map(|s| s.into_bytes_with_nul());
unsafe {
let raw_name = raw_name.as_ref().as_ptr() as *mut _;
diff --git a/rust/src/tags.rs b/rust/src/tags.rs
index d215ec1b..6f1f5fba 100644
--- a/rust/src/tags.rs
+++ b/rust/src/tags.rs
@@ -33,7 +33,7 @@ impl Tag {
}
pub fn new<S: BnStrCompatible>(t: &TagType, data: S) -> Ref<Self> {
- let data = data.as_bytes_with_nul();
+ let data = data.into_bytes_with_nul();
unsafe { Self::from_raw(BNCreateTag(t.handle, data.as_ref().as_ptr() as *mut _)) }
}
@@ -50,7 +50,7 @@ impl Tag {
}
pub fn set_data<S: BnStrCompatible>(&self, data: S) {
- let data = data.as_bytes_with_nul();
+ let data = data.into_bytes_with_nul();
unsafe {
BNTagSetData(self.handle, data.as_ref().as_ptr() as *mut _);
}
@@ -119,7 +119,7 @@ impl TagType {
}
pub fn set_icon<S: BnStrCompatible>(&self, icon: S) {
- let icon = icon.as_bytes_with_nul();
+ let icon = icon.into_bytes_with_nul();
unsafe {
BNTagTypeSetName(self.handle, icon.as_ref().as_ptr() as *mut _);
}
@@ -130,7 +130,7 @@ impl TagType {
}
pub fn set_name<S: BnStrCompatible>(&self, name: S) {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNTagTypeSetName(self.handle, name.as_ref().as_ptr() as *mut _);
}
@@ -149,7 +149,7 @@ impl TagType {
}
pub fn set_type<S: BnStrCompatible>(&self, t: S) {
- let t = t.as_bytes_with_nul();
+ let t = t.into_bytes_with_nul();
unsafe {
BNTagTypeSetName(self.handle, t.as_ref().as_ptr() as *mut _);
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 9e7d20f2..90abeb41 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -21,7 +21,7 @@ use std::borrow::Cow;
use std::ffi::CStr;
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
-use std::iter::IntoIterator;
+use std::iter::{zip, IntoIterator};
use std::os::raw::c_char;
use std::{fmt, mem, ptr, result, slice};
@@ -88,6 +88,12 @@ impl<'a, T> From<&'a Conf<T>> for Conf<&'a T> {
}
}
+impl<'a, T: RefCountable> From<&'a Conf<Ref<T>>> for Conf<&'a T> {
+ fn from(c: &'a Conf<Ref<T>>) -> Self {
+ Conf::new(c.contents.as_ref(), c.confidence)
+ }
+}
+
#[inline]
pub fn min_confidence() -> u8 {
u8::MIN
@@ -397,7 +403,7 @@ impl TypeBuilder {
pub fn named_int<S: BnStrCompatible>(width: usize, is_signed: bool, alt_name: S) -> Self {
let mut is_signed = Conf::new(is_signed, max_confidence()).into();
// let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.as_bytes_with_nul(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
+ let alt_name = alt_name.into_bytes_with_nul(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
unsafe {
Self::from_raw(BNCreateIntegerTypeBuilder(
@@ -419,7 +425,7 @@ impl TypeBuilder {
pub fn named_float<S: BnStrCompatible>(width: usize, alt_name: S) -> Self {
// let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.as_bytes_with_nul(); // See same line in `named_int` above
+ let alt_name = alt_name.into_bytes_with_nul(); // See same line in `named_int` above
unsafe {
Self::from_raw(BNCreateFloatTypeBuilder(
@@ -785,7 +791,7 @@ impl Type {
pub fn named_int<S: BnStrCompatible>(width: usize, is_signed: bool, alt_name: S) -> Ref<Self> {
let mut is_signed = Conf::new(is_signed, max_confidence()).into();
// let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.as_bytes_with_nul(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
+ let alt_name = alt_name.into_bytes_with_nul(); // This segfaulted once, so the above version is there if we need to change to it, but in theory this is copied into a `const string&` on the C++ side; I'm just not 100% confident that a constant reference copies data
unsafe {
Self::ref_from_raw(BNCreateIntegerType(
@@ -807,7 +813,7 @@ impl Type {
pub fn named_float<S: BnStrCompatible>(width: usize, alt_name: S) -> Ref<Self> {
// let alt_name = BnString::new(alt_name);
- let alt_name = alt_name.as_bytes_with_nul(); // See same line in `named_int` above
+ let alt_name = alt_name.into_bytes_with_nul(); // See same line in `named_int` above
unsafe { Self::ref_from_raw(BNCreateFloatType(width, alt_name.as_ref().as_ptr() as _)) }
}
@@ -885,7 +891,7 @@ 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().as_bytes_with_nul();
+ let raw_name = parameter.name.clone().into_bytes_with_nul();
let location = match &parameter.location {
Some(location) => location.into_raw(),
None => unsafe { mem::zeroed() },
@@ -930,26 +936,32 @@ impl Type {
pub fn function_with_options<
'a,
A: Architecture,
- S: BnStrCompatible + Copy,
+ S: BnStrCompatible + Clone,
T: Into<Conf<&'a Type>>,
+ C: Into<Conf<&'a CallingConvention<A>>>,
>(
return_type: T,
parameters: &[FunctionParameter<S>],
variable_arguments: bool,
- calling_convention: Conf<&CallingConvention<A>>,
+ calling_convention: C,
stack_adjust: Conf<i64>,
) -> Ref<Self> {
let mut return_type = return_type.into().into();
let mut variable_arguments = Conf::new(variable_arguments, max_confidence()).into();
let mut can_return = Conf::new(true, min_confidence()).into();
let mut raw_calling_convention: BNCallingConventionWithConfidence =
- calling_convention.into();
+ calling_convention.into().into();
let mut stack_adjust = stack_adjust.into();
let mut raw_parameters = Vec::<BNFunctionParameter>::with_capacity(parameters.len());
let mut parameter_name_references = Vec::with_capacity(parameters.len());
+ let mut name_ptrs = vec![];
for parameter in parameters {
- let raw_name = parameter.name.as_bytes_with_nul();
+ name_ptrs.push(parameter.name.clone());
+ }
+
+ for (name, parameter) in zip(name_ptrs, parameters) {
+ let raw_name = name.into_bytes_with_nul();
let location = match &parameter.location {
Some(location) => location.into_raw(),
None => unsafe { mem::zeroed() },
@@ -1124,6 +1136,7 @@ impl ToOwned for Type {
///////////////////////
// FunctionParameter
+#[derive(Clone, Debug)]
pub struct FunctionParameter<S: BnStrCompatible> {
pub t: Conf<Ref<Type>>,
pub name: S,
@@ -1172,6 +1185,7 @@ impl FunctionParameter<BnString> {
//////////////
// Variable
+#[derive(Clone, Copy, Debug)]
pub struct Variable {
pub t: BNVariableSourceType,
pub index: u32,
@@ -1248,7 +1262,7 @@ impl EnumerationBuilder {
}
pub fn append<'a, S: BnStrCompatible>(&'a mut self, name: S) -> &'a mut Self {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddEnumerationBuilderMember(self.handle, name.as_ref().as_ptr() as _);
}
@@ -1256,7 +1270,7 @@ impl EnumerationBuilder {
}
pub fn insert<'a, S: BnStrCompatible>(&'a mut self, name: S, value: u64) -> &'a mut Self {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddEnumerationBuilderMemberWithValue(self.handle, name.as_ref().as_ptr() as _, value);
}
@@ -1269,7 +1283,7 @@ impl EnumerationBuilder {
name: S,
value: u64,
) -> &'a mut Self {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNReplaceEnumerationBuilderMember(self.handle, id, name.as_ref().as_ptr() as _, value);
}
@@ -1453,7 +1467,7 @@ impl StructureBuilder {
access: MemberAccess,
scope: MemberScope,
) -> &'a mut Self {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddStructureBuilderMember(
self.handle,
@@ -1493,7 +1507,7 @@ impl StructureBuilder {
access: MemberAccess,
scope: MemberScope,
) -> &'a mut Self {
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
unsafe {
BNAddStructureBuilderMemberAtOffset(
self.handle,
@@ -1718,7 +1732,7 @@ impl NamedTypeReference {
type_id: S,
mut name: QualifiedName,
) -> Self {
- let type_id = type_id.as_bytes_with_nul();
+ let type_id = type_id.into_bytes_with_nul();
Self {
handle: unsafe {
@@ -1770,7 +1784,7 @@ impl QualifiedName {
impl<S: BnStrCompatible> From<S> for QualifiedName {
fn from(name: S) -> Self {
let join = BnString::new("::");
- let name = name.as_bytes_with_nul();
+ let name = name.into_bytes_with_nul();
let mut list = vec![name.as_ref().as_ptr() as *const _];
QualifiedName(BNQualifiedName {
@@ -1786,7 +1800,7 @@ impl<S: BnStrCompatible> From<Vec<S>> for QualifiedName {
let join = BnString::new("::");
let names = names
.into_iter()
- .map(|n| n.as_bytes_with_nul())
+ .map(|n| n.into_bytes_with_nul())
.collect::<Vec<_>>();
let mut list = names
.iter()