I'm trying to access a 32bit address, but when i create the IntPtr it throws an OverflowException. Here's the code:
uint memAddr = 0xF5920824;
IntPtr bufPtr = new IntPtr(memAddr);
byte[] data = new byte[4];
Marshal.Copy(bufPtr, data, 0, 4);
How can i access that address?
Your program CANNOT access a memory address of another program (regardless that the address you're going to read can't fit an Int32
, see this post to understand what it is) simply using an IntPtr
because they run within their private address space.
It must be shared somehow by the first program (shared memory or something else). Moreover an address XYZ in one program may be something completely different even in another instance of the same program (because the address is VIRTUAL).
If you're sure about the memory address (how? it could be even necessary to scan process memory) you have to P/Invoke ReadProcessMemory()
, it's a function designed for debugging purposes and if your executable has enough privileges you can read the memory of another process.
See this post here on SO for an example.