Fix cfgs for frida asan (#353)

* fix

* fmt
This commit is contained in:
Toka 2021-11-06 01:15:59 +09:00 committed by GitHub
parent 1ea95e73f4
commit 380196cf41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ use capstone::{
Capstone, Insn, Capstone, Insn,
}; };
#[cfg(target_arch = "x86_64")] #[cfg(all(target_arch = "x86_64", unix))]
use capstone::{ use capstone::{
arch::{self, x86::X86OperandType, ArchOperand::X86Operand, BuildsCapstone}, arch::{self, x86::X86OperandType, ArchOperand::X86Operand, BuildsCapstone},
Capstone, Insn, RegId, Capstone, Insn, RegId,
@ -105,9 +105,11 @@ pub struct FridaInstrumentationHelper<'a> {
map: [u8; MAP_SIZE], map: [u8; MAP_SIZE],
previous_pc: [u64; 1], previous_pc: [u64; 1],
current_log_impl: u64, current_log_impl: u64,
#[cfg(unix)]
current_report_impl: u64, current_report_impl: u64,
/// Transformer that has to be passed to FridaInProcessExecutor /// Transformer that has to be passed to FridaInProcessExecutor
transformer: Option<Transformer<'a>>, transformer: Option<Transformer<'a>>,
#[cfg(unix)]
capstone: Capstone, capstone: Capstone,
#[cfg(unix)] #[cfg(unix)]
asan_runtime: AsanRuntime, asan_runtime: AsanRuntime,
@ -130,6 +132,10 @@ impl<'a> FridaHelper<'a> for FridaInstrumentationHelper<'a> {
self.asan_runtime.register_thread(); self.asan_runtime.register_thread();
} }
#[cfg(not(unix))]
fn pre_exec<I: Input + HasTargetBytes>(&mut self, _input: &I) {}
#[cfg(unix)]
fn pre_exec<I: Input + HasTargetBytes>(&mut self, input: &I) { fn pre_exec<I: Input + HasTargetBytes>(&mut self, input: &I) {
let target_bytes = input.target_bytes(); let target_bytes = input.target_bytes();
let slice = target_bytes.as_slice(); let slice = target_bytes.as_slice();
@ -149,6 +155,7 @@ impl<'a> FridaHelper<'a> for FridaInstrumentationHelper<'a> {
DrCovWriter::new(&filename, &self.ranges, &mut self.drcov_basic_blocks).write(); DrCovWriter::new(&filename, &self.ranges, &mut self.drcov_basic_blocks).write();
} }
#[cfg(unix)]
if self.options.asan_enabled() { if self.options.asan_enabled() {
if self.options.asan_detect_leaks() { if self.options.asan_detect_leaks() {
self.asan_runtime.check_for_leaks(); self.asan_runtime.check_for_leaks();
@ -251,7 +258,7 @@ fn pc(context: &CpuContext) -> usize {
context.pc() as usize context.pc() as usize
} }
#[cfg(all(target_arch = "x86_64", not(windows)))] #[cfg(all(target_arch = "x86_64", unix))]
fn pc(context: &CpuContext) -> usize { fn pc(context: &CpuContext) -> usize {
context.rip() as usize context.rip() as usize
} }
@ -296,6 +303,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
map: [0u8; MAP_SIZE], map: [0u8; MAP_SIZE],
previous_pc: [0u64; 1], previous_pc: [0u64; 1],
current_log_impl: 0, current_log_impl: 0,
#[cfg(unix)]
current_report_impl: 0, current_report_impl: 0,
transformer: None, transformer: None,
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
@ -305,7 +313,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
.detail(true) .detail(true)
.build() .build()
.expect("Failed to create Capstone object"), .expect("Failed to create Capstone object"),
#[cfg(target_arch = "x86_64")] #[cfg(all(target_arch = "x86_64", unix))]
capstone: Capstone::new() capstone: Capstone::new()
.x86() .x86()
.mode(arch::x86::ArchMode::Mode64) .mode(arch::x86::ArchMode::Mode64)
@ -383,7 +391,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
} }
if helper.options().asan_enabled() { if helper.options().asan_enabled() {
#[cfg(target_arch = "x86_64")] #[cfg(all(target_arch = "x86_64", unix))]
if let Ok((segment, width, basereg, indexreg, scale, disp)) = if let Ok((segment, width, basereg, indexreg, scale, disp)) =
helper.asan_is_interesting_instruction(address, instr) helper.asan_is_interesting_instruction(address, instr)
{ {
@ -465,7 +473,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
// frida registers: https://docs.rs/frida-gum/0.4.0/frida_gum/instruction_writer/enum.X86Register.html // frida registers: https://docs.rs/frida-gum/0.4.0/frida_gum/instruction_writer/enum.X86Register.html
// capstone registers: https://docs.rs/capstone-sys/0.14.0/capstone_sys/x86_reg/index.html // capstone registers: https://docs.rs/capstone-sys/0.14.0/capstone_sys/x86_reg/index.html
#[cfg(target_arch = "x86_64")] #[cfg(all(target_arch = "x86_64", unix))]
#[must_use] #[must_use]
#[inline] #[inline]
#[allow(clippy::unused_self)] #[allow(clippy::unused_self)]
@ -831,6 +839,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
#[inline] #[inline]
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[cfg(all(target_arch = "x86_64", unix))]
pub fn emit_shadow_check( pub fn emit_shadow_check(
&mut self, &mut self,
address: u64, address: u64,
@ -1312,7 +1321,7 @@ impl<'a> FridaInstrumentationHelper<'a> {
Err(()) Err(())
} }
#[cfg(target_arch = "x86_64")] #[cfg(all(target_arch = "x86_64", unix))]
#[inline] #[inline]
fn asan_is_interesting_instruction( fn asan_is_interesting_instruction(
&self, &self,