From c3fdda9727f5507818e3f55576ad32215a22b0f9 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 30 Apr 2025 17:38:40 -0400 Subject: [Rust] Remove Architecture trait bound on LLIL related structures --- plugins/warp/src/cache.rs | 20 ++++++-------------- plugins/warp/src/lib.rs | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 26 deletions(-) (limited to 'plugins') diff --git a/plugins/warp/src/cache.rs b/plugins/warp/src/cache.rs index 4b1df5af..7219b547 100644 --- a/plugins/warp/src/cache.rs +++ b/plugins/warp/src/cache.rs @@ -1,6 +1,5 @@ use crate::convert::{from_bn_symbol, from_bn_type_internal}; use crate::{build_function, function_guid}; -use binaryninja::architecture::Architecture; use binaryninja::binary_view::{BinaryView, BinaryViewExt}; use binaryninja::confidence::MAX_CONFIDENCE; use binaryninja::function::Function as BNFunction; @@ -68,10 +67,7 @@ pub fn try_cached_function_match(function: &BNFunction) -> Option { .to_owned() } -pub fn cached_function( - function: &BNFunction, - llil: &RegularLowLevelILFunction, -) -> Function { +pub fn cached_function(function: &BNFunction, llil: &RegularLowLevelILFunction) -> Function { let view = function.view(); let view_id = ViewID::from(view.as_ref()); let function_cache = FUNCTION_CACHE.get_or_init(Default::default); @@ -122,9 +118,9 @@ where } } -pub fn cached_function_guid( +pub fn cached_function_guid( function: &BNFunction, - llil: &LowLevelILFunction>, + llil: &LowLevelILFunction>, ) -> FunctionGUID { let view = function.view(); let view_id = ViewID::from(view); @@ -202,11 +198,7 @@ pub struct FunctionCache { } impl FunctionCache { - pub fn function( - &self, - function: &BNFunction, - llil: &RegularLowLevelILFunction, - ) -> Function { + pub fn function(&self, function: &BNFunction, llil: &RegularLowLevelILFunction) -> Function { let function_id = FunctionID::from(function); match self.cache.get(&function_id) { Some(function) => function.value().to_owned(), @@ -330,10 +322,10 @@ impl GUIDCache { } } - pub fn function_guid( + pub fn function_guid( &self, function: &BNFunction, - llil: &LowLevelILFunction>, + llil: &LowLevelILFunction>, ) -> FunctionGUID { let function_id = FunctionID::from(function); match self.cache.get(&function_id) { diff --git a/plugins/warp/src/lib.rs b/plugins/warp/src/lib.rs index 3f2fc276..3d68b402 100644 --- a/plugins/warp/src/lib.rs +++ b/plugins/warp/src/lib.rs @@ -16,7 +16,7 @@ use binaryninja::low_level_il::function::{ use binaryninja::low_level_il::instruction::{ InstructionHandler, LowLevelILInstruction, LowLevelILInstructionKind, }; -use binaryninja::low_level_il::{LowLevelILRegister, VisitorAction}; +use binaryninja::low_level_il::{LowLevelILRegisterKind, VisitorAction}; use binaryninja::rc::Ref as BNRef; use std::path::PathBuf; use warp::signature::basic_block::BasicBlockGUID; @@ -44,9 +44,9 @@ pub fn user_signature_dir() -> PathBuf { binaryninja::user_directory().join("signatures/") } -pub fn build_function( +pub fn build_function( func: &BNFunction, - llil: &LowLevelILFunction>, + llil: &LowLevelILFunction>, ) -> Function { let bn_fn_ty = func.function_type(); Function { @@ -76,9 +76,9 @@ pub fn sorted_basic_blocks(func: &BNFunction) -> Vec( +pub fn function_guid( func: &BNFunction, - llil: &LowLevelILFunction>, + llil: &LowLevelILFunction>, ) -> FunctionGUID { let basic_blocks = sorted_basic_blocks(func); let basic_block_guids = basic_blocks @@ -88,9 +88,9 @@ pub fn function_guid( FunctionGUID::from_basic_blocks(&basic_block_guids) } -pub fn basic_block_guid( +pub fn basic_block_guid( basic_block: &BNBasicBlock, - llil: &LowLevelILFunction>, + llil: &LowLevelILFunction>, ) -> BasicBlockGUID { let func = basic_block.function(); let view = func.view(); @@ -98,7 +98,7 @@ pub fn basic_block_guid( let max_instr_len = arch.max_instr_len(); // NOPs and useless moves are blacklisted to allow for hot-patchable functions. - let is_blacklisted_instr = |instr: &LowLevelILInstruction>| { + let is_blacklisted_instr = |instr: &LowLevelILInstruction>| { match instr.kind() { LowLevelILInstructionKind::Nop(_) => true, LowLevelILInstructionKind::SetReg(op) => { @@ -107,7 +107,7 @@ pub fn basic_block_guid( if op.dest_reg() == source_op.source_reg() => { match op.dest_reg() { - LowLevelILRegister::ArchReg(r) => { + LowLevelILRegisterKind::Arch(r) => { // If this register has no implicit extend then we can safely assume it's a NOP. // Ex. on x86_64 we don't want to remove `mov edi, edi` as it will zero the upper 32 bits. // Ex. on x86 we do want to remove `mov edi, edi` as it will not have a side effect like above. @@ -116,7 +116,7 @@ pub fn basic_block_guid( ImplicitRegisterExtend::NoExtend ) } - LowLevelILRegister::Temp(_) => false, + LowLevelILRegisterKind::Temp(_) => false, } } _ => false, @@ -126,8 +126,8 @@ pub fn basic_block_guid( } }; - let is_variant_instr = |instr: &LowLevelILInstruction>| { - let is_variant_expr = |expr: &LowLevelILExpressionKind>| { + let is_variant_instr = |instr: &LowLevelILInstruction>| { + let is_variant_expr = |expr: &LowLevelILExpressionKind>| { // TODO: Checking the section here is slow, we should gather all section ranges outside of this. match expr { LowLevelILExpressionKind::ConstPtr(op) -- cgit v1.3.1