使用 WH_GETMESSAGE 调用 setwindowshookex 不适用于除注入器之外的任何进程

发布于 2024-10-05 08:00:11 字数 699 浏览 7 评论 0原文

我以前问过类似的问题,但我相信这次情况有所不同。

我有一个 DLL,它具有标准的 hook、unhook 和 msgProc 函数。我在主应用程序中加载此 DLL,然后调用“hook”,如下所示:

HOOKDLL_API BOOL setHook( HWND hWnd, DWORD threadID )
{

if( hWndServer != NULL )
    return FALSE;

hook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)msghook, hInstance, threadID );

if( hook != NULL )
{
    hWndServer = hWnd;

    ofstream logFile;
    logFile.open( "LOG.txt" );
    logFile << "Hooked for: " << hWndServer << endl;
    logFile.close();

    return TRUE;
}

return FALSE;
}

问题是,如果我将其设置为全局,并且 threadID = 0,则 msgHook 仅捕获该进程的窗口接收到的消息加载库而不加载任何其他内容,即使它应该是全局挂钩。

如果我提供其他窗口的 threadID,那么我根本不会收到消息。

其原因可能是什么?

I previously asked a question about something similar but I believe this time the circumstances are different.

I have a DLL that has standard hook, unhook and msgProc functions. I load this DLL in my main application and then call 'hook', that is below:

HOOKDLL_API BOOL setHook( HWND hWnd, DWORD threadID )
{

if( hWndServer != NULL )
    return FALSE;

hook = SetWindowsHookEx( WH_GETMESSAGE, (HOOKPROC)msghook, hInstance, threadID );

if( hook != NULL )
{
    hWndServer = hWnd;

    ofstream logFile;
    logFile.open( "LOG.txt" );
    logFile << "Hooked for: " << hWndServer << endl;
    logFile.close();

    return TRUE;
}

return FALSE;
}

The problem is that if I make it global, with threadID = 0, then msgHook only and only captures the messages received by the window of the process that loaded the library and nothing else, even if it is supposed to be a global hook.

If I supply a threadID of some other window, then I don't receive messages at all.

What could perhaps be the reason for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2024-10-12 08:00:14
  • 您使用的是 64 位 Windows 吗?如果是这样,
    你的钩子进程和DLL必须匹配
    您的进程的位数
    希望挂钩。

  • 您的示例中的 hInstance 是什么?
    DLL 还是 EXE 实例?它
    应该是包含以下内容的DLL
    msgHook 函数。

  • 你的 msgHook 是做什么的?你怎么样
    检测是否正在
    叫?请注意,它将被称为
    在您挂钩的进程中,
    不在您自己的流程内。 (所以如果
    你已经在它上面设置了一个断点,它
    除非您附加,否则不会触发
    调试器到您已经完成的进程
    着迷,而不是过程
    安装了钩子。)

  • Are you using 64-bit Windows? If so,
    your hook process and DLL must match
    the bitness of the process(es) you
    wish to hook.

  • What is hInstance in your example?
    The DLL or the EXE instance? It
    should be the DLL that contains the
    msgHook function.

  • What does your msgHook do? How do you
    detect whether or not it is being
    called? Note that it will be called
    within the process(es) that you hook,
    not within your own process. (So if
    you've set a breakpoint on it, it
    won't be triggered unless you attach
    the debugger to the process you've
    hooked, rather than the process that
    installed the hook.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文