Results 1 to 2 of 2

Thread: [RESOLVED] WriteProcessMemory Help, Will Not Write Value

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Resolved [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:
    1. Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
    2.     Public Const PROCESS_VM_WRITE As Integer = &H20
    3.     Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
    4.     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
    5.     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
    6.     Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
    7.     Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr
    8.  
    9.     Private Sub setValue(ByVal hWnd As IntPtr, ByVal Address As Integer, ByVal nSize As Integer, ByVal value As Integer)
    10.         Dim pId As Integer        ' Process ID
    11.         Dim pHandle As IntPtr     ' Process Handle, changed to IntPtr
    12.         'Dim lvi As ListViewItem
    13.         Try
    14.             If nSize <= 0 OrElse Address <= 0 Then Exit Sub ' Get the ProcId of the Window
    15.             GetWindowThreadProcessId(hWnd, pId)
    16.  
    17.             ' Now use the pId to get a process handle
    18.             pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
    19.  
    20.             If (pHandle.ToInt32 = 0) Then
    21.                 Exit Sub
    22.             End If
    23.  
    24.             WriteProcessMemory(pHandle, Address, value, nSize, 0&)
    25.  
    26.             'Close the handle
    27.             CloseHandle(pHandle)
    28.         Catch ex As System.Exception
    29.             MsgBox(ex.Message)
    30.         End Try
    31.     End Sub

    I can read from this location no problem, but when I try to write, it just plain never happens. Thanks in advance.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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:
    1. 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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width