Hey there all, I am looking for some help with WriteProcessMemory. I am using VB 2005 and Trying to write a value to memory. Here is my write function, It does not error, but nothing ever gets written to the address, any help would be appreciated.
VB Code:
Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF Public Const PROCESS_VM_WRITE As Integer = &H20 Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByRef lpBaseAddress As Object, ByRef lpBuffer As Object, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr Private Sub setValue(ByVal hWnd As IntPtr, ByVal Address As Integer, ByVal nSize As Integer, ByVal value As Integer) Dim pId As Integer ' Process ID Dim pHandle As IntPtr ' Process Handle, changed to IntPtr 'Dim lvi As ListViewItem Try If nSize <= 0 OrElse Address <= 0 Then Exit Sub ' Get the ProcId of the Window GetWindowThreadProcessId(hWnd, pId) ' Now use the pId to get a process handle pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId) If (pHandle.ToInt32 = 0) Then Exit Sub End If WriteProcessMemory(pHandle, Address, value, nSize, 0&) 'Close the handle CloseHandle(pHandle) Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub
I can read from this location no problem, but when I try to write, it just plain never happens. Thanks in advance.






Reply With Quote