Exemplo n.º 1
0
    def WriteSerializedObject(cls, event_tag):
        """Writes an event tag to serialized form.

    Args:
      event_tag: an event tag (instance of EventTag).

    Returns:
      A protobuf object containing the serialized form (instance of
      plaso_storage_pb2.EventTagging).
    """
        proto = plaso_storage_pb2.EventTagging()

        # TODO: Once we move EventTag to slots we need to query __slots__
        # instead of __dict__
        for attribute_name in event_tag.__dict__:
            attribute_value = getattr(event_tag, attribute_name, None)

            if (attribute_name == u'_tags'
                    and isinstance(attribute_value, (tuple, list))):
                for tag_string in attribute_value:
                    proto_tag_add = proto.tags.add()
                    proto_tag_add.value = tag_string

            elif attribute_value is not None:
                setattr(proto, attribute_name, attribute_value)

        comment = getattr(event_tag, u'comment', u'')
        if comment:
            proto.comment = comment

        color = getattr(event_tag, u'color', u'')
        if color:
            proto.color = color

        return proto
Exemplo n.º 2
0
    def ReadSerialized(cls, proto_string):
        """Reads an event tag from serialized form.

    Args:
      proto_string: a protobuf string containing the serialized form.

    Returns:
      An event tag (instance of EventTag).
    """
        proto = plaso_storage_pb2.EventTagging()
        proto.ParseFromString(proto_string)

        return cls.ReadSerializedObject(proto)
Exemplo n.º 3
0
    def setUp(self):
        """Sets up the needed objects used throughout the test."""
        proto = plaso_storage_pb2.EventTagging()
        proto.store_number = 234
        proto.store_index = 18
        proto.comment = u'My first comment.'
        proto.color = u'Red'
        proto_tag = proto.tags.add()
        proto_tag.value = u'Malware'
        proto_tag = proto.tags.add()
        proto_tag.value = u'Common'

        self._proto_string = proto.SerializeToString()
Exemplo n.º 4
0
  def setUp(self):
    """Makes preparations before running an individual test."""
    proto = plaso_storage_pb2.EventTagging()
    proto.store_number = 234
    proto.store_index = 18
    proto.comment = u'My first comment.'
    proto.color = u'Red'
    proto_tag = proto.tags.add()
    proto_tag.value = u'Malware'
    proto_tag = proto.tags.add()
    proto_tag.value = u'Common'

    self._proto_string = proto.SerializeToString()
    self._serializer = protobuf_serializer.ProtobufEventTagSerializer