def ReturnHello(self, _): return [rdfvalue.RDFString("Hello World")]
def Run(self, args): del args # Unused. self.SendReply(rdfvalue.RDFString("zażółć gęślą jaźń 🎮"))
def SendSomething(self, responses=None): del responses # Unused. self.SendReply(rdfvalue.RDFString("foo"), tag="tag:foo") self.SendReply(rdfvalue.RDFString("bar"), tag="tag:bar")
def ReceiveHello(self, responses): # Relay the client's message to our parent for response in responses: self.SendReply(rdfvalue.RDFString("Child received")) self.SendReply(response)
def Run(self): client_id = self.SetupClient(0).Basename() if data_store.RelationalDBReadEnabled("hunts"): hunt_id = self.CreateHunt() flow_id = flow_test_lib.StartFlow(flows_processes.ListProcesses, client_id=client_id, parent_hunt_id=hunt_id) with test_lib.FakeTime( rdfvalue.RDFDatetime.FromSecondsSinceEpoch(2)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah1")) ]) with test_lib.FakeTime( rdfvalue.RDFDatetime.FromSecondsSinceEpoch(43)): data_store.REL_DB.WriteFlowResults([ rdf_flow_objects.FlowResult( client_id=client_id, flow_id=flow_id, hunt_id=hunt_id, payload=rdfvalue.RDFString("blah2-foo")) ]) else: hunt_urn = rdfvalue.RDFURN("aff4:/hunts/H:123456") hunt_id = hunt_urn.Basename() results = implementation.GRRHunt.ResultCollectionForHID(hunt_urn) with data_store.DB.GetMutationPool() as pool: result = rdf_flows.GrrMessage( source=client_id, payload=rdfvalue.RDFString("blah1"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(1)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) result = rdf_flows.GrrMessage( source=client_id, payload=rdfvalue.RDFString("blah2-foo"), age=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42)) results.Add(result, timestamp=result.age + rdfvalue.Duration("1s"), mutation_pool=pool) replace = {hunt_id: "H:123456"} self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, count=1), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, offset=1, count=1), replace=replace) self.Check("ListHuntResults", args=hunt_plugin.ApiListHuntResultsArgs(hunt_id=hunt_id, filter="foo"), replace=replace)
def testLessThanWithBytes(self): self.assertLess(rdfvalue.RDFString(u"abc"), b"def") self.assertGreater(rdfvalue.RDFString(u"xyz"), b"ghi") self.assertLess(rdfvalue.RDFString(u"012"), b"\x80\x81\x81")
def Run(self, _): self.SendReply(rdfvalue.RDFString("Hello World"))
def Parse(self, stat, knowledge_base): _ = knowledge_base value = stat.registry_data.GetValue() yield rdfvalue.RDFString("cp_%s" % value)
def testRDFStringGetItem(self): rdfstring = rdfvalue.RDFString("123456789") self.assertEqual(rdfstring[3], "4") self.assertEqual(rdfstring[-3:], "789") self.assertEqual(rdfstring[3:-3], "456")
def testLenOfEmoji(self): self.assertLen(rdfvalue.RDFString("🚀🚀"), 2)
def GenerateSample(self, number=0): return rdfvalue.RDFString(u"Grüezi %s" % number)
def ParseResponse( self, knowledge_base: rdf_client.KnowledgeBase, response: rdf_client_fs.StatEntry, ) -> Iterable[rdfvalue.RDFString]: return [rdfvalue.RDFString(f"{knowledge_base.os}:{response.st_dev}")]
def testStr(self): """Test RDFValue.__str__.""" self.assertEqual(str(rdfvalue.RDFInteger(1)), "1") self.assertEqual(str(rdfvalue.RDFString(long_string)), long_string)
def SendSomething(self, responses=None): del responses self.SendReply(rdfvalue.RDFString("oh"))
def testStr(self): """Test RDFValue.__str__.""" self.assertEqual(unicode(rdfvalue.RDFBool(True)), "1") self.assertEqual(unicode(rdfvalue.RDFString(long_string)), long_string)
def _GenerateApiFileDetails(path_infos): """Generate file details based on path infos history.""" type_attrs = [] hash_attrs = [] size_attrs = [] stat_attrs = [] pathspec_attrs = [] def _Value(age, value): """Generate ApiAff4ObjectAttributeValue from an age and a value.""" v = ApiAff4ObjectAttributeValue() # TODO(user): get rid of RDF builtin "age" property. v.Set("age", age) # With dynamic values we first have to set the type and # then the value itself. # TODO(user): refactor dynamic values logic so that it's not needed, # possibly just removing the "type" attribute completely. v.Set("type", compatibility.GetName(value.__class__)) v.value = value return v for pi in path_infos: if pi.directory: object_type = "VFSDirectory" else: object_type = "VFSFile" type_attrs.append(_Value(pi.timestamp, rdfvalue.RDFString(object_type))) if pi.hash_entry: hash_attrs.append(_Value(pi.timestamp, pi.hash_entry)) size_attrs.append( _Value(pi.timestamp, rdfvalue.RDFInteger(pi.hash_entry.num_bytes))) if pi.stat_entry: stat_attrs.append(_Value(pi.timestamp, pi.stat_entry)) if pi.stat_entry.pathspec: pathspec_attrs.append( _Value(pi.timestamp, pi.stat_entry.pathspec)) return ApiAff4ObjectRepresentation(types=[ ApiAff4ObjectType( name="AFF4Object", attributes=[ ApiAff4ObjectAttribute( name="TYPE", values=type_attrs, ), ], ), ApiAff4ObjectType( name="AFF4Stream", attributes=[ ApiAff4ObjectAttribute( name="HASH", values=hash_attrs, ), ApiAff4ObjectAttribute( name="SIZE", values=size_attrs, ), ], ), ApiAff4ObjectType( name="VFSFile", attributes=[ ApiAff4ObjectAttribute( name="PATHSPEC", values=pathspec_attrs, ), ApiAff4ObjectAttribute( name="STAT", values=stat_attrs, ), ], ), ])
def testEqualWithBytes(self): self.assertEqual(rdfvalue.RDFString(u"foo"), b"foo") self.assertNotEqual(rdfvalue.RDFString(u"foo"), b"\x80\x81\x82")
def Parse(self, stat, knowledge_base): value = stat.registry_data.GetValue() or "All Users" all_users_dir = artifact_utils.ExpandWindowsEnvironmentVariables( "%ProfilesDirectory%\\" + value, knowledge_base) yield rdfvalue.RDFString(all_users_dir)
def Convert(self, metadata, value): _ = metadata return [rdfvalue.RDFString(str(value))]