summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/msp430/src/flag.rs8
-rw-r--r--arch/riscv/disasm/src/lib.rs4
-rw-r--r--arch/riscv/src/lib.rs4
-rw-r--r--plugins/idb_import/src/types.rs2
-rw-r--r--plugins/warp/src/cache/type_reference.rs2
-rw-r--r--plugins/warp/src/convert/types.rs2
-rw-r--r--plugins/warp/src/lib.rs2
-rw-r--r--plugins/warp/src/plugin.rs4
-rw-r--r--rust/src/base_detection.rs38
-rw-r--r--rust/src/binary_view.rs2
-rw-r--r--rust/src/binary_view/reader.rs17
-rw-r--r--rust/src/binary_view/writer.rs12
-rw-r--r--rust/src/data_buffer.rs2
-rw-r--r--rust/src/data_renderer.rs2
-rw-r--r--rust/src/language_representation.rs2
-rw-r--r--rust/src/line_formatter.rs2
-rw-r--r--rust/src/render_layer.rs8
17 files changed, 56 insertions, 57 deletions
diff --git a/arch/msp430/src/flag.rs b/arch/msp430/src/flag.rs
index 5baca412..698f3b19 100644
--- a/arch/msp430/src/flag.rs
+++ b/arch/msp430/src/flag.rs
@@ -16,7 +16,7 @@ pub enum Flag {
impl architecture::Flag for Flag {
type FlagClass = FlagClass;
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
match self {
Self::C => "c".into(),
Self::Z => "z".into(),
@@ -62,7 +62,7 @@ impl TryFrom<FlagId> for Flag {
pub struct FlagClass {}
impl architecture::FlagClass for FlagClass {
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
unimplemented!()
}
@@ -78,7 +78,7 @@ impl architecture::FlagGroup for FlagGroup {
type FlagType = Flag;
type FlagClass = FlagClass;
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
unimplemented!()
}
@@ -107,7 +107,7 @@ impl architecture::FlagWrite for FlagWrite {
type FlagType = Flag;
type FlagClass = FlagClass;
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
match self {
Self::All => "*".into(),
Self::Nz => "nz".into(),
diff --git a/arch/riscv/disasm/src/lib.rs b/arch/riscv/disasm/src/lib.rs
index 152817c6..c35e76d3 100644
--- a/arch/riscv/disasm/src/lib.rs
+++ b/arch/riscv/disasm/src/lib.rs
@@ -1775,7 +1775,7 @@ pub enum Instr<D: RiscVDisassembler> {
}
impl<D: RiscVDisassembler> Instr<D> {
- pub fn mnem(&self) -> Mnem<D> {
+ pub fn mnem(&self) -> Mnem<'_, D> {
Mnem(self)
}
@@ -2116,7 +2116,7 @@ impl<'a, D: RiscVDisassembler + 'a> Mnem<'a, D> {
}
}
- fn suffix(&self) -> Option<Cow<str>> {
+ fn suffix(&self) -> Option<Cow<'_, str>> {
match self.0 {
// &Instr::Rv16(_) => None,
&Instr::Rv32(ref op) | &Instr::Rv16(ref op) => match *op {
diff --git a/arch/riscv/src/lib.rs b/arch/riscv/src/lib.rs
index f59e1ebb..ef9e12e1 100644
--- a/arch/riscv/src/lib.rs
+++ b/arch/riscv/src/lib.rs
@@ -169,7 +169,7 @@ impl<D: RiscVDisassembler> RegisterInfo for Register<D> {
impl<D: RiscVDisassembler> architecture::Register for Register<D> {
type InfoType = Self;
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
match self.reg_type() {
RegType::Integer(id) => match id {
0 => "zero".into(),
@@ -393,7 +393,7 @@ impl<D: RiscVDisassembler> From<Intrinsic> for RiscVIntrinsic<D> {
}
impl<D: RiscVDisassembler> architecture::Intrinsic for RiscVIntrinsic<D> {
- fn name(&self) -> Cow<str> {
+ fn name(&self) -> Cow<'_, str> {
match self.id {
Intrinsic::Uret => "_uret".into(),
Intrinsic::Sret => "_sret".into(),
diff --git a/plugins/idb_import/src/types.rs b/plugins/idb_import/src/types.rs
index 77c089e9..933fec12 100644
--- a/plugins/idb_import/src/types.rs
+++ b/plugins/idb_import/src/types.rs
@@ -630,7 +630,7 @@ pub fn translate_til_types(
arch: CoreArchitecture,
til: &TILSection,
progress: impl Fn(usize, usize) -> Result<(), ()>,
-) -> Result<Vec<TranslatesIDBType>> {
+) -> Result<Vec<TranslatesIDBType<'_>>> {
let total = til.symbols.len() + til.types.len();
let mut types = Vec::with_capacity(total);
let mut types_by_ord = HashMap::with_capacity(total);
diff --git a/plugins/warp/src/cache/type_reference.rs b/plugins/warp/src/cache/type_reference.rs
index 0b07c139..2c59c2fb 100644
--- a/plugins/warp/src/cache/type_reference.rs
+++ b/plugins/warp/src/cache/type_reference.rs
@@ -39,7 +39,7 @@ pub fn cached_type_reference(
}
}
-pub fn cached_type_references(view: &BinaryView) -> Option<Ref<ViewID, TypeRefCache>> {
+pub fn cached_type_references(view: &BinaryView) -> Option<Ref<'_, ViewID, TypeRefCache>> {
let view_id = ViewID::from(view);
let type_ref_cache = TYPE_REF_CACHE.get_or_init(Default::default);
type_ref_cache.get(&view_id)
diff --git a/plugins/warp/src/convert/types.rs b/plugins/warp/src/convert/types.rs
index 2401a039..f8ead6af 100644
--- a/plugins/warp/src/convert/types.rs
+++ b/plugins/warp/src/convert/types.rs
@@ -281,7 +281,7 @@ pub fn to_bn_calling_convention<A: BNArchitecture>(
// Always pass the architecture unless you know what you're doing!
pub fn to_bn_type<A: BNArchitecture + Copy>(arch: Option<A>, ty: &Type) -> BNRef<BNType> {
- let bits_to_bytes = |val: u64| (val / 8);
+ let bits_to_bytes = |val: u64| val / 8;
let addr_size = arch.map(|a| a.address_size()).unwrap_or(8) as u64;
match &ty.class {
TypeClass::Void => BNType::void(),
diff --git a/plugins/warp/src/lib.rs b/plugins/warp/src/lib.rs
index 9f40acef..1e622d58 100644
--- a/plugins/warp/src/lib.rs
+++ b/plugins/warp/src/lib.rs
@@ -254,7 +254,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
pub fn filtered_instructions_at<M: FunctionMutability>(
il: &LowLevelILFunction<M, NonSSA>,
addr: u64,
-) -> Vec<LowLevelILInstruction<M, NonSSA>> {
+) -> Vec<LowLevelILInstruction<'_, M, NonSSA>> {
il.instructions_at(addr)
.into_iter()
.enumerate()
diff --git a/plugins/warp/src/plugin.rs b/plugins/warp/src/plugin.rs
index f384a6f5..9fe6cd3f 100644
--- a/plugins/warp/src/plugin.rs
+++ b/plugins/warp/src/plugin.rs
@@ -19,7 +19,6 @@ use log::LevelFilter;
mod commit;
mod create;
-mod debug;
mod ffi;
mod file;
mod function;
@@ -29,6 +28,9 @@ mod render_layer;
mod settings;
mod workflow;
+#[cfg(debug_assertions)]
+mod debug;
+
fn load_bundled_signatures() {
let global_bn_settings = Settings::new();
let plugin_settings =
diff --git a/rust/src/base_detection.rs b/rust/src/base_detection.rs
index c74f3f3a..51c47c96 100644
--- a/rust/src/base_detection.rs
+++ b/rust/src/base_detection.rs
@@ -1,8 +1,9 @@
use binaryninjacore_sys::*;
-use std::ffi::{c_char, CStr};
+use std::ffi::CStr;
use crate::architecture::CoreArchitecture;
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner};
+use crate::string::IntoCStr;
use std::num::NonZeroU32;
use std::ptr::NonNull;
@@ -11,7 +12,7 @@ pub type BaseAddressDetectionConfidence = BNBaseAddressDetectionConfidence;
pub type BaseAddressDetectionPOIType = BNBaseAddressDetectionPOIType;
/// This is the architecture name used to use the architecture auto-detection feature.
-const BASE_ADDRESS_AUTO_DETECTION_ARCH: &CStr = c"auto detect";
+const BASE_ADDRESS_AUTO_DETECTION_ARCH: &str = "auto detect";
pub enum BaseAddressDetectionAnalysis {
Basic,
@@ -149,23 +150,22 @@ impl Drop for BaseAddressDetection {
}
}
-/// Build the initial analysis.
-///
-/// * `analysis` - analysis mode
-/// * `min_strlen` - minimum length of a string to be considered a point-of-interest
-/// * `alignment` - byte boundary to align the base address to while brute-forcing
-/// * `low_boundary` - lower boundary of the base address range to test
-/// * `high_boundary` - upper boundary of the base address range to test
-/// * `poi_analysis` - specifies types of points-of-interest to use for analysis
-/// * `max_pointers` - maximum number of candidate pointers to collect per pointer cluster
+/// Builds the initial analysis settings for base address detection.
pub struct BaseAddressDetectionSettings {
arch: Option<CoreArchitecture>,
+ /// Analysis mode to use
analysis: BaseAddressDetectionAnalysis,
+ /// Minimum length of a string to be considered a point-of-interest
min_string_len: u32,
+ /// Byte boundary to align the base address to while brute-forcing
alignment: NonZeroU32,
+ /// Lower boundary of the base address range to test
lower_boundary: u64,
+ /// Upper boundary of the base address range to test
upper_boundary: u64,
+ /// Specifies types of points-of-interest to use for analysis
poi_analysis: BaseAddressDetectionPOISetting,
+ /// Maximum number of candidate pointers to collect per pointer cluster
max_pointers: u32,
}
@@ -173,10 +173,11 @@ impl BaseAddressDetectionSettings {
pub(crate) fn into_raw(value: &Self) -> BNBaseAddressDetectionSettings {
let arch_name = value
.arch
- .map(|a| a.name().as_ptr())
- .unwrap_or(BASE_ADDRESS_AUTO_DETECTION_ARCH.as_ptr() as *const u8);
+ .map(|a| a.name())
+ .unwrap_or(BASE_ADDRESS_AUTO_DETECTION_ARCH.to_string());
+ let c_arch_name = arch_name.to_cstr();
BNBaseAddressDetectionSettings {
- Architecture: arch_name as *const c_char,
+ Architecture: c_arch_name.into_raw(),
Analysis: value.analysis.as_raw().as_ptr(),
MinStrlen: value.min_string_len,
Alignment: value.alignment.get(),
@@ -207,6 +208,9 @@ impl BaseAddressDetectionSettings {
self
}
+ /// Specify the lower boundary of the base address range to test.
+ ///
+ /// NOTE: The passed `value` **must** be less than the upper boundary.
pub fn low_boundary(mut self, value: u64) -> Self {
assert!(
self.upper_boundary >= value,
@@ -216,6 +220,9 @@ impl BaseAddressDetectionSettings {
self
}
+ /// Specify the upper boundary of the base address range to test.
+ ///
+ /// NOTE: The passed `value` **must** be greater than the lower boundary.
pub fn high_boundary(mut self, value: u64) -> Self {
assert!(
self.lower_boundary <= value,
@@ -230,6 +237,9 @@ impl BaseAddressDetectionSettings {
self
}
+ /// Specify the maximum number of candidate pointers to collect per pointer cluster.
+ ///
+ /// NOTE: The passed `value` **must** be at least 2.
pub fn max_pointers(mut self, value: u32) -> Self {
assert!(value > 2, "max pointers must be at least 2");
self.max_pointers = value;
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs
index 0f2deb56..4b55e321 100644
--- a/rust/src/binary_view.rs
+++ b/rust/src/binary_view.rs
@@ -1392,7 +1392,7 @@ pub trait BinaryViewExt: BinaryViewBase {
for address in addresses {
let funcs = self.functions_at(address);
for func in funcs.into_iter() {
- if func.start() == address && plat.map_or(true, |p| p == func.platform().as_ref()) {
+ if func.start() == address && plat.is_none_or(|p| p == func.platform().as_ref()) {
functions.push(func.clone());
}
}
diff --git a/rust/src/binary_view/reader.rs b/rust/src/binary_view/reader.rs
index 685914e2..3ec105fc 100644
--- a/rust/src/binary_view/reader.rs
+++ b/rust/src/binary_view/reader.rs
@@ -21,7 +21,7 @@ use crate::binary_view::{BinaryView, BinaryViewBase};
use crate::Endianness;
use crate::rc::Ref;
-use std::io::{ErrorKind, Read, Seek, SeekFrom};
+use std::io::{Read, Seek, SeekFrom};
pub struct BinaryReader {
view: Ref<BinaryView>,
@@ -107,14 +107,11 @@ impl Seek for BinaryReader {
SeekFrom::End(end_offset) => {
// We do NOT need to add the image base here as
// the reader (unlike the writer) can set the virtual base.
- let offset =
- self.view
- .len()
- .checked_add_signed(end_offset)
- .ok_or(std::io::Error::new(
- ErrorKind::Other,
- "Seeking from end overflowed",
- ))?;
+ let offset = self
+ .view
+ .len()
+ .checked_add_signed(end_offset)
+ .ok_or(std::io::Error::other("Seeking from end overflowed"))?;
self.seek_to_offset(offset);
}
};
@@ -130,7 +127,7 @@ impl Read for BinaryReader {
let result = unsafe { BNReadData(self.handle, buf.as_mut_ptr() as *mut _, len) };
if !result {
- Err(std::io::Error::new(ErrorKind::Other, "Read out of bounds"))
+ Err(std::io::Error::other("Read out of bounds"))
} else {
Ok(len)
}
diff --git a/rust/src/binary_view/writer.rs b/rust/src/binary_view/writer.rs
index 176a54d8..ca570761 100644
--- a/rust/src/binary_view/writer.rs
+++ b/rust/src/binary_view/writer.rs
@@ -21,7 +21,7 @@ use crate::binary_view::{BinaryView, BinaryViewBase, BinaryViewExt};
use crate::Endianness;
use crate::rc::Ref;
-use std::io::{ErrorKind, Seek, SeekFrom, Write};
+use std::io::{Seek, SeekFrom, Write};
pub struct BinaryWriter {
view: Ref<BinaryView>,
@@ -88,10 +88,7 @@ impl Seek for BinaryWriter {
let view_end = self.view.original_image_base() + self.view.len();
let offset = view_end
.checked_add_signed(end_offset)
- .ok_or(std::io::Error::new(
- ErrorKind::Other,
- "Seeking from end overflowed",
- ))?;
+ .ok_or(std::io::Error::other("Seeking from end overflowed"))?;
self.seek_to_offset(offset);
}
};
@@ -105,10 +102,7 @@ impl Write for BinaryWriter {
let len = buf.len();
let result = unsafe { BNWriteData(self.handle, buf.as_ptr() as *mut _, len) };
if !result {
- Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "write out of bounds",
- ))
+ Err(std::io::Error::other("write out of bounds"))
} else {
Ok(len)
}
diff --git a/rust/src/data_buffer.rs b/rust/src/data_buffer.rs
index 5f59393e..7a5e543c 100644
--- a/rust/src/data_buffer.rs
+++ b/rust/src/data_buffer.rs
@@ -234,7 +234,7 @@ impl Eq for DataBuffer {}
impl PartialOrd for DataBuffer {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- Some(self.as_ref().cmp(other.as_ref()))
+ Some(self.cmp(other))
}
}
diff --git a/rust/src/data_renderer.rs b/rust/src/data_renderer.rs
index 6fa19b59..e193b32d 100644
--- a/rust/src/data_renderer.rs
+++ b/rust/src/data_renderer.rs
@@ -235,7 +235,7 @@ unsafe extern "C" fn cb_free_lines(
lines: *mut BNDisassemblyTextLine,
count: usize,
) {
- let lines = Box::from_raw(core::slice::from_raw_parts_mut(lines, count));
+ let lines = Box::from_raw(std::ptr::slice_from_raw_parts_mut(lines, count));
for line in lines {
let _ = DisassemblyTextLine::from_raw(&line);
}
diff --git a/rust/src/language_representation.rs b/rust/src/language_representation.rs
index 6008ec0c..34524b96 100644
--- a/rust/src/language_representation.rs
+++ b/rust/src/language_representation.rs
@@ -507,7 +507,7 @@ unsafe extern "C" fn cb_free_lines(
count: usize,
) {
let lines: Box<[BNDisassemblyTextLine]> =
- Box::from_raw(core::slice::from_raw_parts_mut(lines, count));
+ Box::from_raw(std::ptr::slice_from_raw_parts_mut(lines, count));
for line in lines {
DisassemblyTextLine::free_raw(line);
}
diff --git a/rust/src/line_formatter.rs b/rust/src/line_formatter.rs
index 50f1900c..9e6460c7 100644
--- a/rust/src/line_formatter.rs
+++ b/rust/src/line_formatter.rs
@@ -160,7 +160,7 @@ unsafe extern "C" fn cb_free_lines(
count: usize,
) {
let lines: Box<[BNDisassemblyTextLine]> =
- Box::from_raw(core::slice::from_raw_parts_mut(raw_lines, count));
+ Box::from_raw(std::ptr::slice_from_raw_parts_mut(raw_lines, count));
for line in lines {
DisassemblyTextLine::free_raw(line);
}
diff --git a/rust/src/render_layer.rs b/rust/src/render_layer.rs
index 181294d4..cd53c9ac 100644
--- a/rust/src/render_layer.rs
+++ b/rust/src/render_layer.rs
@@ -13,10 +13,12 @@ use std::ptr::NonNull;
/// The state in which the [`RenderLayer`] will be registered with.
#[repr(u32)]
+#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub enum RenderLayerDefaultState {
/// Register the [`RenderLayer`] as disabled, the user must then enable it via the UI.
///
/// This is the default registration value.
+ #[default]
Disabled = 0,
/// Register the [`RenderLayer`] as enabled, the user must then disable it via the UI.
Enabled = 1,
@@ -54,12 +56,6 @@ impl From<RenderLayerDefaultState> for BNRenderLayerDefaultEnableState {
}
}
-impl Default for RenderLayerDefaultState {
- fn default() -> Self {
- Self::Disabled
- }
-}
-
/// Register a [`RenderLayer`] with the API.
pub fn register_render_layer<T: RenderLayer>(
name: &str,