I've seen some tuts on mid function hooking if that's what it's called. Any ways i am trying it out and my target process is cheat engine's first tutorial.
but when i inject the dll and hit "hit me" the program crashes, i know it is something wrong with my hook length, and the assembly code. i would really appreciate it if some one can help me out here. all i want it to do is instead of sub let it add that's all
#include <iostream>
#include <Windows.h>
using namespace std;
void Hook(BYTE*original,DWORD dwMyFunc,DWORD dwLen) {
DWORD oldProtection;
DWORD newProtection;
DWORD relAddress;
VirtualProtect(original, dwLen, PAGE_EXECUTE_READWRITE, &oldProtection);
relAddress = (DWORD)(dwMyFunc - (DWORD)original) - 5;
*original = 0xE9;
*((DWORD*)(original + 0x1)) = relAddress;
for (DWORD x = 0x5; x < dwLen; x++) {
*(original + x) = 0x90;
}
VirtualProtect(original, dwLen, oldProtection, &newProtection);
}
DWORD jmpBackAddress;
void _declspec(naked) myfunc() {
__asm {
add eax, edx
mov dword ptr ds:[ebx+480], eax
jmp [jmpBackAddress]
}
}
DWORD WINAPI myThread(LPVOID lpParam) {
DWORD hookLength = 0x8;
DWORD original = 0x00423AFE;
jmpBackAddress = original + hookLength;
Hook((BYTE*)original, (DWORD)myfunc, hookLength);
FreeLibraryAndExitThread((HMODULE)lpParam, 0);
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserve) {
switch (dwReason) {
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, &myThread, hModule, 0, NULL);
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return 1;
}