use windows::Win32::Foundation::HMODULE;
use windows::Win32::System::WindowsProgramming::DELAYLOAD_INFO;
type DelayHook = unsafe extern "C" fn(dli_notify: DliNotify, pdli: DELAYLOAD_INFO) -> HMODULE;
#[unsafe(no_mangle)]
static __pfnDliFailureHook2: DelayHook = delaylink_hook;
#[allow(dead_code, clippy::enum_variant_names)] #[repr(C)]
enum DliNotify {
DliNoteStartProcessing = 0,
DliNotePreLoadLibrary,
DliNotePreGetProcAddress,
DliFailLoadLib,
DliFailGetProc,
DliNoteEndProcessing,
}
extern "C" fn delaylink_hook(dli_notify: DliNotify, pdli: DELAYLOAD_INFO) -> HMODULE {
if let DliNotify::DliFailLoadLib = dli_notify {
let name = unsafe { pdli.TargetDllName.to_string() }.unwrap_or_default();
if name == "qemu.exe" {
return HMODULE(
libloading::os::windows::Library::this()
.expect("Get QEMU module")
.into_raw() as *mut _,
);
}
}
HMODULE::default()
}