Created
June 25, 2011 13:31
-
-
Save bartku/1046488 to your computer and use it in GitHub Desktop.
Logs functions names called by ProcessRemoteFunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <detours.h> | |
#include <tchar.h> | |
#pragma comment(lib, "detours.lib") | |
#pragma comment(lib, "detoured.lib") | |
// ?ProcessRemoteFunction@AActor@@UAEHPAVUFunction@@PAXPAUFFrame@@@Z | |
// public: virtual int __thiscall AActor::ProcessRemoteFunction(class UFunction *,void *,struct FFrame *) | |
typedef int (__stdcall *processRemoteFunction_t)(class UFunction *, void *, struct FFrame *); | |
processRemoteFunction_t prft = NULL; | |
int __stdcall MyProcessRemoteFunction(class UFunction *arg1, void *arg2, struct FFrame *arg3) | |
{ | |
__asm pushad; | |
GLog->Logf(TEXT("[Logger] called %s [%s]"), arg1->GetFullName(), arg1->GetName()); | |
__asm popad; | |
return prft(arg1, arg2, arg3); | |
} | |
void Hook(void) | |
{ | |
prft = (processRemoteFunction_t) GetProcAddress(GetModuleHandle(TEXT("Engine.dll")), | |
"?ProcessRemoteFunction@AActor@@UAEHPAVUFunction@@PAXPAUFFrame@@@Z"); | |
DetourTransactionBegin(); | |
DetourUpdateThread(GetCurrentThread()); | |
DetourAttach(&(PVOID &)prft, MyProcessRemoteFunction); | |
DetourTransactionCommit(); | |
GLog->Logf(TEXT("[Logger] Hooking...")); | |
} | |
void UnHook(void) | |
{ | |
GLog->Logf(TEXT("[Logger] Unhooking...")); | |
DetourTransactionBegin(); | |
DetourUpdateThread(GetCurrentThread()); | |
DetourDetach(&(PVOID &)prft, MyProcessRemoteFunction); | |
DetourTransactionCommit(); | |
} | |
BOOL APIENTRY DllMain(HMODULE module, DWORD reason, | |
LPVOID reserved) | |
{ | |
switch (reason) | |
{ | |
case DLL_PROCESS_ATTACH: | |
GLog->Logf(TEXT("[Logger] ATTACH")); | |
DisableThreadLibraryCalls(module); | |
Hook(); | |
break; | |
case DLL_PROCESS_DETACH: | |
GLog->Logf(TEXT("[Logger] DETACH")); | |
UnHook(); | |
break; | |
} | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment