no idea why i was doing all that

This commit is contained in:
2024-12-31 08:35:33 +00:00
parent ffd8da0343
commit e3f6613c6d
3 changed files with 10 additions and 12 deletions
-4
View File
@@ -1,5 +1,4 @@
#![allow(clippy::module_inception)]
#![allow(clippy::module_name_repetitions)]
mod handle;
mod memory;
@@ -9,6 +8,3 @@ mod snapshot;
pub use module::Module;
pub use process::{Identifier, Process};
type ProcessSnapshot = snapshot::Process;
type ModuleSnapshot = snapshot::Module;
+4 -4
View File
@@ -1,4 +1,4 @@
use super::{handle::Handle, memory, module::Module, ModuleSnapshot, ProcessSnapshot};
use super::{handle::Handle, memory, module::Module, snapshot};
use derive_more::derive::Display;
@@ -35,10 +35,10 @@ impl Process {
pub fn from<T: Into<Identifier>>(identifier: T) -> Result<Self, crate::Error> {
let identifier = identifier.into();
let Some(snapshot) = (match identifier {
Identifier::Pid(pid) => ProcessSnapshot::get_processes()?
Identifier::Pid(pid) => snapshot::ProcessSnapshot::get_processes()?
.into_iter()
.find(|snapshot| snapshot.id == pid),
Identifier::Name(ref name) => ProcessSnapshot::get_processes()?
Identifier::Name(ref name) => snapshot::ProcessSnapshot::get_processes()?
.into_iter()
.find(|snapshot| snapshot.name == *name),
}) else {
@@ -57,7 +57,7 @@ impl Process {
}
pub fn module(&self, name: &str) -> Result<Module, crate::Error> {
let Some(snapshot) = ModuleSnapshot::get_modules(self.id)?
let Some(snapshot) = snapshot::ModuleSnapshot::get_modules(self.id)?
.into_iter()
.find(|snapshot| snapshot.name == name)
else {
+6 -4
View File
@@ -1,15 +1,17 @@
#![allow(clippy::module_name_repetitions)]
use windows::Win32::System::Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, Module32FirstW, Module32NextW, Process32FirstW, Process32NextW,
MODULEENTRY32W, PROCESSENTRY32W, TH32CS_SNAPMODULE, TH32CS_SNAPMODULE32, TH32CS_SNAPPROCESS,
};
#[derive(Debug)]
pub struct Process {
pub struct ProcessSnapshot {
pub id: u32,
pub name: String,
}
impl Process {
impl ProcessSnapshot {
pub fn get_processes() -> Result<Vec<Self>, crate::Error> {
let snapshot = unsafe {
match CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) {
@@ -56,14 +58,14 @@ impl Process {
}
#[derive(Debug)]
pub struct Module {
pub struct ModuleSnapshot {
pub name: String,
pub path: String,
pub base_address: usize,
pub base_size: usize,
}
impl Module {
impl ModuleSnapshot {
pub fn get_modules(pid: u32) -> Result<Vec<Self>, crate::Error> {
let snapshot = unsafe {
match CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid) {