Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] How to read pointers with ReadProcess

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
testingbls
How do I cheat?
Reputation: 0

Joined: 01 Sep 2011
Posts: 2

PostPosted: Thu Sep 01, 2011 3:43 pm    Post subject: [C++] How to read pointers with ReadProcess Reply with quote

Heya, I've been trying to get a view of different variables of a game in my program, and I've been using this function, which works fine with non-pointer addresses, for example if I input 3E2CD4 as the address I get the hit points and so on. But I can't get a 2nd-level pointer to work.

Code:
int addressHandler::readAddress( unsigned long address, string handleName )
{
   int value = -1;

   HANDLE phandle = getHandle( handleName );
   int addr = base + address;

   if(!phandle)
   {
      MessageBoxA(NULL, "Could not get handle!", "title", NULL);
      return -1;
   }

   ReadProcessMemory(phandle,LPCVOID(addr),&value,4,0);
   cout << value;

   return value;
}


I've tried using the "method" posted here (couldn't post urls for some reason, but viewtopic.php?p=4386205#4386205)
I modified the function to look like this (just for testing):


Code:
int addressHandler::readAddress( unsigned long address, string handleName )
{
   int value = -1;

   HANDLE phandle = getHandle( handleName );
   int addr = base + address;

   if(!phandle)
   {
      MessageBoxA(NULL, "Could not get handle!", "title", NULL);
      return -1;
   }

   DWORD pid;
   HWND hwnd = FindWindow(NULL,handleName.c_str());
   GetWindowThreadProcessId(hwnd,&pid);
   DWORD *thefirst = (DWORD*)(*(DWORD*)GetModuleBase( (LPSTR)handleName.c_str(), pid ) + 0x46F694 + 0x1c);
   DWORD *thesecond = (DWORD*)(*(DWORD*)thefirst + 0x20);
   ReadProcessMemory(phandle,LPCVOID(thesecond),&value,4,0);
   cout << value;

   return value;
}


But it just returns -1.

I've searched the forums but haven't really found any other thread than the one I linked. If this has already been asked and resolved before I humbly ask for a link to that topic, and apologize for this post.

Thanks!
Back to top
View user's profile Send private message
FLiNG
Newbie cheater
Reputation: 0

Joined: 09 Apr 2011
Posts: 19

PostPosted: Thu Sep 01, 2011 11:00 pm    Post subject: Reply with quote

You may need to use ReadProcessMemory multiple times (or loop) to get the multi level pointer.
This is how I find a multi level pointer.
I first write these codes in C#, then rewrite them in c++, tested with the game "The Baconing", it should work fine.

Code:
int FindPointerAddr(HANDLE pHandle,int baseaddr, int pLevel, int offset0 = 0,int offset1 = 0,int offset2 = 0,int offset3 = 0, int offset4 = 0)
{
   int Address = baseaddr;
   int offset = 0;
   for (int i = 0; i < pLevel; i++)
   {
      if (i == 0)
      {
         offset = offset0;
      }
      else if (i == 1)
      {
         offset = offset1;
      }
      else if (i == 2)
      {
         offset = offset2;
      }
      else if (i == 3)
      {
         offset = offset3;
      }
      else if (i == 4)
      {
         offset = offset4;
      }
      ReadProcessMemory(pHandle, (LPCVOID)Address, &Address , 4, NULL);
      Address += offset;
   }
   return Address;
}


EXAMPLE: (Offsets are optional)
2nd level pointer example:
Code:
          int offset0 = 0x678;
          int offset1 = 0x14;
          int myaddr = FindPointerAddr(ProcessHandle, 0x00270740, 2, offset0, offset1);
          MessageBox::Show("The Address is : " + String::Format("{0:X}",myaddr));


5th level pointer example:
Code:

          int offset0 = 0x678;
          int offset1 = 0x14;
          int offset2 = 0x758;
          int offset3 = 0x678;
          int offset4 = 0x5B4;
          int myaddr = FindPointerAddr(ProcessHandle, 0x00270740, 5, offset0, offset1, offset2, offset3, offset4);
          MessageBox::Show("The Address is : " + String::Format("{0:X}",myaddr));
Back to top
View user's profile Send private message
testingbls
How do I cheat?
Reputation: 0

Joined: 01 Sep 2011
Posts: 2

PostPosted: Fri Sep 02, 2011 4:56 am    Post subject: Reply with quote

Wow, awesome! It actually works! Thanks a lot! Now I have something to go on. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites