QuestionHelpC++ dll Problem [Help Request]

Posts 1–5 of 5 · Page 1 of 1
C++ dll Problem [Help Request]
So I wanna do some dll hacking and I came to a problem...
So I want to hack Command & Conquer RA3 but that doesnt really matter.

I have already found out the adress and the offset of the pointer (to get money)
But I dont know why It isnt working...

So the adress is 0x10D791D0 and the offset is 4.

So this is a Part of the code:

 
Code

DWORD WINAPI HackThread( LPVOID )
{
while(1)
{
try
{
DWORD dwMoney = MemoryTools::ReadMemory<DWORD>(0x10D791D0, 0);
dwMoney = MemoryTools::ReadMemory<DWORD>(dwMoney, 0x04);
DWORD Current = MemoryTools::ReadMemory<DWORD>(dwMoney, 0);


if (Current == 1)
{
MemoryTools::WriteMemory<int>(dwMoney , 500);


}
}
catch (DWORD)
{

}

Sleep(100);

}


So a Part of the MemoryTools.h is

 
Code2
template <class T> static T ReadMemory(DWORD, WORD);
template <class T> static bool WriteMemory(DWORD, T value);



 
Code3

T MemoryTools::ReadMemory(DWORD address, WORD Offset)
{
DWORD OldProtect;

if (VirtualProtect((LPVOID)address, sizeof(T), PAGE_READWRITE, &OldProtect))
{
T result = *(T*)(address + Offset);

if (OldProtect != PAGE_READWRITE) VirtualProtect((LPVOID)address, sizeof(T), OldProtect, &OldProtect);
return result;
}
throw address;
}

template <class T>
bool MemoryTools::WriteMemory(DWORD address, T value)
{
DWORD OldProtect;

if (VirtualProtect((LPVOID)address, sizeof(T), PAGE_READWRITE, &OldProtect))
{
*(T*)address = value;

if (OldProtect != PAGE_READWRITE) VirtualProtect((LPVOID)address, sizeof(T), OldProtect, &OldProtect);
return true;
}
return false;
}


I dont understand why its not working, can someone help me? (I am still a newbie)
Quote Originally Posted by xReFlecTiVe View Post
So I wanna do some dll hacking and I came to a problem...
So I want to hack Command & Conquer RA3 but that doesnt really matter.

I have already found out the adress and the offset of the pointer (to get money)
But I dont know why It isnt working...

So the adress is 0x10D791D0 and the offset is 4.

So this is a Part of the code:

 
Code

DWORD WINAPI HackThread( LPVOID )
{
while(1)
{
try
{
DWORD dwMoney = MemoryTools::ReadMemory<DWORD>(0x10D791D0, 0);
dwMoney = MemoryTools::ReadMemory<DWORD>(dwMoney, 0x04);
DWORD Current = MemoryTools::ReadMemory<DWORD>(dwMoney, 0);


if (Current == 1)
{
MemoryTools::WriteMemory<int>(dwMoney , 500);


}
}
catch (DWORD)
{

}

Sleep(100);

}


So a Part of the MemoryTools.h is

 
Code2
template <class T> static T ReadMemory(DWORD, WORD);
template <class T> static bool WriteMemory(DWORD, T value);



 
Code3

T MemoryTools::ReadMemory(DWORD address, WORD Offset)
{
DWORD OldProtect;

if (VirtualProtect((LPVOID)address, sizeof(T), PAGE_READWRITE, &OldProtect))
{
T result = *(T*)(address + Offset);

if (OldProtect != PAGE_READWRITE) VirtualProtect((LPVOID)address, sizeof(T), OldProtect, &OldProtect);
return result;
}
throw address;
}

template <class T>
bool MemoryTools::WriteMemory(DWORD address, T value)
{
DWORD OldProtect;

if (VirtualProtect((LPVOID)address, sizeof(T), PAGE_READWRITE, &OldProtect))
{
*(T*)address = value;

if (OldProtect != PAGE_READWRITE) VirtualProtect((LPVOID)address, sizeof(T), OldProtect, &OldProtect);
return true;
}
return false;
}


I dont understand why its not working, can someone help me? (I am still a newbie)
Well, I don't know why it's not working but Why you don't use easier method? like :memcpy() function
Ehmm... I made a better code for you :

Code:
#include <windows.h>
#include <process.h>
#include <tlhelp32.h>

#define Pointer 0x10D791D0
#define Offset1 0x4

void HackThread()
{
	DWORD dwMoney = *(DWORD*)Pointer;               //I hope that the money value is 4 bytes :)
	DWORD Step1 = *(DWORD*)(dwMoney + Offset1);
	*(DWORD*)(Step1)=500;
}

BOOL APIENTRY DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
{
	DisableThreadLibraryCalls(hDll);
	if(dwReason == DLL_PROCESS_ATTACH)
	{
		_beginthreadex((void(*)(void*))HackThread,sizeof(&HackThread),0);
	}
	return TRUE;
}
This should work!
And for loop put
Code:
for(;;)
{

}

or put

while(1)
{

}
Quote Originally Posted by XXkillerFin1 View Post
Well, I don't know why it's not working but Why you don't use easier method? like :memcpy() function
WTF...
He doesn't want to overwrite bytes to nops / jnz to je or something like this.
He want to change the money value...
Quote Originally Posted by _PuRe.LucK* View Post


WTF...
He doesn't want to overwrite bytes to nops / jnz to je or something like this.
He want to change the money value...
Wrong thread,sorry
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Talk with us