应用程序挂钩 :: x64 系统
挂钩 64 位和 64 位有什么秘密吗? 64位系统上的32位进程?
在我当前正在编写的应用程序中,我需要能够挂钩 64 位进程。 Hooking 32 位进程在 64 和 64 上运行得很好。 32 位系统,但是,尝试挂钩 64 位应用程序时不会收到任何消息。
在有人告诉我我不应该做这样的事情之前,让我解释一下,这对我来说是非常必要的事情。如果不设置全局系统挂钩,我的应用程序将毫无用处/毫无意义。
该应用程序是用 C#/WPF 编写的,但使用 C++ dll 进行实际的挂钩。 我已经尝试为 64 位系统编译 dll,但它仍然没有执行它应该执行的操作。 当为 32 位系统编译并运行时,它的工作方式完全符合预期。
*编辑::我正在谈论挂钩窗口消息 - WH_CBT & WH_SHELL消息
Is there some kind of secret to hooking both 64bit & 32bit process on a 64bit system?
In an application that I'm currently writing I need to be able to hook 64bit processes. Hooking 32bit processes works just fine on 64 & 32bit systems but, no messages are received when trying to hook 64bit applications.
Before anyone tells me that I shouldn't be doing something like this let me explain that this is a very necessary thing for me to do.. Without setting global system hooks my application would be useless/pointless.
This application is written in C#/WPF but, using a C++ dll to do the actual hooking. I've tried compiling the dll for 64bit systems although it still isn't doing what it's supposed to do. When compiled for and running on 32bit systems it works exactly as it should.
*Edit:: I am talking about hooking window messages - WH_CBT & WH_SHELL messages
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了挂钩 32 位和 64 位进程,您需要确保:
后者基本上意味着您必须创建 32 位和 64 位可执行文件,它们都调用 SetWindowsHookEx(),分别提供 32 位和 64 位 DLL 作为 hMod 参数。
如果您的应用程序是 32 位,则必须生成 64 位进程,该进程将调用 SetWindowsHookEx(),并且在取消挂钩之前可能不执行任何其他操作。 请注意,当/如果此进程退出/终止时,Windows 将自动取消设置挂钩,因此它必须在您需要挂钩的所有时间(可能是应用程序的整个生命周期)保持活动状态 - 在这种情况下,您可以使您的 64 位进程WaitForSingleObject() 直到主应用程序进程退出/终止,并在 WaitForSingleObject() 完成后取消挂钩并退出。
In order to hook both 32-bit and 64-bit processes you need to make sure that:
The latter basically means that you have to create both 32-bit and 64-bit executable that both call SetWindowsHookEx(), providing 32-bit and 64-bit DLL respectively as an hMod parameter.
If you application is 32-bit, you will have to spawn 64-bit process that will call SetWindowsHookEx() and probably do nothing else until you unhook. Note that Windows will automatically unset hook when/if this process exits/terminates, so it has to remain alive all the time you need the hooks, probably, the whole lifetime you your application - in this case you can make your 64-bit process WaitForSingleObject() until your main application process exits/terminates and unhook and exit after WaitForSingleObject() completes.