mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.3.x] added : typedVar.castTo method ( cast variable to the type and return new typedVar instance )
git-svn-id: https://pykd.svn.codeplex.com/svn@90986 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
b1bf26e0af
commit
c53436ffe5
@ -827,6 +827,10 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return value by pointer" )
|
||||
.def("type", TypedVarAdapter::getType,
|
||||
"Return typeInfo instance" )
|
||||
.def("castTo", TypedVarAdapter::castByName,
|
||||
"Cast variable to the type and return new typedVar instance")
|
||||
.def("castTo", TypedVarAdapter::castByTypeInfo,
|
||||
"Cast variable to the type and return new typedVar instance")
|
||||
.def("__getattr__", TypedVarAdapter::getFieldAttr,
|
||||
"Return field of structure as an object attribute" )
|
||||
.def( "__str__", TypedVarAdapter::print )
|
||||
|
@ -173,6 +173,18 @@ struct TypedVarAdapter {
|
||||
{
|
||||
return !isZero(typedVar);
|
||||
}
|
||||
|
||||
static kdlib::TypedVarPtr castByName(kdlib::TypedVar& typedVar, const std::wstring &typeName)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return typedVar.castTo(typeName);
|
||||
}
|
||||
|
||||
static kdlib::TypedVarPtr castByTypeInfo(kdlib::TypedVar& typedVar, const kdlib::TypeInfoPtr& typeInfo)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return typedVar.castTo(typeInfo);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace pykd
|
||||
|
@ -369,3 +369,7 @@ class TypedVarTest( unittest.TestCase ):
|
||||
tv = target.module.typedVar( "structTest", target.module.g_structTest )
|
||||
self.assertFalse(tv==None)
|
||||
self.assertTrue(tv!=None)
|
||||
|
||||
def testCastTo(self):
|
||||
self.assertEqual(0xD2, target.module.typedVar( "ulonglongVar" ).castTo("UInt1B"))
|
||||
self.assertEqual(0, target.module.typedVar( "g_structTest" ).castTo("UInt4B"))
|
||||
|
Loading…
Reference in New Issue
Block a user