environment: windows10, python 3.15 I have some assembly code that I need to execute within another process using PythonForWindows. ``` import windows.native_exec.simple_x86 as x86 import windows.winobject.process def run_asm(code, pid: int = 0, handle: int = 0, name: str = "", ppid: int = 0) -> None: _wp = windows.winobject.process.WinProcess(pid=pid, handle=handle, name=name, ppid=ppid) _addr = _wp.virtual_alloc(len(code.get_code())) _wp.write_memory(_addr, code.get_code()) _wp.create_thread(_addr, 0).wait() _wp.virtual_free(_addr) code = x86.MultipleInstr() code += x86.Pushad() code += x86.Mov("EBP", "ESP") code += x86.Mov("ESI", esi) code += x86.Push(x86.mem("[esi+0x4]")) code += x86.Lea("EAX", x86.mem("[esi+0x8]")) code += x86.Push("EAX") code += x86.Mov("EBX", addr.ess['call_unpack_name']) code += x86.Call("EBX") code += x86.Mov("esp", "ebp") code += x86.Popad() code += x86.Ret() run_asm(code, pid=self.pid) ``` But after I upgraded Python to 3.15, the code stopped working correctly. Here is an error message. > File "E:\code\call\func.py", line 696, in decode_name run_asm(code, pid=self.pid) ~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "E:\code\call\func.py", line 73, in run_asm _addr = _wp.virtual_alloc(len(code.get_code())) File "E:\code\call\.venv\Lib\site-packages\windows\winobject\process.py", line 1116, in virtual_alloc return winproxy.VirtualAllocEx(self.handle, lpAddress=addr, dwSize=size, flAllocationType=type, flProtect=prot) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\code\call\.venv\Lib\site-packages\windows\winproxy\apis\kernel32.py", line 277, in VirtualAllocEx return VirtualAllocEx.ctypes_function(hProcess, lpAddress, dwSize, flAllocationType, flProtect) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\code\call\.venv\Lib\site-packages\windows\winproxy\apiproxy.py", line 99, in perform_call return self._cprototyped(*args) ~~~~~~~~~~~~~~~~~^^^^^^^ File "E:\code\call\.venv\Lib\site-packages\windows\winproxy\error.py", line 49, in fail_on_zero raise WinproxyError(func_name) windows.winproxy.error.WinproxyError: VirtualAllocEx: [WinError 6] Invalid handle
Activity
hakril commentedon Nov 2, 2026
Hi,
Thank you for the issue.
From what I understand, it seems the error is in the default
handlevalue you are trying to pass to theWinProcessconstructor.The default (non-set) value for
handleshould beNoneand not0(https://github.com/hakril/PythonForWindows/blob/master/windows/winobject/process.py#L1061).Passing
0will makeWinProcesuse this handle forVirtualAllocExwhich will results inInvalid handle.Example:
Hope this help !