python-3.x - ReadProcessMemory 无效句柄
问题描述
我正在尝试使用 Python 从另一个进程中读取一个值。
我遇到了这个答案,尽管它似乎不起作用。
我的代码:
from ctypes import *
from ctypes.wintypes import *
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle
PROCESS_ALL_ACCESS = 0x1F0FFF
pid = 4580
address = 0x04782FF8
buffer = c_uint()
bufferSize = sizeof(buffer)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
print("Success:", buffer)
else:
print("Failed.")
CloseHandle(processHandle)
GetLastError()
似乎返回 6,这意味着句柄无效。
虽然,OpenProcess()
返回一个非零值,并且GetLastError()
不显示任何内容。
我尝试编辑传入的第一个参数OpenProcess()
(我将其设为 0x0010),但仍然没有结果。
解决方案
进程 ID 是 dec,而不是 hex,这破坏了一些东西。
我还必须用 create_string_buffer(4) 替换 c_uint() 作为缓冲区。
现在似乎工作正常!
推荐阅读
- aws-lambda - AWS Statemachine 无法将输入 json 数据传递给第一个 Lambda
- javascript - 使用页面语言(WordPress)动态更新按钮href
- r - 在 R/Shiny 中,有没有办法为 renderTree 创建进度条
- c - cygwin tty下msvc编译的程序输出不同
- python - Pyside6中的打印预览页面方向
- azure-monitoring - 如何使用 Powershell 或任何其他方法每天在 csv 中导出 Azure vm 指标数据?
- c# - 未授予所需的权限。必须至少授予以下权限之一: 管理组织树
- typescript - TypeScript 导入以不一致的方式包装在模块中
- loops - 内循环运行了多少次?
- c++ - 关于 vcpkg 和 pcl/visualization 的问题