10
class MemoryTest( unittest.TestCase ):
12
def testLoadChars( self ):
13
s = pykd.loadChars( target.module.helloStr, 5 )
14
self.assertEqual( "Hello", s )
16
def testLoadWChars( self ):
17
s = pykd.loadWChars( target.module.helloWStr, 5 )
18
self.assertEqual( "Hello", s )
20
def testLoadBytes( self ):
21
ucharArray = pykd.loadBytes( target.module.ucharArray, 5 )
22
testArray = [ 0, 10, 0x78, 128, 0xFF ]
23
self.assertEqual( 5, len(ucharArray) )
24
self.assertEqual( 0, len( [ ucharArray[i] for i in range(5) if ucharArray[i] != testArray[i] ] ) )
26
def testLoadWords( self ):
27
loadArray = pykd.loadWords( target.module.ushortArray, 5 )
28
testArray = [ 0, 10, 0xFF, 0x8000, 0xFFFF ]
29
self.assertEqual( len(testArray), len(loadArray) )
30
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
32
def testLoadDWords( self ):
33
loadArray = pykd.loadDWords( target.module.ulongArray, 5 )
34
testArray = [ 0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF ]
35
self.assertEqual( len(testArray), len(loadArray) )
36
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
38
def testLoadQWords( self ):
39
loadArray = pykd.loadQWords( target.module.ulonglongArray, 5 )
40
testArray = [ 0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF ]
41
self.assertEqual( len(testArray), len(loadArray) )
42
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
44
def testLoadSignBytes( self ):
45
charArray = pykd.loadSignBytes( target.module.ucharArray, 5 )
46
testArray = [ 0, 10, 0x78, -128, -1 ]
47
self.assertEqual( 5, len(charArray) )
48
self.assertEqual( 0, len( [ charArray[i] for i in range(len(testArray)) if charArray[i] != testArray[i] ] ) )
50
def testLoadSignWords( self ):
51
loadArray = pykd.loadSignWords( target.module.ushortArray, 5 )
52
testArray = [ 0, 10, 255, -32768, -1 ]
53
self.assertEqual( len(testArray), len(loadArray) )
54
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
56
def testLoadSignDWords( self ):
57
loadArray = pykd.loadSignDWords( target.module.ulongArray, 5 )
58
testArray = [0, 255, 32768, -2147483648, -1]
59
self.assertEqual( len(testArray), len(loadArray) )
60
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
62
def testLoadSignQWords( self ):
63
loadArray = pykd.loadSignQWords( target.module.ulonglongArray, 5 )
64
testArray = [0, 255, 4294967295, -9223372036854775808, -1]
65
self.assertEqual( len(testArray), len(loadArray) )
66
self.assertEqual( 0, len( [ loadArray[i] for i in range(len(testArray)) if loadArray[i] != testArray[i] ] ) )
68
def testWriteBytes( self ):
69
testArray = pykd.loadBytes( target.module.ucharArray, 5 )
70
pykd.writeBytes( target.module.ucharArrayPlace, testArray )
71
ucharArray = pykd.loadBytes( target.module.ucharArrayPlace, 5 )
72
self.assertEqual( 0, len( [ ucharArray[i] for i in range(5) if ucharArray[i] != testArray[i] ] ) )
74
def testWriteWords( self ):
75
testArray = pykd.loadWords( target.module.ushortArray, 5 )
76
pykd.writeWords( target.module.ushortArrayPlace, testArray )
77
ushortArray = pykd.loadWords( target.module.ushortArrayPlace, 5 )
78
self.assertEqual( 0, len( [ ushortArray[i] for i in range(5) if ushortArray[i] != testArray[i] ] ) )
80
def testWriteDWords( self ):
81
testArray = pykd.loadDWords( target.module.ulongArray, 5 )
82
pykd.writeDWords( target.module.ulongArrayPlace, testArray )
83
ulongArray = pykd.loadDWords( target.module.ulongArrayPlace, 5 )
84
self.assertEqual( 0, len( [ ulongArray[i] for i in range(5) if ulongArray[i] != testArray[i] ] ) )
86
def testWriteQWords( self ):
87
testArray = pykd.loadQWords( target.module.ulonglongArray, 5 )
88
pykd.writeQWords( target.module.ulonglongArrayPlace, testArray )
89
ulonglongArray = pykd.loadQWords( target.module.ulonglongArrayPlace, 5 )
90
self.assertEqual( 0, len( [ ulonglongArray[i] for i in range(5) if ulonglongArray[i] != testArray[i] ] ) )
92
def testWriteSignBytes( self ):
93
testArray = pykd.loadSignBytes( target.module.charArray, 5 )
94
pykd.writeSignBytes( target.module.charArrayPlace, testArray )
95
charArray = pykd.loadSignBytes( target.module.charArrayPlace, 5 )
96
self.assertEqual( 0, len( [ charArray[i] for i in range(5) if charArray[i] != testArray[i] ] ) )
98
def testWriteSignWords( self ):
99
testArray = pykd.loadSignWords( target.module.shortArray, 5 )
100
pykd.writeSignWords( target.module.shortArrayPlace, testArray )
101
shortArray = pykd.loadSignWords( target.module.shortArrayPlace, 5 )
102
self.assertEqual( 0, len( [ shortArray[i] for i in range(5) if shortArray[i] != testArray[i] ] ) )
104
def testWriteSignDWords( self ):
105
testArray = pykd.loadSignDWords( target.module.longArray, 5 )
106
pykd.writeSignDWords( target.module.longArrayPlace, testArray )
107
longArray = pykd.loadSignDWords( target.module.longArrayPlace, 5 )
108
self.assertEqual( 0, len( [ longArray[i] for i in range(5) if longArray[i] != testArray[i] ] ) )
110
def testWriteSignQWords( self ):
111
testArray = pykd.loadSignQWords( target.module.longlongArray, 5 )
112
pykd.writeSignQWords( target.module.longlongArrayPlace, testArray )
113
longlongArray = pykd.loadSignQWords( target.module.longlongArrayPlace, 5 )
114
self.assertEqual( 0, len( [ longlongArray[i] for i in range(5) if longlongArray[i] != testArray[i] ] ) )
116
def testWriteFloats( self ):
117
testArray = pykd.loadFloats( target.module.floatArray, 5 )
118
pykd.writeFloats( target.module.floatArrayPlace, testArray )
119
floatArray = pykd.loadFloats( target.module.floatArrayPlace, 5 )
120
self.assertEqual( 0, len( [ floatArray[i] for i in range(5) if floatArray[i] != testArray[i] ] ) )
122
def testWriteDoubles( self ):
123
testArray = pykd.loadDoubles( target.module.doubleArray, 5 )
124
pykd.writeDoubles( target.module.doubleArrayPlace, testArray )
125
doubleArray = pykd.loadDoubles( target.module.doubleArrayPlace, 5 )
126
self.assertEqual( 0, len( [ doubleArray[i] for i in range(5) if doubleArray[i] != testArray[i] ] ) )
128
def testPtrRead( self ):
129
self.assertEqual( 0x80, pykd.ptrByte( target.module.bigValue ) )
130
self.assertEqual( 0x8080, pykd.ptrWord( target.module.bigValue ) )
131
self.assertEqual( 0x80808080, pykd.ptrDWord( target.module.bigValue ) )
132
self.assertEqual( 0x8080808080808080, pykd.ptrQWord( target.module.bigValue ) )
133
self.assertEqual( -128, pykd.ptrSignByte( target.module.bigValue ) )
134
self.assertEqual( -32640, pykd.ptrSignWord( target.module.bigValue ) )
135
self.assertEqual( -2139062144, pykd.ptrSignDWord( target.module.bigValue ) )
136
self.assertEqual( -9187201950435737472, pykd.ptrSignQWord( target.module.bigValue ) )
138
def testSetValue( self ):
139
pykd.setByte( target.module.ullValuePlace, pykd.ptrByte( target.module.bigValue ) )
140
self.assertEqual( pykd.ptrByte( target.module.bigValue ), pykd.ptrByte( target.module.ullValuePlace ) )
142
pykd.setWord( target.module.ullValuePlace, pykd.ptrWord( target.module.bigValue ) )
143
self.assertEqual( pykd.ptrWord( target.module.bigValue ), pykd.ptrWord( target.module.ullValuePlace ) )
145
pykd.setDWord( target.module.ullValuePlace, pykd.ptrDWord( target.module.bigValue ) )
146
self.assertEqual( pykd.ptrDWord( target.module.bigValue ), pykd.ptrDWord( target.module.ullValuePlace ) )
148
pykd.setQWord( target.module.ullValuePlace, pykd.ptrQWord( target.module.bigValue ) )
149
self.assertEqual( pykd.ptrQWord( target.module.bigValue ), pykd.ptrQWord( target.module.ullValuePlace ) )
151
pykd.setSignByte( target.module.ullValuePlace, -128 )
152
self.assertEqual( -128, pykd.ptrSignByte( target.module.ullValuePlace ) )
154
pykd.setSignWord( target.module.ullValuePlace, pykd.ptrSignWord( target.module.bigValue ) )
155
self.assertEqual( pykd.ptrSignWord( target.module.bigValue ), pykd.ptrSignWord( target.module.ullValuePlace ) )
157
pykd.setSignDWord( target.module.ullValuePlace, pykd.ptrSignDWord( target.module.bigValue ) )
158
self.assertEqual( pykd.ptrSignDWord( target.module.bigValue ), pykd.ptrSignDWord( target.module.ullValuePlace ) )
160
pykd.setSignQWord( target.module.ullValuePlace, pykd.ptrSignQWord( target.module.bigValue ) )
161
self.assertEqual( pykd.ptrSignQWord( target.module.bigValue ), pykd.ptrSignQWord( target.module.ullValuePlace ) )
163
pykd.setFloat( target.module.floatValuePlace, pykd.ptrFloat( target.module.floatValue ) )
164
self.assertEqual( pykd.ptrFloat( target.module.floatValue ), pykd.ptrFloat( target.module.floatValuePlace ) )
166
pykd.setDouble( target.module.doubleValuePlace, pykd.ptrDouble( target.module.doubleValue ) )
167
self.assertEqual( pykd.ptrDouble( target.module.doubleValue ), pykd.ptrDouble( target.module.doubleValuePlace ) )
169
def testCompare( self ):
170
self.assertTrue( pykd.compareMemory( target.module.helloStr, pykd.ptrPtr(target.module.strArray), 5 ) )
171
self.assertFalse( pykd.compareMemory( target.module.helloStr, target.module.helloWStr, 5 ) )
173
def testCStr( self ):
174
self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) )
175
self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) )
177
def testBigCStr( self ):
178
self.assertEqual( 0x2000, len( pykd.loadCStr( target.module.bigCStr ) ) )
179
self.assertEqual( 0x2000, len( pykd.loadWStr( target.module.bigWStr ) ) )
181
def testVaValid( self ):
182
self.assertTrue( pykd.isValid( target.module.begin() ) )
183
self.assertFalse( pykd.isValid( 0 ) )
184
self.assertFalse( pykd.isValid( 0xDEADBEAF ) )
186
def testVaAttrib(self):
188
(pykd.memoryProtect.PageWriteCopy, pykd.memoryState.Commit, pykd.memoryType.Image), \
189
pykd.getVaAttributes(target.module.begin()) \
192
def testPtrList( self ):
193
lst = pykd.loadPtrList( target.module.g_listHead )
194
self.assertEqual( 5, len( lst ) )
196
def testPtrArray( self ):
197
lst = pykd.loadPtrs( target.module.arrIntMatrixPtrs, 3 )
198
self.assertEqual( 3, len( lst ) )
200
def testInvalidAddr( self ):
202
pykd.loadSignBytes( 0xDEADBEEF, 5 )
203
except pykd.MemoryException:
204
self.assertTrue( True )
206
def testPtrFloat(self):
207
self.assertTrue( math.fabs( pykd.ptrFloat( target.module.floatVar) + 5.99 ) < 0.001 )
208
self.assertTrue( math.fabs( pykd.ptrDouble( target.module.doubleVar) - 6.00000001 ) < 0.0000001 )
210
def testLoadFloats(self):
211
testArray = [ 1.0, 0.001, -199.999, 20000.01, 0.111111 ];
212
readArray = pykd.loadFloats( target.module.floatArray, 5 );
214
self.assertTrue( math.fabs( testArray[i] - readArray[i] ) < 0.001 )
216
def testLoadDoubles(self):
217
testArray = [ 1.0000000, 0.0000000001, -199.99999999998, 200000.00000001, 0.3333333333 ];
218
readArray = pykd.loadDoubles( target.module.doubleArray, 5 );
220
self.assertTrue( math.fabs( testArray[i] - readArray[i] ) < 0.0000001 )