检测CRT初始化是否在注入进程中完成
我正在开发一个在进程启动时注入 dll 的应用程序(挂起 --> 注入 --> 恢复) DllMain 中使用 DLL_PROCESS_ATTACH (在我注入的 dll 中)的第一个调用是对 MessageBox() 的调用(仅用于调试目的)。 但是,对 MessageBox() 的调用有时会弹出错误并使注入的进程崩溃。
运行时错误!
程序:C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE
R6030
- CRT 未初始化
例如,这可以通过 Outlook 和 Winword 重现。通过记事本、IE、CMD、Calc 和许多其他 - 打印消息框并正常继续。
打印消息框对我来说不是必须的,所以我只是想能够检查CRT是否已完成初始化,这样我就可以像这样正常继续:
case DLL_PROCESS_ATTACH:
if (IsCRTInitialized())
MessageBox(...);
如果缺少某些信息,请告诉我。 谢谢!
I'm working on an application that injects a dll when a process starts (Suspend --> Inject --> Resume)
The very first call in DllMain with DLL_PROCESS_ATTACH (in the dll I injected) is a call to MessageBox() (just for debugging purpose).
However, this call to MessageBox() sometimes pops an error and crashes the injected process.
Runtime Error!
Program: C:\Program Files\Microsoft
Office\Office14\OUTLOOK.EXER6030
- CRT not initialized
This is reproducible with Outlook and Winword for example. Though Notepad, IE, CMD, Calc and many others - print the message box and continue normally.
Printing a message box is not a must-have for me, so I just want to be able to check whether CRT has done initialization or not, so I can continue normally like this:
case DLL_PROCESS_ATTACH:
if (IsCRTInitialized())
MessageBox(...);
Please let me know if some information is missing.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当入口函数 DLLMain 被调用。 MessageBox 驻留在 user32.dll 中,并按照 从 user32.dll 创建 DLL 调用函数的最佳实践是严格禁止的。
您可以
调用OutputDebugString 用于任何调试器跟踪。此函数驻留在 kernel32.dll 中,应该可以安全调用。
在您的应用程序加载任何其他 dll 之前,请自行调用 MessageBox。这将确保 user32.dll 及其依赖项
已经加载。这样在 DllMain 中调用 MessageBox 可能会有
更好的成功机会。但您的情况可能会有所不同。
Kernel32.dll is guaranteed to be loaded in the process address space when the entry-point function DLLMain is called. MessageBox resides in user32.dll and as per Best practices for creating DLL calling functions from user32.dll is a strict no-no.
You can either
Call OutputDebugString for any debugger tracing. This function resides in kernel32.dll and should be safe to call.
Before your application loads any other dlls, call MessageBox yourself. This will ensure that user32.dll and its dependencies are
already loaded. This way calling MessageBox in DllMain may have
a better chance of succeeding. But your mileage may vary.
问题不在于 CRT。您不得从
DllMain
调用MessageBox
或任何其他重要函数The problem isn't the CRT. You're not allowed to call
MessageBox
or any other non-trivial function fromDllMain