Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten 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 EnumProcesses Lib "psapi.dll" (lpidProcess As Any, ByVal cb As Long, cbNeeded As Long) As Boolean
Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, lphModule As Any, ByVal cb As Long, lpcbNeeded) As Boolean
Private Declare Function GetModuleBaseName Lib "psapi.dll" Alias "GetModuleBaseNameA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpBaseName As String, ByVal nSize As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
sub ReadMemory()
Dim blnReturn As Boolean
Dim lProcessID(1023) As Long
Dim hModuleHandle As Long
Dim lModuleNeed As Long
Dim lProcessNum As Long
Dim I As Integer
Dim hProcess As Long
Dim lReturn As Long
Dim strModName As String
Dim lAddress As Long
Dim bytBuffer() As Byte
Dim lReadCount As Long
blnReturn = EnumProcesses(lProcessID(0), UBound(lProcessID) + 1, lProcessNum)
If blnReturn Then
For I = 0 To UBound(lProcessID)
strModName = ""
If lProcessID(I) <> 0 Then
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, lProcessID(I))
If hProcess <> 0 Then
If EnumProcessModules(hProcess, hModuleHandle, Len(hModuleHandle), lModuleNeed) Then
strModName = String(127, Chr(0))
lReturn = GetModuleBaseName(hProcess, hModuleHandle, strModName, Len(strModName))
If lReturn > 0 Then
strModName = Mid(strModName, 1, lReturn)
MsgBox "Module Name:" & strModName
End If
CloseHandle hModuleHandle
End If
If strModName <> "" Then
lAddress = 0
ReDim bytBuffer(1023)
lReturn = ReadProcessMemory(hProcess, lAddress, bytBuffer(0), UBound(bytBuffer), lReadCount)
Do Until lReadCount < UBound(bytBuffer) Or lReturn = 0
'do yourself
ReDim bytBuffer(1023)
lReturn = ReadProcessMemory(hProcess, lAddress, bytBuffer(0), UBound(bytBuffer), lReadCount)
lAddress = lAddress + UBound(bytBuffer)
Loop
End If
End If
CloseHandle hProcess
End If
Next I
End If
End Sub