1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::memory::{error::MemoryResult, MemoryManipulation};
use crate::process::Process;
#[derive(Default, Debug, Copy, Clone)]
pub struct InternalManipulator;
impl MemoryManipulation for InternalManipulator {
fn read(&self, address: usize, buf: &mut [u8]) -> MemoryResult<usize> {
let pointer = unsafe { std::mem::transmute::<usize, *const u8>(address) };
unsafe { std::ptr::copy(pointer, buf[0] as *mut u8, buf.len()) };
Ok(buf.len())
}
fn write(&self, address: usize, payload: &[u8]) -> MemoryResult<usize> {
let pointer = unsafe { std::mem::transmute::<usize, *mut u8>(address) };
unsafe { std::ptr::copy(payload[0] as *const u8, pointer, payload.len()) };
Ok(payload.len())
}
}
impl Process for InternalManipulator {
fn pid(&self) -> i32 {
std::process::id() as i32
}
}