ReadProcessMemory保持返回0
-
19-08-2019 - |
题
我目前正在开发一个小爱好的项目,以显示我的G15键盘在VB.NET在游戏的健康信息。
当我经由API调用中使用ReadProcessMemory,它使返回为零。 MSDN文档提到我用Marshal.GetLastWin32Error()调用来找出哪些是错误的,它返回1400:无效的窗口句柄
我现在困惑的函数的第一个参数是否想要一个窗口句柄或进程ID。无论如何,我曾经尝试都与FindWindow函数和应用程序运行时硬编码的进程ID(从任务管理器得到它)。
我曾尝试三种不同的游戏,城市恐怖,侠盗猎车手:SA和三维弹球窗户,正从所谓的作弊引擎的应用程序的内存地址;它们似乎都失败。
下面是我使用这样做的代码:
API调用:
Private Declare Function ReadProcessMemory Lib "kernel32" ( _
ByVal hProcess As Integer, _
ByVal lpBaseAddress As Integer, _
ByRef lpBuffer As Single, _
ByVal nSize As Integer, _
ByRef lpNumberOfBytesWritten As Integer _
) As Integer
方法:
Dim address As Integer
address = &HA90C62&
Dim valueinmemory As Integer
Dim proc As Process = Process.GetCurrentProcess
For Each proc In Process.GetProcesses
If proc.MainWindowTitle = "3D Pinball for Windows - Space Cadet" Then
If ReadProcessMemory(proc.Handle.ToInt32, address, valueinmemory, 4, 0) = 0 Then
MsgBox("aww")
Else
MsgBox(CStr(valueinmemory))
End If
End If
Next
Dim lastError As Integer
lastError = Marshal.GetLastWin32Error()
MessageBox.Show(CStr(lastError))
为什么它不工作对我来说可能有人请解释一下吗?由于事先。
解决方案
首先,你的方法签名是错误的,单=浮动而原始参数是LPBUF型的。
使用此方法的签名:
<DllImport("kernel32.dll", SetLastError=true)> _
Public Shared Function ReadProcessMemory( _
ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
<Out()>ByVal lpBuffer() As Byte, _
ByVal dwSize as Integer, _
ByRef lpNumberOfBytesRead as Integer
) As Boolean
End Function
其次,我相信hProcess手柄预计通过OpenProcess函数打开的手柄,而不是窗口的句柄。
其他提示
感谢您了Arul,我已经有点固定我的问题。
Dim address As Integer
address = &HA90C62&
Dim floatvalueinmemory() As Byte
Dim proc As Process = Process.GetCurrentProcess
For Each proc In Process.GetProcesses
If proc.MainWindowTitle = "3D Pinball for Windows - Space Cadet" Then
Dim winhandle As IntPtr = OpenProcess(PROCESS_ACCESS.PROCESS_VM_READ, True, proc.Id)
If ReadProcessMemory(winhandle, address, floatvalueinmemory, 4, 0) = 0 Then
Dim lastError As Integer
lastError = Marshal.GetLastWin32Error()
MessageBox.Show(CStr(lastError))
MsgBox("aww")
Else
MsgBox("woo")
End If
CloseHandle(winhandle)
End If
Next
现在它认为手柄是有效的并且试图读取进程的内存,但是我得到的错误消息299:只有ReadProcessMemory或WriteProcessMemory的请求的一部分已完成
没有人有任何想法,我应该如何着手解决这个问题?
消息299:只有ReadProcessMemory或WriteProcessMemory的请求的一部分已完成的意思,我试图读取被保护的存储器
感谢您的帮助,我要庆祝了Arul的答案的答案。
不隶属于 StackOverflow