diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 34e7bb3..a24d8ed 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -84,5 +84,12 @@ ULONG breakPointSet( ULONG64 offset, bool hardware = false, ULONG size = 0, ULON void breakPointRemove( ULONG id ); void breakPointRemoveAll(); + +// processes end threads +ULONG64 getCurrentProcess(); +ULONG64 getImplicitThread(); +void setCurrentProcess( ULONG64 processAddr ); +void setImplicitThread( ULONG64 threadAddr ); + }; diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 43a2859..882738b 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -235,6 +235,16 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "removeAllBp", &removeAllBp, "Remove all breapoints" ); + // processes and threads + python::def( "getCurrentProcess", &getCurrentProcess, + "Return pointer to current process's block" ); + python::def( "getImplicitThread", &getImplicitThread, + "Return implicit thread for current process" ); + python::def( "setCurrentProcess", &setCurrentProcess, + "Set current process by address" ); + python::def( "setImplicitThread", &setImplicitThread, + "Set implicit thread for current process" ); + // custom types python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align" ), "Create empty structure. Use append() method for building" ) ); diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index 148a013..89c54cc 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -943,6 +943,68 @@ HRESULT STDMETHODCALLTYPE DebugEngine::Breakpoint( /////////////////////////////////////////////////////////////////////////////// +ULONG64 +getCurrentProcess() +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 processAddr = 0; + + hres = g_dbgEng->system->GetImplicitProcessDataOffset( &processAddr ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" ); + + return processAddr; +} + +/////////////////////////////////////////////////////////////////////////////// + +ULONG64 +getImplicitThread() +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 threadOffset = -1; + + hres = g_dbgEng->system->GetImplicitThreadDataOffset( &threadOffset ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" ); + + return threadOffset; +} + +/////////////////////////////////////////////////////////////////////////////// + +void setCurrentProcess( ULONG64 processAddr ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + processAddr = addr64(processAddr); + hres = g_dbgEng->system->SetImplicitProcessDataOffset( processAddr ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::SetImplicitProcessDataOffset failed" ); +} + +/////////////////////////////////////////////////////////////////////////////// + +void setImplicitThread( ULONG64 threadAddr ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + threadAddr = addr64(threadAddr); + hres = g_dbgEng->system->SetImplicitThreadDataOffset( threadAddr ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" ); +} + +/////////////////////////////////////////////////////////////////////////////// + } // end pykd namespace