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 Const PROCESS_ALL_ACCESS = &H1F0FFF
Public hProcess As Long
Function rMem(vAdd As Long, l As Integer) As Long
Dim ret As Long
Call ReadProcessMemory(hProcess, vAdd, ret, l, 0&)
rMem = ret
End Function
Function wMem(vAdd As Long, value As Long, l As Integer)
Call WriteProcessMemory(hProcess, vAdd, value, l, 0&)
End Function
规范的修改器需要对游戏是否已经启动作判断的:
这里我用FindGame这个函数了:
Function FindGame() As Boolean
Dim GameHwnd As Long, Pid As Long
hProcess = 0
GameHwnd = FindWindow(vbNullString, "********") '*******就是系统的进程名,就是你运行游戏看到的系统的进程名
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 Function