Skip to content

Commit

Permalink
Merge pull request #12 from novafacing/fix-windows-delayload
Browse files Browse the repository at this point in the history
Fixup documentation and naming in Windows delay load handling
  • Loading branch information
novafacing authored Apr 2, 2024
2 parents 8d06bab + b83f772 commit ed66662
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.buildScripts.enable": false
}
13 changes: 10 additions & 3 deletions qemu-plugin/src/win_link_hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) } {
Expand Down

0 comments on commit ed66662

Please sign in to comment.