隐藏C ++中Keylogger的控制台窗口

时间:2018-09-16 08:53:00

标签: c++ windows-console keylogger

任何人都可以解释以下代码,该代码用于在c ++中执行Keylogger项目时隐藏控制台窗口

void hide();
int main()
{
    hide();
    MSG Msg; 

    //IO::MKDir(IO::GetOurPath(true));

    //InstallHook();

    while (GetMessage(&Msg, NULL, 0, 0)) 
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    //MailTimer.Stop();
    return 0;
}

void hide()
{
    HWND stealth; 
    AllocConsole();
    stealth = FindWindowA("ConsoleWindowClass", NULL);
    ShowWindow(stealth, 0);
}

1 个答案:

答案 0 :(得分:0)

让我们把它分成小块:

void hide();
int main()
{
    hide();
    MSG Msg; 

    //IO::MKDir(IO::GetOurPath(true));

    //InstallHook();

   while (GetMessage(&Msg, NULL, 0, 0))
   {
       TranslateMessage(&Msg);
       DispatchMessage(&Msg);
   }

以上循环称为message pump。由于Windows GUI程序是事件驱动的,因此such a loop is the pattern将为Windows进程处理传入的 windows消息。当您的程序将收到WM_QUIT消息时,GetMessage()将返回FALSE,并且循环将退出。 TranslateMessage()可以将虚拟键消息转换为字符消息,以便在需要时进一步处理管道。 DispatchMessage()可以确保发送到特定窗口的邮件将找到通往该窗口WindowProc callback的方式。

    //MailTimer.Stop();
    return 0;
}

void hide()
{
    HWND stealth; 
    AllocConsole();

上面的最后一行是allocating a new console for the process.。如果您的进程已经有一个控制台,则此调用将失败,并返回零。

    stealth = FindWindowA("ConsoleWindowClass", NULL);

FindWindowA()的作用是将窗口句柄(HWND)返回到具有指定类名和窗口名的窗口。在这里,它在省略名称(第二个参数)并仅指定类的情况下使用,在控制台窗口的情况下,该类只能有一个窗口,其类为"ConsoleWindowClass"

    ShowWindow(stealth, 0);
}

All this line does正在隐藏由传递的句柄标识的窗口,这就是我们的控制台窗口,正如我们在代码段中已经知道的那样。在这种情况下,第二个参数0SW_HIDE的枚举值,因此在此行之后,控制台窗口被隐藏。

相关问题