Skip to content

Commit

Permalink
Add method to open tracee memory as File (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranweiler committed Sep 4, 2023
1 parent 0a7e800 commit 86a7f13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add accessors for the default options applied to newly-spawned tracees
- Add `Tracee::memory()` to support reading tracee memory as a `File`

### Changed

Expand Down
6 changes: 5 additions & 1 deletion src/ptracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl Tracee {
pub fn read_memory_mut(&self, addr: u64, data: &mut [u8]) -> Result<usize> {
use std::os::unix::fs::FileExt;

let mem = fs::File::open(self.proc_mem_path())?;
let mem = self.memory()?;
let len = mem.read_at(data, addr)?;
Ok(len)
}
Expand All @@ -211,6 +211,10 @@ impl Tracee {
format!("/proc/{}/mem", tid)
}

pub fn memory(&self) -> Result<fs::File> {
Ok(fs::File::open(self.proc_mem_path())?)
}

pub fn siginfo(&self) -> Result<Option<Siginfo>> {
let info = if let Stop::SignalDelivery { .. } = self.stop {
Some(ptrace::getsiginfo(self.pid).died_if_esrch(self.pid)?)
Expand Down

0 comments on commit 86a7f13

Please sign in to comment.