Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup documentation and naming in Windows delay load handling #12

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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