• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

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
0
DelphiUK
Asked:
DelphiUK
  • 4
  • 3
1 Solution
 
LMiller7Commented:
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


0
 
DelphiUKAuthor Commented:
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?

0
 
ThievingSixCommented:
What is the error code returned?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
DelphiUKAuthor Commented:
Error code 87 - Wrong parameter (In WriteProcessMemory function)
0
 
DelphiUKAuthor Commented:
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.
0
 
ThievingSixCommented:
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?
0
 
DelphiUKAuthor Commented:
I did find the problem. The problem occur because I was using a wrong Process PID in OpenProcess function. Thats why I get ErrorCode 87.

0
 
ThievingSixCommented:
A good! Glad you found it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now