Read and Write Process Memory functions
In all windows system (I think from WindowsXP) there are funcions that allow to access, read and modify the memory of running processes. These functions are: ReadProcessMemory and WriteProcessMemory. First function allow to read bytes from an area of memory in a specified process. Second function allow to write bytes to an area of memory in a specified process. This two functions require Kernel32.lib to be declared and used.
The syntax of the two functions:
BOOL WINAPI ReadProcessMemory( |
Declarations of these functions are:
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer |
These functions have to be applicated to a process and for this reason you need to use anothers functions to find and open process. In VB.net you can find process using the class 'Process'. You can get process by name and nextly get its 'ID'.
A small example may help:
Dim myProcesses As Process() = Process.GetProcessesByName("MyApplication") |
HANDLE WINAPI OpenProcess( |
Declaration of OpenProcess:
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer |
Now we are ready to open process; below another smallest example:
processHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, myProcesses(0).Id) |
Now our process is open and ready to be read and written.
Example that explain both functions:
Dim RBuff As Long |
