#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
#![deny(unused_results)]
#![deny(unreachable_pub)]
#![deny(missing_debug_implementations)]
#![deny(rust_2018_idioms)]
#![deny(bad_style)]
#![deny(unused)]
#![deny(clippy::pedantic)]
mod architecture;
mod data_member;
mod local_member;
pub use architecture::Architecture;
pub use data_member::DataMember;
pub use local_member::LocalMember;
#[cfg(target_os = "linux")]
#[path = "linux.rs"]
mod platform;
#[cfg(target_os = "macos")]
#[path = "macos.rs"]
mod platform;
#[cfg(windows)]
#[path = "windows.rs"]
mod platform;
pub trait CopyAddress {
fn copy_address(&self, addr: usize, buf: &mut [u8]) -> std::io::Result<()>;
fn get_offset(&self, offsets: &[usize]) -> std::io::Result<usize> {
let mut offset: usize = 0;
let noffsets: usize = offsets.len();
let mut copy = vec![0_u8; self.get_pointer_width() as usize];
for next_offset in offsets.iter().take(noffsets - 1) {
offset += next_offset;
self.copy_address(offset, &mut copy)?;
offset = self.get_pointer_width().pointer_from_ne_bytes(©);
}
offset += offsets[noffsets - 1];
Ok(offset)
}
fn get_pointer_width(&self) -> Architecture;
}
pub trait PutAddress {
fn put_address(&self, addr: usize, buf: &[u8]) -> std::io::Result<()>;
}
pub use platform::Pid;
pub use platform::ProcessHandle;
pub trait TryIntoProcessHandle {
fn try_into_process_handle(&self) -> std::io::Result<ProcessHandle>;
}
impl TryIntoProcessHandle for ProcessHandle {
fn try_into_process_handle(&self) -> std::io::Result<platform::ProcessHandle> {
Ok(*self)
}
}
pub trait ProcessHandleExt {
fn check_handle(&self) -> bool;
#[must_use]
fn null_type() -> ProcessHandle;
#[must_use]
fn set_arch(self, arch: Architecture) -> Self;
}
pub trait Memory<T> {
fn set_offset(&mut self, new_offsets: Vec<usize>);
fn get_offset(&self) -> std::io::Result<usize>;
unsafe fn read(&self) -> std::io::Result<T>;
fn write(&self, value: &T) -> std::io::Result<()>;
}
pub fn copy_address<T>(addr: usize, length: usize, source: &T) -> std::io::Result<Vec<u8>>
where
T: CopyAddress,
{
let mut copy = vec![0; length];
source.copy_address(addr, &mut copy)?;
Ok(copy)
}