[0.2.x] fixed : findSymbol routine

[0.2.x] added : findSymbolAndDisp routine ( Return tuple(symbol_name, displacement) by virtual address )

git-svn-id: https://pykd.svn.codeplex.com/svn@82900 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-03-12 08:56:07 +00:00 committed by Mikhail I. Izmestev
parent 0c548cefb6
commit 9234fdf0ae
9 changed files with 63 additions and 19 deletions

View File

@ -299,14 +299,13 @@ std::string Module::getSymbolNameByVa( ULONG64 offset, bool showDisplacement )
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
python::tuple Module::getSymbolAndDispByVa( ULONG64 offset ) void Module::getSymbolAndDispByVa( ULONG64 offset, std::string &symbolName, LONG &displacement)
{ {
offset = prepareVa(offset); offset = prepareVa(offset);
LONG displacement = 0;
SymbolPtr sym = getSymSession()->findByRva( (ULONG)(offset - m_base ), SymTagNull, &displacement ); SymbolPtr sym = getSymSession()->findByRva( (ULONG)(offset - m_base ), SymTagNull, &displacement );
return python::make_tuple(sym->getName(), displacement); symbolName = sym->getName();
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -133,7 +133,7 @@ public:
std::string getSymbolNameByVa( ULONG64 offset, bool showDisplacement = true ); std::string getSymbolNameByVa( ULONG64 offset, bool showDisplacement = true );
python::tuple getSymbolAndDispByVa( ULONG64 offset ); void getSymbolAndDispByVa( ULONG64 offset, std::string &symbolName, LONG &displacement);
void getSourceLine( ULONG64 offset, std::string &fileName, ULONG &lineNo, LONG &displacement ); void getSourceLine( ULONG64 offset, std::string &fileName, ULONG &lineNo, LONG &displacement );

View File

@ -231,8 +231,10 @@ BOOST_PYTHON_MODULE( pykd )
"Return source file name, line and displacement by the specified offset" ) ); "Return source file name, line and displacement by the specified offset" ) );
python::def( "getOffset", &TypeInfo::getOffset, python::def( "getOffset", &TypeInfo::getOffset,
"Return traget virtual address for specified symbol" ); "Return traget virtual address for specified symbol" );
python::def( "findSymbol", &TypeInfo::findSymbol, findSymbol_( python::args( "offset", "safe"), python::def( "findSymbol", &TypeInfo::findSymbol, findSymbol_( python::args( "offset", "showDisplacement"),
"Find symbol by the target virtual memory offset" ) ); "Find symbol by the target virtual memory offset" ) );
python::def("findSymbolAndDisp", &pysupport::findSymbolAndDisp,
"Return tuple(symbol_name, displacement) by virtual address" );
python::def( "sizeof", &TypeInfo::getSymbolSize, python::def( "sizeof", &TypeInfo::getSymbolSize,
"Return a size of the type or variable" ); "Return a size of the type or variable" );
python::def("typedVarList", &getTypedVarListByTypeName, python::def("typedVarList", &getTypedVarListByTypeName,
@ -376,7 +378,7 @@ BOOST_PYTHON_MODULE( pykd )
"Return offset of the symbol" ) "Return offset of the symbol" )
.def("findSymbol", &Module::getSymbolNameByVa, Module_findSymbol( python::args("offset", "showDisplacement"), .def("findSymbol", &Module::getSymbolNameByVa, Module_findSymbol( python::args("offset", "showDisplacement"),
"Return symbol name by virtual address" ) ) "Return symbol name by virtual address" ) )
.def("findSymbolAndDisp", &Module::getSymbolAndDispByVa, .def("findSymbolAndDisp", &pysupport::moduleFindSymbolAndDisp,
"Return tuple(symbol_name, displacement) by virtual address" ) "Return tuple(symbol_name, displacement) by virtual address" )
.def("rva", &Module::getSymbolRva, .def("rva", &Module::getSymbolRva,
"Return rva of the symbol" ) "Return rva of the symbol" )

View File

@ -2,6 +2,7 @@
#include "pysupport.h" #include "pysupport.h"
#include "dbgengine.h" #include "dbgengine.h"
#include "typeinfo.h"
#include <vector> #include <vector>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -32,6 +33,27 @@ python::tuple getBugCheckData()
return python::make_tuple(bugCheckData.code, bugCheckData.arg1, bugCheckData.arg2, bugCheckData.arg3, bugCheckData.arg4); return python::make_tuple(bugCheckData.code, bugCheckData.arg1, bugCheckData.arg2, bugCheckData.arg3, bugCheckData.arg4);
} }
python::tuple findSymbolAndDisp( ULONG64 offset )
{
std::string symbolName;
LONG displacement;
pykd::TypeInfo::findSymbolAndDisp( offset, symbolName, displacement );
return python::make_tuple(symbolName,displacement);
}
python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset )
{
std::string symbolName;
LONG displacement;
module.getSymbolAndDispByVa( offset, symbolName, displacement );
return python::make_tuple(symbolName,displacement);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
} } //pykd::support namespace end } } //pykd::support namespace end

