PDA

View Full Version : Please help with memory reading/writing object oriented code.



can1357
05-25-2013, 12:32 PM
My old code which works fine adds 100 and frozes ammo to 50


// HackForBOPS2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <ctime>
using namespace std;
string GameName = "Call of Duty®: Black Ops II - Zombies"; char* GameStatus = "Waiting for game...";
LPCSTR LGameWindow = "Call of Duty®: Black Ops II - Zombies";
/*
ADRESSES FOR BOPS2


*/
bool Ammo1 = false, Money1 = false, Ammo2 = false, Money2 = false;
char* AmmoStatus1 = "OFF";
char* AmmoStatus2 = "OFF";
bool isAvail, updateOn;
DWORD AmmoBaseAdress1 = {0x000022F6CC4};
DWORD AmmoOffset1[] = {38129};
DWORD AmmoBaseAdress2 = {0x0000104D22A};
DWORD AmmoOffset2[] = {24633};
DWORD MoneyBaseAdress1 = {0x0000104D22A};
DWORD MoneyOffset1[] = {22997};
DWORD MoneyBaseAdress2 = {0x0000008F08E};
DWORD MoneyOffset2[] = {45520};

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD offsets[], DWORD BaseAdress);
void WriteToMem(HANDLE hProcHandle);
int _tmain(int argc, _TCHAR* argv[])
{
HWND hGameWindow = NULL;
int lastUpdate = clock();
int onePressTMR = clock();
int GameAvailTMR = clock();
DWORD dwProcId = NULL;
HANDLE hProcHandle = NULL;
updateOn = true;


while(!GetAsyncKeyState(VK_INSERT)){
try{
if(clock() - GameAvailTMR > 100){
GameAvailTMR = clock();
isAvail = false;
hGameWindow = FindWindowA(NULL, LGameWindow);
if(hGameWindow){
GetWindowThreadProcessId(hGameWindow, &dwProcId);
if(dwProcId!= 0){
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS,false, dwProcId);
if(hProcHandle == INVALID_HANDLE_VALUE ||hProcHandle == NULL){
GameStatus = "Failed to open process for vailed handle , inject failed.";
}else{
isAvail = true;
GameStatus = "Injected to Memory of game.";
}
}else{
GameStatus = "Failed to get process ID.";
}
}else{
GameStatus = "Waiting for game...";
}
if(updateOn ||clock() - lastUpdate > 600){
system("cls");

cout << "################################################## ##############################" << endl;
cout << " BLACK OPS II - Zombies Hack BY GoldenGamin.net/com/org " << endl;
cout << "################################################## ##############################" << endl << endl;
cout << ("GAME:") << (GameStatus ) << endl << endl;;
cout << "[F1]Slot 1 Unlimited Ammo:" << AmmoStatus1 << endl;
cout << "[F2]Slot 2 Unlimited Ammo:" << AmmoStatus2 << endl;
cout << "[F3]Slot 1 +100$" << endl;
cout << "[F4]Slot 2 +100$" << endl;
cout << "[INSERT] Exit"<< endl;
updateOn = true;
lastUpdate = clock();
if(isAvail){
WriteToMem(hProcHandle);
if(GetAsyncKeyState(VK_F1))
{
Ammo1 = !Ammo1;
if(Ammo1){
AmmoStatus1 = "ON";
}else{
AmmoStatus1 = "OFF";
}
}else if(GetAsyncKeyState(VK_F2))
{
Ammo2 = !Ammo2;
if(Ammo2){
AmmoStatus2 = "ON";
}else{
AmmoStatus2 = "OFF";
}
}
else if(GetAsyncKeyState(VK_F3))
{
Money1 = true;
}
else if(GetAsyncKeyState(VK_F4))
{
Money2 = true;
}
}
}

}

}catch(int e){

}
}
try{
CloseHandle(hProcHandle);
CloseHandle(hGameWindow);
}catch(int e){

}
return 0;
}
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD offsets[], DWORD BaseAdress){
try{DWORD pointer = BaseAdress;
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;
}catch(int e){


}
return 0;
}
DWORD returnData(int PointerLevel, HANDLE hProcHandle, DWORD offsets[], DWORD BaseAdress){
try{DWORD pointer = BaseAdress;
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 pTemp;
}catch(int e){

}
return 0;
}
void WriteToMem(HANDLE hProcHandle){
try{
DWORD AmmoValue[] = {50};
DWORD moneyValue = 100;
if(Ammo1){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, AmmoOffset1, AmmoBaseAdress1);
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &AmmoValue, sizeof(AmmoValue), NULL);
}
if(Ammo2){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, AmmoOffset2, AmmoBaseAdress2);
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &AmmoValue, sizeof(AmmoValue), NULL);
}
if(Money1){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, MoneyOffset1, MoneyBaseAdress1);
DWORD MoneyValue[] = {returnData(1,hProcHandle, MoneyOffset1, MoneyBaseAdress1)+moneyValue};
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &MoneyValue, sizeof(MoneyValue), NULL);
Money1 = false;
}
if(Money2){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, MoneyOffset2, MoneyBaseAdress2);
DWORD MoneyValue[] = {returnData(1,hProcHandle, MoneyOffset2, MoneyBaseAdress2)+moneyValue};
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &MoneyValue, sizeof(MoneyValue), NULL);
Money2 = false;
}
}catch(int e){

}
}

My new code, object based but adds more then limit like -19264561 and makes ammo bigger then 1023, and cant read well.


#include "stdafx.h"
#include <Windows.h>
#include "iostream"
#include <ctime>
using namespace std;

class GameScreen{
public:
HWND hGameWindow;
DWORD dwProcId;
HANDLE hProcHandle;
char* GameStatus;
bool isAvailable;
LPCSTR LGameWindow;
public:
GameScreen(char* game){
LGameWindow = game;
GameStatus = "Waiting for game...";
hGameWindow = NULL;
dwProcId = NULL;
hProcHandle = NULL;
isAvailable = false;
}
public:
void update(){
hGameWindow = FindWindowA(NULL, LGameWindow);
if(hGameWindow){
GetWindowThreadProcessId(hGameWindow, &dwProcId);
if(dwProcId!= 0){
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS,false, dwProcId);
if(hProcHandle == INVALID_HANDLE_VALUE ||hProcHandle == NULL){
GameStatus = "Failed to open process for vailed handle , inject failed.";
}else{
isAvailable = true;
GameStatus = "Injected to Memory of game.";
}
}else{
GameStatus = "Failed to get process ID.";
}
}else{
GameStatus = "Waiting for game...";
}
}
};
class RAMVariable{
public:
DWORD* RAMOFFSET;
DWORD RAMADRESS;
RAMVariable(DWORD offset[], DWORD adress){
RAMOFFSET = offset;
RAMADRESS = adress;
}
DWORD getData(HANDLE hProcHandle){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, RAMOFFSET, RAMADRESS);
return returnData(1,hProcHandle, RAMOFFSET, RAMADRESS);
}
void setData(HANDLE hProcHandle, DWORD* DATA){
DWORD AdressToWrite = FindDmaAddy(1,hProcHandle, RAMOFFSET, RAMADRESS);
WriteProcessMemory(hProcHandle, (BYTE*)AdressToWrite, &DATA, sizeof(DATA), NULL);
}
private:
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD offsets[], DWORD BaseAdress){
try{DWORD pointer = BaseAdress;
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;
}catch(int e){


}
return 0;
}
DWORD returnData(int PointerLevel, HANDLE hProcHandle, DWORD offsets[], DWORD BaseAdress){
try{DWORD pointer = BaseAdress;
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 pTemp;
}catch(int e){

}
return 0;
}
};
bool Ammo1 = false, Money1 = false, Ammo2 = false, Money2 = false;
char* AmmoStatus1 = "OFF";
char* AmmoStatus2 = "OFF";
void WriteToMem(HANDLE hProcHandle);
DWORD AmmoBaseAdress1 = {0x000022F6CC4};
DWORD AmmoOffset1[] = {38129};
DWORD AmmoBaseAdress2 = {0x0000104D22A};
DWORD AmmoOffset2[] = {24633};
DWORD MoneyBaseAdress1 = {0x0000104D22A};
DWORD MoneyOffset1[] = {22997};
DWORD MoneyBaseAdress2 = {0x0000008F08E};
DWORD MoneyOffset2[] = {45520};
RAMVariable ammo1 = RAMVariable(AmmoOffset1, AmmoBaseAdress1);
RAMVariable ammo2 = RAMVariable(AmmoOffset2, AmmoBaseAdress2);
RAMVariable money1 = RAMVariable(MoneyOffset1, MoneyBaseAdress1);
RAMVariable money2 = RAMVariable(MoneyOffset2, MoneyBaseAdress2);
int _tmain(int argc, _TCHAR* argv[])
{
GameScreen g = GameScreen("Call of Duty®: Black Ops II - Zombies");
g.update();
int lastUpdate = clock();
while(true){
g.update();
if(clock() - lastUpdate > 200){
lastUpdate = clock();

system("cls");
cout << "################################################## ##############################" << endl;
cout << " BLACK OPS II - Zombies Hack BY GoldenGamin.net/com/org " << endl;
cout << "################################################## ##############################" << endl << endl;
cout << ("GAME:") << (g.GameStatus ) << endl << endl;;
cout << "[F1]Slot 1 Unlimited Ammo:" << AmmoStatus1;
cout << endl;
cout << "[F2]Slot 2 Unlimited Ammo:" << AmmoStatus2;

cout << endl;
cout << "[F3]Slot 1 +100$" << endl;
cout << "[F4]Slot 2 +100$" << endl;
cout << "[INSERT] Exit"<< endl;
if(g.isAvailable){
WriteToMem(g.hProcHandle);
if(GetAsyncKeyState(VK_F1))
{
Ammo1 = !Ammo1;
if(Ammo1){
AmmoStatus1 = "ON";
}else{
AmmoStatus1 = "OFF";
}
}else if(GetAsyncKeyState(VK_F2))
{
Ammo2 = !Ammo2;
if(Ammo2){
AmmoStatus2 = "ON";
}else{
AmmoStatus2 = "OFF";
}
}
else if(GetAsyncKeyState(VK_F3))
{
Money1 = true;
}
else if(GetAsyncKeyState(VK_F4))
{
Money2 = true;
}
}
}
}
}

void WriteToMem(HANDLE hProcHandle){
try{
DWORD AmmoValue[] = {50};
DWORD moneyValue = 100;
ammo1 = RAMVariable(AmmoOffset1, AmmoBaseAdress1);
ammo2 = RAMVariable(AmmoOffset2, AmmoBaseAdress2);
money1 = RAMVariable(MoneyOffset1, MoneyBaseAdress1);
money2 = RAMVariable(MoneyOffset2, MoneyBaseAdress2);
if(Ammo1){
ammo1.setData(hProcHandle, AmmoValue);
}
if(Ammo2){
ammo2.setData(hProcHandle, AmmoValue);
}
if(Money1){
DWORD MoneyValue[] = {money1.getData(hProcHandle)+moneyValue};
money1.setData(hProcHandle, MoneyValue);
Money1 = false;
}
if(Money2){
DWORD MoneyValue[] = {money2.getData(hProcHandle)+moneyValue};
money2.setData(hProcHandle, MoneyValue);
Money2 = false;
}
}catch(int e){

}
}
[COLOR="Silver"]