6 Commits
5 changed files with 20 additions and 43 deletions
+8 -7
View File
@@ -9,18 +9,19 @@ repository = "https://github.com/elituf/haxor"
keywords = ["memory", "game", "hacking", "process"] keywords = ["memory", "game", "hacking", "process"]
[dependencies] [dependencies]
derive_more = { version = "2", features = ["debug", "display"] } derive_more = { version = "2", features = [
"debug",
"deref",
"display",
"from",
] }
log = "0.4" log = "0.4"
thiserror = "2" thiserror = "2"
windows = { version = "0.62", features = [
[dependencies.windows]
version = "0.62"
features = [
"Win32_Foundation",
"Win32_System_Threading", "Win32_System_Threading",
"Win32_System_Diagnostics_ToolHelp", "Win32_System_Diagnostics_ToolHelp",
"Win32_System_Diagnostics_Debug", "Win32_System_Diagnostics_Debug",
] ] }
[lib] [lib]
doctest = false doctest = false
+5 -21
View File
@@ -1,8 +1,8 @@
use crate::{ use crate::{
Error, error::Error,
sys::{handle::Handle, memory, snapshot}, sys::{handle::Handle, memory, snapshot},
}; };
use derive_more::{Debug, derive::Display}; use derive_more::{Debug, Display, From};
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
/// a process running on the system /// a process running on the system
@@ -137,29 +137,13 @@ pub struct Module {
pub base_size: usize, pub base_size: usize,
} }
#[derive(Display)] #[derive(Display, From)]
/// an identifier for searching for a process /// an identifier for searching for a process
pub enum Identifier { pub enum Identifier {
/// process id to search for /// process id to search for
#[from(u32)]
Pid(u32), Pid(u32),
/// process name to search for /// process name to search for
#[from(&str, String)]
Name(String), Name(String),
} }
impl From<u32> for Identifier {
fn from(value: u32) -> Self {
Self::Pid(value)
}
}
impl From<&str> for Identifier {
fn from(value: &str) -> Self {
Self::Name(value.to_string())
}
}
impl From<String> for Identifier {
fn from(value: String) -> Self {
Self::Name(value)
}
}
+5 -13
View File
@@ -1,24 +1,16 @@
use crate::Error; use crate::error::Error;
use std::ops::Deref; use derive_more::Deref;
use windows::Win32::{ use windows::Win32::{
Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE}, Foundation::{CloseHandle, HANDLE},
System::Threading::{OpenProcess, PROCESS_ALL_ACCESS, PROCESS_VM_READ, PROCESS_VM_WRITE}, System::Threading::{OpenProcess, PROCESS_ALL_ACCESS, PROCESS_VM_READ, PROCESS_VM_WRITE},
}; };
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Deref, Clone)]
pub struct Handle(pub HANDLE); pub struct Handle(pub HANDLE);
unsafe impl Send for Handle {} unsafe impl Send for Handle {}
unsafe impl Sync for Handle {} unsafe impl Sync for Handle {}
impl Deref for Handle {
type Target = HANDLE;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Drop for Handle { impl Drop for Handle {
fn drop(&mut self) { fn drop(&mut self) {
if let Err(why) = unsafe { CloseHandle(**self) } { if let Err(why) = unsafe { CloseHandle(**self) } {
@@ -36,7 +28,7 @@ impl Handle {
"failed to open process with needed access: {why}", "failed to open process with needed access: {why}",
)) ))
})?; })?;
if handle == INVALID_HANDLE_VALUE { if handle.is_invalid() {
return Err(Error::ObtainHandleError( return Err(Error::ObtainHandleError(
"failed to get a valid handle".to_string(), "failed to get a valid handle".to_string(),
)); ));
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::{Error, sys::handle::Handle}; use crate::{error::Error, sys::handle::Handle};
use std::{ffi::c_void, ptr}; use std::{ffi::c_void, ptr};
use windows::Win32::System::Diagnostics::Debug::{ReadProcessMemory, WriteProcessMemory}; use windows::Win32::System::Diagnostics::Debug::{ReadProcessMemory, WriteProcessMemory};
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::Error; use crate::error::Error;
use windows::Win32::System::Diagnostics::ToolHelp::{ use windows::Win32::System::Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, MODULEENTRY32W, Module32FirstW, Module32NextW, PROCESSENTRY32W, CreateToolhelp32Snapshot, MODULEENTRY32W, Module32FirstW, Module32NextW, PROCESSENTRY32W,
Process32FirstW, Process32NextW, TH32CS_SNAPMODULE, TH32CS_SNAPMODULE32, TH32CS_SNAPPROCESS, Process32FirstW, Process32NextW, TH32CS_SNAPMODULE, TH32CS_SNAPMODULE32, TH32CS_SNAPPROCESS,