小弟想编一个小程序用于监视内存数据,通过内存地址得到“空当接龙游戏”,剩余纸牌数
我有一个例子但用不起,不知道错在那里。模块:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public hProcess As Long代码:
Option ExplicitPrivate Sub Command1_Click()
Dim X As String * 5
Dim strLen As Long
If FindGame Then
ReadProcessMemory hProcess, &H1008350, X, 5, strLen
Command1.Caption = Chr(X)
End If
End SubFunction FindGame() As Boolean
Dim PID As Long, Gamehwnd As Long
FindGame = False
Gamehwnd = FindWindow(vbNullString, "空当接龙游戏 #3866")
If (Gamehwnd = 0) Then Exit Function
GetWindowThreadProcessId Gamehwnd, PID
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
If (hProcess = 0) Then Exit Function
FindGame = True
End FunctionPrivate Sub mb_Click()
FindGame
End Sub

解决方案 »

  1.   

    这句的问题~
    Gamehwnd = FindWindow(vbNullString, "空当接龙游戏 #3866")"空当接龙游戏 #3866" 固定的话
    代码就只有在选局选到第3866局时才有用需要给FindGame加个参数才行
      

  2.   

    我执行到这句就死机
    ReadProcessMemory hProcess, &H1008350, X, 5, strLen
      

  3.   

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Sub Check1_Click()
    Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
    Dim pid As Long ' 储存进程标识符( Process Id )
    Dim pHandle As Long ' 储存进程句柄' 取得目标窗口的句柄
    hwnd = FindWindow(vbNullString, "legend of mir2")
    If (hwnd = 0) Then
    MsgBox "请运行传奇"
    Exit Sub
    End If
    ' 取得进程标识符
    GetWindowThreadProcessId hwnd, pid' 取得进程句柄
    pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    If (pHandle = 0) Then
    MsgBox "请运行传奇"
    Exit Sub
    End IfSelect Case Check1.Value
    Case 0
    WriteProcessMemory pHandle, &H47A0DE, 1367609088, 4, 0&
    WriteProcessMemory pHandle, &H47A0DF, 22119439, 4, 0&
    WriteProcessMemory pHandle, &H47A0E2, -1962934271, 4, 0&
    WriteProcessMemory pHandle, &H47A0E3, 1166737408, 4, 0&
    Case 1
    WriteProcessMemory pHandle, &H47A0DE, -1869574144, 4, 0&
    WriteProcessMemory pHandle, &H47A0DF, -1869574000, 4, 0&
    WriteProcessMemory pHandle, &H47A0E2, -1953460080, 4, 0&
    WriteProcessMemory pHandle, &H47A0E3, 1166774416, 4, 0&End Select
    ' 关闭进程句柄
    CloseHandle hProcessEnd Sub这是我写的传奇显血的代码。加了简单注释。
      

  4.   

    我是XP系统 VB6.0+SP6 
    这里不会死机倒是这里有点问题
    Command1.Caption = Chr(X)将就原来的改了下下~Private Sub Command1_Click()Dim X As String * 5
    Dim strLen As LongIf FindGame Then
        If ReadProcessMemory(hProcess, &H1008350, X, 4, strLen) = 0 Then MsgBox "ReadMemory Error"
        Command1.Caption = CStr(X) & vbCrLf & Asc(X) & "," & Asc(Left$(X, 2)) & "," & Asc(Left$(X, 3)) & "," & Asc(Left$(X, 4)) & "," & Asc(Left$(X, 5))
    Else
        Command1.Caption = "Not Found"
    End IfEnd Sub