主题:关于游戏修改器的问题
看了一片关于制作游戏修改器的文章,自己照猫画虎用vb写了一个游戏修改器,可是老出现变量没有找到的错误(错误老是指着OpenProcess函数中的PROCESS_ALL_ACCESS参数),即使生成exe文件以后,修改游戏时老时出现“没有打开修改权限”.请求大虾帮忙看一下,找出其中的错误.以下是代码.
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 CloseHandle Lib "kernel32" (ByVal hObject 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
以上代码是写在模块中的
Option Explicit
Private Sub cmd2_Click()
Dim hOK As Long
Dim ID As Long
Dim hwnd As Long
hwnd = FindWindow("SWDMD", vbNullString)
If hwnd = False Then
MsgBox ("游戏没有打开")
Exit Sub
Else
GetWindowThreadProcessId hwnd, ID
hOK = OpenProcess(PROCESS_ALL_ACCESS, False, ID)
If hOK = 0 Then
MsgBox ("没有打开修改权限")
Exit Sub
Else
Dim a2 As Long '金钱的内存地址变量
Dim b2 As Long '生命的内存地址变量
Dim c2 As Long '灵力的内存地址变量
Dim d2 As Long '体力的内存地址变量
Dim a3 As Long '金钱
Dim b3 As Long '生命
Dim c3 As Long '灵力
Dim d3 As Long
a3 = Val(txt1.Text)
b3 = Val(txt2.Text)
c3 = Val(txt3.Text)
d3 = Val(txt4.Text)
b2 = &HBCDFF0
a2 = &HBCEC84
c2 = &HBCDFFC
d2 = &HBCE000
If txt1.Text <> "" Then
WriteProcessMemory hOK, ByVal a2, a3, 2, 0
End If '修改金钱属性
If txt2.Text <> "" Then
WriteProcessMemory hOK, ByVal b2, b3, 2, 0
End If '修改生命属性
If txt3.Text <> "" Then
WriteProcessMemory hOK, ByVal c2, c3, 2, 0
End If '修改灵力属性
If txt4.Text <> "" Then
WriteProcessMemory hOK, ByVal d2, d3, 2, 0
End If '修改体力属性
MsgBox ("complete")
End If
End If
CloseHandle (hOK)
End Sub