mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[0.2.x] ~ get symbol name by "strict" VA (pykd.module.getSymbolName)
git-svn-id: https://pykd.svn.codeplex.com/svn@82747 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
c5b12433e6
commit
3e5acdaaf4
@ -121,6 +121,18 @@ SymbolSessionPtr& Module::getSymSession()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG64 Module::prepareVa(ULONG64 offset)
|
||||
{
|
||||
offset = addr64(offset);
|
||||
|
||||
if ( offset < m_base || offset > getEnd() )
|
||||
throw DbgException( "address is out of the module space" );
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SymbolPtr Module::getSymScope()
|
||||
{
|
||||
return getSymSession()->getSymbolScope();
|
||||
@ -189,10 +201,7 @@ std::string Module::print()
|
||||
TypedVarPtr
|
||||
Module::getTypedVarByAddr( ULONG64 offset )
|
||||
{
|
||||
offset = addr64(offset);
|
||||
|
||||
if ( offset < m_base || offset > getEnd() )
|
||||
throw DbgException( "address is out of the module space" );
|
||||
offset = prepareVa(offset);
|
||||
|
||||
SymbolPtr symVar = getSymSession()->findByRva( (ULONG)(offset - m_base ) );
|
||||
|
||||
@ -224,7 +233,7 @@ Module::getTypedVarByName( const std::string &symName )
|
||||
TypedVarPtr
|
||||
Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 offset )
|
||||
{
|
||||
offset = addr64(offset);
|
||||
offset = prepareVa(offset);
|
||||
|
||||
TypeInfoPtr typeInfo = getTypeByName( typeName );
|
||||
|
||||
@ -258,21 +267,16 @@ python::list Module::getTypedVarListByTypeName( ULONG64 listHeadAddress, const s
|
||||
|
||||
SymbolPtr Module::getSymbolByVa( ULONG64 offset, ULONG symTag, LONG* displacment )
|
||||
{
|
||||
offset = addr64(offset);
|
||||
|
||||
if ( offset < m_base || offset > getEnd() )
|
||||
throw DbgException( "address is out of the module space" );
|
||||
offset = prepareVa(offset);
|
||||
|
||||
return getSymSession()->findByRva( (ULONG)(offset - m_base ), symTag, displacment );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string Module::getSymbolNameByVa( ULONG64 offset, bool showDisplacement )
|
||||
{
|
||||
offset = addr64(offset);
|
||||
|
||||
if ( offset < m_base || offset > getEnd() )
|
||||
throw DbgException( "address is out of the module space" );
|
||||
offset = prepareVa(offset);
|
||||
|
||||
LONG displacement = 0;
|
||||
|
||||
@ -295,6 +299,23 @@ std::string Module::getSymbolNameByVa( ULONG64 offset, bool showDisplacement )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string Module::getStrictSymbolNameByVa( ULONG64 offset )
|
||||
{
|
||||
offset = prepareVa(offset);
|
||||
|
||||
LONG displacement = 0;
|
||||
|
||||
const ULONG rva = (ULONG)(offset - m_base );
|
||||
SymbolPtr sym = getSymSession()->findByRva( rva , SymTagNull, &displacement );
|
||||
|
||||
if (displacement || rva != sym->getRva())
|
||||
throw SymbolException( "Not exact address of symbol" );
|
||||
|
||||
return sym->getName();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Module::getSourceLine( ULONG64 offset, std::string &fileName, ULONG &lineNo, LONG &displacement )
|
||||
{
|
||||
getSymSession()->getSourceLine( offset, fileName, lineNo, displacement );
|
||||
|
@ -133,6 +133,8 @@ public:
|
||||
|
||||
std::string getSymbolNameByVa( ULONG64 offset, bool showDisplacement = true );
|
||||
|
||||
std::string getStrictSymbolNameByVa( ULONG64 offset );
|
||||
|
||||
void getSourceLine( ULONG64 offset, std::string &fileName, ULONG &lineNo, LONG &displacement );
|
||||
|
||||
std::string getSourceFile( ULONG64 offset );
|
||||
@ -149,6 +151,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
ULONG64 prepareVa(ULONG64 addr);
|
||||
|
||||
SymbolPtr getSymScope();
|
||||
|
||||
SymbolSessionPtr& getSymSession();
|
||||
|
@ -370,6 +370,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return offset of the symbol" )
|
||||
.def("findSymbol", &Module::getSymbolNameByVa, Module_findSymbol( python::args("offset", "showDisplacement"),
|
||||
"Return symbol name by virtual address" ) )
|
||||
.def("getSymbolName", &Module::getStrictSymbolNameByVa,
|
||||
"Return symbol name by virtual address (without displacement)" )
|
||||
.def("rva", &Module::getSymbolRva,
|
||||
"Return rva of the symbol" )
|
||||
.def("sizeof", &Module::getSymbolSize,
|
||||
|
@ -173,7 +173,7 @@ TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &typeSym )
|
||||
ptr = TypeInfoPtr( new ArrayTypeInfo( typeSym ) );
|
||||
break;
|
||||
|
||||
case SymTagPointerType:
|
||||
case SymTagPointerType:
|
||||
return TypeInfoPtr( new PointerTypeInfo( typeSym ) );
|
||||
|
||||
case SymTagVTable:
|
||||
|
@ -48,15 +48,20 @@ class ModuleTest( unittest.TestCase ):
|
||||
self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() )
|
||||
self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() )
|
||||
self.assertEqual( target.module.rva("FuncWithName0"), pykd.getOffset( target.module.name() + "!FuncWithName0") - target.module.begin() )
|
||||
|
||||
|
||||
def testFindSymbol( self ):
|
||||
self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) )
|
||||
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) )
|
||||
|
||||
|
||||
self.assertEqual( "_FuncWithName2+10", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) )
|
||||
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10, showDisplacement = False ) )
|
||||
|
||||
|
||||
|
||||
def testGetSymbolName( self ):
|
||||
vaFuncWithName0 = target.module.offset("FuncWithName0")
|
||||
self.assertEqual( "FuncWithName0", target.module.getSymbolName(vaFuncWithName0) )
|
||||
self.assertRaises( pykd.SymbolException, target.module.getSymbolName, vaFuncWithName0 + 1 )
|
||||
self.assertRaises( pykd.SymbolException, target.module.getSymbolName, vaFuncWithName0 - 1 )
|
||||
|
||||
def testType( self ):
|
||||
self.assertEqual( "structTest", target.module.type("structTest").name() );
|
||||
self.assertEqual( "structTest", target.module.type("g_structTest").name() );
|
||||
|
Loading…
Reference in New Issue
Block a user