Source Code ProcMem.h C++ Memory Class

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Nether

The Angel Of Verdun
Meme Tier VIP
Dank Tier Donator
Dec 11, 2013
293
3,738
16
Hey Guys,

I have updated my ProcMem.h memory class for you guys, I am really enjoying the language even the hours I spend trying to fix a silly problem that's usually down to a wrong variable name or something silly, so I would really appreciate your feedback on what I could improve on - I will continue studying and reading and update this class when I learn more.

UPDATES:

- Added Error Handling
- Added Base Address Function ( e.g (DWORD)base + 0x8BF3E / Equivalent of Solitaire.exe+8BF3E )
- Added Functionality For Pointers ( Still Buggy - Ill provide examples )
- Added Get Process Parameter To Constructor (Easier for people who don't want to modify the class)

Updates To Come:

- Easier Function To Read/Write Pointers With Ease (Fix Bugs)
- Improved Code When I Learn More
- Code Injection
- DLL Injection (Will Most likely be Load-library Function First Then Ill Add More)
- More Comments So People Can Understand The Code Better
- Improved Function For Reading/Writing Strings [char]
- Advanced Error Handling
- Procmem.h

Includes.h
C++:
#pragma once

#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
ProcMem.h
C++:
#include "Includes.h"

class ProcMem{

private:
	HANDLE hProcess; //Handle for this class
	DWORD Proc_ID; //Varible to store Process ID
	
public:

	DWORD *base; //Stores Module Base Address
	
	ProcMem(LPCSTR WindowName); //Constructor - Finds Process Via Window Name

	//READ MEMORY
	template <class cData>
	
cData read(DWORD (Address)){
   try{
	  if(Proc_ID > 0){
       cData B;// Generic Varible to store Address+Value
       ReadProcessMemory(hProcess, (LPVOID)(Address), &B, sizeof(B), NULL);
	   return B;
	  }
	  else{
		  throw 1; //Throw Error Number / Defined In Catch
	  }
	} //Try End
   catch(int error){
		cout << "No Memory Found, ERROR: " << error <<  endl;
   } // Catch End

return 0;
} //Read End
     
     //WRITE MEMORY
	 template <class cData>
	 
cData write(DWORD (Address), cData B){
     try{
		if(Proc_ID > 0){
         WriteProcessMemory(hProcess, (LPVOID)(Address), &B, sizeof(B), NULL);
         return B;
		}
		else{
			throw 1; //Throw Error Number / Defined In Catch
		}
	 } // Try End
	catch(int error){
			cout << "No Memory Found, ERROR: " << error << endl;
	} //Catch End

return 0;
} //Write End

};
ProcMem.cpp
C++:
#include "Includes.h"
#include "ProcMem.h"

using namespace std;

ProcMem::ProcMem(LPCSTR WindowName){

	HWND hWindow = FindWindowA(NULL, WindowName); //Get the process window by name

	if(hWindow)
	{
		GetWindowThreadProcessId(hWindow, &Proc_ID); //Gets The Process ID From The Process Window and stores it in the temp address of Proc_ID
	    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Proc_ID); //Declare hProcess As The HANDLE for the Process And Give It Full Access
		cout << "\nProcess Running!" << endl;

	    HANDLE hModule = INVALID_HANDLE_VALUE; //Declare Function Handle [Must Be Separate Handle]
        MODULEENTRY32 ePoint; //Declare Entry Point Variable

        hModule = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, Proc_ID ); //Take a snapshot of all modules in the specified process. 
        
        ePoint.dwSize = sizeof( MODULEENTRY32 ); //Set the size of the structure before using it. 

        Module32First(hModule, &ePoint); //Initialize function to get Process Module Information from (hModule), and store in address of (ePoint)

	    base = (DWORD*) ePoint.modBaseAddr; //Copy the Module Base Address to (base - Public Variable)

        CloseHandle( hModule ); //Close this handle as it is no longer required
	}

	else 
	{ 
		cout << "\nProcess Is Not Running!" << endl; 
	}
	
}
main.cpp
C++:
#include "Includes.h"
#include "ProcMem.h"

