mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[+] added: !pycmd command for windbg extension
git-svn-id: https://pykd.svn.codeplex.com/svn@53591 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
6ee2fc538f
commit
6e7d492e18
@ -3,96 +3,7 @@
|
|||||||
#include "dbgext.h"
|
#include "dbgext.h"
|
||||||
#include "dbgcmd.h"
|
#include "dbgcmd.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
|
#include "dbgcallback.h"
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// êëàññ äëÿ ïåðåõâàòà âûâîäà â îòëàä÷èê
|
|
||||||
|
|
||||||
class OutputReader : public IDebugOutputCallbacks {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
OutputReader( IDebugClient *debugClient )
|
|
||||||
{
|
|
||||||
HRESULT hres;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
m_debugClient = debugClient;
|
|
||||||
m_debugClient->AddRef();
|
|
||||||
|
|
||||||
hres = m_debugClient->GetOutputCallbacks( &m_previousCallback );
|
|
||||||
if ( FAILED( hres ) )
|
|
||||||
{
|
|
||||||
throw hres;
|
|
||||||
}
|
|
||||||
|
|
||||||
hres = m_debugClient->SetOutputCallbacks( this );
|
|
||||||
if ( FAILED( hres ) )
|
|
||||||
{
|
|
||||||
throw hres;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch( ... )
|
|
||||||
{
|
|
||||||
m_debugClient->Release();
|
|
||||||
m_debugClient = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~OutputReader()
|
|
||||||
{
|
|
||||||
if ( m_debugClient )
|
|
||||||
{
|
|
||||||
m_debugClient->SetOutputCallbacks( m_previousCallback );
|
|
||||||
m_debugClient->Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string&
|
|
||||||
Line() const {
|
|
||||||
return m_readLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// IUnknown.
|
|
||||||
STDMETHOD(QueryInterface)(
|
|
||||||
__in REFIID InterfaceId,
|
|
||||||
__out PVOID* Interface ) {
|
|
||||||
return E_NOINTERFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHOD_(ULONG, AddRef)() {
|
|
||||||
return 1L;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
STDMETHOD_(ULONG, Release)() {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
STDMETHOD(Output)(
|
|
||||||
__in ULONG Mask,
|
|
||||||
__in PCSTR Text )
|
|
||||||
{
|
|
||||||
if ( Mask == DEBUG_OUTPUT_NORMAL )
|
|
||||||
{
|
|
||||||
m_readLine += std::string( Text );
|
|
||||||
}
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::string m_readLine;
|
|
||||||
|
|
||||||
IDebugClient *m_debugClient;
|
|
||||||
|
|
||||||
IDebugOutputCallbacks *m_previousCallback;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -10,5 +10,8 @@
|
|||||||
std::string
|
std::string
|
||||||
dbgCommand( const std::string &command );
|
dbgCommand( const std::string &command );
|
||||||
|
|
||||||
|
void
|
||||||
|
dbgGoCommand();
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
133
pykd/dbgext.cpp
133
pykd/dbgext.cpp
@ -23,11 +23,38 @@
|
|||||||
#include "dbgdump.h"
|
#include "dbgdump.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
#include "dbgsession.h"
|
#include "dbgsession.h"
|
||||||
|
#include "dbgcallback.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// óêàçàòåëü íà òåêóùéè èíòåðôåéñ
|
||||||
DbgExt *dbgExt = NULL;
|
DbgExt *dbgExt = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class WindbgGlobalSession
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
WindbgGlobalSession() {
|
||||||
|
interactiveMode = false;
|
||||||
|
main = boost::python::import("__main__");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
global() {
|
||||||
|
return main.attr("__dict__");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
boost::python::object main;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
WindbgGlobalSession *windbgGlobalSession = NULL;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE( pykd )
|
BOOST_PYTHON_MODULE( pykd )
|
||||||
@ -94,6 +121,8 @@ DebugExtensionInitialize(
|
|||||||
|
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
|
|
||||||
|
windbgGlobalSession = new WindbgGlobalSession();
|
||||||
|
|
||||||
dbgSessionStarted = true;
|
dbgSessionStarted = true;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -104,6 +133,9 @@ VOID
|
|||||||
CALLBACK
|
CALLBACK
|
||||||
DebugExtensionUninitialize()
|
DebugExtensionUninitialize()
|
||||||
{
|
{
|
||||||
|
delete windbgGlobalSession;
|
||||||
|
windbgGlobalSession = NULL;
|
||||||
|
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,3 +247,104 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
HRESULT
|
||||||
|
CALLBACK
|
||||||
|
pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
DbgExt ext = { 0 };
|
||||||
|
|
||||||
|
SetupDebugEngine( client, &ext );
|
||||||
|
dbgExt = &ext;
|
||||||
|
|
||||||
|
if ( !std::string( args ).empty() )
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
boost::python::exec( args, windbgGlobalSession->global(), windbgGlobalSession->global() );
|
||||||
|
}
|
||||||
|
catch( boost::python::error_already_set const & )
|
||||||
|
{
|
||||||
|
// îøèáêà â ñêðèïòå
|
||||||
|
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
||||||
|
|
||||||
|
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
||||||
|
|
||||||
|
if(errvalue != NULL)
|
||||||
|
{
|
||||||
|
PyObject *s = PyObject_Str(errvalue);
|
||||||
|
|
||||||
|
DbgPrint::dprintln( PyString_AS_STRING( s ) );
|
||||||
|
|
||||||
|
Py_DECREF(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(errvalue);
|
||||||
|
Py_XDECREF(errtype);
|
||||||
|
Py_XDECREF(traceback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char str[100];
|
||||||
|
ULONG inputSize;
|
||||||
|
bool stopInput = false;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
std::string output;
|
||||||
|
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, ">>>" );
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
OutputReader outputReader( dbgExt->client );
|
||||||
|
|
||||||
|
HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) || std::string( str ) == "" )
|
||||||
|
{
|
||||||
|
stopInput = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while( FALSE );
|
||||||
|
|
||||||
|
if ( !stopInput )
|
||||||
|
try {
|
||||||
|
boost::python::exec( str, windbgGlobalSession->global(), windbgGlobalSession->global() );
|
||||||
|
}
|
||||||
|
catch( boost::python::error_already_set const & )
|
||||||
|
{
|
||||||
|
// îøèáêà â ñêðèïòå
|
||||||
|
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
||||||
|
|
||||||
|
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
||||||
|
|
||||||
|
if(errvalue != NULL)
|
||||||
|
{
|
||||||
|
PyObject *s = PyObject_Str(errvalue);
|
||||||
|
|
||||||
|
DbgPrint::dprintln( PyString_AS_STRING( s ) );
|
||||||
|
|
||||||
|
Py_DECREF(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(errvalue);
|
||||||
|
Py_XDECREF(errtype);
|
||||||
|
Py_XDECREF(traceback);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while( !stopInput );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -16,8 +16,6 @@ struct DbgExt {
|
|||||||
IDebugSymbols3 *symbols3;
|
IDebugSymbols3 *symbols3;
|
||||||
|
|
||||||
IDebugDataSpaces *dataSpaces;
|
IDebugDataSpaces *dataSpaces;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DbgExt *dbgExt;
|
extern DbgExt *dbgExt;
|
||||||
|
@ -4,3 +4,4 @@ EXPORTS
|
|||||||
|
|
||||||
info
|
info
|
||||||
py
|
py
|
||||||
|
pycmd
|
@ -445,6 +445,10 @@
|
|||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\dbgcallback.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgcmd.h"
|
RelativePath=".\dbgcmd.h"
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user