def ParseFolder(self, uuidtext_folder_path): '''Parse the uuidtext folder specified and parse all uuidtext/dsc files, adding them to the cache''' try: # dsc dsc_path = self.vfs.path_join(uuidtext_folder_path, 'dsc') entries = self.vfs.listdir(dsc_path) for dsc_name in entries: if len(dsc_name) == 32: dsc_path = self.vfs.get_virtual_file(self.vfs.path_join(dsc_path, dsc_name), 'Dsc') dsc = dsc_file.Dsc(dsc_path) dsc.Parse() self.cached_dsc[dsc_name] = dsc # uuidtext - can't have this or python will complain of too many open files! # entries = self.vfs.listdir(uuidtext_folder_path) # index = 0 # for index in range(0x100): # folder_name = '{:02X}'.format(index) # #if vfs.path_exists(folder_path): # if folder_name in entries: # folder_path = self.vfs.path_join(uuidtext_folder_path, folder_name) # uuid_names = self.vfs.listdir(folder_path) # for uuid_name in uuid_names: # if len(uuid_name) == 30: # filtering out possibly other files there! # uuidtext_path = self.vfs.path_join(folder_path, uuid_name) # file_object = self.vfs.get_virtual_file(uuidtext_path, 'Uuidtext') # ut = uuidtext_file.Uuidtext(file_object, UUID(folder_name + uuid_name)) # ut.Parse() # self.cached_uuidtext[folder_name + uuid_name] = ut # else: # logger.debug(folder_name + ' does not exist') except Exception: logger.exception('')
def testDebugPrintDsc(self): '''Tests the DebugPrintDsc function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) test_file.DebugPrintDsc()
def testParse(self): '''Tests the Parse function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) self.assertTrue(test_file.Parse()) self.assertTrue(test_file._file.is_valid) self.assertEqual(len(test_file.range_entries), 1) self.assertEqual(len(test_file.uuid_entries), 1)
def testParseFileObject(self): '''Tests the _ParseFileObject function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) with open(path, 'rb') as file_object: self.assertTrue(test_file._ParseFileObject(file_object)) self.assertTrue(test_file._file.is_valid) self.assertEqual(len(test_file.range_entries), 1) self.assertEqual(len(test_file.uuid_entries), 1)
def testGetUuidEntryFromVirtualOffset(self): '''Tests the GetUuidEntryFromVirtualOffset function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) test_uuid_entry = test_file.GetUuidEntryFromVirtualOffset(0x00030000) self.assertIsNone(test_uuid_entry) self.assertTrue(test_file.Parse()) test_uuid_entry = test_file.GetUuidEntryFromVirtualOffset(0x00030000) self.assertIsNotNone(test_uuid_entry) test_uuid_entry = test_file.GetUuidEntryFromVirtualOffset(0xffffffff) self.assertIsNone(test_uuid_entry)
def testReadFmtStringAndEntriesFromVirtualOffset(self): '''Tests the ReadFmtStringAndEntriesFromVirtualOffset function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) with self.assertRaises(KeyError): test_file.ReadFmtStringAndEntriesFromVirtualOffset(0x00048a40) self.assertTrue(test_file.Parse()) test_string, test_range_entry, test_uuid_entry = ( test_file.ReadFmtStringAndEntriesFromVirtualOffset(0x00048a40)) self.assertEqual(test_string, '%s Unknown app vocabulary type - %@') self.assertIsNotNone(test_range_entry) self.assertIsNotNone(test_uuid_entry) with self.assertRaises(KeyError): test_file.ReadFmtStringAndEntriesFromVirtualOffset(0xffffffff)
def testFindVirtualOffsetEntries(self): '''Tests the FindVirtualOffsetEntries function.''' path = self._GetTestFilePath(['8E21CAB1DCF936B49F85CF860E6F34EC']) file_entry = virtual_file.VirtualFile(path, filetype='dsc') test_file = dsc_file.Dsc(file_entry) test_range_entry, test_uuid_entry = test_file.FindVirtualOffsetEntries( 0x00048a40) self.assertIsNone(test_range_entry) self.assertIsNone(test_uuid_entry) self.assertTrue(test_file.Parse()) test_range_entry, test_uuid_entry = test_file.FindVirtualOffsetEntries( 0x00048a40) self.assertIsNotNone(test_range_entry) self.assertIsNotNone(test_uuid_entry) test_range_entry, test_uuid_entry = test_file.FindVirtualOffsetEntries( 0xffffffff) self.assertIsNone(test_range_entry) self.assertIsNone(test_uuid_entry)