Last active
June 23, 2019 16:13
-
-
Save jD91mZM2/82e57df6e1b5c9dffdbb565f51e4f56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use ptrace_test_redox::e; | |
use std::{ | |
fs::File, | |
io::{prelude::*, Result}, | |
os::unix::io::{AsRawFd, FromRawFd, RawFd} | |
}; | |
use syscall::{ | |
data::IntRegisters, | |
flag::* | |
}; | |
const FLAGS: usize = WUNTRACED; | |
fn main() -> Result<()> { | |
let pid = e(unsafe { syscall::clone(0) })?; | |
if pid == 0 { | |
e(syscall::kill(e(syscall::getpid())?, SIGSTOP))?; | |
let file = e(syscall::open("file:/bin/regs", O_RDONLY))?; | |
e(syscall::fexec(file, &[["regs".as_ptr() as usize, 4]], &[]))?; | |
// println!("Hello from the child"); | |
// println!("This is a testing test"); | |
// println!("Pretty amazing honsetly"); | |
return Ok(()); | |
} | |
let mut status = 0; | |
println!("Waiting... (Initial)"); | |
e(syscall::waitpid(pid, &mut status, FLAGS))?; | |
println!("Waited! (Initial)"); | |
let mut trace_file = File::open(format!("proc:{}/trace", pid))?; | |
let mut regs_file = unsafe { | |
File::from_raw_fd( | |
e(syscall::dup(trace_file.as_raw_fd() as usize, b"regs/int"))? as RawFd | |
) | |
}; | |
// Won't actually restart the process, because it's stopped by ptrace | |
e(syscall::kill(pid, SIGCONT))?; | |
loop { | |
trace_file.write(&[PTRACE_SYSCALL])?; | |
let mut regs = IntRegisters::default(); | |
regs_file.read(&mut regs)?; | |
println!("SYSCALL: {} ({}, {}, {})", regs.rax, regs.rdi, regs.rsi, regs.rdx); | |
trace_file.write(&[PTRACE_SYSCALL])?; | |
let mut regs = IntRegisters::default(); | |
regs_file.read(&mut regs)?; | |
println!("SYSCALL RET: {}", regs.rax); | |
} | |
// Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment