From d2e5dacb503bd7e3e9f8d0b19fdd4f2daf206c65 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 16 Aug 2010 15:04:22 +0000 Subject: [PATCH] [+] added: loadLinkedList routine [+] added: getPdbFile routine [+] added: reloadSymbols git-svn-id: https://pykd.svn.codeplex.com/svn@54138 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 6 +++- pykd/dbgext.h | 3 ++ pykd/dbgmem.cpp | 15 ++++++++++ pykd/dbgmem.h | 3 ++ pykd/dbgsystem.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgsystem.h | 8 ++++++ 6 files changed, 104 insertions(+), 1 deletion(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 7f30a05..019be5f 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -86,7 +86,8 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "loadSignQWords", &loadArray<__int64> ); boost::python::def( "loadPtrs", &loadPtrArray ); boost::python::def( "loadUnicodeString", &loadUnicodeStr ); - boost::python::def( "loadAnsiString", &loadAnsiStr ); + boost::python::def( "loadAnsiString", &loadAnsiStr ); + boost::python::def( "loadLinkedList", &loadLinkedList ); boost::python::def( "ptrByte", &loadByPtr ); boost::python::def( "ptrSignByte", &loadByPtr ); boost::python::def( "ptrWord", &loadByPtr ); @@ -98,6 +99,8 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "ptrPtr", &loadPtrByPtr ); boost::python::def( "compareMemory", &compareMemory ); boost::python::def( "getStack", &getStack ); + boost::python::def( "reloadSymbols", &reloadSymbols ); + boost::python::def( "getPdbFile", &getPdbFile ); boost::python::class_( "typedVarClass" ) .def("getAddress", &typedVarClass::getAddress ); boost::python::class_( "dbgModuleClass" ) @@ -163,6 +166,7 @@ SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt ) client->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dbgExt->dataSpaces ); + client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 ); } ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.h b/pykd/dbgext.h index 8188ff9..16a6fdb 100644 --- a/pykd/dbgext.h +++ b/pykd/dbgext.h @@ -1,6 +1,7 @@ #pragma once #include +#include struct DbgExt { @@ -16,6 +17,8 @@ struct DbgExt { IDebugSymbols3 *symbols3; IDebugDataSpaces *dataSpaces; + + IDebugAdvanced2 *advanced2; }; extern DbgExt *dbgExt; diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 5cf5856..97582de 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -296,4 +296,19 @@ loadAnsiStr( ULONG64 address ) return boost::python::object( "" ); } +/////////////////////////////////////////////////////////////////////////////////// + +boost::python::object +loadLinkedList( ULONG64 address ) +{ + ULONG64 entryAddress = 0; + + boost::python::list objList; + + for( entryAddress = loadPtrByPtr( address ); entryAddress != address; entryAddress = loadPtrByPtr( entryAddress ) ) + objList.append( entryAddress ); + + return objList; +} + /////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index 11cca1e..0dc47fc 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -65,4 +65,7 @@ compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length ); ULONG64 addr64( ULONG64 addr ); +boost::python::object +loadLinkedList( ULONG64 address ); + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgsystem.cpp b/pykd/dbgsystem.cpp index c966bec..c0aa2ab 100644 --- a/pykd/dbgsystem.cpp +++ b/pykd/dbgsystem.cpp @@ -70,3 +70,73 @@ dbgSymPath() /////////////////////////////////////////////////////////////////////////////////// + +std::string +getPdbFile( ULONG64 moduleBase ) +{ + HRESULT hres; + + try { + + + IMAGEHLP_MODULEW64 imageHelpInfo = { 0 }; + + hres = + dbgExt->advanced2->GetSymbolInformation( + DEBUG_SYMINFO_IMAGEHLP_MODULEW64, + moduleBase, + 0, + &imageHelpInfo, + sizeof( imageHelpInfo ), + NULL, + NULL, + 0, + NULL ); + + char fileName[ 256 ]; + WideCharToMultiByte( CP_ACP, 0, imageHelpInfo.LoadedPdbName, 256, fileName, 256, NULL, NULL ); + + return std::string( fileName ); + + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return std::string(); +} + +/////////////////////////////////////////////////////////////////////////////////// + +void +reloadSymbols( const char * moduleName ) +{ + HRESULT hres; + + try { + + std::string reloadParam( "/f " ); + reloadParam += moduleName; + + hres = dbgExt->symbols->Reload( reloadParam.c_str() ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::Reload failed" ); + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } +} + +/////////////////////////////////////////////////////////////////////////////////// + diff --git a/pykd/dbgsystem.h b/pykd/dbgsystem.h index 8e76778..bc06c49 100644 --- a/pykd/dbgsystem.h +++ b/pykd/dbgsystem.h @@ -16,5 +16,13 @@ ptrSize() { std::string dbgSymPath(); +std::string +getPdbFile( ULONG64 moduleBase ); + +std::string +getImageFile( ULONG64 moduleBase ); + +void +reloadSymbols( const char * moduleName ); ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file