问题描述
我的目标是从另一个 C++ 程序控制一个正在运行的 WinDbg 实例。我看到 API DebugConnectWide 可以让您远程连接到调试客户端,因此我尝试使用它,并确保通过输入以下命令从正在运行的 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.dll
和 dbgeng.lib
,那么我如何确保我的 C++ 应用程序运行的是相同版本的 dbgeng?
解决方法
是的,您需要服务器运行的 dbgen.dll 版本
通常在服务器和客户端安装相同的windbg版本并从客户端windbg安装文件夹运行应用程序即可
或者你也可以将dbgen复制到exe所在的本地文件夹
复制 c:\prograxxxxxx\dbgen.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",dbgclient);
}
else
{
printf("usage %s remote connection string",argv[0]);
}
return 0;
}
使用vs2017社区开发cmdprompt在win10 1803中以x64编译为x64
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_dbgen.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