我试图用Python3在Windows(64位)中获取进程的基址,假设知道PID。 我查看了堆栈上的所有问题,但解决方案是旧的/不起作用的
我假设进程的PID在一个名为PID的变量中
我尝试过的许多代码之一是
PROCESS_ALL_ACCESS = 0x1F0FFF
processHandle = win32api.OpenProcess(PROCESS_ALL_ACCESS, False, pid)
modules = win32process.EnumProcessModules(processHandle)
fileName = win32process.GetModuleFileNameEx(processHandle, modules[0])
base_address = win32api.GetModuleHandle(fileName)
processHandle.close()
但是我在GetModuleHandle上得到错误:“不可能找到指定的模块”
谢谢你的帮助
根据[MS.Docs]: GetModuleHandleW function(重点是我的):
这意味着它对于当前进程可以正常工作,但是对于任何其他进程,您都会得到未定义的行为,因为您尝试检索:
虽然没有关于这个主题的明确文档(或者至少我找不到任何文档),但是句柄是基址。这是一个您也依赖的原则(调用GetModuleHandle),但是您可以直接使用EnumProcessModules返回的值(请看下面的示例,这些值是相同的)如果您想要严格,可以使用[MS.Docs]: GetModuleInformation function。不幸的是,PyWin32没有导出它,另一种方法是使用[Python 3.Docs]: ctypes - A foreign function library for Python
code00.py:
输出:
更新#0
根据[MS.Docs]: MODULEINFO structure(备注部分,强调仍然是我的):
所以,事情似乎很简单
code01.py:
输出:
相关问题 更多 >
编程相关推荐