use std::ffi::CStr;
use windows::Win32::Foundation::{HINSTANCE, PSTR};
use windows::Win32::System::LibraryLoader::GetModuleHandleA;
use windows::Win32::System::WindowsProgramming::{DELAYLOAD_INFO, PDELAYLOAD_FAILURE_DLL_CALLBACK};
const HOST_BINARIES: &[&[u8]] = &[b"node.exe", b"electron.exe"];
unsafe extern "C" fn load_exe_hook(event: u32, info: *const DELAYLOAD_INFO) -> HINSTANCE {
if event != 0x01
{
return HINSTANCE::default();
}
let dll_name = CStr::from_ptr((*info).TargetDllName.0 as *mut i8);
if !HOST_BINARIES
.iter()
.any(|&host_name| host_name == dll_name.to_bytes())
{
return HINSTANCE::default();
}
GetModuleHandleA(PSTR::default())
}
#[no_mangle]
static mut __pfnDliNotifyHook2: *mut PDELAYLOAD_FAILURE_DLL_CALLBACK =
load_exe_hook as *mut PDELAYLOAD_FAILURE_DLL_CALLBACK;