clippy fixes

This commit is contained in:
Dominik Maier 2021-05-05 13:15:59 +02:00 committed by Andrea Fioraldi
parent 9b4fb23ec2
commit 1d7baffea9
2 changed files with 25 additions and 16 deletions

View File

@ -746,6 +746,7 @@ impl AsanRuntime {
} }
/// Reset all allocations so that they can be reused for new allocation requests. /// Reset all allocations so that they can be reused for new allocation requests.
#[allow(clippy::unused_self)]
pub fn reset_allocations(&self) { pub fn reset_allocations(&self) {
Allocator::get().reset(); Allocator::get().reset();
} }
@ -759,11 +760,13 @@ impl AsanRuntime {
} }
} }
#[allow(clippy::unused_self)]
pub fn errors(&mut self) -> &Option<AsanErrors> { pub fn errors(&mut self) -> &Option<AsanErrors> {
unsafe { &ASAN_ERRORS } unsafe { &ASAN_ERRORS }
} }
/// Make sure the specified memory is unpoisoned /// Make sure the specified memory is unpoisoned
#[allow(clippy::unused_self)]
pub fn unpoison(&self, address: usize, size: usize) { pub fn unpoison(&self, address: usize, size: usize) {
Allocator::get().map_shadow_for_region(address, address + size, true); Allocator::get().map_shadow_for_region(address, address + size, true);
} }
@ -779,6 +782,7 @@ impl AsanRuntime {
} }
/// Unpoison all the memory that is currently mapped with read/write permissions. /// Unpoison all the memory that is currently mapped with read/write permissions.
#[allow(clippy::unused_self)]
fn unpoison_all_existing_memory(&self) { fn unpoison_all_existing_memory(&self) {
let mut allocator = Allocator::get(); let mut allocator = Allocator::get();
walk_self_maps(&mut |start, end, permissions, _path| { walk_self_maps(&mut |start, end, permissions, _path| {
@ -794,6 +798,7 @@ impl AsanRuntime {
/// Register the current thread with the runtime, implementing shadow memory for its stack and /// Register the current thread with the runtime, implementing shadow memory for its stack and
/// tls mappings. /// tls mappings.
#[allow(clippy::unused_self)]
pub fn register_thread(&self) { pub fn register_thread(&self) {
let mut allocator = Allocator::get(); let mut allocator = Allocator::get();
let (stack_start, stack_end) = Self::current_stack(); let (stack_start, stack_end) = Self::current_stack();
@ -855,6 +860,7 @@ impl AsanRuntime {
/// Locate the target library and hook it's memory allocation functions /// Locate the target library and hook it's memory allocation functions
#[cfg(unix)] #[cfg(unix)]
#[allow(clippy::unused_self)]
fn hook_library(&mut self, path: &str) { fn hook_library(&mut self, path: &str) {
let target_lib = GotHookLibrary::new(path, false); let target_lib = GotHookLibrary::new(path, false);
@ -925,6 +931,8 @@ impl AsanRuntime {
} }
} }
#[allow(clippy::cast_sign_loss)] // for displacement
#[allow(clippy::too_many_lines)]
extern "C" fn handle_trap(&mut self) { extern "C" fn handle_trap(&mut self) {
let mut actual_pc = self.regs[31]; let mut actual_pc = self.regs[31];
actual_pc = match self.stalked_addresses.get(&actual_pc) { actual_pc = match self.stalked_addresses.get(&actual_pc) {
@ -990,6 +998,7 @@ impl AsanRuntime {
base_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16; base_reg -= capstone::arch::arm64::Arm64Reg::ARM64_REG_S0 as u16;
} }
#[allow(clippy::clippy::cast_possible_wrap)]
let mut fault_address = let mut fault_address =
(self.regs[base_reg as usize] as isize + displacement as isize) as usize; (self.regs[base_reg as usize] as isize + displacement as isize) as usize;
@ -1043,6 +1052,7 @@ impl AsanRuntime {
} }
} else { } else {
let mut allocator = Allocator::get(); let mut allocator = Allocator::get();
#[allow(clippy::option_if_let_else)]
if let Some(metadata) = if let Some(metadata) =
allocator.find_metadata(fault_address, self.regs[base_reg as usize]) allocator.find_metadata(fault_address, self.regs[base_reg as usize])
{ {
@ -1076,6 +1086,7 @@ impl AsanRuntime {
self.report_error(error); self.report_error(error);
} }
#[allow(clippy::too_many_lines)]
fn report_error(&mut self, error: AsanError) { fn report_error(&mut self, error: AsanError) {
unsafe { unsafe {
ASAN_ERRORS.as_mut().unwrap().errors.push(error.clone()); ASAN_ERRORS.as_mut().unwrap().errors.push(error.clone());
@ -1356,6 +1367,7 @@ impl AsanRuntime {
} }
} }
#[allow(clippy::unused_self)]
fn generate_shadow_check_blob(&mut self, bit: u32) -> Box<[u8]> { fn generate_shadow_check_blob(&mut self, bit: u32) -> Box<[u8]> {
let shadow_bit = Allocator::get().shadow_bit as u32; let shadow_bit = Allocator::get().shadow_bit as u32;
macro_rules! shadow_check { macro_rules! shadow_check {
@ -1386,6 +1398,7 @@ impl AsanRuntime {
ops_vec[..ops_vec.len() - 4].to_vec().into_boxed_slice() ops_vec[..ops_vec.len() - 4].to_vec().into_boxed_slice()
} }
#[allow(clippy::unused_self)]
fn generate_shadow_check_exact_blob(&mut self, val: u32) -> Box<[u8]> { fn generate_shadow_check_exact_blob(&mut self, val: u32) -> Box<[u8]> {
let shadow_bit = Allocator::get().shadow_bit as u32; let shadow_bit = Allocator::get().shadow_bit as u32;
macro_rules! shadow_check_exact { macro_rules! shadow_check_exact {
@ -1422,6 +1435,8 @@ impl AsanRuntime {
/// ///
/// Generate the instrumentation blobs for the current arch. /// Generate the instrumentation blobs for the current arch.
#[allow(clippy::similar_names)] // We allow things like dword and qword #[allow(clippy::similar_names)] // We allow things like dword and qword
#[allow(clippy::cast_possible_wrap)]
#[allow(clippy::too_many_lines)]
fn generate_instrumentation_blobs(&mut self) { fn generate_instrumentation_blobs(&mut self) {
let mut ops_report = dynasmrt::VecAssembler::<dynasmrt::aarch64::Aarch64Relocation>::new(0); let mut ops_report = dynasmrt::VecAssembler::<dynasmrt::aarch64::Aarch64Relocation>::new(0);
dynasm!(ops_report dynasm!(ops_report
@ -1522,7 +1537,7 @@ impl AsanRuntime {
//offset r30 (x30) at cfa-8 //offset r30 (x30) at cfa-8
//offset r29 (x29) at cfa-16 //offset r29 (x29) at cfa-16
; .dword 0x1d0c4c00 ; .dword 0x1d0c4c00
; .dword 0x9d029e10 as u32 as i32 ; .dword 0x9d029e10u32 as i32
; .dword 0x04 ; .dword 0x04
// empty next FDE: // empty next FDE:
; .dword 0x0 ; .dword 0x0

View File

@ -378,7 +378,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Aarch64Register::X0, Aarch64Register::X0,
Aarch64Register::X1, Aarch64Register::X1,
Aarch64Register::Sp, Aarch64Register::Sp,
-(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64, -(16 + redzone_size) as i64,
IndexMode::PreAdjust, IndexMode::PreAdjust,
); );
@ -459,7 +459,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
let displacement = displacement let displacement = displacement
+ if basereg == Aarch64Register::Sp { + if basereg == Aarch64Register::Sp {
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32 16 + redzone_size
} else { } else {
0 0
}; };
@ -536,7 +536,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Aarch64Register::X0, Aarch64Register::X0,
Aarch64Register::X1, Aarch64Register::X1,
Aarch64Register::Sp, Aarch64Register::Sp,
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64, 16 + redzone_size as i64,
IndexMode::PostAdjust, IndexMode::PostAdjust,
)); ));
} }
@ -662,6 +662,8 @@ impl<'a> FridaInstrumentationHelper<'a> {
#[inline] #[inline]
fn emit_coverage_mapping(&mut self, address: u64, output: &StalkerOutput) { fn emit_coverage_mapping(&mut self, address: u64, output: &StalkerOutput) {
let writer = output.writer(); let writer = output.writer();
#[allow(clippy::cast_possible_wrap)] // gum redzone size is u32, we need an offset as i32.
let redzone_size = frida_gum_sys::GUM_RED_ZONE_SIZE as i32;
if self.current_log_impl == 0 if self.current_log_impl == 0
|| !writer.can_branch_directly_to(self.current_log_impl) || !writer.can_branch_directly_to(self.current_log_impl)
|| !writer.can_branch_directly_between(writer.pc() + 128, self.current_log_impl) || !writer.can_branch_directly_between(writer.pc() + 128, self.current_log_impl)
@ -686,11 +688,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
{ {
println!("here"); println!("here");
writer.put_lea_reg_reg_offset( writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, -(redzone_size));
X86Register::Rsp,
X86Register::Rsp,
-(frida_gum_sys::GUM_RED_ZONE_SIZE as i32),
);
writer.put_push_reg(X86Register::Rdi); writer.put_push_reg(X86Register::Rdi);
writer.put_mov_reg_address( writer.put_mov_reg_address(
X86Register::Rdi, X86Register::Rdi,
@ -698,11 +696,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
); );
writer.put_call_address(self.current_log_impl); writer.put_call_address(self.current_log_impl);
writer.put_pop_reg(X86Register::Rdi); writer.put_pop_reg(X86Register::Rdi);
writer.put_lea_reg_reg_offset( writer.put_lea_reg_reg_offset(X86Register::Rsp, X86Register::Rsp, redzone_size);
X86Register::Rsp,
X86Register::Rsp,
frida_gum_sys::GUM_RED_ZONE_SIZE as i32,
);
} }
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
{ {
@ -710,7 +704,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Aarch64Register::Lr, Aarch64Register::Lr,
Aarch64Register::X0, Aarch64Register::X0,
Aarch64Register::Sp, Aarch64Register::Sp,
-(16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i32) as i64, -(16 + redzone_size) as i64,
IndexMode::PreAdjust, IndexMode::PreAdjust,
); );
writer.put_ldr_reg_u64( writer.put_ldr_reg_u64(
@ -722,7 +716,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Aarch64Register::Lr, Aarch64Register::Lr,
Aarch64Register::X0, Aarch64Register::X0,
Aarch64Register::Sp, Aarch64Register::Sp,
16 + frida_gum_sys::GUM_RED_ZONE_SIZE as i64, 16 + redzone_size as i64,
IndexMode::PostAdjust, IndexMode::PostAdjust,
); );
} }