美文网首页
Windows挂钩(Hook)注入

Windows挂钩(Hook)注入

作者: 星星之火666 | 来源:发表于2019-11-28 18:35 被阅读0次

①、我们设计一个DLL,里面添加三个函数和一个全局变量,如下:

HHOOK g_hHook = NULL;

static LRESULT WINAPI GetMsgProc(int code, WPARAM wParam, LPARAM lParam)
{
    return CallNextHookEx(g_hHook, code, wParam, lParam);
}

static HMODULE ModuleFromAddress(PVOID pv)
{
    MEMORY_BASIC_INFORMATION mbi;
    return (VirtualQuery(pv, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL;
}

void inject(DWORD threadId)
{
    g_hHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, ModuleFromAddress(inject), threadId);
}

②、设计一个EXE程序,加载这个DLL,并使用其中的inject函数,如下所示:

inject(0);

相关文章

网友评论

      本文标题:Windows挂钩(Hook)注入

      本文链接:https://www.haomeiwen.com/subject/hgxiwctx.html