Link to home
Start Free TrialLog in
Avatar of DelphiUK
DelphiUKFlag for Denmark

asked on

WriteProcessMemory with same address.

Hi

I have created a main application which do the following thing:

1. OpenProcess Function (Let's say we open "calc.exe").
2. VirtualAllocEx Function (Allocate some bytes in "calc.exe" memory).
3. WriteProcessMemory Function (Write some bytes in "calc.exe")
4. CloseHandle

Then I try to do the the same thing again with the same instance of "calc.exe".
But this time I know the allocated memory address from the last time so I only need to do the following thing:

1. OpenProcess Function (Same instance).
2. WriteProcessMemory Function (Write some bytes. I know the address from before)
3. CloseHandle

Why is this not posible?
I get an error when I second time tries to write in the same memory address
Avatar of LMiller7
LMiller7
Flag of Canada image

You cannot write to any processes address space, or even your own, until physical storage has been committed to the address range in question. That is what VirtualAllocEx does. WriteProcessMemory does not do this. Read more about this on MSDN:
http://msdn.microsoft.com/en-us/library/aa366779%28v=VS.85%29.aspx


Avatar of DelphiUK

ASKER

Yes but I use "VirtualAllocEx" the first time to allocate some memory as you can see.
So I just can't get why I am not able to use WriteProcessMemory second time.
I use the same address as I was using the first time?

Avatar of ThievingSix
What is the error code returned?
Error code 87 - Wrong parameter (In WriteProcessMemory function)
Because it is only in the second time when I am using WriteProcessMemory  I get the error.

And I don't get it because I use the same address as I was using in the first time.
You wouldn't get that error because the address is wrong. Can you post the code of both uses of WriteProcessMemory() and the surrounding code?
ASKER CERTIFIED SOLUTION
Avatar of DelphiUK
DelphiUK
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A good! Glad you found it.