Source Code C++ Memory Class - Progress (Looking To Improve)

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 used to watch Fleeps tutorials and made a few things based of the sources he released, and I havent coded in awhile till recently.

I have been studying basics of C++ just so I can understand the language abit better (Have Previously coded in VB ALOT),
and well Ive made a simple read memory function for a console.

I know there is the ReadProcessMemory Function but I tried to make it shorter to use but would like some tips/hints on what I could improove on,
I do plan to make it so you can read/write all data types and hex/string addresses (game.exe+1234) < like that :).

mem.cpp
C++:
#include "stdafx.h"

using namespace std;

#pragma region Storage

DWORD Game_ID;
HANDLE hProcess;
HWND Game;

#pragma endregion Storage For Varibles


mem::mem()// GetProc
{
	//wchar_t Pname[20];//Window Name Varible (wide character - LPCSTR [.c_str] / LPCWSTR [wchar_t]
	//cout << "Enter Process Window Name: ";
	//wcin >> Pname;

	Game = FindWindow(NULL, L"Solitaire");//find the Process Via Its Window Name

	if(Game)// If The Process Is Running
	{
		GetWindowThreadProcessId(Game, &Game_ID);//Gets The Process ID From The Process Window
	    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Game_ID);//Declare hProcess As The Process/Handle And Give It Full Access
		cout << "\nProcess Running!" << endl;
	}
	else
	{
		cout << "\nProcess Is Not Running!" << endl;
	}
}

void mem::MemRead(string Address, int nBytes){

    DWORD _Address = strtol(Address.c_str(), 0, 0);

	switch(nBytes){
	 
		case 4:
			int DataTypeI;
			ReadProcessMemory(hProcess, (LPVOID)_Address, &DataTypeI, sizeof(DataTypeI), NULL);
			cout << "The Address " << Address << " Stores An Integer Value ( " << DataTypeI << " )" << endl;
			break;

		case 16:
			float DataTypeF;
			ReadProcessMemory(hProcess, (LPVOID)_Address, &DataTypeF, sizeof(DataTypeF), NULL);
			cout << "The Address " << Address << " Stores A Float Value ( " << DataTypeF << " )" << endl;
			break;

		case 32:
			double DataTypeD;
			ReadProcessMemory(hProcess, (LPVOID)_Address, &DataTypeD, sizeof(DataTypeD), NULL);
			cout << "The Address " << Address << " Stores A Double Value ( " << DataTypeD << " )" << endl;
			break;

		default:
			cout << "Invalid Selection, [Integer = 4 | Float = 16 | Double = 32]" << endl;
			break;

	}
}

void mem::Read(string Address, string Data){

	if(Data == "Integer"){
		MemRead(Address, 4);
	}

	if(Data == "Float"){
		MemRead(Address, 16);
	}

	if(Data == "Double"){
		MemRead(Address, 32);
	}
}
main.cpp
C++:
#include "stdafx.h"
using namespace std;


int main()
{
	
	mem OB;
        OB.MemRead("0x6B02808", 32);
	OB.Read("0x6B02808", "Double");
	system("pause");
	return 0;
}
So you can read memory by either:

Read("Address As String", "Data Type")
MemRead("Address As String", Data In Bytes) < its just a switch

What I want to do is make one function with only one ReadProcessMemory, and you dont need all that code and have something like this mem.read("addy", Type(float))

I will continue reading books and online tutorials for general C++ programming as i want to understand more about programming with C++ not just focused around hacks, so when
I get into situations like this ill know exactly what to do or atleast have an idea of where im going and what is possible :).

The Idea for this came to me when i saw other sources on here and it had tons of read/write process memory in peoples code, i just wanted to make a class for it so it can be called in
a small line of code and in the end bring the overall ammount of code down, although this may be pointless its helping me play around with classes and learn more about the language :)
 
Last edited:

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
This is very cool, if you happen to complete it and decide to share that class many of us would appreciate it :)

Good work

Fleep
 

TastyHorror

Coder
Dank Tier Donator
Nobleman
Oct 11, 2012
179
2,268
8
You should use the switch statement in your read function to increase performance and efficiency. Also, don't use global variables.
 
Last edited:

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Declare those global vars in the class instead.

If you have 2 objects of the vlass, the first one will probably lead to unexpected behaviour.

Rather than outputing the result, return it, and use templates to reduce the size of the class.
 

Nether

The Angel Of Verdun
Meme Tier VIP
Dank Tier Donator
Dec 11, 2013
293
3,738
16
Thank you for the information / tips you have provided I will continue to work on this :D, thank you for the support :)
 
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