|
-
Dec 26th, 2006, 09:06 AM
#1
[RESOLVED] WriteProcessMemory Help, Will Not Write Value
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.
-
Dec 26th, 2006, 10:46 AM
#2
Re: WriteProcessMemory Help, Will Not Write Value
Got it working, looks like I had an issue with my declaration, changed it to this and it works.
VB Code:
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|