15,466
社区成员
发帖
与我相关
我的任务
分享// HookDll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "HookDll.h"
#include "stdio.h"
0
struct {
HHOOK m_hHook_WH_JOURNALRECORD;
HANDLE m_hInstance;
}g_data;
FILE *g_logFile_WH_JOURNALRECORD;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_data.m_hInstance = hModule;
g_logFile_WH_JOURNALRECORD = fopen("log_WH_JOURNALRECORD.txt", "w+t");
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
fclose(g_logFile_WH_JOURNALRECORD);
break;
}
return TRUE;
}
// This is an example of an exported variable
HOOKDLL_API int nHookDll=0;
// This is an example of an exported function.
HOOKDLL_API int fnHookDll(void)
{
return 42;
}
// This is the constructor of a class that has been exported.
// see HookDll.h for the class definition
CHookDll::CHookDll()
{
return;
}
LRESULT HOOKDLL_API CALLBACK MyHookProc_WH_JOURNALRECORD(
int nCode,
WPARAM wParam,
LPARAM lParam
);
void SetHook()
{
g_data.m_hHook_WH_JOURNALRECORD = SetWindowsHookEx(WH_JOURNALRECORD,
MyHookProc_WH_JOURNALRECORD,
(HINSTANCE)g_data.m_hInstance,
0);
}
void UnSetHook()
{
if ( g_data.m_hHook_WH_JOURNALRECORD )
{
UnhookWindowsHookEx(g_data.m_hHook_WH_JOURNALRECORD);
}
}
LRESULT HOOKDLL_API CALLBACK MyHookProc_WH_JOURNALRECORD(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
//TRACE("HOOK!%d %d %d\n",nCode, wParam, lParam);
if (nCode == HC_ACTION )
{
PEVENTMSG pEventMsg = (PEVENTMSG)lParam;
char buf[50] = "";
sprintf(buf,"%p %u %u %u %d\n",
pEventMsg->hwnd,
pEventMsg->message,
pEventMsg->paramH,
pEventMsg->paramL,
pEventMsg->time);
WM_PAINT;
fwrite(buf,sizeof(char),strlen(buf),g_logFile_WH_JOURNALRECORD);
}
return CallNextHookEx(g_data.m_hHook_WH_JOURNALRECORD, nCode,
wParam, lParam);
}