Solved

ReadProcessMemory only returning one byte

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 28
Please explain "Multi-Tenant Services" 5 63
How do ASP.NET and MVC work together? 4 28
Error in page 3 46
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now