class DataPresent(unittest.TestCase): """When there is an existing file and the target dll data is mingled in with other data. """ def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) shutil.copy( caseOneFile , scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'common\\lang\\xml\\rel32\\hxxml.dll' self.size = 0x20000 self.newSize = 0x40000 self.base = 0x60000000 self.newBase = 0x601c0000 self.basefile.lock() self.basefile.readData() def tearDown( self ): self.basefile.unlock() def testIsDLLRecorded( self ): assertEquals( 'isDLLRecorded: ', self.basefile.isDLLRecorded( self.dllName ), 1 ) def testGetBaseAddressOfFile( self ): assertEquals( 'Base address: ', self.basefile.getBaseAddressOfFile( self.dllName ), self.base ) def testGetSizeOfFile( self ): assertEquals( 'DLL Size: ', self.basefile.getSizeOfFile( self.dllName ), self.size ) def testGetNextBaseAddress( self ): assertEquals( 'Base address: ', self.basefile.getNextBaseAddress( self.dllName ) , self.newBase ) def testRecordDLL( self ): self.basefile.recordDLL( self.dllName , self.newBase , self.newSize ) assertEquals( 'Base address: ', self.basefile.getNextBaseAddress( 'bogus' ), self.newBase + self.newSize ) def testNumberOfTimesInFile( self ): self.basefile.recordDLL( self.dllName , self.newBase , self.newSize ) count = 0 for line in open( scratchFile , "r" ).readlines(): l = string.split(line,";")[0] l = string.replace(l,"\t"," ") if l == 'common\\lang\\xml\\rel32\\hxxml.dll 0x601c0000 0x40000 ': count += 1 assertEquals( '# of occurences of dll found in file: ', count, 1 )
class DataPresent(unittest.TestCase): """When there is an existing file and the target dll data is mingled in with other data. """ def setUp(self): if os.path.exists(scratchFile): os.remove(scratchFile) shutil.copy(caseOneFile, scratchFile) self.basefile = Basefile(scratchFile, 0x60000000) self.dllName = 'common\\lang\\xml\\rel32\\hxxml.dll' self.size = 0x20000 self.newSize = 0x40000 self.base = 0x60000000 self.newBase = 0x601c0000 self.basefile.lock() self.basefile.readData() def tearDown(self): self.basefile.unlock() def testIsDLLRecorded(self): assertEquals('isDLLRecorded: ', self.basefile.isDLLRecorded(self.dllName), 1) def testGetBaseAddressOfFile(self): assertEquals('Base address: ', self.basefile.getBaseAddressOfFile(self.dllName), self.base) def testGetSizeOfFile(self): assertEquals('DLL Size: ', self.basefile.getSizeOfFile(self.dllName), self.size) def testGetNextBaseAddress(self): assertEquals('Base address: ', self.basefile.getNextBaseAddress(self.dllName), self.newBase) def testRecordDLL(self): self.basefile.recordDLL(self.dllName, self.newBase, self.newSize) assertEquals('Base address: ', self.basefile.getNextBaseAddress('bogus'), self.newBase + self.newSize) def testNumberOfTimesInFile(self): self.basefile.recordDLL(self.dllName, self.newBase, self.newSize) count = 0 for line in open(scratchFile, "r").readlines(): l = string.split(line, ";")[0] l = string.replace(l, "\t", " ") if l == 'common\\lang\\xml\\rel32\\hxxml.dll 0x601c0000 0x40000 ': count += 1 assertEquals('# of occurences of dll found in file: ', count, 1)
class NotPresent(unittest.TestCase): """When there is an existing file but the target dll is not present. """ def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) shutil.copy( caseOneFile , scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\fs\\adminfs\\rel32\\bogus.dll' self.newSize = 0x40000 self.newBase = 0x601c0000 self.basefile.lock() self.basefile.readData() def tearDown( self ): self.basefile.unlock() def testIsDLLRecorded( self ): assertEquals( 'isDLLRecorded: ', self.basefile.isDLLRecorded( self.dllName ), 0 ) def testGetBaseAddressOfFile( self ): self.assertRaises( BasefileException, self.basefile.getBaseAddressOfFile, self.dllName ) def testGetSizeOfFile( self ): self.assertRaises( BasefileException, self.basefile.getSizeOfFile, self.dllName ) def testGetNextBaseAddress( self ): assertEquals( 'Base address: ', self.basefile.getNextBaseAddress( self.dllName ) , self.newBase ) def testRecordDLL( self ): self.basefile.recordDLL( self.dllName , self.newBase , self.newSize ) assertEquals( 'Base address: ', self.basefile.getNextBaseAddress( 'bogus' ), self.newBase + self.newSize ) def testNumberOfTimesInFile( self ): self.basefile.recordDLL( self.dllName , self.newBase , self.newSize ) count = 0 for line in open( scratchFile , "r" ).readlines(): l = string.split(line,";")[0] l = string.replace(l,"\t"," ") if l == 'server\\fs\\adminfs\\rel32\\bogus.dll 0x601c0000 0x40000 ': count += 1 assertEquals( '# of occurences of dll found in file: ', count, 1 )
class NotPresent(unittest.TestCase): """When there is an existing file but the target dll is not present. """ def setUp(self): if os.path.exists(scratchFile): os.remove(scratchFile) shutil.copy(caseOneFile, scratchFile) self.basefile = Basefile(scratchFile, 0x60000000) self.dllName = 'server\\fs\\adminfs\\rel32\\bogus.dll' self.newSize = 0x40000 self.newBase = 0x601c0000 self.basefile.lock() self.basefile.readData() def tearDown(self): self.basefile.unlock() def testIsDLLRecorded(self): assertEquals('isDLLRecorded: ', self.basefile.isDLLRecorded(self.dllName), 0) def testGetBaseAddressOfFile(self): self.assertRaises(BasefileException, self.basefile.getBaseAddressOfFile, self.dllName) def testGetSizeOfFile(self): self.assertRaises(BasefileException, self.basefile.getSizeOfFile, self.dllName) def testGetNextBaseAddress(self): assertEquals('Base address: ', self.basefile.getNextBaseAddress(self.dllName), self.newBase) def testRecordDLL(self): self.basefile.recordDLL(self.dllName, self.newBase, self.newSize) assertEquals('Base address: ', self.basefile.getNextBaseAddress('bogus'), self.newBase + self.newSize) def testNumberOfTimesInFile(self): self.basefile.recordDLL(self.dllName, self.newBase, self.newSize) count = 0 for line in open(scratchFile, "r").readlines(): l = string.split(line, ";")[0] l = string.replace(l, "\t", " ") if l == 'server\\fs\\adminfs\\rel32\\bogus.dll 0x601c0000 0x40000 ': count += 1 assertEquals('# of occurences of dll found in file: ', count, 1)
class Highest( unittest.TestCase ): """Getting the nextBaseAddress when current DLL is the highest. """ def setUp( self ): if os.path.exists( scratchFile ): os.remove( scratchFile ) shutil.copy( caseOneFile , scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\access\\auth\\ntauth\\rel32\\svrntauth.dll' self.base = 0x60000000 self.newBase = 0x601b0000 self.basefile.lock() self.basefile.readData() def tearDown( self ): self.basefile.unlock() def testGetNextBaseAddress( self ): assertEquals( 'Next base address: ' , self.basefile.getNextBaseAddress( self.dllName ), self.newBase )
class Highest(unittest.TestCase): """Getting the nextBaseAddress when current DLL is the highest. """ def setUp(self): if os.path.exists(scratchFile): os.remove(scratchFile) shutil.copy(caseOneFile, scratchFile) self.basefile = Basefile(scratchFile, 0x60000000) self.dllName = 'server\\access\\auth\\ntauth\\rel32\\svrntauth.dll' self.base = 0x60000000 self.newBase = 0x601b0000 self.basefile.lock() self.basefile.readData() def tearDown(self): self.basefile.unlock() def testGetNextBaseAddress(self): assertEquals('Next base address: ', self.basefile.getNextBaseAddress(self.dllName), self.newBase)