I need to get the value from memory location 0 to 3 bytes assuming int uses 4 bytes of data and if lon开发者_如何学Pythong uses 8 bytes, I want to read 0 to 7 bytes as long's data and see what value it gives back. Can anyone help me with C# code.
Regards, Vix
This could be very dangerous, how are getting the address and how are you evaluating that it is valid? Not every address will be valid and trying to read from some of them will result in exceptions.
But you can use the Marshal.Read* methods do to this.
int intValue = Marshal.ReadInt32(addr);
long longValue = Marshal.ReadInt64(addr);
You will need to catch AccessViolationException's as well.
Also are you trying to read from a virtual address or from physical memory. From C# you will only be reading from the virtual address space of your process. You'd have to use a kernel mode driver to get direct access to the physical memory on your computer.
精彩评论