Solved

ReadProcessMemory only returning one byte

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

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