【问题标题】:Unable to connect remotely to a windbg server, possibly because of a dll version mismatch?无法远程连接到 windbg 服务器,可能是因为 dll 版本不匹配?
【发布时间】:2021-04-25 22:25:01
【问题描述】:

我的目标是从另一个 C++ 程序控制正在运行的 WinDbg 实例。我看到 APIDebugConnectWide 可以让你远程连接到调试客户端,所以我尝试使用它,并确保通过输入以下命令从正在运行的 windbg 客户端启动服务器:

.server npipe:pipe=testname.

我可以通过在命令行参数中输入以下内容来打开第二个 windbg 实例并远程连接到第一个实例:

-remote npipe:Pipe=sup,Server=DESKTOP-JT5S9BR.

但是,当我尝试从我的 C++ 控制台应用程序以编程方式连接时,我从 HRESULT 收到以下错误:The server is currently disabled.

#include <dbgeng.h>
#include <iostream>

int main()
{
    HRESULT hr;
    IDebugClient7* debugger = nullptr;

    hr = DebugConnectWide(L"npipe:Pipe=testname,Server=DESKTOP-NAME", IID_PPV_ARGS(&debugger));

    std::getchar();
}

我在文档中读到,如果 Windbg 的所有实例想要远程连接,那么拥有相同版本很重要。所以我的问题可能与此有关。我看到我的电脑上有很多版本的dbgeng.dlldbgeng.lib,那么如何确保我的C++ 应用运行的是相同版本的dbgeng?

【问题讨论】:

    标签: c++ winapi windbg


    【解决方案1】:

    是的,您需要服务器正在运行的 dbgeng.dll 版本

    通常在服务器和客户端安装相同的windbg版本并从客户端windbg安装文件夹运行应用程序将起作用

    或者您可以将dbgeng复制到exe所在的本地文件夹

    复制 c:\prograxxxxxx\dbgeng.dll 。到可执行文件的目录

    这是一个示例流程

    执行 DebugConnect() 的代码(DebugConectWide 的 Ascii 版本)

    #include <stdio.h>
    #include <dbgeng.h>
    #pragma comment(lib, "dbgeng.lib")
    int main(int argc, char *argv[])
    {
        if (argc == 2)
        {
            IDebugClient *dbgclient = NULL;
            HRESULT hr = E_FAIL;
            hr = DebugConnect(argv[1], __uuidof(IDebugClient), (VOID **)&dbgclient);
            if (hr == S_OK && dbgclient != NULL)
            {
                ULONG mask = 0xdeadbeef;
                hr = dbgclient->GetOutputMask(&mask);
                if (hr == S_OK && mask != 0xdeadbeef)
                {
                    printf("Outputmask = %x\n", mask);
                }
                printf("hresult = %x\tmask = %x\n", hr, mask);
            }
            printf("hresult = %x\tdbgclient = %p\n", hr, dbgclient);
        }
        else
        {
            printf("usage %s remote connection string", argv[0]);
        }
        return 0;
    }
    

    在 x64 中编译为 x64 在 win10 1803 中使用 vs2017 社区开发 cmdprompt 使用

    cl /Zi /W4 /analyze /Od /EHsc /nologo concliw.cpp /link /release
    

    在本地机器上运行的命令行参数中包含 cdb 的进程列表

    server debuggee client and wmic  commandlines 
    
    C:\>whoami
    kr\xxxxx
    
    C:\>wmic process get CommandLine /format:list | grep -i cdb
    CommandLine=cdb  -server npipe:pipe=windpipe cdb
    CommandLine=cdb
    CommandLine=cdb  -remote npipe:server=KR,pipe=windpipe
    CommandLine=grep  -i cdb
    

    复制正确的 dbgeng.dll 并将其重命名为 test_dbgeng.dll

    copy "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbgeng.dll" .
    ren dbgeng.dll test_dbgeng.dll
    

    执行重命名为 dbgeng.dll 的二进制文件并重新执行二进制文件

    concliw.exe
    usage concliw.exe remote connection string
    concliw.exe "npipe:server=KR,pipe=windpipe"
    hresult = 8007053d      dbgclient = 0000000000000000
    
    ren test_dbgeng.dll dbgeng.dll
    
    concliw.exe "npipe:server=KR,pipe=windpipe"
    Outputmask = 3f7
    hresult = 0     mask = 3f7
    hresult = 0     dbgclient = 000001FA6B9D2590
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      • 2011-04-29
      • 2010-11-13
      相关资源
      最近更新 更多