pub struct Mem;Expand description
Tracee memory accessor. Cheap to copy; the probe result is global.
Implementations§
Source§impl Mem
impl Mem
Sourcepub fn write(&self, pid: u32, addr: u64, buf: &[u8]) -> Result<(), i32>
pub fn write(&self, pid: u32, addr: u64, buf: &[u8]) -> Result<(), i32>
Writes buf at addr in pid’s address space.
§Arguments
pid- Tracee thread id.addr- Virtual address in the tracee.buf- Bytes to write; a short write is an error.
Sourcepub fn write_force(&self, pid: u32, addr: u64, buf: &[u8]) -> Result<(), i32>
pub fn write_force(&self, pid: u32, addr: u64, buf: &[u8]) -> Result<(), i32>
Writes buf at addr through /proc/<pid>/mem, whatever the page’s protection.
process_vm_writev honours the mapping’s permissions, so a string in
.rodata cannot be changed that way; /proc/<pid>/mem writes behave
like a debugger’s and copy the page privately. Used for the in-place
argument rewrites of the no-ptrace mode.
§Arguments
pid- Tracee thread id.addr- Virtual address in the tracee.buf- Bytes to write; a short write is an error.
Sourcepub fn read_string(
&self,
pid: u32,
addr: u64,
max: usize,
) -> Result<Vec<u8>, i32>
pub fn read_string( &self, pid: u32, addr: u64, max: usize, ) -> Result<Vec<u8>, i32>
Reads a NUL-terminated string of fewer than max bytes.
Reads stop at page boundaries so a short string next to an unmapped
page does not fault. An argument or environment entry of an exec is
read with MAX_ARG_STRLEN, the kernel’s own limit for one such
string; a path with PATH_MAX.
§Arguments
pid- Tracee thread id.addr- Address of the first byte.max- Length at which the read gives up.
§Returns
The bytes before the NUL.
§Errors
ENAMETOOLONG when no NUL is found within max bytes, EFAULT otherwise.
Sourcepub fn read_ptr_array(
&self,
pid: u32,
addr: u64,
max: usize,
) -> Result<Vec<u64>, i32>
pub fn read_ptr_array( &self, pid: u32, addr: u64, max: usize, ) -> Result<Vec<u64>, i32>
Reads a NUL-terminated array of 8-byte pointers (argv/envp style).
§Arguments
pid- Tracee thread id.addr- Address of the first pointer.max- Give up (withE2BIG) after this many entries.
Sourcepub fn read_ptr_array_sized(
&self,
pid: u32,
addr: u64,
max: usize,
width: usize,
) -> Result<Vec<u64>, i32>
pub fn read_ptr_array_sized( &self, pid: u32, addr: u64, max: usize, width: usize, ) -> Result<Vec<u64>, i32>
Reads a NUL-terminated pointer array whose entries are width bytes (4 or 8).
§Arguments
pid- Tracee thread id.addr- Address of the first pointer.max- Give up (withE2BIG) after this many entries.width- Pointer size of the tracee’s ABI.