Solved

ReadProcessMemory only returning one byte

Posted on 2011-03-16
1
568 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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