Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeinder committed Jun 10, 2021
1 parent 922862e commit 0499191
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:<br>
`PathCchCanonicalizeEx() => PathCanonicalizeW()`<br>
`PathCchCombineEx() => PathCombineW()`
12 changes: 12 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions lib.rs
Original file line number Diff line number Diff line change
@@ -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 };
}

0 comments on commit 0499191

Please sign in to comment.