using namespace std;

ProcMem mem("Solitaire"); //Create Class Object("Window Name")
DWORD* Base = mem.base; // Varible Base points to Value stored inside class(mem.base - Base Module Process.exe+0)

int main()
{
	
	char A = mem.read<char>(0x1800F1424);
	int B = mem.read<int>(0x8EC3620);
	float C = mem.read<float>(0x56571DC);
	double D = mem.read<double>(0x5653A3C);

	cout << A << "\n" << B << "\n" << C << "\n" << D << endl;

	mem.write<int>(0x8EC3620, 12);
	mem.write<float>(0x56571DC, 16.32);
	mem.write<double>(0x5653A3C, 1337.7331);

        DWORD Ptr = mem.read<int>((DWORD)Base + 0xBAFA8); // Solitaire.exe+BAFA8 {Pointer Base = Score)
        DWORD Ptr1 = mem.read<int>((DWORD)Ptr + 0x50); // 1st Level
        DWORD Ptr2 = mem.read<int>((DWORD)Ptr1 + 0x14); // 2nd Level

        cout << Ptr2 << endl; // Displays Value Of Solitaire.exe+BAFA8 + [offset] 50 + [offset] 14 (2 Level Pointer)
      
        mem.write<int>((DWORD)Base + 0xBAFA8, 1337); // Few Bugs with multi-level pointers for writing(works fine with base + Last Offset)

        mem.write<int>(Ptr1 + 0x14, 52);

        system("pause");
        return 0;
}
NOTE: Code must be compiled as x64 if Reading/Writing to 64-bit Applications.
 
Last edited:

Heisa

Jr.Coder
Full Member
Nobleman
Jul 3, 2013
77
703
3
Hey Guys,

I have updated my memory class for you guys, I am really enjoying the language even the hours I spend trying to fix a silly problem that's usually down to a wrong variable name or something silly, so I would really appreciate your feedback on what I could improve on - I will continue studying and reading and update this class when I learn more.

UPDATES:

- Added Error Handling
- Added Base Address Function ( e.g (DWORD)base + 0x8BF3E / Equivalent of Solitaire.exe+8BF3E )
- Added Functionality For Pointers ( Still Buggy - Ill provide examples )
- Added Get Process Parameter To Constructor (Easier for people who don't want to modify the class)

Updates To Come:

- Easier Function To Read/Write Pointers With Ease (Fix Bugs)
- Improved Code When I Learn More
- Code Injection
- DLL Injection (Will Most likely be Load-library Function First Then Ill Add More)
- More Comments So People Can Understand The Code Better
- Improved Function For Reading/Writing Strings [char]
- Advanced Error Handling

Includes.h
C++:
#pragma once

#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
ProcMem.h
C++:
#include "Includes.h"

class ProcMem{

private:
	HANDLE hProcess; //Handle for this class
	DWORD Proc_ID; //Varible to store Process ID
	
public:

	DWORD *base; //Stores Module Base Address
	
	ProcMem(LPCSTR WindowName); //Constructor - Finds Process Via Window Name

	//READ MEMORY
	template <class cData>
	
cData read(DWORD (Address)){
   try{
	  if(Proc_ID > 0){
       cData B;// Generic Varible to store Address+Value
       ReadProcessMemory(hProcess, (LPVOID)(Address), &B, sizeof(B), NULL);
	   return B;
	  }
	  else{
		  throw 1; //Throw Error Number / Defined In Catch
	  }
	} //Try End
   catch(int error){
		cout << "No Memory Found, ERROR: " << error <<  endl;
   } // Catch End

return 0;
} //Read End
     
     //WRITE MEMORY
	 template <class cData>
	 
cData write(DWORD (Address), cData B){
     try{
		if(Proc_ID > 0){
         WriteProcessMemory(hProcess, (LPVOID)(Address), &B, sizeof(B), NULL);
         return B;
		}
		else{
			throw 1; //Throw Error Number / Defined In Catch
		}
	 } // Try End
	catch(int error){
			cout << "No Memory Found, ERROR: " << error << endl;
	} //Catch End

return 0;
} //Write End

};
ProcMem.cpp
C++:
#include "Includes.h"
#include "ProcMem.h"

using namespace std;

ProcMem::ProcMem(LPCSTR WindowName){

	HWND hWindow = FindWindowA(NULL, WindowName); //Get the process window by name

	if(hWindow)
	{
		GetWindowThreadProcessId(hWindow, &Proc_ID); //Gets The Process ID From The Process Window and stores it in the temp address of Proc_ID
	    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Proc_ID); //Declare hProcess As The HANDLE for the Process And Give It Full Access
		cout << "\nProcess Running!" << endl;

	    HANDLE hModule = INVALID_HANDLE_VALUE; //Declare Function Handle [Must Be Separate Handle]
        MODULEENTRY32 ePoint; //Declare Entry Point Variable

        hModule = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, Proc_ID ); //Take a snapshot of all modules in the specified process. 
        
        ePoint.dwSize = sizeof( MODULEENTRY32 ); //Set the size of the structure before using it. 

        Module32First(hModule, &ePoint); //Initialize function to get Process Module Information from (hModule), and store in address of (ePoint)

	    base = (DWORD*) ePoint.modBaseAddr; //Copy the Module Base Address to (base - Public Variable)

        CloseHandle( hModule ); //Close this handle as it is no longer required
	}

	else 
	{ 
		cout << "\nProcess Is Not Running!" << endl; 
	}
	
}
main.cpp
C++:
#include "Includes.h"
#include "ProcMem.h"

