QuestionHelpGetting started with C++ DLL hacking - Basic Memory Editing

Posts 1–3 of 3 · Page 1 of 1
C++ DLL Problem - Program Crashing
So basically i've made a dll ready to inject into Garry's Mod (hl2.exe) but whenever i inject it into hl2.exe, hl2.exe crashes!
Could someone please tell me why my dll is making the program crash?
Here's my script for the dll:
Code:
#include <windows.h>

DWORD Base = (DWORD)GetModuleHandle((LPCTSTR)"client.dll") + (DWORD)0x5B5340;
DWORD* Address = (DWORD*)Base;

void mainthread() {
	while(1) {
		*Address = 2;
                Sleep(250);
	}
}


BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD callReason, LPVOID lpReserved) {
	if(callReason == DLL_PROCESS_ATTACH) {
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&mainthread, 0, 0, 0);
		MessageBoxA(NULL,"Hack Injected Successfully!", "DLL Injection" ,NULL);
	}
	return 1;
}
Thanks in advance!
I'm not 100% percent sure, but I think Garry's Mod shuts down if it detects anything being edited from an exterior?

I'm not sure though.
Quote Originally Posted by eCho' View Post
I'm not 100% percent sure, but I think Garry's Mod shuts down if it detects anything being edited from an exterior?

I'm not sure though.
At this point, i'm pretty sure it's not just Garry's Mod. I tried using the method i have here on the cheat engine tutorial (on step 2) trying to change the amount of 'health'. The tutorial crashed as Garry's Mod did. Although, this could just be a coincidence...

---------- Post added at 01:26 PM ---------- Previous post was at 01:03 PM ----------

And still i get the same crash when i try a different method...
Code:
#include <windows.h>
#include <stdio.h>

#define ADR_Wallhack GetModuleHandle("client.dll") + 0x005B5340

void mainthread() {
	while(1) {
		DWORD OldProt;
		int WallhackOn = 2;
		int WallhackOff = 1;
		VirtualProtect((void*)ADR_Wallhack, sizeof(WallhackOn), PAGE_READWRITE, &OldProt);
		memcpy((void*)ADR_Wallhack, &WallhackOn, sizeof(WallhackOn));
		VirtualProtect((void*)ADR_Wallhack, sizeof(WallhackOn), OldProt, 0;
		Sleep(250);
	}
}


BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD callReason, LPVOID lpReserved) {
	if(callReason == DLL_PROCESS_ATTACH) {
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&mainthread, 0, 0, 0);
		MessageBoxA(NULL,"Hack Written Successful", "DLL Injection" ,NULL);
	}
	return 1;
}
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?