Skip to content

Commit 1ab3d40

Browse files
authored
Merge e959ca9 into 85efa6d
2 parents 85efa6d + e959ca9 commit 1ab3d40

1 file changed

Lines changed: 39 additions & 19 deletions

File tree

source/appModuleHandler.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class processEntry32W(ctypes.Structure):
7979
]
8080

8181

82+
class _PROCESS_MACHINE_INFORMATION(ctypes.Structure):
83+
_fields_ = [
84+
("ProcessMachine", ctypes.wintypes.USHORT),
85+
("Res0", ctypes.wintypes.USHORT),
86+
("MachineAttributes", ctypes.wintypes.DWORD)
87+
]
88+
89+
8290
def __getattr__(attrName: str) -> Any:
8391
"""Module level `__getattr__` used to preserve backward compatibility.
8492
The module level variable `NVDAProcessID` is deprecated
@@ -671,7 +679,7 @@ def _get_isRunningUnderDifferentLogonSession(self) -> bool:
671679
self.isRunningUnderDifferentLogonSession = False
672680
return self.isRunningUnderDifferentLogonSession
673681

674-
def _get_appArchitecture(self):
682+
def _get_appArchitecture(self) -> str:
675683
"""Returns the target architecture for the specified app.
676684
This is useful for detecting X86/X64 apps running on ARM64 releases of Windows 10.
677685
The following strings are returned:
@@ -682,28 +690,40 @@ def _get_appArchitecture(self):
682690
@rtype: str
683691
"""
684692
# Details: https://docs.microsoft.com/en-us/windows/desktop/SysInfo/image-file-machine-constants
685-
# The only value missing is ARM64 (AA64)
686-
# because it is only applicable if ARM64 app is running on ARM64 machines.
687693
archValues2ArchNames = {
688694
0x014c: "x86", # I386-32
689695
0x8664: "AMD64", # X86-64
690-
0x01c0: "ARM" # 32-bit ARM
696+
0x01c0: "ARM", # 32-bit ARM
697+
0xaa64: "ARM64" # 64-bit ARM
691698
}
692-
# IsWow64Process2 can be used on Windows 10 Version 1511 (build 10586) and later.
693-
# Just assume this is an x64 (AMD64) app.
694-
# if this is a64-bit app running on 7 through 10 Version 1507 (build 10240).
695-
try:
696-
# If a native app is running (such as x64 app on x64 machines), app architecture value is not set.
697-
processMachine = ctypes.wintypes.USHORT()
698-
ctypes.windll.kernel32.IsWow64Process2(self.processHandle, ctypes.byref(processMachine), None)
699-
if not processMachine.value:
700-
self.appArchitecture = os.environ.get("PROCESSOR_ARCHITEW6432")
701-
else:
702-
# On ARM64, two 32-bit architectures are supported: x86 (via emulation) and ARM (natively).
703-
self.appArchitecture = archValues2ArchNames[processMachine.value]
704-
except AttributeError:
705-
# Windows 10 Version 1507 (build 10240) and earlier.
706-
self.appArchitecture = "AMD64" if self.is64BitProcess else "x86"
699+
# #14403: GetProcessInformation can be called from Windows 11 and later to obtain process machine.
700+
if winVersion.getWinVer() >= winVersion.WIN11:
701+
processMachineInfo = _PROCESS_MACHINE_INFORMATION()
702+
# Constant comes from PROCESS_INFORMATION_CLASS enumeration.
703+
ProcessMachineTypeInfo = 9
704+
ctypes.windll.kernel32.GetProcessInformation(
705+
self.processHandle,
706+
ProcessMachineTypeInfo,
707+
ctypes.byref(processMachineInfo),
708+
ctypes.sizeof(_PROCESS_MACHINE_INFORMATION)
709+
)
710+
self.appArchitecture = archValues2ArchNames[processMachineInfo.ProcessMachine]
711+
else:
712+
# IsWow64Process2 can be used on Windows 10 Version 1511 (build 10586) and later.
713+
# Just assume this is an x64 (AMD64) app.
714+
# if this is a64-bit app running on 7 through 10 Version 1507 (build 10240).
715+
try:
716+
# If a native app is running (such as x64 app on x64 machines), app architecture value is not set.
717+
processMachine = ctypes.wintypes.USHORT()
718+
ctypes.windll.kernel32.IsWow64Process2(self.processHandle, ctypes.byref(processMachine), None)
719+
if not processMachine.value:
720+
self.appArchitecture = os.environ.get("PROCESSOR_ARCHITEW6432")
721+
else:
722+
# On ARM64, two 32-bit architectures are supported: x86 (via emulation) and ARM (natively).
723+
self.appArchitecture = archValues2ArchNames[processMachine.value]
724+
except AttributeError:
725+
# Windows 10 Version 1507 (build 10240) and earlier.
726+
self.appArchitecture = "AMD64" if self.is64BitProcess else "x86"
707727
return self.appArchitecture
708728

709729
def isGoodUIAWindow(self,hwnd):

0 commit comments

Comments
 (0)