From da56036fee60060829072ec713caf967dc7455da Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 23 Dec 2011 11:51:16 +0000 Subject: [PATCH] [0.1.x] added : detachProcess [0.1.x] added : killProcess git-svn-id: https://pykd.svn.codeplex.com/svn@72653 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.cpp | 31 +++++++++++++++++++ pykd/dbgclient.h | 67 +++++----------------------------------- pykd/dbgext.cpp | 25 +++++++++------ test/scripts/basetest.py | 4 ++- 4 files changed, 58 insertions(+), 69 deletions(-) diff --git a/pykd/dbgclient.cpp b/pykd/dbgclient.cpp index b66fe23..fad59df 100644 --- a/pykd/dbgclient.cpp +++ b/pykd/dbgclient.cpp @@ -226,6 +226,21 @@ void attachProcess( ULONG processId ) { /////////////////////////////////////////////////////////////////////////////////// +void DebugClient::detachProcess() +{ + HRESULT hres; + + hres = m_client->DetachCurrentProcess(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::DetachCurrentProcess failed" ); +} + +void detachProcess() { + g_dbgClient->detachProcess(); +} + +/////////////////////////////////////////////////////////////////////////////////// + void DebugClient::attachKernel( const std::wstring ¶m ) { HRESULT hres; @@ -383,4 +398,20 @@ ULONG ptrSize() /////////////////////////////////////////////////////////////////////////////////// +void DebugClient::terminateProcess() +{ + HRESULT hres; + + hres = m_client->TerminateCurrentProcess(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::TerminateCurrentProcess failed" ); +} + +void terminateProcess() +{ + g_dbgClient->terminateProcess(); +} + +/////////////////////////////////////////////////////////////////////////////////// + }; // end of namespace pykd diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 2a1cb9c..cdd08d3 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -51,6 +51,8 @@ public: bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr = FALSE ); + void detachProcess(); + DbgOut dout() { return DbgOut( m_client ); } @@ -189,6 +191,8 @@ public: python::object getRegByIndex( ULONG index ); void setExecutionStatus( ULONG status ); + + void terminateProcess(); void waitForEvent(); @@ -278,6 +282,8 @@ void attachProcess( ULONG processId ); void attachKernel( const std::wstring ¶m ); +void detachProcess(); + std::string findSymbol( ULONG64 offset ); python::tuple getDebuggeeType(); @@ -298,6 +304,8 @@ ULONG ptrSize(); void setExecutionStatus( ULONG status ); +void terminateProcess(); + void waitForEvent(); ///////////////////////////////////////////////////////////////////////////////// @@ -370,62 +378,3 @@ void changeDebuggerStatus() }; // namespace pykd - - - - - - - - -//#include "dbgext.h" -//#include "dbgeventcb.h" -// -///////////////////////////////////////////////////////////////////////////////// -// -//class dbgClient { -// -//public: -// -// dbgClient() -// { -// m_callbacks = NULL; -// -// IDebugClient4 *client = NULL; -// DebugCreate( __uuidof(IDebugClient4), (void **)&client ); -// -// m_ext = new DbgExt( client ); -// -// client->Release(); -// } -// -// ~dbgClient() -// { -// removeEventsMgr(); -// -// delete m_ext; -// } -// -// void startEventsMgr() { -// -// m_callbacks = new DbgEventCallbacksManager( m_ext->client ); -// } -// -// void removeEventsMgr() { -// -// if ( m_callbacks ) -// { -// delete m_callbacks; -// m_callbacks = NULL; -// } -// } -// -//private: -// -// DbgExt *m_ext; -// DbgEventCallbacksManager *m_callbacks; -//}; -// -//extern dbgClient g_dbgClient; -// -///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index a27bd6e..47298a5 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -149,6 +149,8 @@ BOOST_PYTHON_MODULE( pykd ) "Attach debugger to a exsisting process" ) .def( "attachKernel", &DebugClient::attachKernel, "Attach debugger to a target's kernel" ) + .def( "detachProcess", &DebugClient::detachProcess, + "Detach debugger from the current process" ) .def( "expr", &DebugClient::evaluate, "Evaluate windbg expression" ) .def( "findSymbol", &DebugClient::findSymbol, @@ -183,6 +185,8 @@ BOOST_PYTHON_MODULE( pykd ) "Check if kernel dubugging is running" ) .def( "isValid", &DebugClient::isVaValid, "Check if the virtual address is valid" ) + .def( "killProcess", &DebugClient::terminateProcess, + "Stop debugging and terminate current process" ) .def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of unsigned bytes" ) ) .def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ), @@ -255,21 +259,21 @@ BOOST_PYTHON_MODULE( pykd ) "Return a CPU regsiter value by the register's name" ) .def( "reg", &DebugClient::getRegByIndex, "Return a CPU regsiter value by the register's value" ) - .def( "setExecutionStatus", &pykd::DebugClient::setExecutionStatus, + .def( "setExecutionStatus", &DebugClient::setExecutionStatus, "Requests that the debugger engine enter an executable state" ) - .def( "step", &pykd::DebugClient::changeDebuggerStatus, + .def( "step", &DebugClient::changeDebuggerStatus, "Change debugger status to DEBUG_STATUS_STEP_OVER" ) - .def( "trace", &pykd::DebugClient::changeDebuggerStatus, + .def( "trace", &DebugClient::changeDebuggerStatus, "Change debugger status to DEBUG_STATUS_STEP_INTO" ) - .def( "waitForEvent", &pykd::DebugClient::waitForEvent, + .def( "waitForEvent", &DebugClient::waitForEvent, "Wait for events that breaks into the debugger" ) - .def( "addSynSymbol", &pykd::DebugClient::addSyntheticSymbol, + .def( "addSynSymbol", &DebugClient::addSyntheticSymbol, "Add new synthetic symbol for virtual address" ) - .def( "delAllSynSymbols", &pykd::DebugClient::delAllSyntheticSymbols, + .def( "delAllSynSymbols", &DebugClient::delAllSyntheticSymbols, "Delete all synthetic symbol for all modules") - .def( "delSynSymbol", &pykd::DebugClient::delSyntheticSymbol, + .def( "delSynSymbol", &DebugClient::delSyntheticSymbol, "Delete synthetic symbols by virtual address" ) - .def( "delSynSymbolsMask", &pykd::DebugClient::delSyntheticSymbolsMask, + .def( "delSynSymbolsMask", &DebugClient::delSyntheticSymbolsMask, "Delete synthetic symbols by mask of module and symbol name"); python::def( "addr64", &addr64, @@ -288,6 +292,8 @@ BOOST_PYTHON_MODULE( pykd ) "Attach debugger to a exsisting process" ); python::def( "attachKernel", &attachKernel, "Attach debugger to a kernel target" ); + python::def( "detachProcess", &detachProcess, + "Detach denugger from the current process" ); python::def( "expr", &evaluate, "Evaluate windbg expression" ); python::def( "findSymbol", &findSymbol, @@ -326,6 +332,8 @@ BOOST_PYTHON_MODULE( pykd ) "Check if script works in windbg context" ); python::def( "isValid", &isVaValid, "Check if the virtual address is valid" ); + python::def( "killProcess", &terminateProcess, + "Stop debugging and terminate current process" ); python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as liat of unsigned bytes" ) ); python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), @@ -388,7 +396,6 @@ BOOST_PYTHON_MODULE( pykd ) "Delete synthetic symbols by virtual address" ); boost::python::def( "delSynSymbolsMask", &delSyntheticSymbolsMask, "Delete synthetic symbols by mask of module and symbol name"); - python::def( "loadExt", &pykd::loadExtension, "Load a debuger extension" ); python::def( "loadModule", &loadModuleByName, diff --git a/test/scripts/basetest.py b/test/scripts/basetest.py index f2e7817..0788fac 100644 --- a/test/scripts/basetest.py +++ b/test/scripts/basetest.py @@ -56,7 +56,7 @@ class BaseTest( unittest.TestCase ): self.assertTrue( hasattr(pykd, 'loadWChars') ) self.assertTrue( hasattr(pykd, 'loadWStr') ) self.assertTrue( hasattr(pykd, 'loadWords') ) - self.assertTrue( hasattr(pykd, 'locals') ) + #self.assertTrue( hasattr(pykd, 'locals') ) self.assertTrue( hasattr(pykd, 'ptrByte') ) self.assertTrue( hasattr(pykd, 'ptrDWord') ) self.assertTrue( hasattr(pykd, 'ptrMWord') ) @@ -114,9 +114,11 @@ class BaseTest( unittest.TestCase ): def testNewAddededApi( self ): """ Branch test: new API 0.1.x what must be available """ self.assertTrue( hasattr(pykd, 'createDbgClient') ) + self.asseerTrue( hasattr(pykd, 'detachProcess') ) self.assertTrue( hasattr(pykd, 'diaLoadPdb') ) self.assertTrue( hasattr(pykd, 'getDebuggeeType' ) ) self.assertTrue( hasattr(pykd, 'getExecutionStatus' ) ) + self.asseerTrue( hasattr(pykd, 'killProcess') ) self.assertTrue( hasattr(pykd, 'loadExt') ) self.assertTrue( hasattr(pykd, 'loadPtrList') ) self.assertTrue( hasattr(pykd, 'loadPtrArray') )