我的目标是从另一个C++程序控制一个正在运行的WinDbg实例。我看到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呢?
发布于 2021-04-25 22:25:01
是的,您需要服务器正在运行的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中编译为win10 1803中的x64,并使用vs2017社区开发命令提示符
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 = 000001FA6B9D2590https://stackoverflow.com/questions/67249960
复制相似问题