Removed old PTraceError variant and renamed CustomPtraceError to PTraceError
This commit is contained in:
parent
e61f62487b
commit
123ec6e7d7
|
|
@ -8,11 +8,7 @@ pub use stopped_target::*;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
#[error("Error when calling ptrace: {0}")]
|
#[error("Error when calling ptrace: {0}")]
|
||||||
pub struct PTraceError(#[from] nix::errno::Errno);
|
pub struct PTraceError(#[from] clibwrap::ErrnoError);
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
|
||||||
#[error("Error when calling ptrace: {0}")]
|
|
||||||
pub struct CustomPTraceError(#[from] clibwrap::ErrnoError);
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
#[error("Error when waiting on child process: {0}")]
|
#[error("Error when waiting on child process: {0}")]
|
||||||
|
|
@ -23,9 +19,6 @@ pub enum DebugError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
PTraceError(#[from] PTraceError),
|
PTraceError(#[from] PTraceError),
|
||||||
|
|
||||||
#[error(transparent)]
|
|
||||||
CustomPTraceError(#[from] CustomPTraceError),
|
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
WaitError(#[from] WaitError),
|
WaitError(#[from] WaitError),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::clibwrap;
|
use crate::clibwrap;
|
||||||
use crate::debug_target::{CustomPTraceError, DebugError, RunningTarget, WaitError};
|
use crate::debug_target::{DebugError, PTraceError, RunningTarget, WaitError};
|
||||||
use crate::syscall_info::{syscall_info, SyscallInfo, SyscallInfoError};
|
use crate::syscall_info::{syscall_info, SyscallInfo, SyscallInfoError};
|
||||||
use libc::c_long;
|
use libc::c_long;
|
||||||
use nix::sys::wait::{waitid, Id, WaitPidFlag};
|
use nix::sys::wait::{waitid, Id, WaitPidFlag};
|
||||||
|
|
@ -21,11 +21,11 @@ impl StoppedTarget {
|
||||||
pub fn new(pid: Pid) -> Result<Self, DebugError> {
|
pub fn new(pid: Pid) -> Result<Self, DebugError> {
|
||||||
waitid(Id::Pid(pid), WaitPidFlag::WSTOPPED).map_err(WaitError)?;
|
waitid(Id::Pid(pid), WaitPidFlag::WSTOPPED).map_err(WaitError)?;
|
||||||
// Needed for waiting on syscalls and apparently also for getting syscall info (can not get it to work without this)
|
// Needed for waiting on syscalls and apparently also for getting syscall info (can not get it to work without this)
|
||||||
clibwrap::ptrace::set_options(pid.as_raw(), clibwrap::ptrace::PTraceOptions::PTRACE_O_TRACESYSGOOD).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::set_options(pid.as_raw(), clibwrap::ptrace::PTraceOptions::PTRACE_O_TRACESYSGOOD).map_err(PTraceError)?;
|
||||||
Ok(Self { pid, breakpoints: HashMap::new() })
|
Ok(Self { pid, breakpoints: HashMap::new() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_breakpoint(&self) -> Result<bool, CustomPTraceError> {
|
pub fn on_breakpoint(&self) -> Result<bool, PTraceError> {
|
||||||
let rip = self.get_registers()?.rip;
|
let rip = self.get_registers()?.rip;
|
||||||
Ok(self.breakpoints.contains_key(&(rip - 1)))
|
Ok(self.breakpoints.contains_key(&(rip - 1)))
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ impl StoppedTarget {
|
||||||
let mut registers = self.get_registers()?;
|
let mut registers = self.get_registers()?;
|
||||||
self.remove_breakpoint(registers.rip - 1)?;
|
self.remove_breakpoint(registers.rip - 1)?;
|
||||||
registers.rip -= 1;
|
registers.rip -= 1;
|
||||||
clibwrap::ptrace::set_regs(self.pid.as_raw(), registers).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::set_regs(self.pid.as_raw(), registers).map_err(PTraceError)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ impl StoppedTarget {
|
||||||
if self.on_breakpoint()? {
|
if self.on_breakpoint()? {
|
||||||
self.breakpoint_remove_and_rewind()?;
|
self.breakpoint_remove_and_rewind()?;
|
||||||
}
|
}
|
||||||
clibwrap::ptrace::cont(self.pid.as_raw()).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::cont(self.pid.as_raw()).map_err(PTraceError)?;
|
||||||
Ok(self.to_running())
|
Ok(self.to_running())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ impl StoppedTarget {
|
||||||
if self.on_breakpoint()? {
|
if self.on_breakpoint()? {
|
||||||
self.breakpoint_remove_and_rewind()?;
|
self.breakpoint_remove_and_rewind()?;
|
||||||
}
|
}
|
||||||
clibwrap::ptrace::single_step(self.pid.as_raw()).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::single_step(self.pid.as_raw()).map_err(PTraceError)?;
|
||||||
Ok(self.to_running())
|
Ok(self.to_running())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,12 +58,12 @@ impl StoppedTarget {
|
||||||
if self.on_breakpoint()? {
|
if self.on_breakpoint()? {
|
||||||
self.breakpoint_remove_and_rewind()?;
|
self.breakpoint_remove_and_rewind()?;
|
||||||
}
|
}
|
||||||
clibwrap::ptrace::syscall(self.pid.as_raw()).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::syscall(self.pid.as_raw()).map_err(PTraceError)?;
|
||||||
Ok(self.to_running())
|
Ok(self.to_running())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_registers(&self) -> Result<clibwrap::ptrace::registers, CustomPTraceError> {
|
pub fn get_registers(&self) -> Result<clibwrap::ptrace::registers, PTraceError> {
|
||||||
clibwrap::ptrace::get_regs(self.pid.as_raw()).map_err(CustomPTraceError)
|
clibwrap::ptrace::get_regs(self.pid.as_raw()).map_err(PTraceError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_syscall_info(&self) -> Result<SyscallInfo, SyscallInfoError> {
|
pub fn get_syscall_info(&self) -> Result<SyscallInfo, SyscallInfoError> {
|
||||||
|
|
@ -75,10 +75,10 @@ impl StoppedTarget {
|
||||||
if self.breakpoints.contains_key(&address) {
|
if self.breakpoints.contains_key(&address) {
|
||||||
return Err(DebugError::DuplicateBreakpoint { address });
|
return Err(DebugError::DuplicateBreakpoint { address });
|
||||||
}
|
}
|
||||||
let orig_bytes = clibwrap::ptrace::peek_data(self.pid.as_raw(), address).map_err(CustomPTraceError)?;
|
let orig_bytes = clibwrap::ptrace::peek_data(self.pid.as_raw(), address).map_err(PTraceError)?;
|
||||||
let target_byte: u8 = (orig_bytes & 0xFF as c_long) as u8;
|
let target_byte: u8 = (orig_bytes & 0xFF as c_long) as u8;
|
||||||
let new_content = (orig_bytes & (!0xff as c_long)) | (0xCC as c_long);
|
let new_content = (orig_bytes & (!0xff as c_long)) | (0xCC as c_long);
|
||||||
clibwrap::ptrace::poke_data(self.pid.as_raw(), address, new_content).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::poke_data(self.pid.as_raw(), address, new_content).map_err(PTraceError)?;
|
||||||
|
|
||||||
self.breakpoints.insert(address, target_byte);
|
self.breakpoints.insert(address, target_byte);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -89,9 +89,9 @@ impl StoppedTarget {
|
||||||
match self.breakpoints.remove(&address) {
|
match self.breakpoints.remove(&address) {
|
||||||
None => Err(DebugError::NonExistingBreakpoint { address }),
|
None => Err(DebugError::NonExistingBreakpoint { address }),
|
||||||
Some(original_byte) => {
|
Some(original_byte) => {
|
||||||
let content = clibwrap::ptrace::peek_data(self.pid.as_raw(), address).map_err(CustomPTraceError)?;
|
let content = clibwrap::ptrace::peek_data(self.pid.as_raw(), address).map_err(PTraceError)?;
|
||||||
let new_content = (content & (!0xff as c_long)) | (original_byte as c_long);
|
let new_content = (content & (!0xff as c_long)) | (original_byte as c_long);
|
||||||
clibwrap::ptrace::poke_data(self.pid.as_raw(), address, new_content).map_err(CustomPTraceError)?;
|
clibwrap::ptrace::poke_data(self.pid.as_raw(), address, new_content).map_err(PTraceError)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue