Write memory - #41
Conversation
| } | ||
|
|
||
| /// Executes the memory write operation. | ||
| pub unsafe fn apply(self) -> Result<(), Box<dyn std::error::Error>> { |
There was a problem hiding this comment.
This is safe as it can only crash the remote process, right?
|
I can help with adding test for writing to write-protected pages if you want? |
No worries, I should finish this today. :) Thanks! |
- Use immutable ref for lifetime invariance in WriteMemory - Allow to pass slices to write Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
- Use ptr::read_volatile for volatile read operations - Simpler capacity calc expression Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
Memory write operations are split into those which are applicable to memory pages which are writable, and those which need to resort to ptrace for writing to write-protected memory pages.
Use a single type for both writing and reading memory instead of a trait. This approach simplifies generic memory operations (like splitting memory ops based on page permissions or splitting memory ops on page boundary), while still leaving place for introducing write- or read- specific functions in the future. This commit also changes the approach used for splitting write operations into word-sized groups. Instead of allocating a new vector, we now use a custom iterator. This should reduce a number of unnecessary allocations. Finally, this commit also introduces a delay before reading written values in ptrace writing tests.
- Add `LinuxTarget::write()` - Also make `WriteMem::apply` safe as it operates only on the debuggee process.
- Reduce `linux::MemoryOp` visibility to `pub(crate)` - Improve doc comments. - Make macOS `WriteMem` conforming to Linux API. Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
|
Hmm, writemem tests fail sporadically. This seems to be caused by fork deadlock ( Edit: |
lazy_static can fail if it's used in a forked process, so this commit uses an explicit apply_ptrace() instead of reading debuggee memory maps and determining what memory write operation to use. This is a temporary workaround until we find a better approach.
It looks like there's no quick fix for this. I've used a workaround - the test that was failing now uses an explicit |
Implements #7
process_vm_writeon Linux.ptraceon Linux.mach_vm_writeon macOS.