diff --git a/src/error.rs b/src/error.rs index ea77a48..21b8261 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,5 +11,5 @@ pub enum Error { #[error("failed to create snapshot")] SnapshotError(String), #[error("failed to convert integer")] - IntegerConversionError(#[from] std::num::TryFromIntError), + ConvertIntegerError(#[from] std::num::TryFromIntError), } diff --git a/src/lib.rs b/src/lib.rs index c426ff0..01fee44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,4 +2,4 @@ mod error; mod process; pub use error::Error; -pub use process::{Identifier, Process}; +pub use process::{Identifier, Module, Process}; diff --git a/src/process/mod.rs b/src/process/mod.rs index e177c3c..328d625 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -2,7 +2,12 @@ mod handle; mod memory; +mod module; mod process; mod snapshot; +pub use module::Module; pub use process::{Identifier, Process}; + +pub type ProcessSnapshot = snapshot::Process; +pub type ModuleSnapshot = snapshot::Module; diff --git a/src/process/module.rs b/src/process/module.rs new file mode 100644 index 0000000..bcf764d --- /dev/null +++ b/src/process/module.rs @@ -0,0 +1,8 @@ +#[derive(Debug)] +pub struct Module { + pub process_id: u32, + pub name: String, + pub path: String, + pub base_address: usize, + pub base_size: usize, +} diff --git a/src/process/process.rs b/src/process/process.rs index 72edb8b..6705321 100644 --- a/src/process/process.rs +++ b/src/process/process.rs @@ -1,4 +1,4 @@ -use super::{handle::Handle, memory, snapshot}; +use super::{handle::Handle, memory, module::Module, ModuleSnapshot, ProcessSnapshot}; use derive_more::derive::Display; @@ -22,10 +22,10 @@ pub enum Identifier { impl Process { pub fn from(identifier: &Identifier) -> Result { let snapshot = match identifier { - Identifier::Id(pid) => snapshot::Process::get_processes()? + Identifier::Id(pid) => ProcessSnapshot::get_processes()? .into_iter() .find(|snapshot| snapshot.id == *pid), - Identifier::Name(ref name) => snapshot::Process::get_processes()? + Identifier::Name(ref name) => ProcessSnapshot::get_processes()? .into_iter() .find(|snapshot| snapshot.name == *name), }; @@ -52,8 +52,8 @@ impl Process { Self::from(&Identifier::Name(name.to_string())) } - pub fn module(&self, name: &str) -> Result { - let Some(module) = snapshot::Module::get_modules(self.id)? + pub fn module(&self, name: &str) -> Result { + let Some(snapshot) = ModuleSnapshot::get_modules(self.id)? .into_iter() .find(|snapshot| snapshot.name == name) else { @@ -61,6 +61,13 @@ impl Process { "failed to find a module with identifier `{name}`", ))); }; + let module = Module { + process_id: self.id, + name: snapshot.name, + path: snapshot.path, + base_address: snapshot.base_address, + base_size: snapshot.base_size, + }; Ok(module) } @@ -81,7 +88,7 @@ impl Process { Ok(value) } - pub fn get_addr_from_ptr_chain(&self, chain: &[usize]) -> Result { + pub fn addr_from_ptr_chain(&self, chain: &[usize]) -> Result { let mut chain = chain.to_vec(); let mut address = chain.remove(0); while chain.len() > 1 { diff --git a/src/process/snapshot.rs b/src/process/snapshot.rs index 9900142..e52d389 100644 --- a/src/process/snapshot.rs +++ b/src/process/snapshot.rs @@ -57,7 +57,6 @@ impl Process { #[derive(Debug)] pub struct Module { - pub process_id: u32, pub name: String, pub path: String, pub base_address: usize, @@ -99,7 +98,6 @@ impl Module { .trim_end_matches('\0') .to_string(); let module = Self { - process_id: pid, name, path, base_address: module_entry_32_w.modBaseAddr as usize,