summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2024-04-16 19:32:04 -0400
committerKyle Martin <krm504@nyu.edu>2024-05-09 13:11:41 -0400
commit29b62677dad48aa4d55ad2dae5d176d9880216bd (patch)
treef205a5f4ebb7e71ea132fe06a7076c70616d3c62 /rust/src
parent608f261e6bca5869e748d4509da92a5717dce75d (diff)
Fix clippy warnings and run rustfmt
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/binaryview.rs8
-rw-r--r--rust/src/flowgraph.rs4
-rw-r--r--rust/src/lib.rs14
-rw-r--r--rust/src/llil/instruction.rs2
-rw-r--r--rust/src/string.rs4
5 files changed, 15 insertions, 17 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs
index 6e510694..70b1cab0 100644
--- a/rust/src/binaryview.rs
+++ b/rust/src/binaryview.rs
@@ -1584,11 +1584,9 @@ where
ctx: *mut ::std::os::raw::c_void,
view: *mut BNBinaryView,
) {
- ffi_wrap!("EventHandler::on_event", unsafe {
- let mut context = &mut *(ctx as *mut Handler);
-
- let handle = BinaryView::from_raw(BNNewViewReference(view));
- Handler::on_event(&mut context, handle.as_ref());
+ ffi_wrap!("EventHandler::on_event", {
+ let context = unsafe { &*(ctx as *const Handler) };
+ context.on_event(&BinaryView::from_raw(BNNewViewReference(view)));
})
}
diff --git a/rust/src/flowgraph.rs b/rust/src/flowgraph.rs
index c2d4d559..c8505187 100644
--- a/rust/src/flowgraph.rs
+++ b/rust/src/flowgraph.rs
@@ -68,7 +68,7 @@ impl<'a> FlowGraphNode<'a> {
unsafe { FlowGraphNode::from_raw(BNCreateFlowGraphNode(graph.handle)) }
}
- pub fn set_disassembly_lines(&self, lines: &'a Vec<DisassemblyTextLine>) {
+ pub fn set_disassembly_lines(&self, lines: &'a [DisassemblyTextLine]) {
unsafe {
BNSetFlowGraphNodeLines(self.handle, lines.as_ptr() as *mut _, lines.len());
// BNFreeDisassemblyTextLines(lines.as_ptr() as *mut _, lines.len()); // Shouldn't need...would be a double free?
@@ -79,7 +79,7 @@ impl<'a> FlowGraphNode<'a> {
let lines = lines
.iter()
.map(|&line| DisassemblyTextLine::from(&vec![line]))
- .collect();
+ .collect::<Vec<_>>();
self.set_disassembly_lines(&lines);
}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 0d385746..739bfbf6 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -74,16 +74,12 @@
//! ### `main.rs`
//! Standalone binaries need to initialize Binary Ninja before they can work. You can do this through [`headless::Session`], [`headless::script_helper`], or [`headless::init()`] at start and [`headless::shutdown()`] at shutdown.
//! ```rust
-//! fn main() {
-//! // This loads all the core architecture, platform, etc plugins
-//! // Standalone executables need to call this, but plugins do not
-//! let headless_session = binaryninja::headless::Session::new();
+//! // This loads all the core architecture, platform, etc plugins
+//! // Standalone executables need to call this, but plugins do not
+//! let headless_session = binaryninja::headless::Session::new();
//!
-//! println!("Loading binary...");
-//! let bv = headless_session.load("/bin/cat").expect("Couldn't open `/bin/cat`");
-//!
-//! // Your code here...
-//! }
+//! println!("Loading binary...");
+//! let bv = headless_session.load("/bin/cat").expect("Couldn't open `/bin/cat`");
//! ```
//!
//! ### `Cargo.toml`
diff --git a/rust/src/llil/instruction.rs b/rust/src/llil/instruction.rs
index 469c10fb..62e50453 100644
--- a/rust/src/llil/instruction.rs
+++ b/rust/src/llil/instruction.rs
@@ -99,7 +99,7 @@ where
let expr_idx =
unsafe { BNGetLowLevelILIndexForInstruction(self.function.handle, self.instr_idx) };
let op = unsafe { BNGetLowLevelILByIndex(self.function.handle, expr_idx) };
- return op.address;
+ op.address
}
pub fn info(&self) -> InstrInfo<'func, A, M, NonSSA<V>> {
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 75942da9..96830ca5 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -94,6 +94,10 @@ impl BnString {
pub fn len(&self) -> usize {
self.as_ref().len()
}
+
+ pub fn is_empty(&self) -> bool {
+ self.as_ref().is_empty()
+ }
}
impl Drop for BnString {