summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-12-04 15:10:40 -0500
committerMason Reed <mason@vector35.com>2025-12-05 12:26:29 -0500
commit6546844ca4274cd11ec2c91da7c6d7b5e8a82d0b (patch)
tree7341b815993247cba9df7ea95585ce9723510fa0 /rust/src
parent6eb12c3c3f53079a822881bf6e197105b25a0fe3 (diff)
[Rust] Fix misc clippy lints and warnings
These are introduced after changing to Rust 1.91.1
Diffstat (limited to 'rust/src')
-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
9 files changed, 41 insertions, 44 deletions
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,