mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 19:53:22 +08:00
[+] 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
This commit is contained in:
parent
c74a81d560
commit
1604ec506e
@ -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_<dbgExtensionClass>(
|
||||
"ext",
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -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<std::string, ULONG64> OffsetMap;
|
||||
OffsetMap m_offsets;
|
||||
|
||||
void
|
||||
getImagePath();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user