IDebugControl::Execute method enables executing debugger commands. How can I get the output of the executed debugger command? My aim is to check if a driver is loaded, to accomplish that I use Execute to execute the "lm" windbg command and parse the returned output.
Get output of executed windbg command
1.3k views Asked by mikesoft At
2
There are 2 answers
0
On
Once you have your client (IDebugClient*) and your control (IDebugControl*) instances, from the client instance you need to call IDebugClient::SetOutputCallbacks method which sets the output callback. You need to set the output callback before calling the execute() method.
This should look like this:
StdioOutputCallbacks g_OutputCb;
// ...
g_Client->SetOutputCallbacks(&g_OutputCb);
g_Control->Execute(DEBUG_OUTCTL_ALL_CLIENTS,"lm vm", DEBUG_EXECUTE_ECHO);
Your output callback must inherit from IDebugOutputCallbacks
class StdioOutputCallbacks : public IDebugOutputCallbacks
The simple way to do this is to copy and use directly the out.cpp and out.hpp files - present in some samples - that implements the callback class, for ex. in:
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\sdk\samples\dumpstk
The output itself is done in IDebugOutputCallbacks::Output implementation:
STDMETHODIMP
StdioOutputCallbacks::Output(
THIS_
_In_ ULONG Mask,
_In_ PCSTR Text
)
{
UNREFERENCED_PARAMETER(Mask);
fputs(Text, stdout);
return S_OK;
}
you need to implement IDebugOutputCallbacks for a sample take a look at remmon out.cpp and out.hpp in windbg sdk sample (iirc new sdks don't contain samples you need to get it from msdn sample gallery online )
a sample dummy implementation copy the two file out.cpp and out.hpp to the local folder build and execute to show a warning and the output of .echo execution
result of build and execution