class NoDataRead(unittest.TestCase): """Trying to use the class without reading the 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() def tearDown( self ): self.basefile.unlock() def testIsDLLRecorded( self ): self.assertRaises( BasefileException , self.basefile.isDLLRecorded , self.dllName ) 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 ): self.assertRaises( BasefileException , self.basefile.getNextBaseAddress , self.dllName ) def testRecordDLL( self ): self.assertRaises( BasefileException , self.basefile.recordDLL , self.dllName , self.newBase , self.newSize )
def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\fs\\adminfs\\rel32\\bogus.dll' self.newSize = 0x30000 self.newBase = 0x60000000 self.basefile.lock() self.basefile.readData()
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 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()
def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) shutil.copy( caseTwoFile , scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\fs\\adminfs\\rel32\\adminfs.dll' self.size = 0x20000 self.newSize = 0x40000 self.base = 0x600e0000 self.newBase = 0x60000000 self.basefile.lock() self.basefile.readData()
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 NewFile(unittest.TestCase): """When there is no existing file. """ def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\fs\\adminfs\\rel32\\bogus.dll' self.newSize = 0x30000 self.newBase = 0x60000000 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 0x60000000 0x30000 ': count += 1 assertEquals( '# of occurences of dll found in file: ', count, 1 )
class DataOnly(unittest.TestCase): """When there is an existing file and the target dll data is the only data. """ def setUp(self): if os.path.exists( scratchFile ): os.remove( scratchFile ) shutil.copy( caseTwoFile , scratchFile ) self.basefile = Basefile( scratchFile , 0x60000000 ) self.dllName = 'server\\fs\\adminfs\\rel32\\adminfs.dll' self.size = 0x20000 self.newSize = 0x40000 self.base = 0x600e0000 self.newBase = 0x60000000 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 == 'server\\fs\\adminfs\\rel32\\adminfs.dll 0x60000000 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)