Private Declare Function VirtualProtectEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Const MEM_RESERVE = &H2000&
Private Const PROCESS_QUERY_INFORMATION = 1024
Private Const PROCESS_VM_READ = 16
Private Const PAGE_EXECUTE_READWRITE = &H40&
Private Const PAGE_READWRITE = 4&
Private Const PAGE_EXECUTE = &H10&
Private Const PROCESS_VM_OPERATION = &H8
Public Function DumpProcess(ByVal lPid As Long, ByVal pAddr As Long, ByVal dwSize As Long) As Long
Dim OldProt As Long
Dim hProcess As Long
Dim addr As Long
Dim ret As Long
lpAddr = pAddr
hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ, 0, lPid)
ret = VirtualAllocEx(hProcess, VarPtr(lpAddr), dwSize, MEM_RESERVE, PAGE_READWRITE)
'....
'....
'....
ret = VirtualProtectEx(hProcess, VarPtr(lpAddr), dwSize, PAGE_EXECUTE, VarPtr(OldProt))
CloseHandle hProcess
End Function
Есть такой код. И он не работает(
Хэндл процесса определяется правильно.
VirtualAllocEx и VirtualProtectEx возвращают 0.
В pAddr передается база образа исполняемого файла читаемого процесса. В dwSize - размер.
Подскажите, пожалуйста, где я недоглядел.
Ответить
|