From 7ec136e1508ed9e4600305f67680dd8c09c89b21 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 9 Dec 2011 14:01:49 +0000 Subject: [PATCH] [0.1.x] added : getCurrentProcess routine [0.1.x] added : getImplicitThread routine git-svn-id: https://pykd.svn.codeplex.com/svn@72141 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 4 ++++ pykd/dbgext.cpp | 11 +++++++++- pykd/dbgobj.h | 19 ++++++++++------- pykd/process.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ pykd/process.h | 13 ++++++++++++ pykd/pykd_2008.vcproj | 10 ++++++++- 6 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 pykd/process.cpp create mode 100644 pykd/process.h diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 507ced2..45c5855 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -83,8 +83,12 @@ public: std::string findSymbol( ULONG64 offset ); + ULONG64 getCurrentProcess(); + python::tuple getDebuggeeType(); + ULONG64 getImplicitThread(); + ULONG getExecutionStatus(); template diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 420ea1a..e857e01 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -17,6 +17,7 @@ #include "typedvar.h" #include "dbgmem.h" #include "intbase.h" +#include "process.h" using namespace pykd; @@ -132,7 +133,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__long__", &intBase::long_ ) .def( "__int__", &intBase::int_ ); - python::class_("dbgClient", "Class representing a debugging session", python::no_init ) + python::class_("dbgClient", "Class representing a debugging session", python::no_init ) .def( "addr64", &DebugClient::addr64, "Extend address to 64 bits formats" ) .def( "breakin", &DebugClient::breakin, @@ -151,8 +152,12 @@ BOOST_PYTHON_MODULE( pykd ) "Evaluate windbg expression" ) .def( "findSymbol", &DebugClient::findSymbol, "Find symbol by the target virtual memory offset" ) + .def( "getCurrentProcess", &DebugClient::getCurrentProcess, + "Return pointer to current process's block" ) .def( "getDebuggeeType", &DebugClient::getDebuggeeType, "Return type of the debuggee" ) + .def( "getImplicitThread", &getImplicitThread, + "Return implicit thread for current process" ) .def( "getExecutionStatus", &DebugClient::getExecutionStatus, "Return information about the execution status of the debugger" ) .def( "go", &DebugClient::changeDebuggerStatus, @@ -264,8 +269,12 @@ BOOST_PYTHON_MODULE( pykd ) "Evaluate windbg expression" ); python::def( "findSymbol", &findSymbol, "Find symbol by the target virtual memory offset" ); + python::def( "getCurrentProcess", &getCurrentProcess, + "Return pointer to current process's block" ); python::def( "getDebuggeeType", &getDebuggeeType, "Return type of the debuggee" ); + python::def( "getImplicitThread", &getImplicitThread, + "Return implicit thread for current process" ); python::def( "debuggerPath", &getDebuggerImage, "Return full path to the process image that uses pykd" ); python::def( "getExecutionStatus", &getExecutionStatus, diff --git a/pykd/dbgobj.h b/pykd/dbgobj.h index 4b809c0..93f2832 100644 --- a/pykd/dbgobj.h +++ b/pykd/dbgobj.h @@ -41,17 +41,22 @@ protected: hres = client->QueryInterface( __uuidof(IDebugRegisters2), (void**)&m_registers ); if ( FAILED( hres ) ) throw DbgException("QueryInterface IDebugDataSpaces failed"); + + hres = client->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&m_system ); + if ( FAILED( hres ) ) + throw DbgException("QueryInterface IDebugSystem2 failed"); } virtual ~DbgObject() {}; - CComPtr m_client5; - CComPtr m_client; - CComPtr m_control; - CComPtr m_symbols; - CComPtr m_advanced; - CComPtr m_dataSpaces; - CComPtr m_registers; + CComPtr m_client5; + CComPtr m_client; + CComPtr m_control; + CComPtr m_symbols; + CComPtr m_advanced; + CComPtr m_dataSpaces; + CComPtr m_registers; + CComPtr m_system; }; diff --git a/pykd/process.cpp b/pykd/process.cpp new file mode 100644 index 0000000..85e6905 --- /dev/null +++ b/pykd/process.cpp @@ -0,0 +1,49 @@ +#include "stdafx.h" +#include "dbgclient.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 +DebugClient::getCurrentProcess() +{ + HRESULT hres; + ULONG64 processAddr = 0; + + hres = m_system->GetImplicitProcessDataOffset( &processAddr ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" ); + + return processAddr; +} + +ULONG64 +getCurrentProcess() +{ + return g_dbgClient->getCurrentProcess(); +} + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 +DebugClient::getImplicitThread() +{ + HRESULT hres; + ULONG64 threadOffset = -1; + + hres = m_system->GetImplicitThreadDataOffset( &threadOffset ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" ); + + return threadOffset; +} + +ULONG64 +getImplicitThread() { + return g_dbgClient->getImplicitThread(); +} + +/////////////////////////////////////////////////////////////////////////////////// + +} \ No newline at end of file diff --git a/pykd/process.h b/pykd/process.h new file mode 100644 index 0000000..aeda263 --- /dev/null +++ b/pykd/process.h @@ -0,0 +1,13 @@ +#pragma once + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 getCurrentProcess(); + +ULONG64 getImplicitThread(); + +/////////////////////////////////////////////////////////////////////////////////// + +} diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 157b1c9..2b15ed8 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -1,7 +1,7 @@ + + @@ -531,6 +535,10 @@ RelativePath=".\module.h" > + +