From ce94282e1cf3f6a415ebb960e053f5f0ebdea3a1 Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 29 Jul 2022 17:10:40 +0000 Subject: ripple/minitrace: interpret CString arguments to syscalls Change-Id: Ib8ddefb7a969e5cfd7e891233d083670a0c72596 --- ripple/minitrace/src/main.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index eaabad0..09b694c 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -108,11 +108,11 @@ macro_rules! define_syscalls { } impl $SyscallEntry { - fn from_regs(regs: libc::user_regs_struct) -> Result<$SyscallEntry> { + fn from_regs(process: &Process, regs: libc::user_regs_struct) -> Result<$SyscallEntry> { Ok(match (regs.orig_rax, [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9]) { $( ($nr, [$($arg),*, ..]) => $SyscallEntry::$syscall { - $($arg: match SyscallArg::try_from_reg($arg) { + $($arg: match ProcessSyscallArg::try_from_process_reg(process, $arg) { Some(x) => x, None => bail!("couldn't parse {}(2) {}: 0x{:08x}", stringify!($syscall), stringify!($arg), $arg) }),* @@ -178,6 +178,22 @@ macro_rules! syscall_bitflags { }; } +trait ProcessSyscallArg: Sized { + fn try_from_process_reg(process: &Process, reg: u64) -> Option; +} + +impl ProcessSyscallArg for CString { + fn try_from_process_reg(process: &Process, reg: u64) -> Option { + process.read_mem_cstr(reg).ok() + } +} + +impl ProcessSyscallArg for T { + fn try_from_process_reg(_process: &Process, reg: u64) -> Option { + SyscallArg::try_from_reg(reg) + } +} + trait SyscallArg: Sized { fn try_from_reg(reg: u64) -> Option; } @@ -328,7 +344,7 @@ fn main() -> Result<()> { assert_eq!(tid, event_tid); let regs = ptrace::getregs(event_tid.as_pid())?; - let entry = match SyscallEntry::from_regs(regs) { + let entry = match SyscallEntry::from_regs(&process, regs) { Ok(entry) => entry, Err(err) => { ptrace::kill(event_tid.as_pid())?; -- cgit 1.4.1