DllMain在一个exe? [英] DllMain in an exe?

查看:151
本文介绍了DllMain在一个exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



编辑:是否可以收到DllMain像独立的exe中的线程附加/分离的通知?这只是一个与我正在做的测试有关的理论问题。不是真实的生活情况。

解决方案

有趣的问题。我不知道Win32内置的东西 - 我想你可能必须鞭打一个DLL,它有一个API,当它有各种附加/分离消息时,会发出一个信号事件或发布消息的API。



一个不需要单独的DLL,但需要一些破解技巧的替代方法是具体使用调试API( WaitForDebugEvent())。如果您的应用程序具有特殊的测试模式(可能由命令行选项指示),则只需使用 CreateProcess()重新启动exe即可使用 DEBUG_ONLY_THIS_PROCESS 标志,父('debugger')进程可以调用 WaitForDebugEvent()来获取线程开始和结束事件的通知以及一堆其他有趣的事件。父进程可以将它们作为消息传递给孩子,或者通过信号发送事件(如果需要的话)或执行自己的日志记录,如果需要的话。



由不是一个简单的事情,但它会工作,不需要一个单独的DLL或图像,只是一个特殊的模式,当你想执行这些测试。


Is it possible to receive DllMain like notifications about thread attach/detach in stand-alone exe without using any extra dlls?

Edit: This is just a theoretical question that has to do with some testing I'm doing. not a real life situation.

解决方案

Interesting question. I don't know of anything built into Win32 - I think you might have to to whip up a DLL that has an API that signaled events or posted messages when it got the various attach/detach messages.

An alternative that would not require a separate DLL but would require some hack trickery is to use the debugging API (WaitForDebugEvent() specifically). If your application has a special 'test' mode (maybe indicated by a command line option) that does nothing but relaunch the exe using CreateProcess() with the DEBUG_ONLY_THIS_PROCESS flag, the parent ('debugger') process can call WaitForDebugEvent() to get notification of the thread start and end events as well as a bunch of other interesting events. The parent process can pass them on to the child as messages or by signaling events (if that's what you want) or perform its own logging if thats all you need.

By no means a simple thing, but it would work and would not require a separate DLL or image, just a special mode for when you want to perform these tests.

这篇关于DllMain在一个exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