我的是xp系统,下面的函数可以读任何虚拟内存地址数据,但是在&H400000以上就不能写入数据了,已经用了VirtualProtectEx函数,100分请高手指点,在线等!!!
'------------------------------------
Option Explicit
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const PROCESS_VM_READ = &H10
Public Const PROCESS_VM_WRITE = &H20Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As LongDeclare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As LongPublic Const TH32CS_SNAPPROCESS As Long = 2&Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szexeFile As String * 260
End Type'声明:
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
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 GetCurrentProcessId Lib "kernel32" () 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 VirtualAlloc Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Public Declare Function VirtualFree Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Public Declare Function VirtualProtectEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Public Declare Function VirtualQueryEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, lpBuffer As MEMORY_BASIC_INFORMATION, ByVal dwLength As Long) As Long
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPublic Type MEMORY_BASIC_INFORMATION
     BaseAddress As Long
     AllocationBase As Long
     AllocationProtect As Long
     RegionSize As Long
     State As Long
     Protect As Long
     lType As Long
End TypePublic Const PAGE_EXECUTE_READWRITE = &H40
Public Const PAGE_READWRITE As Long = &H4
Public Const MEM_COMMIT As Long = &H1000
Public Const MEM_DECOMMIT As Long = &H4000
Public Function ReadWriteMemory(ByVal lAddr As Long, buff() As Byte, Optional fRead As Boolean = True, Optional ByVal pid As Long = -1) As Boolean
    Dim hProcess As Long
    Dim mi As MEMORY_BASIC_INFORMATION
    Dim lpAddress As Long, lOldProtect As Long
    Dim lBytesReadWrite As Long
    Dim bTmp() As Byte
    
    lpAddress = lAddr
    
    If pid = -1 Then
        pid = GetCurrentProcessId
    End If
    
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, pid)    If hProcess Then
        If VirtualQueryEx(hProcess, ByVal lpAddress, mi, Len(mi)) Then
        
        VirtualProtectEx hProcess, ByVal mi.BaseAddress, mi.RegionSize, PAGE_READWRITE, lOldProtect'(返回0,不知道为什么,地址(&H400000)以上他就返回0)        '  If VirtualProtectEx(hProcess, ByVal mi.BaseAddress, mi.RegionSize, PAGE_READWRITE, lOldProtect) <> 0 Then                 If fRead Then
                    ReadProcessMemory hProcess, ByVal lpAddress, buff(0), UBound(buff), lBytesReadWrite
                    
                Else
                    ReDim bTmp(UBound(buff))
                    'ReadProcessMemory hProcess, ByVal lpAddress, bTmp(0), UBound(bTmp) + 1, lBytesReadWrite
                    
                    WriteProcessMemory hProcess, ByVal lpAddress, buff(0), UBound(buff), lBytesReadWrite
                   
                   'CopyMemory buff(0), bTmp(0), UBound(bTmp) + 1
                End If
                Call VirtualProtectEx(hProcess, ByVal mi.BaseAddress, mi.RegionSize, lOldProtect, lOldProtect)
                ReadWriteMemory = (lBytesReadWrite <> 0)
           'End If
        End If
        CloseHandle hProcess
    End If
End Function'-----------------------------------------------------------------Private Sub Timer1_Timer()
Dim myProcess As PROCESSENTRY32
Dim mySnapshot As Long
Dim i As Integer
Dim hWnd As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符
Dim pHandle As Long ' 储存进程句柄
Dim str As String * 24 ' 存储显示文本
Dim Readlen As Long
Dim j As Long
Dim b(16) As Byte
i = 0
For j = 0 To UBound(b)
    b(j) = Asc("q") + j
    Next j
cboProcess.ClearmyProcess.dwSize = Len(myProcess)mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, myProcess
cboProcess.AddItem myProcess.szexeFile
PIDs(i) = myProcess.th32ProcessID 
If Left(myProcess.szexeFile, 4) = "note" Then If ReadWriteMemory(&H542EA0, b(), false, PIDs(i)) Then
   For j = 0 To UBound(b)
 txt.Text = txt.Text & Chr(b(j))
Next j
  
End If
End If
While ProcessNext(mySnapshot, myProcess)
i = i + 1
PIDs(i) = myProcess.th32ProcessID ' set PID
' 写内存数据
If Left(myProcess.szexeFile, 4) = "note" Then
MsgBox ReadWriteMemory(&H542EA0, b(), False, PIDs(i))
 If ReadWriteMemory(&H542EA0, b(), True, PIDs(i)) Then For j = 0 To UBound(b)
 txt.Text = txt.Text & Chr(b(j))
Next j
End If
End If
  cboProcess.AddItem myProcess.szexeFile 
WendEnd Sub

解决方案 »

  1.   

    呵呵,好像又是我的遗患人间的代码
    你在
    VirtualProtectEx hProcess, ByVal mi.BaseAddress, mi.RegionSize, PAGE_READWRITE, 
    lOldProtect'(返回0,不知道为什么,地址(&H400000)以上他就返回0)
    下面加个
    Debug.Print Err.LastDllErr
    看看是啥错误代码
      

  2.   

    呵呵,好像又是我的遗患人间的代码
    你在
    VirtualProtectEx hProcess, ByVal mi.BaseAddress, mi.RegionSize, PAGE_READWRITE, 
    lOldProtect'(返回0,不知道为什么,地址(&H400000)以上他就返回0)
    下面加个
    Debug.Print Err.LastDllErr
    看看是啥错误代码
    我加的Debug.Print cstr(Err.LastDllErr)
    返回代码 87
    希望指点。
      

  3.   

    87 The parameter is incorrect. ERROR_INVALID_PARAMETER 错误的参数
      

  4.   

    "&H400000以上" 是指 lpAddress > &H400000 吗?
    VirtualProtectEx 在 lpAddress < &H400000 时返回 0 倒是正常的。
      

  5.   

    我记得NT系统里面&H400000以上的虚拟内存都是系统保留不可访问的啊。难道你可以在&H400000以上读写吗?
      

  6.   

    Sorry,好像是某个地址以下……我也去查查