Files
injectionforge/src/loader_windows.rs
Dimitris Zervas a706f1d890 Fix the windows build
Signed-off-by: Dimitris Zervas <dzervas@dzervas.gr>
2024-04-16 19:20:45 +03:00

31 lines
873 B
Rust

#![cfg(all(windows, not(test)))]
use std::ffi::c_void;
use winapi::um::winnt::DLL_PROCESS_ATTACH;
use winapi::um::libloaderapi::LoadLibraryA;
use crate::attach_self;
// For some reason ctor doesn't work on Windows - it hangs the process
// during DeviceManager::obtain. DllMain works fine though.
// Would be nice to have a single entry point for all platforms.
#[no_mangle]
#[allow(non_snake_case, unused_variables)]
pub extern "system" fn DllMain(dll_module: *mut c_void, call_reason: u32, _: *mut ()) -> bool {
match call_reason {
DLL_PROCESS_ATTACH => {
println!("[+] InjectionForge DLL injected");
if let Some(lib_name) = option_env!("LIB_NAME") {
unsafe { LoadLibraryA(lib_name.as_ptr() as *const i8); }
println!("[+] Original DLL {} loaded", lib_name);
}
attach_self();
}
// Maybe we should detach? Is it useful?
_ => ()
}
true
}