def __init__(self, options=None): """Constructor. Args: options: ExportOptions value, which contains settings that may or or may not affect this converter's behavior. """ super(ExportConverter, self).__init__() self.options = options or rdfvalue.ExportOptions()
def testStatEntryToExportedFileConverterWithFetchedAFF4File(self): client_ids = self.SetupClients(1) client_id = client_ids[0] pathspec = rdfvalue.PathSpec( pathtype=rdfvalue.PathSpec.PathType.OS, path=os.path.join(self.base_path, "winexec_img.dd")) pathspec.Append(path="/Ext2IFS_1_10b.exe", pathtype=rdfvalue.PathSpec.PathType.TSK) client_mock = test_lib.ActionMock("TransferBuffer", "StatFile", "HashBuffer") for _ in test_lib.TestFlowHelper( "GetFile", client_mock, token=self.token, client_id=client_id, pathspec=pathspec): pass urn = aff4.AFF4Object.VFSGRRClient.PathspecToURN(pathspec, client_id) fd = aff4.FACTORY.Open(urn, token=self.token) stat = fd.Get(fd.Schema.STAT) self.assertTrue(stat) converter = export.StatEntryToExportedFileConverter() results = list(converter.Convert(rdfvalue.ExportedMetadata(), stat, token=self.token)) self.assertEqual(len(results), 1) self.assertEqual(results[0].basename, "Ext2IFS_1_10b.exe") self.assertEqual(results[0].urn, urn) # Check that by default file contents are not exported self.assertFalse(results[0].content) self.assertFalse(results[0].content_sha256) # Convert again, now specifying export_files_contents=True in options. converter = export.StatEntryToExportedFileConverter( options=rdfvalue.ExportOptions( export_files_contents=True)) results = list(converter.Convert(rdfvalue.ExportedMetadata(), stat, token=self.token)) self.assertTrue(results[0].content) self.assertEqual( results[0].content_sha256, "69264282ca1a3d4e7f9b1f43720f719a4ea47964f0bfd1b2ba88424f1c61395d")
def testStatEntryToExportedFileConverterWithHashedAFF4File(self): client_ids = self.SetupClients(1) client_id = client_ids[0] pathspec = rdfvalue.PathSpec( pathtype=rdfvalue.PathSpec.PathType.OS, path=os.path.join(self.base_path, "winexec_img.dd")) pathspec.Append(path="/Ext2IFS_1_10b.exe", pathtype=rdfvalue.PathSpec.PathType.TSK) urn = aff4.AFF4Object.VFSGRRClient.PathspecToURN(pathspec, client_id) client_mock = test_lib.ActionMock("TransferBuffer", "StatFile", "HashBuffer") for _ in test_lib.TestFlowHelper( "GetFile", client_mock, token=self.token, client_id=client_id, pathspec=pathspec): pass auth_state = rdfvalue.GrrMessage.AuthorizationState.AUTHENTICATED flow.Events.PublishEvent( "FileStore.AddFileToStore", rdfvalue.GrrMessage(payload=urn, auth_state=auth_state), token=self.token) worker = test_lib.MockWorker(token=self.token) worker.Simulate() fd = aff4.FACTORY.Open(urn, token=self.token) hash_value = fd.Get(fd.Schema.HASH) self.assertTrue(hash_value) converter = export.StatEntryToExportedFileConverter( options=rdfvalue.ExportOptions(export_files_hashes=True)) results = list(converter.Convert(rdfvalue.ExportedMetadata(), rdfvalue.StatEntry(aff4path=urn, pathspec=pathspec), token=self.token)) self.assertEqual(results[0].hash_md5, "bb0a15eefe63fd41f8dc9dee01c5cf9a") self.assertEqual(results[0].hash_sha1, "7dd6bee591dfcb6d75eb705405302c3eab65e21a") self.assertEqual( results[0].hash_sha256, "0e8dc93e150021bb4752029ebbff51394aa36f069cf19901578e4f06017acdb5")