Skip to content

Commit

Permalink
Use QueueUserAPC to run before main
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Nov 2, 2023
1 parent bbd8a0b commit 17daf5d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use std::{
use anyhow::{bail, Context, Result};
use patternsleuth::{patterns::resolve_self, scanner::Pattern, PatternConfig};
use retour::static_detour;
use windows::{
Win32::Foundation::*,
Win32::System::{
use windows::Win32::{
Foundation::HMODULE,
System::{
Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS},
SystemServices::*,
Threading::{GetCurrentThread, QueueUserAPC},
},
};

Expand All @@ -36,7 +37,7 @@ extern "system" fn DllMain(dll_module: HMODULE, call_reason: u32, _: *mut ()) ->
unsafe {
match call_reason {
DLL_PROCESS_ATTACH => {
std::thread::spawn(|| patch().ok());
QueueUserAPC(Some(init), GetCurrentThread(), 0);
}
DLL_PROCESS_DETACH => (),
_ => (),
Expand Down Expand Up @@ -69,6 +70,10 @@ impl DRGInstallationType {
}
}

unsafe extern "system" fn init(_: usize) {
patch().ok();
}

unsafe fn patch() -> Result<()> {
let pak_path = std::env::current_exe()
.ok()
Expand Down

0 comments on commit 17daf5d

Please sign in to comment.