Skip to content

Commit

Permalink
Remove loader lock by initializing GDWeave in a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Nov 10, 2024
1 parent cc85a44 commit 32ee3e5
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 3 deletions.
112 changes: 111 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ anyhow = "1.0.89"
isahc = "1.7.2"
netcorehost = "0.17.0"
proxy-dll = "0.2.5"
retour = { version = "0.3.1", features = ["static-detour"] }
thiserror = "1.0.64"
win-msgbox = "0.2.1"
windows = { version = "0.58.0", features = [
"Win32_System_Threading",
"Win32_System_ProcessStatus",
"Win32_System_LibraryLoader",
] }
41 changes: 39 additions & 2 deletions loader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use isahc::ReadResponseExt;
use netcorehost::{error::HostingError, nethost, pdcstr, pdcstring::PdCString};
use proxy_dll::proxy;
use retour::static_detour;
use thiserror::Error;
use win_msgbox::{Okay, YesNo};
use windows::{
core::PCWSTR,
Win32::System::{
LibraryLoader::GetModuleHandleW,
ProcessStatus::{GetModuleInformation, MODULEINFO},
Threading::GetCurrentProcess,
},
};

#[derive(Error, Debug)]
pub enum LoaderError {
Expand Down Expand Up @@ -89,8 +98,11 @@ fn install_net() -> anyhow::Result<()> {
Ok(())
}

#[proxy]
pub fn main() {
static_detour! {
static MainHook: fn() -> i32;
}

pub fn main_detour() -> i32 {
if let Err(e) = init() {
match e {
LoaderError::LoadHostfxrError(_)
Expand Down Expand Up @@ -123,4 +135,29 @@ pub fn main() {
}
}
}

MainHook.call()
}

#[proxy]
pub fn main() {
unsafe {
let process = GetCurrentProcess();
let module = GetModuleHandleW(PCWSTR::null()).unwrap();
let mut lpmodinfo = MODULEINFO::default();
GetModuleInformation(
process,
module,
&mut lpmodinfo,
size_of::<MODULEINFO>() as u32,
)
.unwrap();

let entry = lpmodinfo.EntryPoint;

MainHook
.initialize(std::mem::transmute(entry), main_detour)
.unwrap();
MainHook.enable().unwrap();
}
}

0 comments on commit 32ee3e5

Please sign in to comment.