Okay, so what I'm attempting to do is change the value stored at client.dll+005C58D8 (r_drawothermodels) to 2.
I have completely no idea what I am doing wrong...
I'm a bit of a newbie to C++, so please try to go easy on me and explain as much as you can about what I've done wrong!
Code:
#include <Windows.h>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
HWND hwnd;
HANDLE handle;
DWORD process_ID;
hwnd = FindWindow(NULL, "Garry's Mod");
GetWindowThreadProcessId(hwnd, &process_ID);
handle = OpenProcess(PROCESS_ALL_ACCESS, false, process_ID);
system("cls");
system("title Garry's Mod Wallhack");
system("color 0a");
int newVar = 2;
DWORD* baseAddress = (DWORD*)GetModuleHandle("client.dll");
DWORD* Address = baseAddress + 0x5C58D8;
if(WriteProcessMemory(handle, (DWORD*)Address, &newVar, sizeof(newVar), NULL)) {
cout << "Hacked Successfully!" << endl;
cout << "Press ENTER to end this program...";
cin.get();
}
else {
cout << "Failed to hack..." << endl;
cout << "Press ENTER to end this program...";
cin.get();
}
CloseHandle(handle);
return 1;
}
I think maybe the error might lie around the code below, but i'm not 100% sure.
Code:
DWORD* baseAddress = (DWORD*)GetModuleHandle("client.dll");
DWORD* Address = baseAddress + 0x5C58D8;
if(WriteProcessMemory(handle, (DWORD*)Address, &newVar, sizeof(newVar), NULL))
This part of it is my attempt to join the address at client.dll with the 0x5C58D8 (i think 0x5C58D8 is the offset)
I don't actually get an error really, just the output from my console window is always "Failed to hack..." (The output if the value was unable to be changed)
Also I know that I have a high chance of being vac banned and blah blah blah or something like that because this 'hack' is literally just forcing one of the game's variables. I don't really care about this, this is just a little 'test' to help me get started with 'hacking' using C++.
I know that the answer is probably really really obvious, but like i said, I'm still a newbie to this stuff :S
---------- Post added at 01:47 AM ---------- Previous post was at 01:00 AM ----------
Okay guys, don't worry about it. I managed to find and fix the errors myself. It turns out i was on the right track, just not doing it right.
I needed to change the way i was trying to find the base address of "client.dll"
The second function (DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName) ) is not mine. Yes, i leeched it :S
But hey, at least i got it done. After all, I'm still new to this and learning!
Code:
#include <Windows.h>
#include <iostream>
#include <string.h>
#include <tlhelp32.h>
#include <tchar.h>
using namespace std;
DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName);
int main() {
HWND hwnd;
HANDLE handle;
DWORD process_ID;
hwnd = FindWindow(NULL, "Garry's Mod");
GetWindowThreadProcessId(hwnd, &process_ID);
handle = OpenProcess(PROCESS_ALL_ACCESS, false, process_ID);
system("cls");
system("title Garry's Mod Wallhack");
system("color 0a");
int newVar = 2;
DWORD baseAddress = dwGetModuleBaseAddress(process_ID, _T("client.dll"));
DWORD newAddress = baseAddress + 0x5C58D8;
if(WriteProcessMemory(handle, (DWORD*)newAddress, &newVar, sizeof(newVar), NULL)) {
cout << "Hacked Successfully!" << endl;
cout << "Press ENTER to end this program...";
cin.get();
}
else {
cout << "Failed to hack..." << endl;
cout << "Press ENTER to end this program...";
cin.get();
}
CloseHandle(handle);
return 1;
}
//Find the base address [Not My Code]
DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName)
{
DWORD_PTR dwModuleBaseAddress = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcessIdentifier);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32;
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (_tcscmp(ModuleEntry32.szModule, szModuleName) == 0)
{
dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
break;
}
}
while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
return dwModuleBaseAddress;
}