From 0499191d646da29afe6a02bcebfed036244505c8 Mon Sep 17 00:00:00 2001 From: david-beinder Date: Thu, 10 Jun 2021 19:40:36 +0200 Subject: [PATCH] initial commit --- README.md | 6 +++++- build.bat | 12 ++++++++++++ lib.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 build.bat create mode 100644 lib.rs diff --git a/README.md b/README.md index 437f111..c0a86a8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # python3-win7-shim -Shim DLL to run unpatched Python3.8+ on Win7 +This is a shim DLL to run unpatched Python3.8+ on Windows 7. This built specifically for Python and is not a full featured, general purpose replacement for `api-ms-win-core-path-l1-1-0.dll`. + +It passes through these functions, and only works with `PATHCCH_NONE` flags:
+`PathCchCanonicalizeEx() => PathCanonicalizeW()`
+`PathCchCombineEx() => PathCombineW()` \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..bfee400 --- /dev/null +++ b/build.bat @@ -0,0 +1,12 @@ +@echo off +REM Make sure to run rustup install stable-i686-pc-windows-msvc +REM rustup install stable-x86_64-pc-windows-msvc + +rmdir 64bit /s /q +rmdir 32bit /s /q +mkdir 64bit +mkdir 32bit +rustup default stable-i686-pc-windows-msvc +rustc --target i686-pc-windows-msvc -C panic=abort -C target-feature=+crt-static -o 32bit/api-ms-win-core-path-l1-1-0.dll lib.rs +rustup default stable-x86_64-pc-windows-msvc +rustc --target x86_64-pc-windows-msvc -C panic=abort -C target-feature=+crt-static -o 64bit/api-ms-win-core-path-l1-1-0.dll lib.rs \ No newline at end of file diff --git a/lib.rs b/lib.rs new file mode 100644 index 0000000..557acf4 --- /dev/null +++ b/lib.rs @@ -0,0 +1,41 @@ +#![crate_type = "cdylib"] +#![no_std] + +#[panic_handler] +unsafe fn panic(_panic: &core::panic::PanicInfo) -> ! { ExitProcess(1); loop { } } + +#[no_mangle] +unsafe extern "system" fn _DllMainCRTStartup(_: *const u8, _: u32, _: *const u8) -> u32 { 1 } + +#[link(name = "kernel32")] +#[allow(non_snake_case)] +extern "stdcall" { + fn ExitProcess(exit_code: u32) -> (); +} + +#[link(name = "shlwapi")] +#[allow(non_snake_case)] +extern "stdcall" { + fn PathCanonicalizeW(path_out: *mut u8, path: *const u8) -> bool; + fn PathCombineW(path_out: *mut u8, dir: *const u8, file: *const u8) -> usize; +} + +const MAX_PATH: usize = 256; +const S_OK: u32 = 0; +const E_INVALIDARG: u32 = 0x80070057; +const PATHCCH_NONE: u32 = 0; + + +#[no_mangle] +pub unsafe extern "stdcall" fn PathCchCanonicalizeEx(path_out_buf: *mut u8, buf_size: usize, path: *const u8, flags: u32) -> u32 { + if flags != PATHCCH_NONE || buf_size < MAX_PATH { return E_INVALIDARG; } + let success = PathCanonicalizeW(path_out_buf, path); + return if success { S_OK } else { E_INVALIDARG }; +} + +#[no_mangle] +pub unsafe extern "stdcall" fn PathCchCombineEx(path_out_buf: *mut u8, buf_size: usize, path: *const u8, path_more: *const u8, flags: u32) -> u32 { + if flags != PATHCCH_NONE || buf_size < MAX_PATH { return E_INVALIDARG; } + let str_ptr = PathCombineW(path_out_buf, path, path_more); + return if str_ptr > 0 { S_OK } else { E_INVALIDARG }; +} \ No newline at end of file