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++ DWORD WORD BYTE Multi Pointer OFFSET READ & WRITE

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Wed Dec 30, 2015 7:40 pm    Post subject: C++ DWORD WORD BYTE Multi Pointer OFFSET READ & WRITE Reply with quote

I figured I should release these as I had a hard time finding anything similar to this so I created a few of these myself.. some I took from some random places.. very good for a dll inject solution.

Can't be without these if you are working on some solid trainers that need frequent updates.

Only tested in x86 environment not sure how it would function on a x86-64 trainer probably will have some issues with UINT32 addresses.

Code:

BYTE ReadBytePointer(DWORD ulBase, DWORD ulLevels, ...)
{
   DWORD offset;
   va_list va;
   va_start(va, ulLevels);

   __try
   {
      if (!IsBadReadPtr((void*)ulBase, sizeof(DWORD)))
      {
         ulBase = *(DWORD*)ulBase;
         for (DWORD ulIndex = 1; ulIndex <= ulLevels; ulIndex++) {
            offset = va_arg(va, int);
            if (IsBadReadPtr((void*)(ulBase + offset), sizeof(DWORD)))
            {
               va_end(va);
               return 0;
            }
            ulBase = *(DWORD*)(ulBase + offset);
         }
      }
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { ulBase = 0; }

   va_end(va);

   return (BYTE)ulBase;
}


Code:

WORD ReadWordPointer(DWORD ulBase, DWORD ulLevels, ...)
{
   DWORD offset;
   va_list va;
   va_start(va, ulLevels);

   __try
   {
      if (!IsBadReadPtr((void*)ulBase, sizeof(DWORD)))
      {
         ulBase = *(DWORD*)ulBase;
         for (DWORD ulIndex = 1; ulIndex <= ulLevels; ulIndex++) {
            offset = va_arg(va, int);
            if (IsBadReadPtr((void*)(ulBase + offset), sizeof(DWORD)))
            {
               va_end(va);
               return 0;
            }
            ulBase = *(DWORD*)(ulBase + offset);
         }
      }
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { ulBase = 0; }

   va_end(va);

   return (WORD)ulBase;
}


Code:

DWORD ReadDWordPointer(DWORD ulBase, DWORD ulLevels, ...)
{
   DWORD offset;
   va_list va;
   va_start(va, ulLevels);

   __try
   {
      if (!IsBadReadPtr((void*)ulBase, sizeof(DWORD)))
      {
         ulBase = *(DWORD*)ulBase;
         for (DWORD ulIndex = 1; ulIndex <= ulLevels; ulIndex++) {
            offset = va_arg(va, int);
            if (IsBadReadPtr((void*)(ulBase + offset), sizeof(DWORD)))
            {
               va_end(va);
               return 0;
            }
            ulBase = *(DWORD*)(ulBase + offset);
         }
      }
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { ulBase = 0; }

   va_end(va);

   return ulBase;
}


NEW! QWord reading!

Code:

DWORD64 ReadQWordPointer(DWORD ulBase, DWORD ulLevels, ...)
{
   DWORD offset;
   va_list va;
   va_start(va, ulLevels);

   __try
   {
      if (!IsBadReadPtr((void*)ulBase, sizeof(DWORD)))
      {
         ulBase = *(DWORD*)ulBase;
         for (DWORD ulIndex = 1; ulIndex < ulLevels; ulIndex++) {
            offset = va_arg(va, int);
            if (IsBadReadPtr((void*)(ulBase + offset), sizeof(DWORD)))
            {
               va_end(va);
               return 0;
            }
            ulBase = *(DWORD*)(ulBase + offset);
         }
      }

      offset = va_arg(va, int);
      va_end(va);
      if (IsBadReadPtr((void*)(ulBase + offset), sizeof(DWORD)))
         return 0;
      return *(DWORD64 *)(ulBase + offset);
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { return 0; }

   return 0;
}


Code:

bool WritePointer(DWORD ulBase, int iValue, int numBytes, DWORD ulLevels, ...)
{
   va_list va;
   va_start(va, ulLevels);
   DWORD offset;

   __try {
      DWORD d, ds;
      DWORD tmp;

      if (!IsBadReadPtr((void*)ulBase, sizeof(DWORD)))
         tmp = *(DWORD*)ulBase;

      for (DWORD ulIndex = 1; ulIndex < ulLevels; ulIndex++) {
         offset = va_arg(va, int);

         if (IsBadReadPtr((void*)(tmp + offset), sizeof(DWORD)))
         {
            va_end(va);
            return false;
         }

         tmp = *(DWORD*)(tmp + offset);
      }

      DWORD offset = va_arg(va, int);

      if (numBytes == 4) {
         if (IsBadReadPtr((void*)(tmp + offset), sizeof(DWORD)))
            return false;
         VirtualProtect((LPVOID)(*(DWORD*)(tmp+offset)), sizeof(DWORD), PAGE_EXECUTE_READWRITE, &d);
         *(DWORD*)(tmp + offset) = iValue;
         VirtualProtect((LPVOID)(*(DWORD*)(tmp + offset)), sizeof(DWORD), d, &ds);
      } else if (numBytes == 2) {
         if (IsBadReadPtr((void*)(tmp + offset), sizeof(WORD)))
            return false;
         VirtualProtect((LPVOID)(*(WORD*)(tmp + offset)), sizeof(WORD), PAGE_EXECUTE_READWRITE, &d);
         *(WORD*)(tmp + offset) = iValue;
         VirtualProtect((LPVOID)(*(WORD*)(tmp + offset)), sizeof(WORD), d, &ds);
      } else if (numBytes == 1) {
         if (IsBadReadPtr((void*)(tmp + offset), sizeof(BYTE)))
            return false;
         VirtualProtect((LPVOID)(*(BYTE*)(tmp + offset)), sizeof(BYTE), PAGE_EXECUTE_READWRITE, &d);
         *(BYTE*)(tmp + offset) = iValue;
         VirtualProtect((LPVOID)(*(BYTE*)(tmp + offset)), sizeof(BYTE), d, &ds);
      }
      return true;
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { return false; }
}


This one I like very much.. it solves a complex issue with injecting your DLL into games which already have your bot injected in it..

Also helps identity which game you want to bot/hack on if you have multiple games botting/hacking at once, it will only get the game handle whichever game it's injected into, before this solution I had to use complicated Shared memory global objects to identity which game has which DLL etc..

Code:

HWND FindProcessWindow()
{
   char szBuffer[200];
   DWORD dwTemp;

   for (HWND hWnd = GetTopWindow(NULL); hWnd != NULL; hWnd = GetNextWindow(hWnd, GW_HWNDNEXT))
   {
      GetWindowThreadProcessId(hWnd, &dwTemp);

      if (dwTemp != GetCurrentProcessId()) continue;

      if (!GetClassName(hWnd, szBuffer, sizeof(szBuffer) / sizeof(char))) continue;
      if (!strcmp(szBuffer, "!!! Replace Game Class Name Here !!!"))
      {
         return hWnd;
      }
   }
   return false;
}

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
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