diff --git a/Cargo.toml b/Cargo.toml index 0a91496..870b620 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,6 @@ default = ["capstone4"] thread_safe = [] capstone4 = ["falcon_capstone/capstone4"] static = ["falcon_capstone/static"] -il-expression-ashr = [] [lib] name = "falcon" diff --git a/lib/executor/eval.rs b/lib/executor/eval.rs index ad55261..6e2f223 100644 --- a/lib/executor/eval.rs +++ b/lib/executor/eval.rs @@ -21,7 +21,6 @@ pub fn eval(expr: &il::Expression) -> Result { il::Expression::Xor(ref lhs, ref rhs) => eval(lhs)?.xor(&eval(rhs)?)?, il::Expression::Shl(ref lhs, ref rhs) => eval(lhs)?.shl(&eval(rhs)?)?, il::Expression::Shr(ref lhs, ref rhs) => eval(lhs)?.shr(&eval(rhs)?)?, - #[cfg(feature = "il-expression-ashr")] il::Expression::AShr(ref lhs, ref rhs) => eval(lhs)?.ashr(&eval(rhs)?)?, il::Expression::Cmpeq(ref lhs, ref rhs) => eval(lhs)?.cmpeq(&eval(rhs)?)?, il::Expression::Cmpneq(ref lhs, ref rhs) => eval(lhs)?.cmpneq(&eval(rhs)?)?, diff --git a/lib/executor/state.rs b/lib/executor/state.rs index cb72d50..6c6ce1f 100644 --- a/lib/executor/state.rs +++ b/lib/executor/state.rs @@ -99,7 +99,6 @@ impl State { self.symbolize_expression(lhs)?, self.symbolize_expression(rhs)?, )?, - #[cfg(feature = "il-expression-ashr")] il::Expression::AShr(ref lhs, ref rhs) => il::Expression::ashr( self.symbolize_expression(lhs)?, self.symbolize_expression(rhs)?, diff --git a/lib/graph/mod.rs b/lib/graph/mod.rs index f743c85..579d0ad 100644 --- a/lib/graph/mod.rs +++ b/lib/graph/mod.rs @@ -997,7 +997,7 @@ where .vertices .iter() .map(|v| { - let label = v.1.dot_label().replace("\n", "\\l"); + let label = v.1.dot_label().replace('\n', "\\l"); let fill_color = v.1.dot_fill_color(); let font_color = v.1.dot_font_color(); format!( @@ -1014,7 +1014,7 @@ where .edges .iter() .map(|e| { - let label = e.1.dot_label().replace("\n", "\\l"); + let label = e.1.dot_label().replace('\n', "\\l"); let style = e.1.dot_style(); let fill_color = e.1.dot_fill_color(); let font_color = e.1.dot_font_color(); @@ -1483,7 +1483,7 @@ mod tests { #[test] fn test_is_acyclic_should_return_false_for_cyclic_graph() { let graph = create_test_graph(); - assert_eq!(graph.is_acyclic(1), false); + assert!(!graph.is_acyclic(1)); } #[test] @@ -1523,7 +1523,7 @@ mod tests { graph }; - assert_eq!(graph.is_reducible(1).unwrap(), false); + assert!(!graph.is_reducible(1).unwrap()); } #[test] diff --git a/lib/il/constant.rs b/lib/il/constant.rs index 6039323..02f1433 100644 --- a/lib/il/constant.rs +++ b/lib/il/constant.rs @@ -268,7 +268,7 @@ impl Constant { .value .to_usize() .map(|bits| { - if bits as usize >= self.bits() { + if bits >= self.bits() { BigUint::from_u64(0).unwrap() } else { self.value.clone() << bits diff --git a/lib/il/expression.rs b/lib/il/expression.rs index d125038..8ec9a35 100644 --- a/lib/il/expression.rs +++ b/lib/il/expression.rs @@ -43,7 +43,6 @@ pub enum Expression { Xor(Box, Box), Shl(Box, Box), Shr(Box, Box), - #[cfg(feature = "il-expression-ashr")] AShr(Box, Box), Cmpeq(Box, Box), @@ -76,7 +75,6 @@ impl Expression { | Expression::Xor(ref lhs, _) | Expression::Shl(ref lhs, _) | Expression::Shr(ref lhs, _) => lhs.bits(), - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref lhs, _) => lhs.bits(), Expression::Cmpeq(_, _) | Expression::Cmpneq(_, _) @@ -159,7 +157,6 @@ impl Expression { Expression::Shr(ref lhs, ref rhs) => { Expression::shr(self.map(lhs)?, self.map(rhs)?)? } - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref lhs, ref rhs) => { Expression::ashr(self.map(lhs)?, self.map(rhs)?)? } @@ -228,7 +225,6 @@ impl Expression { | Expression::Cmpneq(ref lhs, ref rhs) | Expression::Cmplts(ref lhs, ref rhs) | Expression::Cmpltu(ref lhs, ref rhs) => lhs.all_constants() && rhs.all_constants(), - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref lhs, ref rhs) => lhs.all_constants() && rhs.all_constants(), Expression::Zext(_, ref rhs) | Expression::Sext(_, ref rhs) @@ -264,7 +260,6 @@ impl Expression { scalars.append(&mut lhs.scalars()); scalars.append(&mut rhs.scalars()); } - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref lhs, ref rhs) => { scalars.append(&mut lhs.scalars()); scalars.append(&mut rhs.scalars()); @@ -308,7 +303,6 @@ impl Expression { scalars.append(&mut lhs.scalars_mut()); scalars.append(&mut rhs.scalars_mut()); } - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref mut lhs, ref mut rhs) => { scalars.append(&mut lhs.scalars_mut()); scalars.append(&mut rhs.scalars_mut()); @@ -642,7 +636,6 @@ impl fmt::Display for Expression { Expression::Xor(ref lhs, ref rhs) => write!(f, "({} ^ {})", lhs, rhs), Expression::Shl(ref lhs, ref rhs) => write!(f, "({} << {})", lhs, rhs), Expression::Shr(ref lhs, ref rhs) => write!(f, "({} >> {})", lhs, rhs), - #[cfg(feature = "il-expression-ashr")] Expression::AShr(ref lhs, ref rhs) => write!(f, "({} >>> {})", lhs, rhs), Expression::Cmpeq(ref lhs, ref rhs) => write!(f, "({} == {})", lhs, rhs), Expression::Cmpneq(ref lhs, ref rhs) => write!(f, "({} != {})", lhs, rhs), diff --git a/lib/il/location.rs b/lib/il/location.rs index 194618e..faa128c 100644 --- a/lib/il/location.rs +++ b/lib/il/location.rs @@ -48,7 +48,7 @@ impl<'p> RefProgramLocation<'p> { continue; } - if function == None { + if function.is_none() { function = Some(f); continue; } diff --git a/lib/loader/elf/elf.rs b/lib/loader/elf/elf.rs index d46fca5..31225b7 100644 --- a/lib/loader/elf/elf.rs +++ b/lib/loader/elf/elf.rs @@ -288,10 +288,7 @@ impl Loader for Elf { ); } - Ok(function_entries - .into_iter() - .map(|(_, entry)| entry) - .collect()) + Ok(function_entries.into_values().collect()) } fn program_entry(&self) -> u64 { diff --git a/lib/loader/elf/elf_linker.rs b/lib/loader/elf/elf_linker.rs index 8add4e0..e395e49 100644 --- a/lib/loader/elf/elf_linker.rs +++ b/lib/loader/elf/elf_linker.rs @@ -206,7 +206,7 @@ impl ElfLinker { } } else { // Ensure all shared objects we rely on are loaded - for so_name in self.loaded[&filename].dt_needed()?.clone() { + for so_name in self.loaded[&filename].dt_needed()? { if self.loaded.get(&so_name).is_none() { self.next_lib_address += LIB_BASE_STEP; let next_lib_address = self.next_lib_address; @@ -289,7 +289,7 @@ impl ElfLinker { None => bail!("Could not resolve symbol {}", sym_name), }; self.memory - .set32(reloc.r_offset as u64 + elf.base_address(), value)?; + .set32(reloc.r_offset + elf.base_address(), value)?; } goblin::elf::reloc::R_386_GOT32 => { bail!("R_386_GOT32"); @@ -322,7 +322,7 @@ impl ElfLinker { } }; self.memory - .set32(reloc.r_offset as u64 + elf.base_address(), value)?; + .set32(reloc.r_offset + elf.base_address(), value)?; } goblin::elf::reloc::R_386_JMP_SLOT => { let sym = &dynsyms @@ -334,12 +334,10 @@ impl ElfLinker { None => bail!("Could not resolve symbol {}", sym_name), }; self.memory - .set32(reloc.r_offset as u64 + elf.base_address(), value)?; + .set32(reloc.r_offset + elf.base_address(), value)?; } goblin::elf::reloc::R_386_RELATIVE => { - let value = self - .memory - .get32(reloc.r_offset as u64 + elf.base_address()); + let value = self.memory.get32(reloc.r_offset + elf.base_address()); let value = match value { Some(value) => elf.base_address() as u32 + value, None => bail!( @@ -349,7 +347,7 @@ impl ElfLinker { ), }; self.memory - .set32(reloc.r_offset as u64 + elf.base_address(), value)?; + .set32(reloc.r_offset + elf.base_address(), value)?; } goblin::elf::reloc::R_386_GOTPC => { bail!("R_386_GOT_PC"); diff --git a/lib/loader/json.rs b/lib/loader/json.rs index 50d7652..ba60119 100644 --- a/lib/loader/json.rs +++ b/lib/loader/json.rs @@ -79,7 +79,7 @@ impl Json { }; let bytes = match segment["bytes"] { - Value::String(ref bytes) => base64::decode(&bytes)?, + Value::String(ref bytes) => base64::decode(bytes)?, _ => bail!("bytes missing for segment"), }; diff --git a/lib/memory/paged.rs b/lib/memory/paged.rs index 3ed544c..c45fe03 100644 --- a/lib/memory/paged.rs +++ b/lib/memory/paged.rs @@ -157,7 +157,7 @@ where /// Set memory permissions for the page at the given address pub fn set_permissions(&mut self, address: u64, len: u64, permissions: MemoryPermissions) { let mut page_address = address & PAGE_MASK; - let total_length = len as u64 + (address - page_address); + let total_length = len + (address - page_address); while page_address < total_length { RC::make_mut( self.pages diff --git a/lib/translator/aarch64/semantics.rs b/lib/translator/aarch64/semantics.rs index 6b6e7c4..f1a6a62 100644 --- a/lib/translator/aarch64/semantics.rs +++ b/lib/translator/aarch64/semantics.rs @@ -743,7 +743,7 @@ pub(super) fn b_cc( pub(super) fn br( instruction_graph: &mut il::ControlFlowGraph, - _successors: &mut Vec<(u64, Option)>, + _successors: &mut [(u64, Option)], instruction: &bad64::Instruction, ) -> Result<()> { let block_index = { @@ -799,7 +799,7 @@ fn cbz_cbnz_tbz_tbnz( let (dst, mut cond_true, mut cond_false); let opr_value = 0; - let opr_bit = test_bit.then(|| 1); + let opr_bit = test_bit.then_some(1); let opr_target = [1, 2][test_bit as usize]; let block_index = { @@ -1202,7 +1202,7 @@ pub(super) fn nop( pub(super) fn ret( instruction_graph: &mut il::ControlFlowGraph, - _successors: &mut Vec<(u64, Option)>, + _successors: &mut [(u64, Option)], _instruction: &bad64::Instruction, ) -> Result<()> { let block_index = { diff --git a/lib/translator/aarch64/test.rs b/lib/translator/aarch64/test.rs index e825da9..206379b 100644 --- a/lib/translator/aarch64/test.rs +++ b/lib/translator/aarch64/test.rs @@ -27,8 +27,7 @@ fn init_driver_block<'d>( .chain(Some(&NOP)) // The following code can be rewritten as `encoding.to_le_bytes() // .into_iter()` in Rust 2021 but not in Rust 2018 - .map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes())) - .flatten() + .flat_map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes())) .collect(); let mut backing = memory::backing::Memory::new(Endian::Big); diff --git a/lib/translator/block_translation_result.rs b/lib/translator/block_translation_result.rs index 5759fe1..22fd502 100644 --- a/lib/translator/block_translation_result.rs +++ b/lib/translator/block_translation_result.rs @@ -77,7 +77,7 @@ impl BlockTranslationResult { control_flow_graph.set_entry(block_index)?; control_flow_graph.set_exit(block_index)?; - for &(_, ref cfg) in &self.instructions { + for (_, cfg) in &self.instructions { control_flow_graph.append(cfg)?; } diff --git a/lib/translator/mips/test.rs b/lib/translator/mips/test.rs index aeeeb59..fac90fd 100644 --- a/lib/translator/mips/test.rs +++ b/lib/translator/mips/test.rs @@ -2070,7 +2070,7 @@ fn nop() { _ => None, }; - assert_eq!(nop.is_some(), true); + assert!(nop.is_some()); } #[test] diff --git a/lib/translator/ppc/semantics.rs b/lib/translator/ppc/semantics.rs index e0632f5..d2e1642 100644 --- a/lib/translator/ppc/semantics.rs +++ b/lib/translator/ppc/semantics.rs @@ -506,7 +506,7 @@ pub fn addze( let src = Expression::add( lhs.clone(), - Expression::zext(lhs.bits() as usize, expr_scalar("carry", 1))?, + Expression::zext(lhs.bits(), expr_scalar("carry", 1))?, )?; block.assign(dst, src); diff --git a/lib/translator/x86/mode.rs b/lib/translator/x86/mode.rs index 21025bb..3787647 100644 --- a/lib/translator/x86/mode.rs +++ b/lib/translator/x86/mode.rs @@ -101,7 +101,7 @@ impl Mode { Expr::add(op, expr_const(mem.disp as u64, self.bits()))? } Ordering::Less => { - Expr::sub(op, expr_const(mem.disp.abs() as u64, self.bits()))? + Expr::sub(op, expr_const(mem.disp.unsigned_abs(), self.bits()))? } Ordering::Equal => op, }