mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 21:03:23 +08:00
[+] pyDia: Symbol::count
[~] pyDia: exception handling in tests git-svn-id: https://pykd.svn.codeplex.com/svn@69989 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
2686b33f4a
commit
4cf5bca175
@ -153,6 +153,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Retrieves the location type of a data symbol: LocIsXxx" )
|
"Retrieves the location type of a data symbol: LocIsXxx" )
|
||||||
.def( "offset", &pyDia::Symbol::getOffset,
|
.def( "offset", &pyDia::Symbol::getOffset,
|
||||||
"Retrieves the offset of the symbol location" )
|
"Retrieves the offset of the symbol location" )
|
||||||
|
.def( "count", &pyDia::Symbol::getCount,
|
||||||
|
"Retrieves the number of items in a list or array" )
|
||||||
.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,
|
||||||
|
@ -193,12 +193,11 @@ std::string Symbol::printImpl(
|
|||||||
sstream << ", ";
|
sstream << ", ";
|
||||||
|
|
||||||
sstream << symTagName[dwValue].second;
|
sstream << symTagName[dwValue].second;
|
||||||
if (SymTagUDT == symTagName[dwValue].first)
|
if ((S_OK == _symbol->get_udtKind(&dwValue)) && (dwValue < cntUdtKindName))
|
||||||
{
|
|
||||||
hres = _symbol->get_udtKind(&dwValue);
|
|
||||||
if ((S_OK == hres) && (dwValue < cntUdtKindName))
|
|
||||||
sstream << ": " << udtKindName[dwValue].second;
|
sstream << ": " << udtKindName[dwValue].second;
|
||||||
}
|
|
||||||
|
if (S_OK == _symbol->get_count(&dwValue))
|
||||||
|
sstream << ", Count: " << std::dec << dwValue;
|
||||||
|
|
||||||
bFuncDebugRange =
|
bFuncDebugRange =
|
||||||
(SymTagFuncDebugStart == symTagName[dwValue].first) ||
|
(SymTagFuncDebugStart == symTagName[dwValue].first) ||
|
||||||
|
@ -142,6 +142,13 @@ LONG Symbol::getOffset()
|
|||||||
return callSymbol(get_offset);
|
return callSymbol(get_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ULONG Symbol::getCount()
|
||||||
|
{
|
||||||
|
return callSymbol(get_count);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Symbol::getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue)
|
void Symbol::getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +99,8 @@ public:
|
|||||||
|
|
||||||
LONG getOffset();
|
LONG getOffset();
|
||||||
|
|
||||||
|
ULONG getCount();
|
||||||
|
|
||||||
static void getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue);
|
static void getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue);
|
||||||
python::object getValue();
|
python::object getValue();
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import pykd
|
|||||||
|
|
||||||
class DiaTest( unittest.TestCase ):
|
class DiaTest( unittest.TestCase ):
|
||||||
def testFind(self):
|
def testFind(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertNotEqual(0, len(gScope))
|
self.assertNotEqual(0, len(gScope))
|
||||||
symFunction = gScope.find("FuncWithName0")
|
symFunction = gScope.find("FuncWithName0")
|
||||||
@ -16,50 +17,91 @@ class DiaTest( unittest.TestCase ):
|
|||||||
"FuNc*Name?",
|
"FuNc*Name?",
|
||||||
pykd.nsCaseInRegularExpression)
|
pykd.nsCaseInRegularExpression)
|
||||||
self.assertTrue(len(symFunction) > 1)
|
self.assertTrue(len(symFunction) > 1)
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testSize(self):
|
def testSize(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual(1, gScope["g_ucharValue"].type().size())
|
self.assertEqual(1, gScope["g_ucharValue"].type().size())
|
||||||
self.assertEqual(2, gScope["g_ushortValue"].type().size())
|
self.assertEqual(2, gScope["g_ushortValue"].type().size())
|
||||||
self.assertEqual(4, gScope["g_ulongValue"].type().size())
|
self.assertEqual(4, gScope["g_ulongValue"].type().size())
|
||||||
self.assertEqual(8, gScope["g_ulonglongValue"].type().size())
|
self.assertEqual(8, gScope["g_ulonglongValue"].type().size())
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testValue(self):
|
def testValue(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual(0x5555, gScope["g_constNumValue"].value())
|
self.assertEqual(0x5555, gScope["g_constNumValue"].value())
|
||||||
self.assertEqual(True, gScope["g_constBoolValue"].value())
|
self.assertEqual(True, gScope["g_constBoolValue"].value())
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testName(self):
|
def testName(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual("g_constNumValue", gScope["g_constNumValue"].name())
|
self.assertEqual( "g_constNumValue",
|
||||||
self.assertEqual("FuncWithName0", gScope["FuncWithName0"].name())
|
gScope["g_constNumValue"].name() )
|
||||||
|
self.assertEqual( "FuncWithName0",
|
||||||
|
gScope["FuncWithName0"].name() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testRva(self):
|
def testRva(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
_rva = gScope["FuncWithName0"].rva()
|
_rva = gScope["FuncWithName0"].rva()
|
||||||
self.assertNotEqual(0, _rva)
|
self.assertNotEqual(0, _rva)
|
||||||
self.assertTrue( _rva < (target.module.end() - target.module.begin()) )
|
modLen = target.module.end() - target.module.begin()
|
||||||
|
self.assertTrue( _rva < modLen )
|
||||||
_rva = gScope["g_string"].rva()
|
_rva = gScope["g_string"].rva()
|
||||||
self.assertNotEqual(0, _rva)
|
self.assertNotEqual(0, _rva)
|
||||||
self.assertTrue( _rva < (target.module.end() - target.module.begin()) )
|
self.assertTrue( _rva < modLen )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testSymTag(self):
|
def testSymTag(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual(pykd.SymTagFunction, gScope["FuncWithName0"].symTag())
|
self.assertEqual( pykd.SymTagFunction,
|
||||||
self.assertEqual(pykd.SymTagData, gScope["g_string"].symTag())
|
gScope["FuncWithName0"].symTag() )
|
||||||
|
self.assertEqual( pykd.SymTagData,
|
||||||
|
gScope["g_string"].symTag() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testLocType(self):
|
def testLocType(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual(pykd.LocIsConstant, gScope["g_constNumValue"].locType())
|
self.assertEqual( pykd.LocIsConstant,
|
||||||
self.assertEqual(pykd.LocIsStatic, gScope["FuncWithName1"].locType())
|
gScope["g_constNumValue"].locType() )
|
||||||
|
self.assertEqual( pykd.LocIsStatic,
|
||||||
|
gScope["FuncWithName1"].locType() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testBasicType(self):
|
def testBasicType(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertFalse(gScope["g_string"].type().isBasic())
|
self.assertFalse(gScope["g_string"].type().isBasic())
|
||||||
self.assertEqual(pykd.btBool, gScope["g_constBoolValue"].type().baseType())
|
self.assertEqual( pykd.btBool,
|
||||||
self.assertEqual(pykd.btULong, gScope["g_ulongValue"].type().baseType())
|
gScope["g_constBoolValue"].type().baseType() )
|
||||||
|
self.assertEqual( pykd.btULong,
|
||||||
|
gScope["g_ulongValue"].type().baseType() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testBits(self):
|
def testBits(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
structWithBits = gScope["structWithBits"]
|
structWithBits = gScope["structWithBits"]
|
||||||
bitField = structWithBits["m_bit0_4"]
|
bitField = structWithBits["m_bit0_4"]
|
||||||
@ -74,21 +116,33 @@ 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())
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testIndexId(self):
|
def testIndexId(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertNotEqual( gScope["classChild"].indexId(),
|
self.assertNotEqual( gScope["classChild"].indexId(),
|
||||||
gScope["classBase"].indexId() )
|
gScope["classBase"].indexId() )
|
||||||
self.assertNotEqual( gScope["FuncWithName0"].indexId(),
|
self.assertNotEqual( gScope["FuncWithName0"].indexId(),
|
||||||
gScope["FuncWithName1"].indexId() )
|
gScope["FuncWithName1"].indexId() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testUdtKind(self):
|
def testUdtKind(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertEqual(pykd.UdtStruct, gScope["structWithBits"].udtKind())
|
self.assertEqual(pykd.UdtStruct, gScope["structTest"].udtKind())
|
||||||
self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind())
|
self.assertEqual(pykd.UdtUnion, gScope["unionTest"].udtKind())
|
||||||
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind())
|
self.assertEqual(pykd.UdtClass, gScope["classBase"].udtKind())
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testOffset(self):
|
def testOffset(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
structTest = gScope["structTest"]
|
structTest = gScope["structTest"]
|
||||||
self.assertEqual( 0, structTest["m_field0"].offset() )
|
self.assertEqual( 0, structTest["m_field0"].offset() )
|
||||||
@ -98,27 +152,51 @@ class DiaTest( unittest.TestCase ):
|
|||||||
structTest["m_field2"].offset() )
|
structTest["m_field2"].offset() )
|
||||||
self.assertTrue( structTest["m_field2"].offset() <
|
self.assertTrue( structTest["m_field2"].offset() <
|
||||||
structTest["m_field3"].offset() )
|
structTest["m_field3"].offset() )
|
||||||
self.assertTrue(structTest["m_field3"].offset() < structTest.size())
|
self.assertTrue( structTest["m_field3"].offset() <
|
||||||
|
structTest.size() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testMachine(self):
|
def testMachine(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
self.assertTrue( (gScope.machineType() == pykd.IMAGE_FILE_MACHINE_I386) or
|
machine = gScope.machineType()
|
||||||
(gScope.machineType() == pykd.IMAGE_FILE_MACHINE_AMD64) )
|
self.assertTrue( (machine == pykd.IMAGE_FILE_MACHINE_I386) or
|
||||||
|
(machine == pykd.IMAGE_FILE_MACHINE_AMD64) )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testFindByRva(self):
|
def testFindByRva(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
func = gScope["FuncWithName0"]
|
func = gScope["FuncWithName0"]
|
||||||
|
|
||||||
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction)
|
tplSymOffset = gScope.findByRva(func.rva(), pykd.SymTagFunction)
|
||||||
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
|
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
|
||||||
self.assertEqual(tplSymOffset[1], 0)
|
self.assertEqual(tplSymOffset[1], 0)
|
||||||
|
tplSymOffset = gScope.findByRva(func.rva()+2, pykd.SymTagFunction)
|
||||||
tplSymOffset = gScope.findByRva(func.rva() + 2, pykd.SymTagFunction)
|
|
||||||
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
|
self.assertEqual(tplSymOffset[0].indexId(), func.indexId())
|
||||||
self.assertEqual(tplSymOffset[1], 2)
|
self.assertEqual(tplSymOffset[1], 2)
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
def testSymbolById(self):
|
def testSymbolById(self):
|
||||||
|
try:
|
||||||
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
func = gScope["FuncWithName0"]
|
func = gScope["FuncWithName0"]
|
||||||
self.assertEqual( gScope.symbolById(func.indexId()).indexId(),
|
self.assertEqual( gScope.symbolById(func.indexId()).indexId(),
|
||||||
func.indexId())
|
func.indexId())
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
|
||||||
|
def testCount(self):
|
||||||
|
try:
|
||||||
|
gScope = pykd.diaLoadPdb( str(target.module.pdb()) )
|
||||||
|
var = gScope["FuncWithName1"]["_unionTest"]
|
||||||
|
self.assertEqual( 2, var.type().count() )
|
||||||
|
except pykd.DiaException as diaExcept:
|
||||||
|
print diaExcept
|
||||||
|
self.assertTrue(False)
|
||||||
|
@ -69,8 +69,8 @@ void FuncWithName0()
|
|||||||
|
|
||||||
void FuncWithName1(int a)
|
void FuncWithName1(int a)
|
||||||
{
|
{
|
||||||
unionTest _unionTest;
|
unionTest _unionTest[2];
|
||||||
_unionTest.m_value = 0;
|
_unionTest[1].m_value = 0;
|
||||||
structTest _structTest;
|
structTest _structTest;
|
||||||
_structTest.m_field1 = a;
|
_structTest.m_field1 = a;
|
||||||
struct2 _struct2;
|
struct2 _struct2;
|
||||||
|
Loading…
Reference in New Issue
Block a user