10
class ModuleTest( unittest.TestCase ):
13
self.assertEqual( target.module.name(), pykd.module(target.module.begin() ).name() )
14
self.assertEqual( target.module.name(), pykd.module(target.module.name() ).name() )
16
#def testMiscellaneous( self ):
17
# self.assertFalse( target.module.unloaded() )
18
# self.assertTrue( target.module.um() )
21
self.assertEqual( target.moduleName, target.module.name() )
24
self.assertNotEqual( 0, target.module.size() )
25
self.assertTrue( pykd.isValid( target.module.begin() + target.module.size() - 1) )
27
def testBegin( self ):
28
self.assertNotEqual( 0, target.module.begin() )
29
self.assertEqual( target.module.begin(), target.module )
30
self.assertEqual( target.module.begin() + 100, target.module + 100 )
33
self.assertEqual( target.module.size(), target.module.end() - target.module.begin() )
34
self.assertTrue( pykd.isValid( target.module.end() - 1) )
37
self.assertNotEqual( "", target.module.symfile() )
39
def testImage( self ):
40
self.assertEqual( target.module.name() + ".exe", target.module.image() )
42
def testFindModule( self ):
43
self.assertRaises( pykd.DbgException, pykd.module, target.module.begin() - 0x10 )
45
self.assertNotEqual( None, pykd.module( target.module.begin() ) )
46
self.assertNotEqual( None, pykd.module( target.module.begin() + 0x10) )
48
self.assertRaises( pykd.DbgException, pykd.module, target.module.end() )
49
self.assertRaises( pykd.DbgException, pykd.module, target.module.end() + 0x10 )
51
def testSymbol( self ):
52
self.assertEqual( target.module.rva("FastcallFunc"), target.module.offset("FastcallFunc") - target.module.begin() )
53
self.assertEqual( target.module.rva("FastcallFunc"), target.module.FastcallFunc - target.module.begin() )
54
self.assertEqual( target.module.rva("FastcallFunc"), pykd.getOffset( target.module.name() + "!FastcallFunc") - target.module.begin() )
56
def testFindSymbol( self ):
57
self.assertEqual( "LocalStaticFunc", target.module.findSymbol( target.module.offset("LocalStaticFunc") ) )
58
self.assertEqual( "CdeclFunc", target.module.findSymbol( target.module.offset("CdeclFunc") ) )
59
self.assertEqual( "StdcallFunc", target.module.findSymbol( target.module.offset("StdcallFunc") ) )
60
self.assertEqual( "FastcallFunc", target.module.findSymbol( target.module.offset("FastcallFunc") ) )
61
self.assertEqual( "_UnderscoreFunc", target.module.findSymbol( target.module.offset("_UnderscoreFunc") ) )
62
self.assertEqual( "PureCStdcallFunc", target.module.findSymbol( target.module.offset("PureCStdcallFunc") ) )
63
self.assertEqual( "PureCCdeclFunc", target.module.findSymbol( target.module.offset("PureCCdeclFunc") ) )
64
self.assertEqual( "PureCFastcallFunc", target.module.findSymbol( target.module.offset("PureCFastcallFunc") ) )
65
#self.assertEqual( "targetapp!FuncWithName0", pykd.findSymbol( target.module.offset("FuncWithName0") ) )
66
#self.assertEqual( "targetapp!_FuncWithName2", pykd.findSymbol( target.module.offset("_FuncWithName2") ) )
67
#self.assertEqual( "_FuncWithName2+10", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) )
68
#self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10, showDisplacement = False ) )
69
#self.assertEqual( "targetapp!_FuncWithName2+10", pykd.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) )
70
#self.assertEqual( "targetapp!_FuncWithName2", pykd.findSymbol( target.module.offset("_FuncWithName2") + 0x10, showDisplacement = False ) )
73
def testFindSymbolAndDisp( self ):
74
#vaFuncWithName0 = target.module.offset("FuncWithName0")
75
#self.assertEqual( ("FuncWithName0", 0), target.module.findSymbolAndDisp(vaFuncWithName0) )
76
#self.assertEqual( ("FuncWithName0", 2), target.module.findSymbolAndDisp(vaFuncWithName0+2) )
77
#self.assertEqual( ("targetapp!FuncWithName0", 0), pykd.findSymbolAndDisp(vaFuncWithName0) )
78
#self.assertEqual( ("targetapp!FuncWithName0", 2), pykd.findSymbolAndDisp(vaFuncWithName0+2) )
82
self.assertEqual( "structTest", target.module.type("structTest").name() );
83
self.assertEqual( "structTest", target.module.type("g_structTest").name() );
85
def testSourceFile( self ):
86
fileName = pykd.getSourceFile(target.module.CdeclFunc )
87
self.assertTrue( re.search('testfunc\\.cpp', fileName ) )
88
fileName, lineNo, displacement = pykd.getSourceLine( target.module.CdeclFunc + 2)
89
self.assertEqual( 30, lineNo )
90
self.assertTrue( re.search('testfunc\\.cpp', fileName ) )
91
self.assertEqual( 2, displacement )
92
#fileName, lineNo, displacement = pykd.getSourceLine()
93
#self.assertEqual( 698, lineNo )
95
def testEnumSymbols( self ):
96
lst = target.module.enumSymbols()
97
self.assertNotEqual( 0, len(lst) )
98
lst = target.module.enumSymbols("hello*Str")
99
self.assertEqual( 2, len(lst) )
101
# 0:000> x targetapp!*Const
102
# targetapp!ulonglongConst = 0xffff`ff000000
103
# targetapp!boolConst = true
104
# targetapp!ulongConst = 0x5555
105
# targetapp!classChild::m_staticConst = <no type information>
106
lst = target.module.enumSymbols( "*Const")
107
self.assertEqual( 3, len(lst) )
109
lst = target.module.enumSymbols( "*cal?Func")
110
self.assertEqual( 4, len(lst) )
111
lst = target.module.enumSymbols( "*virtMethod*")
112
self.assertNotEqual( 0, len(lst) )
113
lst = target.module.enumSymbols( "classChild" )
114
self.assertEqual( 0, len(lst) )
116
#def testGetTypes( self ):
117
# lst1 = target.module.getUdts()
118
# self.assertNotEqual( 0, len(lst1) )
119
# self.assertTrue( "classChild" in lst1 )
120
# self.assertTrue( "classBase" in lst1 )
121
# self.assertTrue( "structTest" in lst1 )
123
# lst2 = target.module.getEnums()
124
# self.assertNotEqual( 0, len(lst2) )
125
# self.assertTrue( "enumType" in lst2 )
127
def testCompare(self):
128
self.assertTrue(target.module.begin() == target.module)
129
self.assertTrue(target.module.begin() + 1 != target.module)
130
self.assertTrue(target.module.begin() + 1 > target.module)
131
self.assertTrue(target.module.begin() + 1 >= target.module)
132
self.assertTrue(target.module.begin() - 1 < target.module)
133
self.assertTrue(target.module.begin() - 1 <= target.module)
134
self.assertTrue( True if target.module else False )
135
self.assertTrue( False if not target.module else True )
136
self.assertFalse(target.module==None)
137
self.assertTrue(target.module!=None)
139
def testModuleList(self):
140
self.assertTrue( [] != pykd.getModulesList() )
142
def testContain(self):
143
self.assertTrue("voidPtr" in target.module)
144
self.assertTrue("structTest" in target.module)
145
self.assertFalse("NotExist" in target.module)
146
self.assertRaises(Exception, lambda md : 2 in md, target.module)
148
def testGetByKey(self):
149
self.assertFalse(None == target.module["voidPtr"])
150
self.assertFalse(None == target.module["structTest"] )
151
self.assertRaises(KeyError, lambda md : target.module["Not Exist"], target.module)
153
def testEvalInModuleScope(self):
154
self.assertEqual( target.module.rva('voidPtr'), eval("voidPtr - %#x" % target.module.begin(), globals(), target.module) )
156
def testHasSymbol(self):
157
self.assertTrue(target.module.hasSymbol("voidPtr"))
158
self.assertTrue(target.module.hasSymbol("structTest"))
159
self.assertFalse(target.module.hasSymbol("notExists"))
162
modAsStr = str(target.module)