From 1604ec506ed98da4c23a10e0f6a37257f0175513 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Tue, 8 Feb 2011 07:36:12 +0000 Subject: [PATCH] [+] added : image() and pdb() method for dbgModuleClass class. They return paths to pdb and image files. git-svn-id: https://pykd.svn.codeplex.com/svn@61168 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 2 + pykd/dbgmodule.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgmodule.h | 17 +++++++++ pykd/dbgsym.cpp | 4 +- 4 files changed, 115 insertions(+), 2 deletions(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 4dca1b6..e4b49e0 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -159,6 +159,8 @@ BOOST_PYTHON_MODULE( pykd ) .def("end", &dbgModuleClass::getEnd ) .def("name", &dbgModuleClass::getName ) .def("contain", &dbgModuleClass::contain ) + .def("image", &dbgModuleClass::getImageSymbolName ) + .def("pdb", &dbgModuleClass::getPdbName ) .def("__getattr__", &dbgModuleClass::getOffset ); boost::python::class_( "ext", diff --git a/pykd/dbgmodule.cpp b/pykd/dbgmodule.cpp index 3ef77ec..a02882b 100644 --- a/pykd/dbgmodule.cpp +++ b/pykd/dbgmodule.cpp @@ -139,6 +139,22 @@ dbgModuleClass::dbgModuleClass( const std::string &name, ULONG64 base, ULONG siz if ( enumHandle ) dbgExt->symbols->EndSymbolMatch( enumHandle ); + + memset( &m_debugInfo, 0, sizeof( m_debugInfo ) ); + + hres = dbgExt->advanced2->GetSymbolInformation( + DEBUG_SYMINFO_IMAGEHLP_MODULEW64, + base, + 0, + &m_debugInfo, + sizeof( m_debugInfo ), + NULL, + NULL, + 0, + NULL ); + + if ( SUCCEEDED( hres ) ) + getImagePath(); } ///////////////////////////////////////////////////////////////////////////////// @@ -213,3 +229,81 @@ dbgModuleClass::getOffset( const std::string &symName ) ///////////////////////////////////////////////////////////////////////////////// +void +dbgModuleClass::getImagePath() +{ + HRESULT hres; + PWSTR pathBuffer = NULL; + + try { + + ULONG pathSize = 0; + hres = dbgExt->symbols3->GetSymbolPathWide( NULL, 0, &pathSize ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol3::GetImagePathWide failed" ); + + pathBuffer = new WCHAR [ pathSize ]; + + hres = dbgExt->symbols3->GetSymbolPathWide( pathBuffer, pathSize, NULL ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol3::GetImagePathWide failed" ); + + std::wstring symPath( pathBuffer, pathSize ); + + std::wstring altName = m_debugInfo.CVData; + altName = altName.substr( 0, altName.find_last_of(L".") ); + + std::wstring imageName = m_debugInfo.LoadedImageName; + altName += imageName.substr( imageName.find_last_of(L".") ); + + for ( size_t offset = 0; offset < symPath.length(); ) + { + size_t newOffset = symPath.find( L";", offset ); + std::wstring subPath = symPath.substr( offset, newOffset - offset ); + + std::wstringstream sstr; + + sstr << subPath << L"\\" << m_debugInfo.LoadedImageName << L"\\" << std::hex << + m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" << + m_debugInfo.LoadedImageName; + + if( (_waccess( sstr.str().c_str(), 0 )) != -1 ) + { + m_imageFullName = sstr.str(); + break; + } + + + std::wstringstream altstr; + + altstr << subPath << L"\\" << altName << L"\\" << std::hex << + m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" << + altName; + + if( (_waccess( altstr.str().c_str(), 0 )) != -1 ) + { + m_imageFullName = altstr.str(); + break; + } + + if ( newOffset == std::wstring::npos ) + break; + + offset = newOffset + 1; + } + + } + 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" ); + } + + if ( pathBuffer ) + delete[] pathBuffer; +} + +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmodule.h b/pykd/dbgmodule.h index 47e0f4f..b90ea03 100644 --- a/pykd/dbgmodule.h +++ b/pykd/dbgmodule.h @@ -48,6 +48,16 @@ public: ULONG64 getOffset( const std::string &symName ); + std::wstring + getImageSymbolName() const { + return m_imageFullName; + } + + std::wstring + getPdbName() const { + return std::wstring( m_debugInfo.LoadedPdbName ); + } + private: @@ -57,8 +67,15 @@ private: std::string m_name; + std::wstring m_imageFullName; + + IMAGEHLP_MODULEW64 m_debugInfo; + typedef std::map OffsetMap; OffsetMap m_offsets; + + void + getImagePath(); }; ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsym.cpp b/pykd/dbgsym.cpp index 7a26680..17fbbe6 100644 --- a/pykd/dbgsym.cpp +++ b/pykd/dbgsym.cpp @@ -23,7 +23,7 @@ findSymbolForAddress( ULONG64 addr ) if ( FAILED( hres ) ) { - return boost::python::object( "out of module" ); + return boost::python::object(); } char moduleName[0x100]; @@ -54,7 +54,7 @@ findSymbolForAddress( ULONG64 addr ) dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); } - return boost::python::object( addr ); + return boost::python::object(); } /////////////////////////////////////////////////////////////////////////////////