C++ hack crashing game.

Posts 1–10 of 10 · Page 1 of 1
C++ hack crashing game.
My very small hack I've made is crashing my game and I don't know why, all I wanted to do was keep the ammo at 42 (favorite number) and not let it decrease. but whenever I start the exe the game crashes... should I make it as a dll and inject it instead? this is the error I get upon starting the exe "win32 exception 0x0000005 [0x36]"
and here is my code

#include "stdafx.h"
#include <iostream>
#include <string>
#include <Windows.h>


using namespace std;

int main(void)
{

int nVal = 42;

HWND hWnd = FindWindowA(0, "AssaultCube");

if (hWnd == 0)
{
cerr << "Could not find window" << endl;
}
else
{
BYTE data[] = { 0x0, 0x14, 0x384, 0x0 };
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pId);

if (!hProc)
{
cerr << "Process can't open.." << endl;
}
else
{
int stat = WriteProcessMemory(hProc, (LPVOID)0x005100F8, &nVal, (DWORD)sizeof(nVal), NULL);

if (stat < 42)
{
clog << "Activated" << endl;
}
else
{
cerr << "Not applied" << endl;
}

CloseHandle(hProc);
}
}
system("pause");
return 0;
}
Here you go
Here you go try changing the address of 0220A1D8
& you need to learn and stop copying and pasting.
http://stackoverflow.com/questions/1...modifying-in-c




Code:
#include <Windows.h>
#include <iostream>
using namespace std;


int main()
{
	const int gameValue = 42;

	HWND hWnd = FindWindow(NULL, L"AssaultCube");

	if(hWnd == NULL)
	{
		cout << "Could not find window " << endl;
	}
	else
	{
		
		DWORD pId;
		GetWindowThreadProcessId(hWnd, &pId);
		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pId);
		
		if(!hProc)
		{
			cout <<"Process can't open .. " << endl;
		}
		else
		{
			for(;;Sleep(100))
			{
			int stat = WriteProcessMemory(hProc,(LPVOID)0x0220A1D8, &gameValue, (DWORD)sizeof(gameValue), NULL);

			if(stat < 42)
			{
				cout << "Active!! " << endl;
			}
			else
			{
				cout << "Not Applied " << endl;
			}
			}
			
		}
		CloseHandle(hProc);
	}

	cin.get();
	return 0;
}
Quote Originally Posted by CoBraX View Post
Here you go try changing the address of 0220A1D8
& you need to learn and stop copying and pasting.
http://stackoverflow.com/questions/1...modifying-in-c




Code:
#include <Windows.h>
#include <iostream>
using namespace std;


int main()
{
	const int gameValue = 42;

	HWND hWnd = FindWindow(NULL, L"AssaultCube");

	if(hWnd == NULL)
	{
		cout << "Could not find window " << endl;
	}
	else
	{
		
		DWORD pId;
		GetWindowThreadProcessId(hWnd, &pId);
		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pId);
		
		if(!hProc)
		{
			cout <<"Process can't open .. " << endl;
		}
		else
		{
			for(;;Sleep(100))
			{
			int stat = WriteProcessMemory(hProc,(LPVOID)0x0220A1D8, &gameValue, (DWORD)sizeof(gameValue), NULL);

			if(stat < 42)
			{
				cout << "Active!! " << endl;
			}
			else
			{
				cout << "Not Applied " << endl;
			}
			}
			
		}
		CloseHandle(hProc);
	}

	cin.get();
	return 0;
}
I'm really not trying to c&p im just learning and trying to teach myself how everything is working, line by line, hence the reason why I asked why this didn't work. Thank you though.
0x0000005 is an access violation exception. Call VirtualProtectEx() in order to change the address protection.
Quote Originally Posted by user590177 View Post
0x000000005 is an access violation exception. Call VirtualProtectEx() in order to change the address protection.
I thought WriteProcessMemory did that for you? o:
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Quote Originally Posted by MSDN
The entire area to be written to must be accessible, and if it is not accessible, the function fails.
Check documentation online regarding the functions you are using, it's a pretty good way to learn more

EDIT: Also I would recommend you some improvements:
- Don't cast sizeof() to DWORD as it is not really needed. Tbh sizeof() is not needed at all, integers' size is 4.
- Don't declare your nVal inside the main() function, rather declare it as a static int outside of the main() function.
Quote Originally Posted by Mayion View Post
. @Mezmaa Have you fixed your problem yet?
No I don't, I think I just need to study C++ more and work on making and troubleshooting console applications and reading others source for their hacks still. I haven't progressed far enough to make my own hacks. back to the books! thank you very much though.
Quote Originally Posted by Mezmaa View Post
No I don't, I think I just need to study C++ more and work on making and troubleshooting console applications and reading others source for their hacks still. I haven't progressed far enough to make my own hacks. back to the books! thank you very much though.
I must insist that you have to make sure that you called virtualprotrctex the correct way plus watch out for the addresses that you unprotect as some of them cannot be unprotected but I cannot really remember which ones (x# of the first addresses)
Ugh this code.

Code:
DWORD val = 0, nBytes = 0, gameValue = 42;
VirtualProtect( proc, LPVOID( 0x220A1D8 ), sizeof( DWORD ), PAGE_EXECUTE_READWRITE, NULL )
for( ; ( val = WriteProcessMemory( proc, LPVOID( 0x220A1D8 ), &gameValue, sizeof( DWORD ), &nBytes ) ), val && nBytes == sizeof( DWORD ) ; Sleep( 100 ) )
   ;
Read the documentation next time.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us