Hooking 을 사용하는 프로그램 내의 구현
int FAR PASCAL InitHooksDll(HWND hMain);
int FAR PASCAL InstallHook();
int FAR PASCAL UnInstallHook();
ON_MESSAGE(WM_KEY_HOOK, OnSetFocus) //사용자가 지정한 함수 Call
// Hook 사용하기 전
static HINSTANCE hinstDLL;
typedef int (WINAPI *inithook)(HWND command);
inithook initkbhook;
hinstDLL = LoadLibrary((LPCTSTR) "Hook.dll");
initkbhook = (inithook)GetProcAddress(hinstDLL, "InitHooksDll");
initkbhook(this->m_hWnd); //Dll Load
typedef BOOL (CALLBACK *inshook)();
inshook instkbhook;
instkbhook = (inshook)GetProcAddress(hinstDLL, "InstallHook");
instkbhook(); //Hook Start
//Hook 사용한 후 (프로그램 종료시)
static HINSTANCE hinstDLL;
typedef int (WINAPI *UnInhook)();
UnInhook UnInkbhook;
hinstDLL = LoadLibrary((LPCTSTR) "Hook.dll");
UnInkbhook = (UnInhook)GetProcAddress(hinstDLL, "UnInstallHook");
UnInkbhook(); //Hook End
--------------------------------------------------------------------------------------
실제 Hook dll
//공유 테이블
#pragma data_seg("SHARDATA")
static HWND hwndMain = NULL;
static HINSTANCE hInstance;
#pragma data_seg()
int FAR PASCAL InitHooksDll(HWND hMain);
//Hook의 init
int FAR PASCAL InstallHook();
//Hook Start
int FAR PASCAL UnInstallHook();
// Hook 해제
LRESULT CALLBACK KeyboardFunc(int nCode,WPARAM wParam,LPARAM lParam);
// 실제 후킹 담당
int CALLBACK InitHooksDll(HWND hMain)
{
hwndMain = hMain;
hInstance = theApp.m_hInstance;
return 1;
}
int CALLBACK InstallHook()
{
hHook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardFunc,hInstance,0);
//키가 눌리는 것을 후킹
return 1;
}
int CALLBACK UnInstallHook()
{
UnhookWindowsHookEx(hHook);
return 1;
}
---------------------------------------------------------
// 실제 하는 작업 부분 (아래는 키보드 Hooking 이다)
LRESULT CALLBACK KeyboardFunc(int nCode,WPARAM wParam,LPARAM lParam)
{
CString message;
if(nCode >= 0)
{
if(wParam != VK_PROCESSKEY)
{
char szTemp[100];
sprintf(szTemp, "wParam=%X, lParam=%X", wParam, lParam);
}
if(wParam == VK_HANJA) //한자키를 누르면 Event를 발생시킨다.
{
HWND ProcB = FindWindow( NULL, "Program Name");
UINT uMsg;
uMsg = WM_KEY_HOOK;
if( ProcB )
{
::PostMessage(ProcB, uMsg, NULL ,NULL);
}
}
}
return (CallNextHookEx(hHook,nCode,wParam,lParam));
}
신라호텔 프로그램 작업할 때 했던 Hooking
정보를 찾고 구현을하고 Test를 하면서 무척 재미있었다.. ㅋㅋ
이제서야 정리를 하네... >.<
'C/C++언어 > 후킹' 카테고리의 다른 글
Anti Game hacking 프로그램의 구현. (0) | 2008.01.17 |
---|---|
Global Hooking in Win32 (0) | 2007.11.11 |
[본문스크랩] 메세지 후킹 (0) | 2007.09.06 |
[본문스크랩] Knowledge Base API (0) | 2007.09.06 |
API Hooking Revealed (0) | 2007.09.06 |