0

IDebugControl::Execute 方法允许执行调试器命令。如何获得已执行的调试器命令的输出?我的目标是检查是否加载了驱动程序,为此我使用 Execute 执行“lm”windbg 命令并解析返回的输出。

4

2 回答 2

1

您需要为示例实现 IDebugOutputCallbacks 看一下 windbg sdk 示例中的 remmon out.cpp 和 out.hpp(iirc 新 sdk 不包含您需要从 msdn 示例库在线获取的示例)

class StdioOutputCallbacks : public IDebugOutputCallbacks
{
public:
............
}

StdioOutputCallbacks g_Callback;

status = g_Client->SetOutputCallbacks( &g_Callback );

示例虚拟实现将两个文件 out.cpp 和 out.hpp 复制到本地文件夹 build 并执行以显示警告和 .echo 执行的输出

//error,relasese() omitted Do_Nothing_sample no proc|thread warn print exit; 
#include <engextcpp.hpp>
#include "out.hpp"
#include "out.cpp"
extern StdioOutputCallbacks g_OutputCb; 
void __cdecl main( void ){
    IDebugClient*   g_Client = NULL;
    IDebugControl*  g_Control= NULL;
    DebugCreate( __uuidof(IDebugClient), (void**)&g_Client );
    g_Client->QueryInterface( __uuidof(IDebugControl), (void**)&g_Control );
    g_Client->SetOutputCallbacks( &g_OutputCb );
    g_Control->Execute( DEBUG_OUTCTL_THIS_CLIENT, 
  ".echo hello iam alive and kicking", DEBUG_EXECUTE_DEFAULT);  
}

构建和执行的结果

    3 files compiled
    1 executable built

WARNING: The debugger does not have a current process or thread
WARNING: Many commands will not work
hello iam alive and kicking
于 2015-12-26T11:17:35.297 回答
1

一旦你有了你的客户端(IDebugClient*)和你的控制(IDebugControl*)实例,你需要从客户端实例调用IDebugClient::SetOutputCallbacks设置输出回调的方法。您需要在调用方法之前execute()设置输出回调。

这应该是这样的:

StdioOutputCallbacks g_OutputCb;

// ...

g_Client->SetOutputCallbacks(&g_OutputCb);
g_Control->Execute(DEBUG_OUTCTL_ALL_CLIENTS,"lm vm", DEBUG_EXECUTE_ECHO);

您的输出回调必须继承自IDebugOutputCallbacks

class StdioOutputCallbacks : public IDebugOutputCallbacks

执行此操作的简单方法是直接复制和使用out.cppout.hpp文件 - 存在于某些示例中 - 实现回调类,例如。在:

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\sdk\samples\dumpstk

输出本身在IDebugOutputCallbacks::Output实现中完成:

STDMETHODIMP
StdioOutputCallbacks::Output(
    THIS_
    _In_ ULONG Mask,
    _In_ PCSTR Text
    )
{
    UNREFERENCED_PARAMETER(Mask);
    fputs(Text, stdout);
    return S_OK;
}
于 2015-12-26T11:20:13.250 回答