View File

@ -2,6 +2,8 @@
#include <boost/python/list.hpp> #include <boost/python/list.hpp>
#include "module.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
namespace pykd { namespace pykd {
@ -11,6 +13,10 @@ python::list getProcessThreads();
python::tuple getBugCheckData(); python::tuple getBugCheckData();
python::tuple findSymbolAndDisp( ULONG64 offset );
python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset );
} } //pykd::support namespace end } } //pykd::support namespace end
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -74,23 +74,15 @@ ULONG64 TypeInfo::getSymbolSize( const std::string &fullName )
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
std::string TypeInfo::findSymbol( ULONG64 offset, bool safe) std::string TypeInfo::findSymbol( ULONG64 offset, bool showDisplacement)
{ {
if ( !safe )
{
ModulePtr module = Module::loadModuleByOffset( offset );
return module->getName() + '!' + module->getSymbolNameByVa( offset );
}
try { try {
ModulePtr module = Module::loadModuleByOffset( offset ); ModulePtr module = Module::loadModuleByOffset( offset );
try { try {
std::string symbolName = module->getSymbolNameByVa( offset, showDisplacement );
return module->getName() + '!' + module->getSymbolNameByVa( offset ); return module->getName() + '!' + symbolName;
} }
catch( DbgException& ) catch( DbgException& )
{ {
@ -110,6 +102,17 @@ std::string TypeInfo::findSymbol( ULONG64 offset, bool safe)
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
void TypeInfo::findSymbolAndDisp( ULONG64 offset, std::string &symbolName, LONG &displacement )
{
ModulePtr module = Module::loadModuleByOffset( offset );
module->getSymbolAndDispByVa( offset, symbolName, displacement );
symbolName = module->getName() + '!' + symbolName;
}
/////////////////////////////////////////////////////////////////////////////////////
ULONG64 TypeInfo::getOffset( const std::string &fullName ) ULONG64 TypeInfo::getOffset( const std::string &fullName )
{ {
std::string moduleName; std::string moduleName;

View File

@ -29,7 +29,10 @@ public:
ULONG64 getSymbolSize( const std::string &symName ); ULONG64 getSymbolSize( const std::string &symName );
static static
std::string findSymbol( ULONG64 offset, bool safe = true ); std::string findSymbol( ULONG64 offset, bool showDisplacement = true );
static
void findSymbolAndDisp( ULONG64 offset, std::string &symbolName, LONG &displacement );
static static
ULONG64 getOffset( const std::string &symbolName ); ULONG64 getOffset( const std::string &symbolName );

View File

@ -52,14 +52,19 @@ class ModuleTest( unittest.TestCase ):
def testFindSymbol( self ): def testFindSymbol( self ):
self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) ) self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) )
self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) ) self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) )
self.assertEqual( "targetapp!FuncWithName0", pykd.findSymbol( target.module.offset("FuncWithName0") ) )
self.assertEqual( "targetapp!_FuncWithName2", pykd.findSymbol( target.module.offset("_FuncWithName2") ) )
self.assertEqual( "_FuncWithName2+10", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) ) 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 ) ) self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10, showDisplacement = False ) )
self.assertEqual( "targetapp!_FuncWithName2+10", pykd.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) )
self.assertEqual( "targetapp!_FuncWithName2", pykd.findSymbol( target.module.offset("_FuncWithName2") + 0x10, showDisplacement = False ) )
def testFindSymbolAndDisp( self ): def testFindSymbolAndDisp( self ):
vaFuncWithName0 = target.module.offset("FuncWithName0") vaFuncWithName0 = target.module.offset("FuncWithName0")
self.assertEqual( ("FuncWithName0", 0), target.module.findSymbolAndDisp(vaFuncWithName0) ) self.assertEqual( ("FuncWithName0", 0), target.module.findSymbolAndDisp(vaFuncWithName0) )
self.assertEqual( ("FuncWithName0", 2), target.module.findSymbolAndDisp(vaFuncWithName0+2) ) self.assertEqual( ("FuncWithName0", 2), target.module.findSymbolAndDisp(vaFuncWithName0+2) )
self.assertEqual( ("targetapp!FuncWithName0", 0), pykd.findSymbolAndDisp(vaFuncWithName0) )
self.assertEqual( ("targetapp!FuncWithName0", 2), pykd.findSymbolAndDisp(vaFuncWithName0+2) )
def testType( self ): def testType( self ):
self.assertEqual( "structTest", target.module.type("structTest").name() ); self.assertEqual( "structTest", target.module.type("structTest").name() );

View File

@ -72,3 +72,7 @@ if __name__ == "__main__":
target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0] target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0]
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() )
#unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite("moduletest.ModuleTest.testFindSymbol") )
raw_input()