44import os
55import sys
66import time
7- import struct
7+ import ctypes
8+
89import textwrap
910import shutil
11+ import re
1012
1113import windows
1214import windows .pipe
@@ -26,8 +28,12 @@ def test_get_current_process_peb(self):
2628 return windows .current_process .peb
2729
2830 def test_get_current_process_modules (self ):
29- # Use sys.executable because executable can be a PyInstaller exe
30- assert os .path .basename (sys .executable ) in windows .current_process .peb .modules [0 ].name
31+ # Use module filename because this executable can be:
32+ # 1. A PyInstaller exe
33+ # 2. A Windows App execution alias (Microsoft Store builds)
34+ current_proc_filename = ctypes .create_string_buffer (1000 )
35+ windows .winproxy .GetModuleFileNameA (None , current_proc_filename , 1000 )
36+ assert os .path .basename (current_proc_filename .value .decode ()) in windows .current_process .peb .modules [0 ].name
3137
3238 def test_get_current_process_exe (self ):
3339 exe = windows .current_process .peb .exe
@@ -38,10 +44,13 @@ def test_get_current_process_exe(self):
3844 def test_current_process_pe_imports (self ):
3945 python_module = windows .current_process .peb .modules [0 ]
4046 imp = python_module .pe .imports
41- assert "kernel32.dll" in imp .keys (), 'Kernel32.dll not in python imports'
42- current_proc_id_iat = [f for f in imp ["kernel32.dll" ] if f .name == "GetCurrentProcessId" ][0 ]
43- k32_base = windows .winproxy .LoadLibraryA (b"kernel32.dll" )
44- assert windows .winproxy .GetProcAddress (k32_base , b"GetCurrentProcessId" ) == current_proc_id_iat .value
47+ python_dll_regex = re .compile (r'python[0-9.]+dll' , re .IGNORECASE )
48+ python_dll_imp = next ((i for i in imp .keys () if python_dll_regex .match (i )), None )
49+ assert python_dll_imp is not None , 'Python dll not in python imports'
50+
51+ imp_id_iat = imp [python_dll_imp ][0 ]
52+ mod_base = windows .winproxy .LoadLibraryA (python_dll_imp .encode ())
53+ assert windows .winproxy .GetProcAddress (mod_base , imp_id_iat .name .encode ()) == imp_id_iat .value
4554
4655 def test_current_process_pe_exports (self ):
4756 mods = [m for m in windows .current_process .peb .modules if m .name == "kernel32.dll" ]
0 commit comments