I'm using this code bellow to write a jmp and detour my functions and its working like a charm. But how do i need to modify the code to get it working under x64 ?
Code: Select all
My Port ( not working -.-' )DWORD cHook::HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID lpFunction, unsigned char *lpBackup)
{
DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandleA(lpModule), lpFuncName);
BYTE jmp[5] = { 0xe9, //jmp
0x00, 0x00, 0x00, 0x00//, //address
//0xc3
}; //retn
ReadProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 5, 0);
DWORD dwCalc = ((DWORD)lpFunction - dwAddr - 5); //((to)-(from)-5)
memcpy(&jmp[1], &dwCalc, 4); //build the jmp
WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, jmp, 5, 0);
return dwAddr;
}
BOOL cHook::UnHookFunction(LPCSTR lpModule, LPCSTR lpFuncName, unsigned char *lpBackup)
{
DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandleA(lpModule), lpFuncName);
if (WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 5, 0))
return TRUE;
return FALSE;
}
Code: Select all
DWORD cHook::HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID lpFunction, unsigned char *lpBackup)
{
DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandleA(lpModule), lpFuncName);
BYTE jmp[10] = { 0xe9, //jmp
0x00, 0x00, 0x00, 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 ,//, //8byte address
0xc3
};
ReadProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 9, 0);
DWORD64 dwCalc = ((DWORD)lpFunction - dwAddr - 10); //((to)-(from)-9)
memcpy(&jmp[1], &dwCalc, 8); //build the jmp
WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, jmp, 10, 0);
return dwAddr;
}
BOOL cHook::UnHookFunction(LPCSTR lpModule, LPCSTR lpFuncName, unsigned char *lpBackup)
{
DWORD dwAddr = (DWORD)GetProcAddress(GetModuleHandleA(lpModule), lpFuncName);
if (WriteProcessMemory(GetCurrentProcess(), (LPVOID)dwAddr, lpBackup, 10, 0))
return TRUE;
return FALSE;
}