恋舞可可版本链接:vb 中怎么修改一大段的内存

来源:百度文库 编辑:高校问答 时间:2024/04/26 03:44:37
我想vb做个内存补丁,已经知道那一段的地址(004A50C0-004A52B0),把这段全部改成"66 66 66 66 66 66........" 翻译过来就是"fffffffffffff"怎么改?

'FindWindow(ClassName, WindowTitle) - FindWindow 返回符合指定的类
'名( ClassName )和窗口名( WindowTitle )的窗口句柄。对我们来说,可以让
'ClassName 为空( Null ),只给出游戏的 WindowTitle。
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long

'GetWindowThreadProcessId(WindowHandle, ProcessId) - 在这里我们把
'FindWindow 函数中得到的句柄作为参数,来获得进程标识符(ProcessId )。
Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwProcessId As Long) As Long

'OpenProcess(DesiredAccess, Inherit, ProcessId) - 这个函数将返回一
'个我们目标进程的句柄,可以用来对目标进行读写操作。 DesiredAccess 参
'数的值决定了句柄对进程的存取权利,对我们来说,要使用
'PROCESS_ALL_ACCESS (完全存取权限)。Inherit 应该总是 False。
'ProcessId 是从 GetWindowThreadProcessId 函数中取得的。
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

'CloseHandle(ProcessHandle) - 每一个打开的句柄必须呼叫这个函数来关闭?
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'WriteProcessMemory(ProcessHandle, Address, value, Sizeofvalue,
'BytesWritten) - 把指定的值 value 写入由 Address 指定的目标地址。
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess _
As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal _
nSize As Long, lpNumberOfBytesWritten As Long) As Long

'ReadProcessMemory(ProcessHandle, Address, value, Sizeofvalue,
'BytesWritten) - 把 Address 指定的目标地址的值存入 value 位置的变量中
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As _
Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize _
As Long, lpNumberOfBytesWritten As Long) As Long
Private Sub Command1_Click()

Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim pHandle As Long ' 储存进程句柄
' 首先取得目标窗口的句柄
hwnd = FindWindow(vbNullString, "计算器")
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 If
' 在内存地址中写入数据
WriteProcessMemory pHandle, &H4603F0C, "3", 1, 0&
' 关闭进程句柄
CloseHandle hProcess

End Sub

使用api,ReadProcessMemory、WriteProcessMemory

只有这样了,vb操作内存本来就弱