Results 1 to 5 of 5
  1. #1
    MiniByte's Avatar
    Join Date
    Aug 2016
    Gender
    female
    Posts
    5
    Reputation
    10
    Thanks
    0

    C++ address and offsets issues

    I'm trying to learn and understand how readproccessmemory work. When I'm using cheat engine to find the static values, it's an success. I can close the game, use my address and offset, and get the correct value every time. However, when I'm trying to execute this in C++, it never returns the correct value?

    This is what my code looks like,

    Code:
    #include <iostream>
    #include <windows.h>
    
    
    using namespace std;
    
    int main()
    {
    
        // Base Address
        DWORD BaseAddress = 0x50F4F4;
    
        // Health
        DWORD healthOfset = 0xf8;
        DWORD healthAddress = (DWORD)(BaseAddress+healthOfset);
        int health = 0;
    
        HWND hwnd;
        DWORD pid;
        HANDLE phandle;
        hwnd = FindWindow(NULL,"AssaultCube");
    
        if(hwnd)
        {
    
            cout << "Game was found.\n" << endl;
            GetWindowThreadProcessId(hwnd,&pid);
            phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
    
            if(phandle)
            {
    
    
                // Read Health
                ReadProcessMemory(phandle,(PCVOID)healthAddress, &health, sizeof(health),0);
                cout << "Health: " << health << endl;
    
            }
    
        } else {
            cout << "Game not found." << endl;
        }
    
        return 0;
    
    }
    The above code returns:

    Game was found.
    Health: -1
    This is what cheat engine is giving me,

    http:/ / image.prntscr.com/image/b3660e76b0174f9794c4322108cb9eab . png (not allowed to post links)

    Am i doing this completely wrong?
    Last edited by MiniByte; 08-16-2016 at 02:34 PM.

  2. #2
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170
    Your link doesn't work so it's hard to say. I don't see too much wrong with the code at first glance. Try using PBYTE* instead of PCVOID in your readprocmem.

    Also you don't have to cast to dword if your assigning a dword to another dword. just do
    Code:
    DWORD healthAddress = (BaseAddress+healthOfset);
    instead of
    DWORD healthAddress = (DWORD)(BaseAddress+healthOfset);
    If you're still having trouble you could try watching the video i posted on reading and writing memory.
    https://www.mpgh.net/forum/showthread.php?t=1155218

  3. #3
    MiniByte's Avatar
    Join Date
    Aug 2016
    Gender
    female
    Posts
    5
    Reputation
    10
    Thanks
    0
    Not sure why the link wasn't working. Using http instead of www seems to work, sorry.

    http:/ / image.prntscr.com/image/b3660e76b0174f9794c4322108cb9eab . png

    I'll watch your video, thanks!

  4. #4
    HexMurder's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Location
    System.Diagnostics
    Posts
    344
    Reputation
    96
    Thanks
    3,170
    Oh wow i'm blind. Your problem is really simple. Your base address is a pointer. Which means you have to read it to see what address it's pointing too. Try it like this. (idk if it works i haven't tested it, but this is DEF your problem.)

    Code:
    #include <iostream>
    #include <windows.h>
    
    
    using namespace std;
    
    int main()
    {
    
        // Base Address
        DWORD BaseAddress = 0x50F4F4;
    	DWORD cBase = 0;
    
        // Health
        DWORD healthOfset = 0xf8;
        int health = 0;
    
        HWND hwnd;
        DWORD pid;
        HANDLE phandle;
        hwnd = FindWindow(NULL,"AssaultCube");
    
        if(hwnd)
        {
    
            cout << "Game was found.\n" << endl;
            GetWindowThreadProcessId(hwnd,&pid);
            phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
    
            if(phandle)
            {
    		//read base
    		ReadProcessMemory(phandle,(PBYTE*)BaseAddress, &cBase, sizeof(DWORD),0);//Assigns the value of base address pointer to cbase
    			
                // Read Health
                ReadProcessMemory(phandle,(PBYTE*)cBase + healthOfset, &health, sizeof(health),0);
                cout << "Health: " << health << endl;
    
            }
    
        } else {
            cout << "Game not found." << endl;
        }
    
        return 0;
    
    }

  5. The Following User Says Thank You to HexMurder For This Useful Post:

    MiniByte (08-16-2016)

  6. #5
    MiniByte's Avatar
    Join Date
    Aug 2016
    Gender
    female
    Posts
    5
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by HexMurder View Post
    Oh wow i'm blind. Your problem is really simple. Your base address is a pointer. Which means you have to read it to see what address it's pointing too. Try it like this. (idk if it works i haven't tested it, but this is DEF your problem.)

    Code:
    #include <iostream>
    #include <windows.h>
    
    
    using namespace std;
    
    int main()
    {
    
        // Base Address
        DWORD BaseAddress = 0x50F4F4;
    	DWORD cBase = 0;
    
        // Health
        DWORD healthOfset = 0xf8;
        int health = 0;
    
        HWND hwnd;
        DWORD pid;
        HANDLE phandle;
        hwnd = FindWindow(NULL,"AssaultCube");
    
        if(hwnd)
        {
    
            cout << "Game was found.\n" << endl;
            GetWindowThreadProcessId(hwnd,&pid);
            phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
    
            if(phandle)
            {
    		//read base
    		ReadProcessMemory(phandle,(PBYTE*)BaseAddress, &cBase, sizeof(DWORD),0);//Assigns the value of base address pointer to cbase
    			
                // Read Health
                ReadProcessMemory(phandle,(PBYTE*)cBase + healthOfset, &health, sizeof(health),0);
                cout << "Health: " << health << endl;
    
            }
    
        } else {
            cout << "Game not found." << endl;
        }
    
        return 0;
    
    }
    wow, thank you so much! nice to see that i almost made it on the first try, thanks again!

Similar Threads

  1. Issue with Addresses and Offsets for Trainer
    By ShadoGuidR in forum Visual Basic Programming
    Replies: 4
    Last Post: 06-27-2016, 06:44 AM
  2. [Solved] AK47 base address and pointer offsets
    By ongjx in forum Blackshot Help
    Replies: 2
    Last Post: 03-29-2016, 04:21 PM
  3. [Release] Assault Cube CT Base Address and OffSets
    By brassh in forum Other First Person Shooter Hacks
    Replies: 2
    Last Post: 06-27-2013, 07:05 AM
  4. How to get a Pointer and Offset Address.
    By ~~Gabriel in forum Coders Lounge
    Replies: 2
    Last Post: 11-26-2012, 02:41 AM
  5. [Patched] Crossfire PH Address and Offset (August 31 2012)
    By Nexuz2011 in forum CrossFire Philippines Hacks
    Replies: 104
    Last Post: 09-27-2012, 11:20 AM