1 Option Explicit
2 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
3 Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
4 Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
5 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
6 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
7 Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
8 Private Const PROCESS_ALL_ACCESS = &H1F0FFF
9 Private hProcess As Long
10 '下面的函数用于查找游戏
11 Function FindGame() As Boolean
12 Dim PID As Long, Gamehwnd As Long
13 FindGame = False
14 Gamehwnd = FindWindow(vbNullString, "蜘蛛") '查找游戏的句柄
15 If (Gamehwnd = 0) Then '如果找不到(例如游戏未运行)就退出函数
16 MsgBox "没有找到蜘蛛游戏"
17 Exit Function
18 End If
19 GetWindowThreadProcessId Gamehwnd, PID '取得进程ID
20 hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID) '以全部权力打开进程
21 If (hProcess = 0) Then '打开进程失败
22 MsgBox "没有打开进程"
23 Exit Function
24 End If
25 FindGame = True '成功!!
26 End Function
27 '回到VB的窗口设计模式,在窗体上放上两个按钮和一个文本框
28 '一个按钮为"读取"一个为"写入",分别用于读取和写入数据
29 '把Text1的Text设为空白
30 Private Sub Command1_Click()
31 Dim retV%, r&
32 'Dim retV%, r&=Dim retV As Integer, r As Long
33 If FindGame Then
34 r = ReadProcessMemory(hProcess, &H1011F20, retV, 2, 0) '这里重要,&H1011F20为内存地址.
35 If r = 0 Then
36 MsgBox "读取内存不成功!"
37 Else
38 Text1 = retV
39 End If
40 End If
41 End Sub
42
43 Private Sub Command2_Click()
44 Dim r&
45 If FindGame Then
46 r = WriteProcessMemory(hProcess, &H1011F20, CInt(Val(Text1)), 2, 0)
47 '参数与上面的基本相同
48 'cInt(Val(Text1))是防止输入的过程有误,,例如,输入了字母,,如果不处理程序就会出错
49 If r = 0 Then
50 MsgBox "写内存不成功!"
51 Else
52 MsgBox "OK"
53 End If
54 End If
55 End Sub
56
2 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
3 Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
4 Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
5 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
6 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
7 Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
8 Private Const PROCESS_ALL_ACCESS = &H1F0FFF
9 Private hProcess As Long
10 '下面的函数用于查找游戏
11 Function FindGame() As Boolean
12 Dim PID As Long, Gamehwnd As Long
13 FindGame = False
14 Gamehwnd = FindWindow(vbNullString, "蜘蛛") '查找游戏的句柄
15 If (Gamehwnd = 0) Then '如果找不到(例如游戏未运行)就退出函数
16 MsgBox "没有找到蜘蛛游戏"
17 Exit Function
18 End If
19 GetWindowThreadProcessId Gamehwnd, PID '取得进程ID
20 hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID) '以全部权力打开进程
21 If (hProcess = 0) Then '打开进程失败
22 MsgBox "没有打开进程"
23 Exit Function
24 End If
25 FindGame = True '成功!!
26 End Function
27 '回到VB的窗口设计模式,在窗体上放上两个按钮和一个文本框
28 '一个按钮为"读取"一个为"写入",分别用于读取和写入数据
29 '把Text1的Text设为空白
30 Private Sub Command1_Click()
31 Dim retV%, r&
32 'Dim retV%, r&=Dim retV As Integer, r As Long
33 If FindGame Then
34 r = ReadProcessMemory(hProcess, &H1011F20, retV, 2, 0) '这里重要,&H1011F20为内存地址.
35 If r = 0 Then
36 MsgBox "读取内存不成功!"
37 Else
38 Text1 = retV
39 End If
40 End If
41 End Sub
42
43 Private Sub Command2_Click()
44 Dim r&
45 If FindGame Then
46 r = WriteProcessMemory(hProcess, &H1011F20, CInt(Val(Text1)), 2, 0)
47 '参数与上面的基本相同
48 'cInt(Val(Text1))是防止输入的过程有误,,例如,输入了字母,,如果不处理程序就会出错
49 If r = 0 Then
50 MsgBox "写内存不成功!"
51 Else
52 MsgBox "OK"
53 End If
54 End If
55 End Sub
56