use derive_more for Deref implementation on Handle
This commit is contained in:
+6
-1
@@ -9,7 +9,12 @@ 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", "from"] }
|
derive_more = { version = "2", features = [
|
||||||
|
"debug",
|
||||||
|
"deref",
|
||||||
|
"display",
|
||||||
|
"from",
|
||||||
|
] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
windows = { version = "0.62", features = [
|
windows = { version = "0.62", features = [
|
||||||
|
|||||||
+2
-10
@@ -1,24 +1,16 @@
|
|||||||
use crate::error::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, INVALID_HANDLE_VALUE},
|
||||||
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) } {
|
||||||
|
|||||||
Reference in New Issue
Block a user