如何取得EXE文件的物理内存起始地址?
Option ExplicitPrivate Const STANDARD_RIGHTS_REQUIRED = &HF0000Private Const SYNCHRONIZE = &H100000Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)Private Sub Command1_Click() Dim strP As String Dim lngStartAdd As Long '进程内存起始地址 Dim lngWindowHwnd As Long '进程句柄 Dim lngPID As Long Dim lngP As Long Dim lngProcessHwnd As Long Dim strValue As String * 20On Error GoTo errSub lngStartAdd = LoadLibrary("c:\windows\system32\calc.exe") '读取软件内存起始地址 lngWindowHwnd = FindWindow(vbNullString, "计算器") '找到窗口句柄 lngP = GetWindowThreadProcessId(lngWindowHwnd, lngPID) '取得进程PID lngProcessHwnd = OpenProcess(PROCESS_ALL_ACCESS, False, lngPID) '读取进程句柄 lngP = ReadProcessMemory(lngProcessHwnd, lngStartAdd, strValue, 20, ByVal 0) Exit SuberrSub:End Sub
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long,byval lpBaseAddress As long,byval lpBuffer As string, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
[解决办法]