WriteProcessMemory() Api Help

I have a problem with WriteProcessMemory() that I am trying to use. My code looks like this:

Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Object, ByVal lpBuffer As Object, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer

Dim appProcess as Process

*gets the process* ' I know it works

Dim offset As Long = 29689060

Dim value As Long = 3

WriteProcessMemory(appProcess.Handle(), offset, value, 4, 0&)

What I am trying to do is to write the memory adress (01C504E4, decimal value 29689060) with the value of 3. The data type is a long, (4 bytes). Is there anything I am doing wrong since I do not see that memory adress changing at all with a trusted debugger when I run the code




Answer this question

WriteProcessMemory() Api Help

  • dzn

    I got it working, but, i need to know how to get the memory address of a variable within my own program and pass it in. Does anyone know the method of getting the memory address of a variable within your program. I saw some IntPtr(variable) but thats no longer supportedd by .net

  • Olivier Moreau

    To he honest with you, for reasons of OS security, I hope this is not possible.

    I wonder if you are not going to have to call an API routine to open the process and get a process handle. Often than call requires certain levels of security, but it also gives to access to a lot more than I think you're ever going to have using the process class.



  • Deasun

    How to change debug registers of certain address
  • Boris Mueller

    A process is a securable resource. If you have full access to the process, you can do things like calling WriteProcessMemory.

    I'd take a look at the declaration of the WriteProcessMemory function:

    http://www.pinvoke.net/default.aspx/kernel32/WriteProcessMemory.html

    Best regards,
    Johan Stenberg



  • Omarat56

    Could you please explain what you are trying to accomplish here

    In the managed world, variables can move around in memory, and you need to pin the variable to prevent it from moving:

    http://msdn.microsoft.com/msdnmag/issues/04/10/NET/

    Please note that I'm far from convinced that this is the right technique for what you are trying to do, and that you may be barking up the wrong tree here...

    Best regards,
    Johan Stenberg



  • Mekon2

    VarPtr() points to an address of a variable in VB.

  • Wellnow

    That looks OK to me.



  • Tomasz007

    I worked in mainframe operating system development for years.certainly we had console debuggers. But the ability of a process to be able to edit another processes memory, is a huge secuity issue.



  • MikeBlig

    I think my main problem is how I am storing my memory adresses.. How should they be stored in visual basic

    I am currently using

    Dim offset As IntPtr = &H1C504E4

    Dim value As IntPtr = &H400004



  • Radu Motisan

    Well, look at a memory editing program. It can open any process, and edit any memory adress within it. I am looking to opena process and modify 1 offset as well.

  • WriteProcessMemory() Api Help