質問

現在、VB.NETを介してG15キーボードでゲームの健康情報を表示するためのちょっとした趣味のプロジェクトを開発しています。

APIコールを介してReadProcessMemoryを使用すると、ゼロが返され続けます。 MSDNのドキュメントでは、Marshal.GetLastWin32Error()呼び出しを使用して、何が間違っているのかを確認し、1400を返します:INVALID WINDOW HANDLE。

私は今、関数の最初の引数がウィンドウハンドルまたはプロセスIDのどちらを必要としているかについて混乱しています。とにかく、アプリケーションの実行中にFindWindowとプロセスIDのハードコーディング(タスクマネージャーから取得)の両方を試しました。

私は3つの異なるゲーム、Urban Terror、Grand Theft Autoを試しました。Windows用のSAと3Dピンボール、Cheat Engineと呼ばれるアプリケーションからメモリアドレスを取得しました。それらはすべて失敗したようです。

これを行うために使用しているコードは次のとおりです。

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タイプであるときに、メソッドの署名が間違っています。Single= Floatです。

このメソッドシグネチャを使用:

<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関数によって開かれたハンドルを想定していると思います。

他のヒント

ありがとうございます、私の問題を修正しました。

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の回答を回答としてマークします。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top