title: Reading memory from ".exe" + offset?
body: <p>I'm using WinAPI's <code>ReadProcessMemory()</code> to read some "hidden" information from a game.</p>
  
  <p>I've used Cheat Engine to find out the static pointers, but I don't know how to read from them.
  Cheat Engine gives me a pointer to something like this: <code>"mygame.exe"+1C50</code></p>
  
  <p>I'm really new to WinAPI, how do I convert <code>"mygame.exe"+1C50</code> to an address that I can read with <code>ReadProcessMemory()</code>?</p>
  
  <p><strong>EDIT:</strong> I tried simplifying the problem, but I guess I should've just given the full code in the first place.
  So I'm working with static addresses and multi level pointers here, but I'm still stuck with getting the base address or w/e.</p>
  
  <p>Here's the full code and <a href="http://pbrd.co/11uVjjf" rel="noreferrer">a picture of my cheat engine address</a>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;tlhelp32.h&gt;
  
  using namespace std;
  
  HANDLE GetProcessHandle(const char *procName);
  
  int main()
  {
      const char *procName = "prism3d.exe";
      HANDLE hProc = GetProcessHandle(procName);
      if (hProc) {
  
       /* This works if I use the dynamic address (f.e. 0x02C2C4DC),
          but it changes every time I restart the game.
          I need to use the static address (prism3d.exe+A1C) to get
          the dynamic address for my "nuke".
        */
          float nuke;
          ReadProcessMemory(hProc, (void*)0x02C2C4DC, &amp;nuke, 4, 0);
          cout &lt;&lt; nuke;
  
      }
      CloseHandle(hProc);
      return 0;
  }
  
  HANDLE GetProcessHandle(const char *procName)
  {
      HANDLE hProc = NULL;
      PROCESSENTRY32 pe32;
      pe32.dwSize = sizeof(PROCESSENTRY32);
      HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      if (Process32First(hSnapshot, &amp;pe32)) {
          do {
              if (!strcmp(pe32.szExeFile, procName)) {
                  hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
                  break;
              }
          } while (Process32Next(hSnapshot, &amp;pe32));
      }
      CloseHandle(hSnapshot);
      return hProc;
  }
  </code></pre>
  
  <p><strong>Edit 2:</strong>
  Here's how I tried reading the value of my nuke, but it gives me random numbers, different every time I restart the game (sometimes it's <code>0</code>, sometimes <code>324324324</code>, etc...):</p>
  
  <pre><code>if (hProc) [
  
      DWORD baseAddr = (DWORD)GetModuleHandle(procName) + 0xA1C50; // also tried this with GetModuleHandle(NULL)
      DWORD mainAddr;
      ReadProcessMemory(hProc, (void*)(baseAddr + 0x111C), &amp;mainAddr, 4, 0);
  
      // Nuke
      float nuke;
      DWORD nukeAddr;
      ReadProcessMemory(hProc, (void*)(mainAddr + 0x48), &amp;nukeAddr, 4, 0);
      ReadProcessMemory(hProc, (void*)nukeAddr, &amp;nuke, 4, 0);
      cout &lt;&lt; nuke;
  }
  </code></pre>