Search code examples
c#memorybyteintptr

How would I shorten a memory address so it works in a IntPtr?


I'm having a problem. So I'm working on an app that will be able to change a float in memory but the address I'm having is too long for IntPtr.

This is the code I have:

VAMemory vam = new VAMemory("APP NAME");

IntPtr ad = 0x264A373E7C0;

vam.WriteByte(ad, (Byte)100); 

So in this ^ WriteByte it says the IntPtr address is too long. I have used this code before and it has worked but somehow it's not working with this address.


Solution

  • If IntPtr.Size == 4 then your program is targeting 32bit.

    Even if you have selected AnyCPU architecture, since VS2013, there is a project build property called Prefer 32-bit and it must be turn off on 64bit machines to get IntPtr.Size == 8.

    When using the Perfer 32-Bit flavor of AnyCPU, the semantics are as follows:

    • If the process runs on a 32bit Windows system, it runs as a 32bit process. IL is compiled to x86 machine code.
    • If the process runs on a 64bit Windows system, it runs as a 32bit process. IL is compiled to x86 machine code.
    • If the process runs on an ARM Windows system, it runs as a 32bit process. IL is compiled to ARM machine code.