diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a5b4d17 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.cargo.buildScripts.enable": false +} diff --git a/qemu-plugin/src/win_link_hook/mod.rs b/qemu-plugin/src/win_link_hook/mod.rs index 0e2a528..e3db704 100644 --- a/qemu-plugin/src/win_link_hook/mod.rs +++ b/qemu-plugin/src/win_link_hook/mod.rs @@ -39,16 +39,23 @@ enum DliNotify { /// /// # Arguments /// -/// * `dli_notify` - The +/// * `dli_notify` - The type of notification +/// * `pdli` - The delay load information +/// +/// # Return value +/// +/// * `HMODULE` - The handle to the module extern "C" fn delaylink_hook(dli_notify: DliNotify, pdli: DELAYLOAD_INFO) -> HMODULE { if let DliNotify::DliFailLoadLib = dli_notify { // SAFETY: Conversion of `PCSTR` to String is not safe because it involves an unchecked - // nul-byte dependent `strcpy`. In this instance, it is safe because + // nul-byte dependent `strcpy`. In this instance, it is as safe as OS guarantees because + // the target dll name is provided by Windows and is null-terminated. let name = unsafe { pdli.TargetDllName.to_string() }.unwrap_or_default(); + let mut module = HMODULE::default(); // NOTE: QEMU executables on windows are named qemu-system.*.exe - if name.starts_with("qemu") { + if name == "qemu.exe" { // SAFETY: Getting the module handle for NULL is safe and does not dereference any // pointers except to write the `module` argument which we know is alive here. match unsafe { GetModuleHandleExA(0, PCSTR::null(), &mut module as *mut HMODULE) } {