a bit around with it to get a better understanding.
I wanted to hook the ammo decrement function in Assult Cube to get Inf. Ammo. It works kinda fine but instead of incrementing the ammo it's just freezing so there has to be something wrong in my Asm code.
I'm also trying to understand what the brackets mean. Because when I use
inc esi it works fine but I thought I need to dereference it to get the actual value of the address so I thought inc [esi] was right. But then the game is crashing. Maybe you could help me out or give me some advises. I'll post the
code below.
Code:
//Includes
#include <Windows.h>
//Prototypes
bool Hook(void* toHook, void* ourFunct, int len);
DWORD WINAPI MainThread(LPVOID param);
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved);
//Vars
DWORD jmpBackAddy;
bool Hook(void* toHook, void* ourFunct, int len) {
if (len < 5) {
return false;
}
//Get access to mem page
DWORD curProtection;
VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection);
//Nop all 6 bytes to
memset(toHook, 0x90, len);
DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5;
*(BYTE*)toHook = 0xE9; //Set jmp instruction
*(DWORD*)((DWORD)toHook + 1) = relativeAddress; //Address for the jump to our func we redirect
//Restore old access
DWORD temp;
VirtualProtect(toHook, len, curProtection, &temp);
return true;
}
void __declspec(naked) ourFunct() {
__asm {
mov esi, [esi+14]
inc esi //Ammo ist not incrementing
//inc [esi] crashes
jmp[jmpBackAddy]
}
}
DWORD WINAPI MainThread(LPVOID param)
{
int hookLength = 5;
DWORD mBase = (DWORD)GetModuleHandle(L"ac_client.exe");
//eip instrcution pointer
DWORD hookAddress = mBase + 0x637E6; //Addr to the hook function
jmpBackAddy = hookAddress + hookLength;
Hook((void*)hookAddress, ourFunct, hookLength);
while (!(GetAsyncKeyState(VK_ESCAPE) & 1))
{
Sleep(50);
}
//Exit
FreeLibraryAndExitThread((HMODULE)param, 0);
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) {
switch (dwReason) {
case DLL_PROCESS_ATTACH:
CreateThread(0, 0, MainThread, hModule, 0, 0);
break;
}
return TRUE;
}






