From cd8ae69d7ff434b1d06fbf327d3d9b9f0059eba6 Mon Sep 17 00:00:00 2001 From: Elnath Date: Fri, 18 Apr 2025 19:27:55 +0200 Subject: [PATCH] Changing a register value --- src/main.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8baa1d7..2a9061f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ mod child; +use nix::libc::user_regs_struct; use nix::sys::ptrace::*; use nix::sys::wait::waitpid; -use nix::unistd::{ForkResult, fork}; +use nix::unistd::{fork, ForkResult}; use std::ffi::CString; -use std::io; use std::process::ExitCode; fn main() -> ExitCode { @@ -38,8 +38,17 @@ fn main() -> ExitCode { }, Stopped(_pid, _signal) => { let regs = getregs(child_pid).unwrap(); - println!("🔎 [{}] rip= 0x{:016X}, rax = 0x{rax:X} ({rax})", before_instruction, regs.rip, rax = regs.rax); - io::stdin().read_line(&mut String::new()).unwrap(); + println!( + "🔎 [{}] rip= 0x{:016X}, rax = 0x{rax:X} ({rax})", + before_instruction, + regs.rip, + rax = regs.rax + ); + if regs.rax == 60 { + println!("Let's change a register!"); + let new_regs = user_regs_struct { rdi: 54, ..regs }; + setregs(child_pid, new_regs).unwrap(); + } before_instruction += 1; step(child_pid, None).unwrap(); }