separate Module from snapshot module
This commit is contained in:
+1
-1
@@ -11,5 +11,5 @@ pub enum Error {
|
|||||||
#[error("failed to create snapshot")]
|
#[error("failed to create snapshot")]
|
||||||
SnapshotError(String),
|
SnapshotError(String),
|
||||||
#[error("failed to convert integer")]
|
#[error("failed to convert integer")]
|
||||||
IntegerConversionError(#[from] std::num::TryFromIntError),
|
ConvertIntegerError(#[from] std::num::TryFromIntError),
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ mod error;
|
|||||||
mod process;
|
mod process;
|
||||||
|
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use process::{Identifier, Process};
|
pub use process::{Identifier, Module, Process};
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
mod handle;
|
mod handle;
|
||||||
mod memory;
|
mod memory;
|
||||||
|
mod module;
|
||||||
mod process;
|
mod process;
|
||||||
mod snapshot;
|
mod snapshot;
|
||||||
|
|
||||||
|
pub use module::Module;
|
||||||
pub use process::{Identifier, Process};
|
pub use process::{Identifier, Process};
|
||||||
|
|
||||||
|
pub type ProcessSnapshot = snapshot::Process;
|
||||||
|
pub type ModuleSnapshot = snapshot::Module;
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
+13
-6
@@ -1,4 +1,4 @@
|
|||||||
use super::{handle::Handle, memory, snapshot};
|
use super::{handle::Handle, memory, module::Module, ModuleSnapshot, ProcessSnapshot};
|
||||||
|
|
||||||
use derive_more::derive::Display;
|
use derive_more::derive::Display;
|
||||||
|
|
||||||
@@ -22,10 +22,10 @@ pub enum Identifier {
|
|||||||
impl Process {
|
impl Process {
|
||||||
pub fn from(identifier: &Identifier) -> Result<Self, crate::Error> {
|
pub fn from(identifier: &Identifier) -> Result<Self, crate::Error> {
|
||||||
let snapshot = match identifier {
|
let snapshot = match identifier {
|
||||||
Identifier::Id(pid) => snapshot::Process::get_processes()?
|
Identifier::Id(pid) => ProcessSnapshot::get_processes()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|snapshot| snapshot.id == *pid),
|
.find(|snapshot| snapshot.id == *pid),
|
||||||
Identifier::Name(ref name) => snapshot::Process::get_processes()?
|
Identifier::Name(ref name) => ProcessSnapshot::get_processes()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|snapshot| snapshot.name == *name),
|
.find(|snapshot| snapshot.name == *name),
|
||||||
};
|
};
|
||||||
@@ -52,8 +52,8 @@ impl Process {
|
|||||||
Self::from(&Identifier::Name(name.to_string()))
|
Self::from(&Identifier::Name(name.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(&self, name: &str) -> Result<snapshot::Module, crate::Error> {
|
pub fn module(&self, name: &str) -> Result<Module, crate::Error> {
|
||||||
let Some(module) = snapshot::Module::get_modules(self.id)?
|
let Some(snapshot) = ModuleSnapshot::get_modules(self.id)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|snapshot| snapshot.name == name)
|
.find(|snapshot| snapshot.name == name)
|
||||||
else {
|
else {
|
||||||
@@ -61,6 +61,13 @@ impl Process {
|
|||||||
"failed to find a module with identifier `{name}`",
|
"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)
|
Ok(module)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +88,7 @@ impl Process {
|
|||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_addr_from_ptr_chain(&self, chain: &[usize]) -> Result<usize, crate::Error> {
|
pub fn addr_from_ptr_chain(&self, chain: &[usize]) -> Result<usize, crate::Error> {
|
||||||
let mut chain = chain.to_vec();
|
let mut chain = chain.to_vec();
|
||||||
let mut address = chain.remove(0);
|
let mut address = chain.remove(0);
|
||||||
while chain.len() > 1 {
|
while chain.len() > 1 {
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ impl Process {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
pub process_id: u32,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub base_address: usize,
|
pub base_address: usize,
|
||||||
@@ -99,7 +98,6 @@ impl Module {
|
|||||||
.trim_end_matches('\0')
|
.trim_end_matches('\0')
|
||||||
.to_string();
|
.to_string();
|
||||||
let module = Self {
|
let module = Self {
|
||||||
process_id: pid,
|
|
||||||
name,
|
name,
|
||||||
path,
|
path,
|
||||||
base_address: module_entry_32_w.modBaseAddr as usize,
|
base_address: module_entry_32_w.modBaseAddr as usize,
|
||||||
|
|||||||
Reference in New Issue
Block a user