I never heard of any of those VB functions, but generally the way to go is importing Windows API DLLs and calling them.
EDIT: I would still use my below classes, but I think that 'x' in your ReadMemory call is an "out" parameter. Could be wrong tho...
If you have to read and write from/to a specific address that is known, then you could use something like what I generally use:
Code:
<Flags> _
Public Enum ProcessAccessFlags As UInteger
All = &H1f0fff
Terminate = &H1
CreateThread = &H2
VMOperation = &H8
VMRead = &H10
VMWrite = &H20
DupHandle = &H40
SetInformation = &H200
QueryInformation = &H400
Synchronize = &H100000
End Enum
<DllImport("kernel32.dll")> _
Private Shared Function OpenProcess(dwDesiredAccess As ProcessAccessFlags, <MarshalAs(UnmanagedType.Bool)> bInheritHandle As Boolean, dwProcessId As Integer) As IntPtr
End Function
<DllImport("kernel32.dll", SetLastError := True)> _
Private Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, lpBuffer As Byte(), nSize As UInteger, lpNumberOfBytesWritten As Integer) As Boolean
End Function
<DllImport("kernel32.dll", SetLastError := True)> _
Private Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, <Out> lpBuffer As Byte(), dwSize As Integer, lpNumberOfBytesRead As Integer) As Boolean
End Function
<DllImport("kernel32.dll")> _
Public Shared Function CloseHandle(hProcess As IntPtr) As Int32
End Function
Public Function ReadMemory(proc As Process, MemoryAddress As IntPtr, bytesToRead As UInteger, bytesRead As Integer) As Byte()
Dim pointerProc As IntPtr = OpenProcess(ProcessAccessFlags.All, False, proc.Id)
Dim buffer As Byte() = New Byte(bytesToRead - 1) {}
Dim ptrBytesRead As IntPtr
ReadProcessMemory(pointerProc, MemoryAddress, buffer, bytesToRead, ptrBytesRead)
CloseHandle(pointerProc)
bytesRead = ptrBytesRead.ToInt32()
Return buffer
End Function
Public Sub WriteMemory(proc As Process, MemoryAddress As IntPtr, bytesToWrite As Byte(), bytesWritten As Integer)
Dim pointerProc As IntPtr = OpenProcess(ProcessAccessFlags.All, False, proc.Id)
Dim ptrBytesWritten As IntPtr
WriteProcessMemory(pointerProc, MemoryAddress, bytesToWrite, CUInt(bytesToWrite.Length), ptrBytesWritten)
CloseHandle(pointerProc)
bytesWritten = ptrBytesWritten.ToInt32()
End Sub
You could then use it like this:
Code:
Dim proc As Process = Process.GetProcessesByName("SomeRandomProcess").FirstOrDefault()
Dim memaddr As Integer = &H1234567
Dim bytesRead As Integer
Dim value As Byte() = ReadMemory(process, address, 4, bytesRead)
Dim memoryValue As Integer = BitConverter.ToInt32(value, 0)
Hope it compiles, haven't written VB in years!!
-jD