7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Dim CsDz As Long
Dim aaa As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS As Long = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
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, ByVal 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, 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, "Form1")
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
CsDz = VarPtr(aaa) 'Csdz就是你要修改的地址
Dim cc As Long '要读取的变量存放’可以是BYTE
ReadProcessMemory pHandle, CsDz, ByVal VarPtr(cc), 4, 0&
Text1 = cc
End Sub
Private Sub Command2_Click()
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim pHandle As Long ' 储存进程句柄
hwnd = FindWindow(vbNullString, "Form1")
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
aaa = CLng("&H" & Text2) '写入的数据
CsDz = VarPtr(aaa) 'Csdz就是你要修改的地址
WriteProcessMemory pHandle, CsDz, aaa, 4, 0&
End Sub
Private Sub Form_Load()
Command1.Caption = "读"
Command2.Caption = "写"
End Sub
dim 读出的数值 as long
dim 读出的字符串(长度) as byte
GetWindowThreadProcessId 句柄, PID
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, PID)
ReadProcessMemory pHandle, 地址, 读出的数值,长度, 0 '读数值
ReadProcessMemory pHandle, 地址, 读出的字符串(),长度, 0 '读字符串
字符串 = StrConv(读出的字符串, vbUnicode)
CloseHandle pHandle