def _ReadTraceV3File(self, tracev3_path, output_writer): '''Reads a tracev3 file. Args: tracev3_path (str): path of the tracev3 file. output_writer (OutputWriter): output writer. Returns: TraceV3: tracev3 file. ''' file_object = virtual_file.VirtualFile(tracev3_path, 'traceV3') trace_file = tracev3_file.TraceV3(self._vfs, file_object, self._ts_list, self._uuidtext_folder_path, None, self._caches) # TODO: remove log_list_process_func callback from TraceV3.Parse() self._output_writer = output_writer trace_file.Parse(log_list_process_func=self._ProcessLogsList) # trace_file.Parse(log_list_process_func=self.dumpLogToStdout) # save the uuid file into self._caches if trace_file._catalog is not None: for f in trace_file._catalog.FileObjects: s = f._file.file_type if f._file is not None else '' if s == 'Uuidtext': key = f.Uuid.hex.upper() if key not in self._caches.cached_uuidtext: self._caches.cached_uuidtext[key] = f pass elif s == 'Dsc': key = f._file.filename if key not in self._caches.cached_dsc: self._caches.cached_dsc[key] = f else: pass
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 testGetFileSize(self): '''Tests the get_file_size function.''' path = self._GetTestFilePath(['7EF56328D53A78B59CCCE3E3189F57']) file_entry = virtual_file.VirtualFile(path, filetype='uuidtext') file_entry.open() try: file_size = file_entry.get_file_size() finally: file_entry.close() self.assertEqual(file_size, 1100)
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 testParse(self): '''Tests the Parse function.''' path = self._GetTestFilePath(['7EF56328D53A78B59CCCE3E3189F57']) file_entry = virtual_file.VirtualFile(path, filetype='uuidtext') uuid_object = uuid.UUID('{007EF563-28D5-3A78-B59C-CCE3E3189F57}') test_file = uuidtext_file.Uuidtext(file_entry, uuid_object) test_file.Parse() self.assertEqual(len(test_file._entries), 1) expected_library_path = ( '/System/Library/PrivateFrameworks/PhotoLibraryPrivate.framework/' 'Versions/A/Frameworks/PhotoPrintProduct.framework/Versions/A/' 'XPCServices/com.apple.PhotoThemeService.xpc/Contents/MacOS/' 'com.apple.PhotoThemeService') self.assertEqual(test_file.library_path, expected_library_path) self.assertEqual(test_file.library_name, 'com.apple.PhotoThemeService')
def _ReadTraceV3File(self, tracev3_path, output_writer): '''Reads a tracev3 file. Args: tracev3_path (str): path of the tracev3 file. output_writer (OutputWriter): output writer. Returns: TraceV3: tracev3 file. ''' file_object = virtual_file.VirtualFile(tracev3_path, 'traceV3') trace_file = tracev3_file.TraceV3( self._vfs, file_object, self._ts_list, self._uuidtext_folder_path, self._caches) # TODO: remove log_list_process_func callback from TraceV3.Parse() self._output_writer = output_writer trace_file.Parse(log_list_process_func=self._ProcessLogsList)
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 _CreateTestFile(self): '''Creates a test tracev3 file. Returns: tuple[VirtualFile, TraceV3]: virtual and tracev3 file objects for testing. ''' file_system = virtual_file_system.VirtualFileSystem( virtual_file.VirtualFile) path = self._GetTestFilePath(['0000000000000030.tracev3']) file_entry = virtual_file.VirtualFile(path, filetype='uuidtext') timesync = self._CreateTestTimesync() timesync_list = [timesync] uuidtext_path = self._GetTestFilePath([]) test_file = tracev3_file.TraceV3(file_system, file_entry, timesync_list, uuidtext_path) return file_entry, test_file
def testReadFmtStringFromVirtualOffset(self): '''Tests the ReadFmtStringFromVirtualOffset function.''' path = self._GetTestFilePath(['7EF56328D53A78B59CCCE3E3189F57']) file_entry = virtual_file.VirtualFile(path, filetype='uuidtext') uuid_object = uuid.UUID('{007EF563-28D5-3A78-B59C-CCE3E3189F57}') test_file = uuidtext_file.Uuidtext(file_entry, uuid_object) test_file.Parse() self.assertEqual(len(test_file._entries), 1) format_string = test_file.ReadFmtStringFromVirtualOffset(21905) self.assertEqual(format_string, 'system.install.apple-software') format_string = test_file.ReadFmtStringFromVirtualOffset(0x80000000) self.assertEqual(format_string, '%s') format_string = test_file.ReadFmtStringFromVirtualOffset(999999) self.assertEqual(format_string, '<compose failure [UUID]>') test_file._file.is_valid = False format_string = test_file.ReadFmtStringFromVirtualOffset(21905) self.assertEqual(format_string, '<compose failure [UUID]>')
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)