Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ReadProcessMemory() problem

ReadProcessMemory() problem

Scheduled Pinned Locked Moved C / C++ / MFC
game-devperformancehelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ALLERSLIT
    wrote on last edited by
    #1

    Hello, i wanted to get an idea of some basic memory editing so i thought writing a simple trainer for my favorite game would be a good idea. So i found out how to get the pointer, now when i use cheat engine it gives the correct value if i add the baseaddress + offset. But if i try that in my program it wont work for some reason.

    			int offset = 0x804;
    			int address = 0x818794;
    			int totalhp = offset + address;
    			int value;
    			ReadProcessMemory(hProcess, (LPCVOID)totalhp, &value, sizeof(value), NULL );
    			std::cout << value << std::endl;
    

    value always returns zero for god knows what reason. Any idea what iam doing wrong?

    Richard Andrew x64R 1 Reply Last reply
    0
    • A ALLERSLIT

      Hello, i wanted to get an idea of some basic memory editing so i thought writing a simple trainer for my favorite game would be a good idea. So i found out how to get the pointer, now when i use cheat engine it gives the correct value if i add the baseaddress + offset. But if i try that in my program it wont work for some reason.

      			int offset = 0x804;
      			int address = 0x818794;
      			int totalhp = offset + address;
      			int value;
      			ReadProcessMemory(hProcess, (LPCVOID)totalhp, &value, sizeof(value), NULL );
      			std::cout << value << std::endl;
      

      value always returns zero for god knows what reason. Any idea what iam doing wrong?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      How are you initializing hProcess?

      A 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        How are you initializing hProcess?

        A Offline
        A Offline
        ALLERSLIT
        wrote on last edited by
        #3

        The problem is not the handle, the problem is the wrong value i get.

        HWND hWnd = FindWindow(0, "AOEII");
        if(hWnd == 0)
        {
        	std::cout << "Cant find handle." << std::endl;
        	\_getch();
        } 
        else 
        {
        	DWORD proccess\_ID;
        	GetWindowThreadProcessId(hWnd, &proccess\_ID);
        	HANDLE hProcess = OpenProcess(PROCESS\_ALL\_ACCESS, FALSE, proccess\_ID);
        	if(!hProcess)
        	{ 
        		std::cout << "Cant open process." << std::endl;
        		\_getch();
        	} 
        	else 
        	{
                       Readprocessstuff...
        
        A 1 Reply Last reply
        0
        • A ALLERSLIT

          The problem is not the handle, the problem is the wrong value i get.

          HWND hWnd = FindWindow(0, "AOEII");
          if(hWnd == 0)
          {
          	std::cout << "Cant find handle." << std::endl;
          	\_getch();
          } 
          else 
          {
          	DWORD proccess\_ID;
          	GetWindowThreadProcessId(hWnd, &proccess\_ID);
          	HANDLE hProcess = OpenProcess(PROCESS\_ALL\_ACCESS, FALSE, proccess\_ID);
          	if(!hProcess)
          	{ 
          		std::cout << "Cant open process." << std::endl;
          		\_getch();
          	} 
          	else 
          	{
                         Readprocessstuff...
          
          A Offline
          A Offline
          ALLERSLIT
          wrote on last edited by
          #4

          Well found the solution, not exactly sure why i have to do it this way but iam reading about it right now, just thought id post the solution before i forget about it.

          			int offset = 0x804;
          			int baseaddress;
          			int value;
          			ReadProcessMemory(hProcess, (LPCVOID)0x00818794, (LPVOID)&baseaddress, sizeof(value), NULL );
          			ReadProcessMemory(hProcess, (LPCVOID)(baseaddress+offset), &value, sizeof(value), NULL );
          

          Thanks for trying to help :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups