1mod driver;
21mod process;
22mod memory;
23pub mod ioctl;
24
25pub use driver::{DriverClient, DriverHandle};
26pub use process::ProcessOps;
27pub use memory::{RemoteMemory, MemoryProtection};
28pub use ioctl::{IoctlCode, IoctlRequest, IoctlResponse};
29
30use std::io;
31
32pub type ClientResult<T> = Result<T, ClientError>;
34
35#[derive(Debug)]
37pub enum ClientError {
38 DriverOpenFailed(io::Error),
40 DriverNotFound,
42 IoctlFailed {
44 code: u32,
45 error: io::Error,
46 },
47 InvalidResponse {
49 expected: usize,
50 received: usize,
51 },
52 ProcessError {
54 pid: u32,
55 reason: String,
56 },
57 MemoryError {
59 address: u64,
60 reason: String,
61 },
62 BufferTooSmall {
64 required: usize,
65 provided: usize,
66 },
67 NotSupported,
69}
70
71impl std::fmt::Display for ClientError {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 match self {
74 Self::DriverOpenFailed(e) => write!(f, "failed to open driver: {e}"),
75 Self::DriverNotFound => write!(f, "driver not found"),
76 Self::IoctlFailed { code, error } => write!(f, "IOCTL {code:#x} failed: {error}"),
77 Self::InvalidResponse { expected, received } => {
78 write!(f, "invalid response: expected {expected} bytes, got {received}")
79 }
80 Self::ProcessError { pid, reason } => {
81 write!(f, "process {pid} error: {reason}")
82 }
83 Self::MemoryError { address, reason } => {
84 write!(f, "memory error at {address:#x}: {reason}")
85 }
86 Self::BufferTooSmall { required, provided } => {
87 write!(f, "buffer too small: need {required}, got {provided}")
88 }
89 Self::NotSupported => write!(f, "operation not supported"),
90 }
91 }
92}
93
94impl std::error::Error for ClientError {}
95
96impl From<io::Error> for ClientError {
97 fn from(e: io::Error) -> Self {
98 Self::DriverOpenFailed(e)
99 }
100}