Results 1 to 4 of 4

Thread: WriteProcessMemory API?

  1. #1

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172

    WriteProcessMemory API?

    can anyone give me an example on how to use the WriteProcessMemory API function?
    No Comment.

  2. #2

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    TOP
    No Comment.

  3. #3

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    top some more?
    No Comment.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    This is just sample code to get you started, you'd have to know the address in memory to actually accomplish something.

    Add a CommandButton (Command1) to the Form.

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Private Sub Command1_Click()
     Dim hWnd As Long
     Dim pid As Long
     Dim pHandle As Long
     hWnd = FindWindow(vbNullString, "Calc")
     
     If (hWnd = 0) Then
      MsgBox "Window not found!"
      Exit Sub
     End If
     
     GetWindowThreadProcessId hWnd, pid
     pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
     WriteProcessMemory pHandle, &H42D120, "", 6, 0& ' Replace &H42D120 with the address in memory you want to edit. Also, replace "" with the value.
     CloseHandle hProcess
    End Sub
    Keep in mind that this code does absolutely NOTHING, it's just something to get you started. BTW, I've messed with WriteProcessMemory a lot, and I know that the format of the above code works.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

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