I am using EasyHook to inject a DLL into a 64bit application. The basic hooking seems to work but as soon as the DLL calls the "LhInstallHook" method the injected application crashes. I think that I have found the right address/offset for the desired function. Therefore I suspect some off my code (in the DLL) beeing corrupt.
Injector:
NTSTATUS nt = RhInjectLibrary(
processId, // The process to inject into
0, // ThreadId to wake up upon injection
EASYHOOK_INJECT_DEFAULT,
NULL, // 32-bit
dllToInject, // 64-bit only
NULL, // data to send to injected DLL entry point
NULL // size of data to send
);
DLL:
struct Player {
_BYTE gap0[128];
__int64 saleStats;
_BYTE gap88[104];
int health;
int units;
};
typedef __int64 func(Player*, int);
func* FunctionBase = (func*)0x7FF7E4513F3D; // Function address found by debugging assembly
__int64 FunctionHook(Player *playerRef, int unitsToAdd);
__int64 FunctionHook(Player *playerRef, int unitsToAdd)
{
Beep(500, 500); // Beep to signal success
return FunctionBase(playerRef, unitsToAdd); // Execute base
}
NTSTATUS result = LhInstallHook( // This is the point where the host crashes
(void*)0x7FF7E4513F3D, // Function to hook
FunctionHook, // delegate
NULL, // callback
&hHook); // handler
I think that my use of the address/offset is wrong but I wasn't able to find resources on that.