diff --git a/Cargo.lock b/Cargo.lock index c6048e7..e2ffba7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,18 +16,19 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.2.30" +version = "1.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44" dependencies = [ + "find-msvc-tools", "shlex", ] [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "crc32fast" @@ -45,6 +46,12 @@ dependencies = [ "object", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d" + [[package]] name = "flate2" version = "1.1.2" @@ -67,9 +74,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libudis86-sys" @@ -117,9 +124,9 @@ dependencies = [ [[package]] name = "object" -version = "0.37.1" +version = "0.37.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" dependencies = [ "flate2", "memchr", @@ -132,6 +139,24 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + [[package]] name = "region" version = "3.0.2" @@ -181,11 +206,22 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a3d689654af89bdfeba29a914ab6ac0236d382eb3b764f7454dde052f2821f8" +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "twox-hash" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b907da542cbced5261bd3256de1b3a1bf340a3d37f93425a07362a1d687de56" +checksum = "9ea3136b675547379c4bd395ca6b938e5ad3c3d20fad76e7fe85f9e0d011419c" [[package]] name = "typenum" @@ -193,6 +229,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +[[package]] +name = "unicode-ident" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" + [[package]] name = "version_check" version = "0.9.5" @@ -221,6 +263,108 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.62.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9579d0e6970fd5250aa29aba5994052385ff55cf7b28a059e484bb79ea842e42" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-link", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a90dd7a7b86859ec4cdf864658b311545ef19dbcf17a672b52ab7cefe80c336f" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57fe7168f7de578d2d8a05b07fd61870d2e73b4020e9f49aa00da8471723497c" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2194dee901458cb79e1148a4e9aac2b164cc95fa431891e7b296ff0b2f1d8a6" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" + +[[package]] +name = "windows-numerics" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ce3498fe0aba81e62e477408383196b4b0363db5e0c27646f932676283b43d8" +dependencies = [ + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -246,6 +390,15 @@ dependencies = [ "windows_x86_64_msvc", ] +[[package]] +name = "windows-threading" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab47f085ad6932defa48855254c758cdd0e2f2d48e62a34118a268d8f345e118" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -301,7 +454,7 @@ dependencies = [ "cc", "region", "retour", - "winapi", + "windows", ] [[package]] diff --git a/crates/zipfixup/Cargo.toml b/crates/zipfixup/Cargo.toml index 105cf04..29460d1 100644 --- a/crates/zipfixup/Cargo.toml +++ b/crates/zipfixup/Cargo.toml @@ -15,14 +15,20 @@ publish.workspace = true name = "zipfixup" crate-type = ["cdylib"] +test = false + [dependencies] retour = "0.3.1" region = "3.0.2" -[dependencies.winapi] -version = "0.3.9" +[dependencies.windows] +version = "0.62.0" default-features = false -features = ["debugapi", "libloaderapi"] +features = [ + "Win32_System_Diagnostics_Debug", # OutputDebugStringA/OutputDebugStringW + "Win32_System_LibraryLoader", # DisableThreadLibraryCalls + "Win32_System_SystemServices", # DLL_PROCESS_ATTACH/DLL_PROCESS_DETACH +] [build-dependencies] cc = "1.2" diff --git a/crates/zipfixup/src/dbg.rs b/crates/zipfixup/src/dbg.rs index f4bc40e..7a15269 100644 --- a/crates/zipfixup/src/dbg.rs +++ b/crates/zipfixup/src/dbg.rs @@ -1,6 +1,7 @@ //! [`output!`] macro to log messages via the Debug API, to be viewed in e.g. //! [DebugView](https://learn.microsoft.com/en-us/sysinternals/downloads/debugview). -use ::winapi::um::debugapi::{OutputDebugStringA, OutputDebugStringW}; +use windows::Win32::System::Diagnostics::Debug::{OutputDebugStringA, OutputDebugStringW}; +use windows::core::{PCSTR, PCWSTR}; macro_rules! output { ($fmt:literal $(, $args:expr)* $(,)?) => {{ @@ -36,22 +37,18 @@ fn encode_unicode(msg: &str) -> Vec { /// version may be slightly faster. pub(crate) fn output_debug_string_w(msg: &str) { let v: Vec = encode_unicode(msg); - let p: *const u16 = v.as_ptr(); + let p = PCWSTR::from_raw(v.as_ptr()); unsafe { OutputDebugStringW(p) }; // paranoia: ensure `v` is valid until after `OutputDebugStringW` drop(v); } -fn encode_ascii(msg: &str) -> Vec { +fn encode_ascii(msg: &str) -> Vec { const ZF: &[u8] = b"[ZF] "; let msg = msg .chars() .map(|c| if c.is_ascii() { c as u8 } else { b'?' }); - ZF.iter() - .copied() - .chain(msg.chain(Some(0))) - .map(|b| b as i8) - .collect() + ZF.iter().copied().chain(msg.chain(Some(0))).collect() } /// Output an ASCII debug string. @@ -61,8 +58,8 @@ fn encode_ascii(msg: &str) -> Vec { /// Microsoft Unicode ineptness). #[allow(dead_code, reason = "Use Unicode version by default")] pub(crate) fn output_debug_string_a(msg: &str) { - let v: Vec = encode_ascii(&msg); - let p: *const i8 = v.as_ptr(); + let v: Vec = encode_ascii(&msg); + let p = PCSTR::from_raw(v.as_ptr()); unsafe { OutputDebugStringA(p) }; // paranoia: ensure `v` is valid until after `OutputDebugStringA` drop(v); diff --git a/crates/zipfixup/src/dll_main.rs b/crates/zipfixup/src/dll_main.rs index c2dd5a9..edaf9a5 100644 --- a/crates/zipfixup/src/dll_main.rs +++ b/crates/zipfixup/src/dll_main.rs @@ -2,21 +2,25 @@ //! executable that loaded the DLL. use crate::{Result, output}; use std::sync::Mutex; -use winapi::shared::minwindef::{BOOL, DWORD, HINSTANCE, LPVOID, TRUE}; -use winapi::um::libloaderapi::DisableThreadLibraryCalls; -use winapi::um::winnt::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH}; +use windows::Win32::Foundation::{HMODULE, TRUE}; +use windows::Win32::System::LibraryLoader::DisableThreadLibraryCalls; +use windows::Win32::System::SystemServices::{DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH}; const VERSION: &str = env!("CARGO_PKG_VERSION"); #[unsafe(no_mangle)] #[allow(non_snake_case)] -extern "system" fn DllMain(dll_module: HINSTANCE, call_reason: DWORD, _reserved: LPVOID) -> BOOL { +extern "system" fn DllMain( + hlibmodule: HMODULE, + call_reason: u32, + _reserved: *mut std::ffi::c_void, +) -> windows::core::BOOL { match call_reason { DLL_PROCESS_ATTACH => { output!("DLL_PROCESS_ATTACH"); // disable DLL_THREAD_ATTACH/DLL_THREAD_DETACH notifications, since // we don't need them, and may help with spawning threads - unsafe { DisableThreadLibraryCalls(dll_module) }; + let _ = unsafe { DisableThreadLibraryCalls(hlibmodule) }; // it's unclear what is allowed to be done in DllMain. // theoretically, even spawning a thread is not "recommended": // https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices