Removing now-useless code from main

This commit is contained in:
Elnath 2025-05-18 17:54:12 +02:00
parent 5897c9e862
commit 14e8d0b386
1 changed files with 2 additions and 54 deletions

View File

@ -5,12 +5,10 @@ mod syscall_info;
use crate::debug_target::{ExitedTarget, StoppedTarget}; use crate::debug_target::{ExitedTarget, StoppedTarget};
use color_eyre::eyre::eyre; use color_eyre::eyre::eyre;
use either::Either; use either::Either;
use nix::libc::user_regs_struct;
use nix::sys::ptrace::*; use nix::sys::ptrace::*;
use nix::sys::signal::Signal::*; use nix::sys::signal::Signal::*;
use nix::sys::wait::{waitid, waitpid, Id, WaitPidFlag, WaitStatus}; use nix::unistd::{fork, ForkResult};
use nix::unistd::{fork, ForkResult, Pid}; use std::ffi::CString;
use std::ffi::{c_long, c_void, CString};
#[allow(dead_code)] #[allow(dead_code)]
fn single_step_all(mut target: StoppedTarget) -> color_eyre::Result<()> { fn single_step_all(mut target: StoppedTarget) -> color_eyre::Result<()> {
@ -45,55 +43,6 @@ fn strace(mut target: StoppedTarget) -> color_eyre::Result<()> {
} }
} }
#[allow(dead_code)]
fn breakpoint_fun(child_pid: Pid) -> color_eyre::Result<()> {
let address: u64 = 0x0000000000401019;
println!("🚧 Setting breakpoint at location 0x{address:x}");
let orig_bytes: [u8; 8] = read(child_pid, address as *mut c_void).expect("Breakpoint memory read").to_le_bytes();
println!("\t🔎 Original content is: {}", orig_bytes.map(|b| format!("{:#04x}", b)).join(" "));
let mut new_bytes = orig_bytes.clone();
new_bytes[0] = 0xCC;
println!(
"\t🌟 New content will be: {}",
new_bytes.map(|b| format!("{:#04x}", b)).join(" ")
);
write(child_pid, address as *mut c_void, c_long::from_le_bytes(new_bytes)).expect("Breakpoint memory write");
println!("\t🖍️ Breakpoint set");
println!("⚙️ Continuing execution waiting for breakpoint");
cont(child_pid, None)?;
match waitpid(child_pid, None)? {
WaitStatus::Stopped(_, SIGTRAP) => {
let registers = getregs(child_pid)?;
let breakpoint_addr = registers.rip - 1;
println!("🛑 Stopped at breakpoint ({:#018x})!", breakpoint_addr);
println!("\t🔎 Registers content: {:?}", registers);
println!("\t🖍️ Restoring instructions to original");
write(child_pid, address as *mut c_void, c_long::from_le_bytes(orig_bytes)).expect("breakpoint restore memory");
println!("\t↪️ Rolling back instruction pointer");
setregs(child_pid, user_regs_struct { rip: breakpoint_addr, ..registers })?;
println!("\t⚙️ One more instruction");
step(child_pid, None)?;
waitid(Id::Pid(child_pid), WaitPidFlag::WSTOPPED)?;
println!("\t⚙️ Continuing execution");
cont(child_pid, None)?;
}
other => {
return Err(eyre!("⚠️ Other (unexpected) wait status: {other:?}"));
}
}
match waitpid(child_pid, None) {
Ok(WaitStatus::Exited(_, exit_code)) => {
println!("👋 Child exited with code {exit_code}");
Ok(())
}
other => {
Err(eyre!("⚠️ Other (unexpected) wait status: {other:?}"))
}
}
}
fn main() -> color_eyre::Result<()> { fn main() -> color_eyre::Result<()> {
color_eyre::install()?; color_eyre::install()?;
let child_exec_path = CString::new(env!("ASM_PROG_PATH"))?; let child_exec_path = CString::new(env!("ASM_PROG_PATH"))?;
@ -127,7 +76,6 @@ fn main() -> color_eyre::Result<()> {
// single_step_all(target) // single_step_all(target)
// strace(target) // strace(target)
// breakpoint_fun(child_pid)
} }
Err(e) => { Err(e) => {
println!("❌ Fork failed: {e}"); println!("❌ Fork failed: {e}");