separate Module from snapshot module
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -22,10 +22,10 @@ pub enum Identifier {
|
||||
impl Process {
|
||||
pub fn from(identifier: &Identifier) -> Result<Self, crate::Error> {
|
||||
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<snapshot::Module, crate::Error> {
|
||||
let Some(module) = snapshot::Module::get_modules(self.id)?
|
||||
pub fn module(&self, name: &str) -> Result<Module, crate::Error> {
|
||||
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<usize, crate::Error> {
|
||||
pub fn addr_from_ptr_chain(&self, chain: &[usize]) -> Result<usize, crate::Error> {
|
||||
let mut chain = chain.to_vec();
|
||||
let mut address = chain.remove(0);
|
||||
while chain.len() > 1 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user