diff options
author | edef <edef@unfathomable.blue> | 2022-07-29 17:10:40 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-07-29 17:10:40 +0000 |
commit | ce94282e1cf3f6a415ebb960e053f5f0ebdea3a1 (patch) | |
tree | 382b7f4b50bace088041bc11d3d58c6b34808517 /ripple | |
parent | f3ca081e2d4eb1aee45f94fa8977aa7a7807a613 (diff) | |
download | unf-legacy-ce94282e1cf3f6a415ebb960e053f5f0ebdea3a1.tar.zst |
ripple/minitrace: interpret CString arguments to syscalls
Change-Id: Ib8ddefb7a969e5cfd7e891233d083670a0c72596
Diffstat (limited to 'ripple')
-rw-r--r-- | ripple/minitrace/src/main.rs | 22 |
1 files 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<Self>; +} + +impl ProcessSyscallArg for CString { + fn try_from_process_reg(process: &Process, reg: u64) -> Option<Self> { + process.read_mem_cstr(reg).ok() + } +} + +impl<T: SyscallArg> ProcessSyscallArg for T { + fn try_from_process_reg(_process: &Process, reg: u64) -> Option<Self> { + SyscallArg::try_from_reg(reg) + } +} + trait SyscallArg: Sized { fn try_from_reg(reg: u64) -> Option<Self>; } @@ -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())?; |