using namespace std;

ProcMem mem("Solitaire"); //Create Class Object("Window Name")
DWORD* Base = mem.base; // Varible Base points to Value stored inside class(mem.base - Base Module Process.exe+0)

int main()
{
	
	char A = mem.read<char>(0x1800F1424);
	int B = mem.read<int>(0x8EC3620);
	float C = mem.read<float>(0x56571DC);
	double D = mem.read<double>(0x5653A3C);

	cout << A << "\n" << B << "\n" << C << "\n" << D << endl;

	mem.write<int>(0x8EC3620, 12);
	mem.write<float>(0x56571DC, 16.32);
	mem.write<double>(0x5653A3C, 1337.7331);

        DWORD Ptr = mem.read<int>((DWORD)Base + 0xBAFA8); // Solitaire.exe+BAFA8 {Pointer Base = Score)
        DWORD Ptr1 = mem.read<int>((DWORD)Ptr + 0x50); // 1st Level
        DWORD Ptr2 = mem.read<int>((DWORD)Ptr1 + 0x14); // 2nd Level

        cout << Ptr2 << endl; // Displays Value Of Solitaire.exe+BAFA8 + [offset] 50 + [offset] 14 (2 Level Pointer)
      
        mem.write<int>((DWORD)Base + 0xBAFA8, 1337); // Few Bugs with multi-level pointers for writing(works fine with base + Last Offset)

        mem.write<int>(Ptr1 + 0x14, 52);

        system("pause");
        return 0;
}
NOTE: Code must be compiled as x64 if Reading/Writing to 64-bit Applications.

Thank you so much for this, I was finally able to use pointers, and not dynamic addresses everytime i started the game for my bot.. :megusta:
 
Last edited:

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
i'd recommend stripping out the cout lines and implementing something else to return back information to the caller, it would make your class a bit more ..portable
 

Nether

The Angel Of Verdun
Meme Tier VIP
Dank Tier Donator
Dec 11, 2013
293
3,738
16
i'd recommend stripping out the cout lines and implementing something else to return back information to the caller, it would make your class a bit more ..portable

Thank you so much for this, I was finally able to use pointers, and not dynamic addresses everytime i started the game for my bot.. :megusta:

:L this is very old now - those "error handeling" messages were just for testing, i have a much better version for using pointers now : https://guidedhacking.com/showthrea...iner-Source-Code&p=19902&viewfull=1#post19902 , ill soon be adding an integrity check but right now im playing some games and working with some maths in C++, ill get back to completing this soon.
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods