diff --git a/plugin/src/arch/aarch64/aarch64data.rs b/plugin/src/arch/aarch64/aarch64data.rs index 0d81d6c6e..3ce7c4f88 100644 --- a/plugin/src/arch/aarch64/aarch64data.rs +++ b/plugin/src/arch/aarch64/aarch64data.rs @@ -125,7 +125,7 @@ pub enum Command { /// `immediate + prev_arg - 1` is encoded in a a bitfield of length `len` at offset `pos` Usum(u8, u8), /// format: `([offsets])` - /// `immediate is in the range `0 .. (1 << offsets.len())` + /// `immediate` is in the range `0 .. (1 << offsets.len())` /// `immediate` is encoded with bit N of the number at offsets[N] Ufields(&'static [u8]), diff --git a/plugin/src/arch/aarch64/compiler.rs b/plugin/src/arch/aarch64/compiler.rs index b388d1d73..21dd696bd 100644 --- a/plugin/src/arch/aarch64/compiler.rs +++ b/plugin/src/arch/aarch64/compiler.rs @@ -328,7 +328,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, data: MatchData) -> Result< if let Some((biased, _)) = static_range_check(value, 0, mask, 0)? { for (i, &field) in bitfields.iter().rev().enumerate() { - statics.push((field as u8, (biased >> i) & 1)); + statics.push((field, (biased >> i) & 1)); } } else { @@ -336,12 +336,12 @@ pub(super) fn compile_instruction(ctx: &mut Context, data: MatchData) -> Result< for (i, &field) in bitfields.iter().rev().enumerate() { if i == 0 { - dynamics.push((field as u8, quote_spanned!{ value.span()=> + dynamics.push((field, quote_spanned!{ value.span()=> { let _dyn_imm: u32 = #value; #check; (_dyn_imm >> #i) & 1 } })); } else { - dynamics.push((field as u8, quote_spanned!{ value.span()=> + dynamics.push((field, quote_spanned!{ value.span()=> (#value >> #i) & 1 })); } @@ -678,7 +678,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, match special { SpecialComm::INVERTED_WIDE_IMMEDIATE_X => if let Some(number) = None::<u64> { // as_unsigned_number(imm) { if let Some(encoded) = encoding_helpers::encode_wide_immediate_64bit(!number) { - statics.push((offset, encoded as u32)); + statics.push((offset, encoded)); return Ok(()); } } else { @@ -697,9 +697,9 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, return Ok(()); }, SpecialComm::INVERTED_WIDE_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) { - if number <= u64::from(std::u32::MAX) { + if number <= u64::from(u32::MAX) { if let Some(encoded) = encoding_helpers::encode_wide_immediate_32bit(!(number as u32)) { - statics.push((offset, encoded as u32)); + statics.push((offset, encoded)); return Ok(()); } } @@ -720,7 +720,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, }, SpecialComm::WIDE_IMMEDIATE_X => if let Some(number) = as_unsigned_number(imm) { if let Some(encoded) = encoding_helpers::encode_wide_immediate_64bit(number) { - statics.push((offset, encoded as u32)); + statics.push((offset, encoded)); return Ok(()); } } else { @@ -739,9 +739,9 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, return Ok(()); }, SpecialComm::WIDE_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) { - if number <= u64::from(std::u32::MAX) { + if number <= u64::from(u32::MAX) { if let Some(encoded) = encoding_helpers::encode_wide_immediate_32bit(number as u32) { - statics.push((offset, encoded as u32)); + statics.push((offset, encoded)); return Ok(()); } } @@ -762,8 +762,8 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, }, SpecialComm::STRETCHED_IMMEDIATE => if let Some(number) = as_unsigned_number(imm) { if let Some(encoded) = encoding_helpers::encode_stretched_immediate(number) { - statics.push((offset, encoded & 0x1F as u32)); - statics.push((offset + 6, encoded & 0xE0 as u32)); + statics.push((offset, encoded & 0x1F)); + statics.push((offset + 6, encoded & 0xE0)); return Ok(()); } } else { @@ -788,7 +788,7 @@ fn handle_special_immediates(offset: u8, special: SpecialComm, imm: &syn::Expr, return Ok(()); }, SpecialComm::LOGICAL_IMMEDIATE_W => if let Some(number) = as_unsigned_number(imm) { - if number <= u64::from(std::u32::MAX) { + if number <= u64::from(u32::MAX) { if let Some(encoded) = encoding_helpers::encode_logical_immediate_32bit(number as u32) { statics.push((offset, u32::from(encoded))); return Ok(()); diff --git a/plugin/src/arch/aarch64/debug.rs b/plugin/src/arch/aarch64/debug.rs index 6f432e205..981949bfa 100644 --- a/plugin/src/arch/aarch64/debug.rs +++ b/plugin/src/arch/aarch64/debug.rs @@ -91,13 +91,13 @@ pub fn format_opdata(name: &str, data: &Opdata) -> Vec<String> { continue; } else if let Matcher::Dot = matcher { after_dot = true; - buf.push_str("."); + buf.push('.'); continue; } if first { if !after_dot { - buf.push_str(" "); + buf.push(' '); first = false; } after_dot = false; @@ -656,13 +656,13 @@ pub fn extract_opdata(name: &str, data: &Opdata) -> Vec<String> { continue; } else if let Matcher::Dot = matcher { after_dot = true; - buf.push_str("."); + buf.push('.'); continue; } if first { if !after_dot { - buf.push_str(" "); + buf.push(' '); first = false; } after_dot = false; @@ -818,4 +818,4 @@ fn extract_constraints(args: &[ArgWithCommands]) -> Vec<String> { } } constraints -} \ No newline at end of file +} diff --git a/plugin/src/arch/aarch64/encoding_helpers.rs b/plugin/src/arch/aarch64/encoding_helpers.rs index 45d4cd90e..30ff908e3 100644 --- a/plugin/src/arch/aarch64/encoding_helpers.rs +++ b/plugin/src/arch/aarch64/encoding_helpers.rs @@ -96,7 +96,7 @@ pub fn encode_wide_immediate_32bit(value: u32) -> Option<u32> { let offset = value.trailing_zeros() & 0b1_0000; let masked = 0xFFFF & (value >> offset); if (masked << offset) == value { - Some((masked as u32) | (offset << 12)) + Some(masked | (offset << 12)) } else { None } diff --git a/plugin/src/arch/aarch64/mod.rs b/plugin/src/arch/aarch64/mod.rs index fb955443f..8a8115821 100644 --- a/plugin/src/arch/aarch64/mod.rs +++ b/plugin/src/arch/aarch64/mod.rs @@ -23,17 +23,11 @@ struct Context<'a, 'b: 'a> { pub state: &'a mut State<'b> } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct ArchAarch64 { } -impl Default for ArchAarch64 { - fn default() -> ArchAarch64 { - ArchAarch64 { } - } -} - impl Arch for ArchAarch64 { fn set_features(&mut self, features: &[syn::Ident]) { if let Some(feature) = features.first() { diff --git a/plugin/src/arch/x64/compiler.rs b/plugin/src/arch/x64/compiler.rs index 9528bcb98..5b6a6fa27 100644 --- a/plugin/src/arch/x64/compiler.rs +++ b/plugin/src/arch/x64/compiler.rs @@ -98,7 +98,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a let mut args = args.into_iter().map(clean_memoryref).collect::<Result<Vec<CleanArg>, _>>()?; // sanitize memory references, determine address size, and size immediates/displacements if possible - let addr_size = sanitize_indirects_and_sizes(&ctx, &mut args)?; + let addr_size = sanitize_indirects_and_sizes(ctx, &mut args)?; let addr_size = addr_size.unwrap_or(match ctx.mode { X86Mode::Long => Size::B_8, X86Mode::Protected => Size::B_4 @@ -141,7 +141,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a match ctx.mode { X86Mode::Protected => if op_size == Size::B_8 { - return Err(Some(format!("'{}': Does not support 64 bit operands in 32-bit mode", op.to_string()))); + return Err(Some(format!("'{}': Does not support 64 bit operands in 32-bit mode", op))); }, X86Mode::Long => () } @@ -151,14 +151,14 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a (Size::B_2, _) => pref_size = true, (Size::B_8, X86Mode::Long) => (), (Size::B_4, X86Mode::Protected) => (), - (Size::B_4, X86Mode::Long) => return Err(Some(format!("'{}': Does not support 32 bit operands in 64-bit mode", op.to_string()))), + (Size::B_4, X86Mode::Long) => return Err(Some(format!("'{}': Does not support 32 bit operands in 64-bit mode", op))), (_, _) => panic!("bad formatting data"), } } else if data.flags.contains(Flags::AUTO_REXW) { if op_size == Size::B_8 { rex_w = true; } else if op_size != Size::B_4 { - return Err(Some(format!("'{}': Does not support 16-bit operands", op.to_string()))); + return Err(Some(format!("'{}': Does not support 16-bit operands", op))); } } else if data.flags.contains(Flags::AUTO_VEXL) { if op_size == Size::B_32 { @@ -241,7 +241,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a // Certain SSE/AVX legacy encoded operations are not available in 32-bit mode // as they require a REX.W prefix to be encoded, which is impossible. We catch those cases here if ctx.mode == X86Mode::Protected { - return Err(Some(format!("'{}': Does not support 64 bit operand size in 32-bit mode", op.to_string()))) + return Err(Some(format!("'{}': Does not support 64 bit operand size in 32-bit mode", op))) } compile_rex(buffer, rex_w, ®, &rm); } @@ -288,7 +288,7 @@ pub(super) fn compile_instruction(ctx: &mut Context, instruction: Instruction, a }; // check addressing mode special cases - let mode_vsib = index.as_ref().map_or(false, |&(ref i, _, _)| i.kind.family() == RegFamily::XMM); + let mode_vsib = index.as_ref().map_or(false, |(i, _, _)| i.kind.family() == RegFamily::XMM); let mode_16bit = addr_size == Size::B_2; let mode_rip_relative = base.as_ref().map_or(false, |b| b.kind.family() == RegFamily::RIP); let mode_rbp_base = base.as_ref().map_or(false, |b| b == &RegId::RBP || b == &RegId::R13 || b.kind.is_dynamic()); @@ -549,7 +549,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> { let mut base_reg_index = None; for (i, reg) in regs.iter().enumerate() { if !(regs.iter().enumerate().any(|(j, other)| i != j && reg == other) || - scaled.iter().any(|&(ref other, _)| reg == other)) { + scaled.iter().any(|(other, _)| reg == other)) { base_reg_index = Some(i); break; } @@ -561,7 +561,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> { let mut joined_regs = Vec::new(); for (reg, s) in scaled { // does this register already have a spot? - if let Some(i) = joined_regs.iter().position(|&(ref other, _)| ® == other) { + if let Some(i) = joined_regs.iter().position(|(other, _)| ® == other) { joined_regs[i].1 += s; } else { joined_regs.push((reg, s)); @@ -626,7 +626,7 @@ fn clean_memoryref(arg: RawArg) -> Result<CleanArg, Option<String>> { let mut joined_regs = Vec::new(); for (reg, s) in scaled { // does this register already have a spot? - if let Some(i) = joined_regs.iter().position(|&(ref other, _)| ® == other) { + if let Some(i) = joined_regs.iter().position(|(other, _)| ® == other) { joined_regs[i].1 += s; } else { joined_regs.push((reg, s)); @@ -1061,47 +1061,47 @@ fn match_format_string(ctx: &Context, fmt: &Opdata, args: &[CleanArg]) -> Result (b'o', &CleanArg::JumpTarget{size, ..}) => size, // specific legacy regs - (x @ b'A' ..= b'P', &CleanArg::Direct{ref reg, ..}) if + (x @ b'A' ..= b'P', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::LEGACY && reg.kind.code() == Some(x - b'A') => Some(reg.size()), // specific segment regs - (x @ b'Q' ..= b'V', &CleanArg::Direct{ref reg, ..}) if + (x @ b'Q' ..= b'V', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::SEGMENT && reg.kind.code() == Some(x - b'Q') => Some(reg.size()), // CR8 can be specially referenced - (b'W', &CleanArg::Direct{ref reg, ..}) if + (b'W', CleanArg::Direct{reg, ..}) if reg.kind == RegId::CR8 => Some(reg.size()), // top of the fp stack is also often used - (b'X', &CleanArg::Direct{ref reg, ..}) if + (b'X', CleanArg::Direct{reg, ..}) if reg.kind == RegId::ST0 => Some(reg.size()), // generic legacy regs - (b'r', &CleanArg::Direct{ref reg, ..}) | - (b'v', &CleanArg::Direct{ref reg, ..}) if + (b'r', CleanArg::Direct{reg, ..}) | + (b'v', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::LEGACY || reg.kind.family() == RegFamily::HIGHBYTE => Some(reg.size()), // other reg types often mixed with memory refs - (b'x', &CleanArg::Direct{ref reg, ..}) | - (b'u', &CleanArg::Direct{ref reg, ..}) if + (b'x', CleanArg::Direct{reg, ..}) | + (b'u', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::MMX => Some(reg.size()), - (b'y', &CleanArg::Direct{ref reg, ..}) | - (b'w', &CleanArg::Direct{ref reg, ..}) if + (b'y', CleanArg::Direct{reg, ..}) | + (b'w', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::XMM => Some(reg.size()), // other reg types - (b'f', &CleanArg::Direct{ref reg, ..}) if + (b'f', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::FP => Some(reg.size()), - (b's', &CleanArg::Direct{ref reg, ..}) if + (b's', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::SEGMENT => Some(reg.size()), - (b'c', &CleanArg::Direct{ref reg, ..}) if + (b'c', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::CONTROL => Some(reg.size()), - (b'd', &CleanArg::Direct{ref reg, ..}) if + (b'd', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::DEBUG => Some(reg.size()), - (b'b', &CleanArg::Direct{ref reg, ..}) if + (b'b', CleanArg::Direct{reg, ..}) if reg.kind.family() == RegFamily::BOUND => Some(reg.size()), // memory offsets @@ -1178,7 +1178,7 @@ fn size_operands(fmt: &Opdata, args: Vec<CleanArg>) -> Result<(Option<Size>, Vec let mut im_size = None; // operand size determination loop - for (arg, (_, fsize)) in args.iter().zip(FormatStringIterator::new(&fmt.args)) { + for (arg, (_, fsize)) in args.iter().zip(FormatStringIterator::new(fmt.args)) { if fsize != b'*' { continue; } @@ -1241,7 +1241,7 @@ fn size_operands(fmt: &Opdata, args: Vec<CleanArg>) -> Result<(Option<Size>, Vec // fill-in loop. default should never be used. let mut new_args = Vec::new(); - for (arg, (code, fsize)) in args.into_iter().zip(FormatStringIterator::new(&fmt.args)) { + for (arg, (code, fsize)) in args.into_iter().zip(FormatStringIterator::new(fmt.args)) { //get the specified operand size from the format string let size = match (fsize, code) { diff --git a/plugin/src/arch/x64/debug.rs b/plugin/src/arch/x64/debug.rs index 5a3663c42..96d2b195f 100644 --- a/plugin/src/arch/x64/debug.rs +++ b/plugin/src/arch/x64/debug.rs @@ -27,7 +27,7 @@ pub fn format_opdata(name: &str, data: &Opdata) -> Vec<String> { let mut first = true; for (ty, size) in FormatStringIterator::new(data.args) { if first { - buf.push_str(" "); + buf.push(' '); first = false; } else { buf.push_str(", "); diff --git a/plugin/src/arch/x64/parser.rs b/plugin/src/arch/x64/parser.rs index 436a5afd9..0f2c6a4f9 100644 --- a/plugin/src/arch/x64/parser.rs +++ b/plugin/src/arch/x64/parser.rs @@ -252,7 +252,7 @@ fn parse_reg(ctx: &Context, expr: &syn::Expr) -> Option<(Span, Register)> { return None; } - let called = if let Some(called) = as_ident(&&*func) { + let called = if let Some(called) = as_ident(&*func) { called } else { return None; diff --git a/plugin/src/serialize.rs b/plugin/src/serialize.rs index 0d452ee9c..88f92772f 100644 --- a/plugin/src/serialize.rs +++ b/plugin/src/serialize.rs @@ -32,7 +32,7 @@ pub fn serialize(name: &TokenTree, stmts: Vec<Stmt>) -> TokenStream { }, Size::B_8 => { let mut buffer = [0u8; 8]; - LittleEndian::write_u64(&mut buffer, value as u64); + LittleEndian::write_u64(&mut buffer, value); const_buffer.extend(&buffer); }, _ => unimplemented!() diff --git a/runtime/src/components.rs b/runtime/src/components.rs index 1d24d9345..27e51bcab 100644 --- a/runtime/src/components.rs +++ b/runtime/src/components.rs @@ -138,7 +138,7 @@ impl MemoryManager { // copy over the data new_buffer[.. old_asmoffset].copy_from_slice(&self.execbuffer.read().unwrap()); - new_buffer[old_asmoffset..].copy_from_slice(&new); + new_buffer[old_asmoffset..].copy_from_slice(new); let new_buffer_addr = new_buffer.as_ptr() as usize; // allow modifications to be made @@ -160,7 +160,7 @@ impl MemoryManager { // update buffer and length buffer.set_len(new_asmoffset); - buffer[old_asmoffset..].copy_from_slice(&new); + buffer[old_asmoffset..].copy_from_slice(new); // ensure that no old data remains in the icache of what we just updated cache_control::synchronize_icache(&buffer[old_asmoffset .. ]); @@ -287,7 +287,7 @@ impl LabelRegistry { /// Returns the offset at which the dynamic label `id` was defined, if one was defined. pub fn resolve_dynamic(&self, id: DynamicLabel) -> Result<AssemblyOffset, DynasmError> { - self.dynamic_labels.get(id.0).and_then(|&e| e).ok_or_else(|| DynasmError::UnknownLabel(LabelKind::Dynamic(id))) + self.dynamic_labels.get(id.0).and_then(|&e| e).ok_or(DynasmError::UnknownLabel(LabelKind::Dynamic(id))) } /// Returns the offset at which the global label `label` was defined, if one was defined. @@ -516,13 +516,13 @@ impl LitPool { /// Add extra alignment for the next value in the literal pool pub fn align(&mut self, size: usize, with: u8) { - let misalign = self.offset % (size as usize); + let misalign = self.offset % size; if misalign == 0 { return; } self.entries.push(LitPoolEntry::Align(with, size)); - self.offset += size as usize - misalign; + self.offset += size - misalign; } /// Encode `value` into the literal pool. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 049b411fd..7529fdae0 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -610,7 +610,7 @@ impl<R: Relocation> Assembler<R> { let mut modifier = Modifier { asmoffset: 0, previous_asmoffset: 0, - buffer: &mut *buffer, + buffer: &mut buffer, labels: &mut self.labels, relocs: &mut self.relocs, diff --git a/runtime/src/mmap.rs b/runtime/src/mmap.rs index fa4a7d281..22e3d6fc5 100644 --- a/runtime/src/mmap.rs +++ b/runtime/src/mmap.rs @@ -10,7 +10,7 @@ use crate::AssemblyOffset; /// A structure holding a buffer of executable memory. It also derefs to a `&[u8]`. /// This structure does not allocate when its size is 0. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct ExecutableBuffer { // length of the buffer that has actually been written to length: usize, @@ -20,7 +20,7 @@ pub struct ExecutableBuffer { /// ExecutableBuffer equivalent that holds a buffer of mutable memory instead of executable memory. It also derefs to a `&mut [u8]`. /// This structure does not allocate when its size is 0. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct MutableBuffer { // length of the buffer that has actually been written to length: usize, @@ -62,7 +62,7 @@ impl ExecutableBuffer { /// Query the backing size of this executable buffer pub fn size(&self) -> usize { - self.buffer.as_ref().map(|b| b.len()).unwrap_or(0) as usize + self.buffer.as_ref().map(|b| b.len()).unwrap_or(0) } /// Change this executable buffer into a mutable buffer. @@ -98,7 +98,7 @@ impl MutableBuffer { /// Query the backing size of this mutable buffer pub fn size(&self) -> usize { - self.buffer.as_ref().map(|b| b.len()).unwrap_or(0) as usize + self.buffer.as_ref().map(|b| b.len()).unwrap_or(0) } /// Set the length of the usable part of this mutable buffer. The length @@ -122,24 +122,6 @@ impl MutableBuffer { } } -impl Default for ExecutableBuffer { - fn default() -> ExecutableBuffer { - ExecutableBuffer { - length: 0, - buffer: None - } - } -} - -impl Default for MutableBuffer { - fn default() -> MutableBuffer { - MutableBuffer { - length: 0, - buffer: None - } - } -} - impl Deref for ExecutableBuffer { type Target = [u8]; fn deref(&self) -> &[u8] {