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++] WriteProcessMemory Multi-level Pointer

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

Joined: 26 Sep 2011
Posts: 4

PostPosted: Sun Dec 28, 2014 7:54 am    Post subject: [C++] WriteProcessMemory Multi-level Pointer Reply with quote

Hi, good day,
i just wan't to ask if why is my code not working.
Im very new in coding :/
Please help me :/

This code compiles but it can't change the value :/
Please Help me T_T
Code:

#include "stdafx.h"

#include <windows.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include "tlhelp32.h"


using namespace std;
DWORD GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
{
   MODULEENTRY32 lpModuleEntry = { 0 };
   HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);

   if (!hSnapShot)
      return NULL;
   lpModuleEntry.dwSize = sizeof(lpModuleEntry);
   BOOL bModule = Module32First(hSnapShot, &lpModuleEntry);
   while (bModule)
   {
      if (!strcmp(lpModuleEntry.szModule, lpModuleName))
      {
         CloseHandle(hSnapShot);
         return (DWORD)lpModuleEntry.modBaseAddr;
      }
      bModule = Module32Next(hSnapShot, &lpModuleEntry);
   }
   CloseHandle(hSnapShot);
   return NULL;
}

int main()
{
   int newValue = 1000;
   HWND hWnd = FindWindowA(0, "Plants vs. Zombies");

   if (hWnd == 0){
      cerr << "Window not found." << endl;
   }
   else{
      DWORD pId;
      GetWindowThreadProcessId(hWnd, &pId);
      HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pId);
      
      if (!hProc){
         cerr << "Process not found." << endl;
      }
      else{

         DWORD BaseAddress = GetModuleBase("popcapgames1.exe",pId);

         DWORD buffer;
         ReadProcessMemory(hProc, (LPCVOID)(BaseAddress + 0x2A9EC0), &buffer, sizeof(buffer), NULL);
         ReadProcessMemory(hProc, (LPCVOID)(buffer + 0x768), &buffer, sizeof(buffer), NULL);
         buffer += 0x5560;

         int isSuccessful = WriteProcessMemory(hProc, (LPVOID)buffer, &newValue, sizeof(newValue), NULL);

         if (isSuccessful > 0){
            cerr << "Memory hacked." << endl;
         }
         else{
            cerr << "Memory can't be hacked." << endl;
         }
         CloseHandle(hProc);
      }
   }
}

Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad Sad

_________________
THE END!!!
Back to top
View user's profile Send private message Send e-mail
dm0000
Newbie cheater
Reputation: 0

Joined: 09 Nov 2014
Posts: 16

PostPosted: Sun Dec 28, 2014 2:57 pm    Post subject: Reply with quote

Try this:

ReadProcessMemory(hProc, (LPCVOID*)(BaseAddress + 0x2A9EC0), &buffer, sizeof(buffer), NULL);
ReadProcessMemory(hProc, (LPCVOID*)(buffer + 0x768), &buffer, sizeof(buffer), NULL);
ReadProcessMemory(hProc, (LPCVOID*)(buffer + 0x5560), &buffer, sizeof(buffer), NULL);

Now you Write.

WriteProcessMemory(hProc, (LPVOID*)buffer, &newValue, sizeof(newValue), NULL);

BTW, make sure your GetModuleBase function is not returning NULL. You never check for it.
Back to top
View user's profile Send private message
Krampus
Cheater
Reputation: 0

Joined: 22 Nov 2014
Posts: 41

PostPosted: Mon Dec 29, 2014 2:53 am    Post subject: Reply with quote

You can also use the FindDmaAddy function.

Code:
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
{
        DWORD pointer = BaseAddress;
        DWORD pTemp;
        DWORD pointerAddr;
     
        for (int c = 0; c < PointerLevel; c++)
        {
                if (c == 0)
                {
                        ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
                }
                pointerAddr = pTemp + Offsets[c];
                ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(pTemp), NULL);
        }
        return pointerAddr;
}


Credits to Fleep.

An example of the use for this code is:
Code:
DWORD AddressToWrite;
DWORD dw_ARifleClipOffset[] = { 0x150 };
BYTE InfAmmo[] = { 0x64, 0x0, 0x0, 0x0 };

AddressToWrite = FindDmaAddy(1, hProcHandle, dw_ARifleClipOffset, Player_Base);
WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &InfAmmo, sizeof(InfAmmo), NULL);


One is the number of offsets, hProcHandle is the handle to the game, dw_ARifleClipOffset is the Assault Rifle's clip offset, and the Player_Base is the base address that the offset(s) are being added to.

_________________
There is no spoon.
Back to top
View user's profile Send private message
pakeke80
How do I cheat?
Reputation: 0

Joined: 26 Sep 2011
Posts: 4

PostPosted: Tue Dec 30, 2014 12:48 pm    Post subject: Reply with quote

Thanks so much guys,
i luv you <3

_________________
THE END!!!
Back to top
View user's profile Send private message Send e-mail
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