[펌]메시지훅 예제

hooking 2009. 11. 2. 10:09 |
출처: wowhacker

// dll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

#pragma data_seg("SHARDATA")
static HINSTANCE hInstance;
static HHOOK hook_inst;
static int hooked;
#pragma data_seg()

LRESULT CALLBACK keyboardproc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if(nCode>=0)
    {
        if((wParam==32) && (((lParam >>30) & 1)==0)&& hooked==0)
            MessageBox(0, "hello world!","DLL Injection Ex",0);
    }
    return CallNextHookEx(hook_inst,nCode, wParam, lParam);
}

extern "C" __declspec(dllexport) int sethook()
{
    HWND h;
    DWORD pid;

    h=FindWindow(0,"계산기");
    if(h==0)
    {
        return 0;
    }

    hook_inst=SetWindowsHookEx(WH_KEYBOARD,keyboardproc,hInstance,GetWindowThreadProcessId(h,NULL));
    return 1;
}

extern "C" __declspec(dllexport) int unhook()
{
    MessageBox(0, "UnHook!","test",0);
    UnhookWindowsHookEx(hook_inst);
    return 1;
}



BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch(ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        hInstance=hModule;
        hooked=0;
    case DLL_THREAD_ATTACH:
        break;
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}


'hooking' 카테고리의 다른 글

outputdebugstring사용  (0) 2011.06.25
지뢰찾기 핵  (0) 2009.11.01
hooking_study_1  (0) 2009.10.23
DLL Injector  (0) 2009.10.02
Posted by applicationlayer
: