def ParseResponse( self, knowledge_base: rdf_client.KnowledgeBase, response: rdfvalue.RDFValue, ) -> Iterator[rdf_standard.PersistenceFile]: """Convert persistence collector output to downloadable rdfvalues.""" pathspecs = [] if isinstance(response, rdf_client.WindowsServiceInformation): if response.HasField("binary"): pathspecs.append(response.binary.pathspec) elif response.HasField("image_path"): pathspecs = self._GetFilePaths(response.image_path, knowledge_base) if (isinstance(response, rdf_client_fs.StatEntry) and response.HasField("registry_type")): pathspecs = self._GetFilePaths(response.registry_data.string, knowledge_base) for pathspec in pathspecs: yield rdf_standard.PersistenceFile(pathspec=pathspec)
def RenderValue(self, value: rdfvalue.RDFValue) -> Dict[str, Any]: """Renders a Protocol Buffers `Any` value into a JSON-like dictionary.""" if not isinstance(value, rdf_structs.AnyValue): raise TypeError(f"Unexpected '{value}' of type '{type(value)}'") # We use a heuristic that the last element of type URL is a name of the RDF # class. If this does not hold, we just render the value as it is. cls_name = value.type_url.split("/")[-1].split(".")[-1] try: cls = rdfvalue.RDFValue.classes[cls_name] except KeyError: return ApiRDFProtoStructRenderer( self.limit_lists).RenderValue(value) return self._PassThrough(value.Unpack(cls))
def ToWireFormat(self, value: rdfvalue.RDFValue): precondition.AssertType(value, self._cls) return value.SerializeToWireFormat()
def ToBytes(self, value: rdfvalue.RDFValue) -> bytes: precondition.AssertType(value, self._cls) return value.SerializeToBytes()