Solved

ReadProcessMemory only returning one byte

Posted on 2011-03-16
1
583 Views
Last Modified: 2012-05-11
Hi, I have the following C# code. It's meant to return an Integer, but it only returns 256 at the most.
It appears that I'm missing the next byte.
Does anybody have any ideas?

Thanks
byte[] buffer = new byte[200];
fixed (byte* cptr = &buffer[0])
{
int x = 0;
int* xptr = &x;
IntPtr hProcess = OpenProcess(PROCESS_VM_READ, false, p[0].Id);
bool result = ReadProcessMemory(hProcess, baseAddress, cptr, 8, null);

Open in new window

0
Comment
Question by:Netlink2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
MedievalWarrior earned 500 total points
ID: 35147319
You don't need to allocate the buffer just pass the pointer to the Integer variable ( This may require some modification to P/Invoke siganture) and it will copy it but make sure you have the correct baseAddress and your using the correct Length of the data type...

** It's meant to return an Integer **

Which type of Integer ? Your code indicates you want a LONG integer because your requesting 8 bytes. If you want Integer then request 4 bytes. You can use the Integer variable as the buffer instead of a byte array and request to read 4 bytes or use a Long variable and request 8 bytes. If you use byte buffer then you could use BitConverter.ToInt32() but make sure you specify the correct offsets. You might also want to allow the last parameter of ReadProcessMemory() to fill in the amount of bytes read so that you can make sure that what you request is the same as what has been returned.


bool result = ReadProcessMemory(hProcess, baseAddress, xptr, 4, cbRead); 

// If cbRead = 4 then you know the call returned you the correct amount of bytes requested

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question