Jason94
Jason94

Reputation: 13608

Looking for a variable inside another programs memory

I'm trying to find an int value inside another program's memory (my own little c++ that only holds that variable). The value is 1234, but I can't seem to find it.

This is what I'm doing:

for (uint adr = 0x00000000; adr <= 0x7FFFFFFF; adr += 1)
{
    // we want status...
    uint progress = (adr*100) / 0x7FFFFFFF;
    Console.WriteLine("Progress: {0} %", progress);

    // look for the int
    IntPtr bytes;
    byte[] buffer = new byte[4];

    ReadProcessMemory(process, adr, buffer, 4, out bytes);

    if (BitConverter.ToInt32(buffer, 0) == 1234)
    {
        // we found it...
    }
}

There are several errors:

  1. The progress does not work.
  2. I never get a hit on found.

Thanks

Upvotes: 0

Views: 143

Answers (2)

driushkin
driushkin

Reputation: 3659

You can compare results from your program with output of some advanced memory scanner, such as cheatengine.

Upvotes: 0

Svisstack
Svisstack

Reputation: 16636

  1. Maybe this value 1234 is saved in 2 byte value not 4 byte.
  2. Check readprocess memory not throw you error because you not OpenProcess.
  3. Try big endian reading too, then try reverse bits before reading.

Upvotes: 2

Related Questions