如何在dllmain中调用MessageBox [英] Howto call MessageBox in dllmain

查看:278
本文介绍了如何在dllmain中调用MessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个小DLL,用于DLL注入POC(概念验证)。我正在使用代码块的c ++ ide。

I'm creating a little dll to use in a DLL-INJECTION POC (proof-of-concept). I'm using codeblocks' c++ ide.

我的dll的主文件(dllmain)如下:

My dll's main (dllmain) looks like this:

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    MessageBox(0, "myfirstdll loaded", "SUCCESS STATUS", MB_OK);
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;
        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}

现在,当我从a加载dll(使用LoadLibrary)时客户端程序(希望满载,它已加载!),我的消息框没有弹出。由于我正在做Poc,这真让人感到沮丧。我知道在dllmain中执行kernel32.dll等密集型业务时普遍存在的安全性问题,但是,我的问题不是安全性;我只需要直接从dllmain中弹出一个消息框。

Now, when I load the dll (using LoadLibrary) from a client program (hopefull, it loads!), my message box doesn't pop. This is quiet frustrating, since I'm doing a poc. I know about security issues that prevail when we do kernel32.dll, etc.-intensive business in dllmain, but then, my problem here is not security; i simply need to pop a message box right from within dllmain.

因此,当dll加载后,如何使我的消息框弹出?

So, how can i make my message box pop when the dll is loaded ?

推荐答案

看到此问题,以了解 DllMain 中的大量限制。不只是安全问题。 user32导出的所有内容都属于此类别。

See this question to read about the huge number of limitations in DllMain. It's not just security problems. Anything exported by user32 falls into this category.

换句话说,不能在<$ c $中使用 MessageBox c> DllMain 。使用类似 OutputDebugString ,它位于kernel32中,不显示任何UI。

In other words, you cannot use MessageBox in DllMain. Use something like OutputDebugString instead, which is in kernel32 and does not display any UI.

这篇关于如何在dllmain中调用MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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