mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 21:03:23 +08:00
[+] pyDia: offset, indexId, udtKind + tests
git-svn-id: https://pykd.svn.codeplex.com/svn@69951 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
9d7ed7cb4d
commit
6091868478
@ -144,13 +144,15 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "type", &pyDia::Symbol::getType,
|
.def( "type", &pyDia::Symbol::getType,
|
||||||
"Retrieves the symbol that represents the type for this symbol" )
|
"Retrieves the symbol that represents the type for this symbol" )
|
||||||
.def( "indexType", &pyDia::Symbol::getIndexType,
|
.def( "indexType", &pyDia::Symbol::getIndexType,
|
||||||
"Retrieves the symbol interface of the array index type of the symbol" )
|
"Retrieves a reference to the class parent of the symbol" )
|
||||||
.def( "rva", &pyDia::Symbol::getRva,
|
.def( "rva", &pyDia::Symbol::getRva,
|
||||||
"Retrieves the relative virtual address (RVA) of the location")
|
"Retrieves the relative virtual address (RVA) of the location")
|
||||||
.def( "symTag", &pyDia::Symbol::getSymTag,
|
.def( "symTag", &pyDia::Symbol::getSymTag,
|
||||||
"Retrieves the symbol type classifier: SymTagXxx" )
|
"Retrieves the symbol type classifier: SymTagXxx" )
|
||||||
.def( "locType", &pyDia::Symbol::getLocType,
|
.def( "locType", &pyDia::Symbol::getLocType,
|
||||||
"Retrieves the location type of a data symbol: LocIsXxx" )
|
"Retrieves the location type of a data symbol: LocIsXxx" )
|
||||||
|
.def( "offset", &pyDia::Symbol::getOffset,
|
||||||
|
"Retrieves the offset of the symbol location" )
|
||||||
.def( "value", &pyDia::Symbol::getValue,
|
.def( "value", &pyDia::Symbol::getValue,
|
||||||
"Retrieves the value of a constant")
|
"Retrieves the value of a constant")
|
||||||
.def( "isBasic", &pyDia::Symbol::isBasicType,
|
.def( "isBasic", &pyDia::Symbol::isBasicType,
|
||||||
@ -159,6 +161,10 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Retrieves the base type for this symbol")
|
"Retrieves the base type for this symbol")
|
||||||
.def( "bitPos", &pyDia::Symbol::getBitPosition,
|
.def( "bitPos", &pyDia::Symbol::getBitPosition,
|
||||||
"Retrieves the base type for this symbol")
|
"Retrieves the base type for this symbol")
|
||||||
|
.def( "indexId", &pyDia::Symbol::getIndexId,
|
||||||
|
"Retrieves the unique symbol identifier")
|
||||||
|
.def( "udtKind", &pyDia::Symbol::getUdtKind,
|
||||||
|
"Retrieves the variety of a user-defined type")
|
||||||
.def( "__str__", &pyDia::Symbol::print)
|
.def( "__str__", &pyDia::Symbol::print)
|
||||||
.def("__getitem__", &pyDia::Symbol::getChildByName)
|
.def("__getitem__", &pyDia::Symbol::getChildByName)
|
||||||
.def("__len__", &pyDia::Symbol::getChildCount )
|
.def("__len__", &pyDia::Symbol::getChildCount )
|
||||||
@ -249,6 +255,12 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
python::scope().attr("diaBasicType") =
|
python::scope().attr("diaBasicType") =
|
||||||
genDict(pyDia::Symbol::basicTypeName, pyDia::Symbol::cntBasicTypeName);
|
genDict(pyDia::Symbol::basicTypeName, pyDia::Symbol::cntBasicTypeName);
|
||||||
|
|
||||||
|
DEF_PY_CONST_ULONG(UdtStruct);
|
||||||
|
DEF_PY_CONST_ULONG(UdtClass);
|
||||||
|
DEF_PY_CONST_ULONG(UdtUnion);
|
||||||
|
python::scope().attr("diaUdtKind") =
|
||||||
|
genDict(pyDia::Symbol::udtKindName, pyDia::Symbol::cntUdtKindName);
|
||||||
|
|
||||||
// exception:
|
// exception:
|
||||||
|
|
||||||
// base exception
|
// base exception
|
||||||
|
@ -91,6 +91,15 @@ const Symbol::ValueNameEntry Symbol::basicTypeName[] = {
|
|||||||
|
|
||||||
const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName);
|
const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName);
|
||||||
|
|
||||||
|
#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x)
|
||||||
|
const Symbol::ValueNameEntry Symbol::udtKindName[] = {
|
||||||
|
_DEF_UDT_KIND(Struct),
|
||||||
|
_DEF_UDT_KIND(Class),
|
||||||
|
_DEF_UDT_KIND(Union)
|
||||||
|
};
|
||||||
|
#undef _DEF_UDT_KIND
|
||||||
|
const size_t Symbol::cntUdtKindName = _countof(udtKindName);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define callSymbol(method) \
|
#define callSymbol(method) \
|
||||||
@ -216,6 +225,13 @@ ULONG Symbol::getLocType()
|
|||||||
return callSymbol(get_locationType);
|
return callSymbol(get_locationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getOffset()
|
||||||
|
{
|
||||||
|
return callSymbol(get_offset);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Symbol::getValueImpl(VARIANT &vtValue)
|
void Symbol::getValueImpl(VARIANT &vtValue)
|
||||||
{
|
{
|
||||||
@ -298,6 +314,20 @@ ULONG Symbol::getBitPosition()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getIndexId()
|
||||||
|
{
|
||||||
|
return callSymbol(get_symIndexId);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getUdtKind()
|
||||||
|
{
|
||||||
|
return callSymbol(get_udtKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Symbol Symbol::getChildByName(const std::string &_name)
|
Symbol Symbol::getChildByName(const std::string &_name)
|
||||||
{
|
{
|
||||||
throwIfNull(__FUNCTION__);
|
throwIfNull(__FUNCTION__);
|
||||||
|
@ -94,6 +94,8 @@ public:
|
|||||||
|
|
||||||
ULONG getLocType();
|
ULONG getLocType();
|
||||||
|
|
||||||
|
ULONG getOffset();
|
||||||
|
|
||||||
void getValueImpl(VARIANT &vtValue);
|
void getValueImpl(VARIANT &vtValue);
|
||||||
python::object getValue();
|
python::object getValue();
|
||||||
|
|
||||||
@ -103,6 +105,10 @@ public:
|
|||||||
|
|
||||||
ULONG getBitPosition();
|
ULONG getBitPosition();
|
||||||
|
|
||||||
|
ULONG getIndexId();
|
||||||
|
|
||||||
|
ULONG getUdtKind();
|
||||||
|
|
||||||
Symbol getChildByName(const std::string &_name);
|
Symbol getChildByName(const std::string &_name);
|
||||||
ULONG getChildCount();
|
ULONG getChildCount();
|
||||||
Symbol getChildByIndex(ULONG _index);
|
Symbol getChildByIndex(ULONG _index);
|
||||||
@ -113,10 +119,15 @@ public:
|
|||||||
typedef std::pair<ULONG, const char *> ValueNameEntry;
|
typedef std::pair<ULONG, const char *> ValueNameEntry;
|
||||||
|
|
||||||
static const ValueNameEntry symTagName[SymTagMax];
|
static const ValueNameEntry symTagName[SymTagMax];
|
||||||
|
|
||||||
static const ValueNameEntry locTypeName[LocTypeMax];
|
static const ValueNameEntry locTypeName[LocTypeMax];
|
||||||
|
|
||||||
static const ValueNameEntry basicTypeName[];
|
static const ValueNameEntry basicTypeName[];
|
||||||
static const size_t cntBasicTypeName;
|
static const size_t cntBasicTypeName;
|
||||||
|
|
||||||
|
static const ValueNameEntry udtKindName[];
|
||||||
|
static const size_t cntUdtKindName;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
template <typename TRet>
|
template <typename TRet>
|
||||||
|
@ -74,3 +74,28 @@ class DiaTest( unittest.TestCase ):
|
|||||||
self.assertEqual(pykd.LocIsBitField, bitField.locType())
|
self.assertEqual(pykd.LocIsBitField, bitField.locType())
|
||||||
self.assertEqual(6, bitField.bitPos())
|
self.assertEqual(6, bitField.bitPos())
|
||||||
self.assertEqual(2, bitField.size())
|
self.assertEqual(2, bitField.size())
|
||||||
|
|
||||||
|
def testIndexId(self):
|
||||||
|
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
|
||||||
|
self.assertNotEqual( globalScope["classChild"].indexId(),
|
||||||
|
globalScope["classBase"].indexId() )
|
||||||
|
self.assertNotEqual( globalScope["FuncWithName0"].indexId(),
|
||||||
|
globalScope["FuncWithName1"].indexId() )
|
||||||
|
|
||||||
|
def testUdtKind(self):
|
||||||
|
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
|
||||||
|
self.assertEqual(pykd.UdtStruct, globalScope["structWithBits"].udtKind())
|
||||||
|
self.assertEqual(pykd.UdtUnion, globalScope["unionTest"].udtKind())
|
||||||
|
self.assertEqual(pykd.UdtClass, globalScope["classBase"].udtKind())
|
||||||
|
|
||||||
|
def testOffset(self):
|
||||||
|
globalScope = pykd.diaOpenPdb( str(target.module.pdb()) )
|
||||||
|
structTest = globalScope["structTest"]
|
||||||
|
self.assertEqual( 0, structTest["m_field0"].offset() )
|
||||||
|
self.assertTrue( structTest["m_field0"].offset() <
|
||||||
|
structTest["m_field1"].offset() )
|
||||||
|
self.assertTrue( structTest["m_field1"].offset() <
|
||||||
|
structTest["m_field2"].offset() )
|
||||||
|
self.assertTrue( structTest["m_field2"].offset() <
|
||||||
|
structTest["m_field3"].offset() )
|
||||||
|
self.assertTrue(structTest["m_field3"].offset() < structTest.size())
|
||||||
|
@ -24,12 +24,49 @@ struct structWithBits {
|
|||||||
};
|
};
|
||||||
structWithBits g_structWithBits = {0};
|
structWithBits g_structWithBits = {0};
|
||||||
|
|
||||||
|
union unionTest {
|
||||||
|
ULONG m_value;
|
||||||
|
structWithBits m_bits;
|
||||||
|
};
|
||||||
|
|
||||||
|
class classBase {
|
||||||
|
public:
|
||||||
|
int m_baseField;
|
||||||
|
void baseMethod() const {}
|
||||||
|
virtual void virtFunc() = 0;
|
||||||
|
virtual void virtFunc2() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct structTest {
|
||||||
|
ULONG m_field0;
|
||||||
|
ULONGLONG m_field1;
|
||||||
|
bool m_field2;
|
||||||
|
USHORT m_field3;
|
||||||
|
};
|
||||||
|
|
||||||
|
class classChild : public classBase {
|
||||||
|
public:
|
||||||
|
int m_childField;
|
||||||
|
int m_childField2;
|
||||||
|
void childMethod() const {}
|
||||||
|
virtual void virtFunc() {}
|
||||||
|
virtual void virtFunc2() {}
|
||||||
|
};
|
||||||
|
|
||||||
void FuncWithName0()
|
void FuncWithName0()
|
||||||
{
|
{
|
||||||
|
classChild _classChild;
|
||||||
|
_classChild.baseMethod();
|
||||||
|
|
||||||
|
reinterpret_cast<classChild *>(&_classChild)->virtFunc2();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuncWithName1()
|
void FuncWithName1()
|
||||||
{
|
{
|
||||||
|
unionTest _unionTest;
|
||||||
|
_unionTest.m_value = 0;
|
||||||
|
structTest _structTest;
|
||||||
|
_structTest.m_field1 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _tmain(int argc, _TCHAR* argv[])
|
int _tmain(int argc, _TCHAR* argv[])
|
||||||
|
Loading…
Reference in New Issue
Block a user