Skip to content

Commit 0499191

Browse files
committed
initial commit
1 parent 922862e commit 0499191

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# python3-win7-shim
2-
Shim DLL to run unpatched Python3.8+ on Win7
2+
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`.
3+
4+
It passes through these functions, and only works with `PATHCCH_NONE` flags:<br>
5+
`PathCchCanonicalizeEx() => PathCanonicalizeW()`<br>
6+
`PathCchCombineEx() => PathCombineW()`

build.bat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@echo off
2+
REM Make sure to run rustup install stable-i686-pc-windows-msvc
3+
REM rustup install stable-x86_64-pc-windows-msvc
4+
5+
rmdir 64bit /s /q
6+
rmdir 32bit /s /q
7+
mkdir 64bit
8+
mkdir 32bit
9+
rustup default stable-i686-pc-windows-msvc
10+
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
11+
rustup default stable-x86_64-pc-windows-msvc
12+
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

lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![crate_type = "cdylib"]
2+
#![no_std]
3+
4+
#[panic_handler]
5+
unsafe fn panic(_panic: &core::panic::PanicInfo) -> ! { ExitProcess(1); loop { } }
6+
7+
#[no_mangle]
8+
unsafe extern "system" fn _DllMainCRTStartup(_: *const u8, _: u32, _: *const u8) -> u32 { 1 }
9+
10+
#[link(name = "kernel32")]
11+
#[allow(non_snake_case)]
12+
extern "stdcall" {
13+
fn ExitProcess(exit_code: u32) -> ();
14+
}
15+
16+
#[link(name = "shlwapi")]
17+
#[allow(non_snake_case)]
18+
extern "stdcall" {
19+
fn PathCanonicalizeW(path_out: *mut u8, path: *const u8) -> bool;
20+
fn PathCombineW(path_out: *mut u8, dir: *const u8, file: *const u8) -> usize;
21+
}
22+
23+
const MAX_PATH: usize = 256;
24+
const S_OK: u32 = 0;
25+
const E_INVALIDARG: u32 = 0x80070057;
26+
const PATHCCH_NONE: u32 = 0;
27+
28+
29+
#[no_mangle]
30+
pub unsafe extern "stdcall" fn PathCchCanonicalizeEx(path_out_buf: *mut u8, buf_size: usize, path: *const u8, flags: u32) -> u32 {
31+
if flags != PATHCCH_NONE || buf_size < MAX_PATH { return E_INVALIDARG; }
32+
let success = PathCanonicalizeW(path_out_buf, path);
33+
return if success { S_OK } else { E_INVALIDARG };
34+
}
35+
36+
#[no_mangle]
37+
pub unsafe extern "stdcall" fn PathCchCombineEx(path_out_buf: *mut u8, buf_size: usize, path: *const u8, path_more: *const u8, flags: u32) -> u32 {
38+
if flags != PATHCCH_NONE || buf_size < MAX_PATH { return E_INVALIDARG; }
39+
let str_ptr = PathCombineW(path_out_buf, path, path_more);
40+
return if str_ptr > 0 { S_OK } else { E_INVALIDARG };
41+
}

0 commit comments

Comments
 (0)