use std::ffi::CStr;
use std::ptr::null_mut;
use winapi::shared::minwindef::{BOOL, DWORD, FARPROC, HMODULE, LPVOID};
use winapi::shared::ntdef::LPCSTR;
use winapi::um::libloaderapi::GetModuleHandleA;
#[repr(C)]
#[allow(non_snake_case)]
struct DelayLoadProc {
fImportByName: BOOL,
szProcName: LPCSTR,
}
#[repr(C)]
#[allow(non_snake_case)]
struct DelayLoadInfo {
cb: DWORD,
pidd: LPVOID,
ppfn: *mut FARPROC,
szDll: LPCSTR,
dlp: DelayLoadProc,
hmodCur: HMODULE,
pfnCur: FARPROC,
dwLastError: DWORD,
}
#[allow(non_snake_case)]
type PfnDliHook = unsafe extern "C" fn(dliNotify: usize, pdli: *const DelayLoadInfo) -> FARPROC;
const HOST_BINARIES: &[&[u8]] = &[b"node.exe", b"electron.exe"];
unsafe extern "C" fn load_exe_hook(event: usize, info: *const DelayLoadInfo) -> FARPROC {
if event != 0x01
{
return null_mut();
}
let dll_name = CStr::from_ptr((*info).szDll);
if !HOST_BINARIES
.iter()
.any(|&host_name| host_name == dll_name.to_bytes())
{
return null_mut();
}
let exe_handle = GetModuleHandleA(null_mut());
exe_handle as FARPROC
}
#[no_mangle]
static mut __pfnDliNotifyHook2: *mut PfnDliHook = load_exe_hook as *mut PfnDliHook;