WriteProcessMemory() Api Help

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

PublicDeclareFunction WriteProcessMemoryLib"kernel32" (ByVal hProcessAsInteger,ByVal lpBaseAddressAsObject,ByVal lpBufferAsObject,ByVal nSizeAsInteger,ByVal lpNumberOfBytesWrittenAsInteger)AsInteger

Dim appProcess as Process

*gets the process* ' I know it works

Dim offsetAsLong = 29689060

Dim valueAsLong = 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?

[2583 byte] By [VBWorker] at [2007-12-24]
# 1

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.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
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.
VBWorker at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

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.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

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

VBWorker at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

That looks OK to me.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

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

MSJohanStenberg at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7
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
VBWorker at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8

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

MSJohanStenberg at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9
How to change debug registers of certain address?
N-Y-M at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 10
VarPtr() points to an address of a variable in VB.
edgarJface at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...