简体   繁体   中英

prevent hook dll loading

Is there a way to way set process security permissions or some other way to disable Windows from loading global window hook dlls? I don't want to disable SetWindowsHookEx, I just want to disable the hook dll from loading in my process.

You might be able to disable all hooks by installing your own hook and then not calling CallNextHookEx() from your hook. To do this correctly you will want to make sure that your hook will be the first hook that's going to be called.

The order the hooks are being called doesn't seem to be documented but it's easy enough to check by trial and error. Just install several hooks from different processes and see which is called first. The most likely cases are

  • The first hook that's installed is the first being called. This is the easy option. Just make sure to install your hook as soon as possible.
  • The first hook called is the only installed last. This one is more tricky. You'll have to make sure at all times that your's is the last hook that was installed. a hackish way to do this is to create a thread that every second or so removes the hook and adds it again.

This solution is far from perfect and, considering that the order is not documented, it may conceivably change at some point in the future. it is also possible that the hook invocation order is completely random, in which case this solution will not do you much good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM