Exemple #1
0
    def Process(self, parser_mediator, data, **kwargs):
        """Determine if this is the correct plugin; if so proceed with processing.

    Process() checks if the current bencode file being processed is a match for
    a plugin by comparing the PATH and KEY requirements defined by a plugin. If
    both match processing continues; else raise WrongBencodePlugin.

    This function also extracts the required keys as defined in
    self.BENCODE_KEYS from the file and stores the result in match[key]
    and calls self.GetEntries() which holds the processing logic implemented by
    the plugin.

    Args:
      parser_mediator (ParserMediator): mediates interactions between parsers
          and other components, such as storage and dfvfs.
      data (dict[str, object]): bencode data values.

    Raises:
      WrongBencodePlugin: If this plugin is not able to process the given file.
      ValueError: If top level is not set.
    """
        if data is None:
            raise ValueError(u'Data is not set.')

        if not set(data.keys()).issuperset(self.BENCODE_KEYS):
            raise errors.WrongBencodePlugin(self.NAME)

        # This will raise if unhandled keyword arguments are passed.
        super(BencodePlugin, self).Process(parser_mediator)

        logging.debug(u'Bencode Plugin Used: {0:s}'.format(self.NAME))
        match = self._GetKeys(data, self.BENCODE_KEYS, 3)

        self.GetEntries(parser_mediator, data=data, match=match)
Exemple #2
0
    def Process(self, top_level=None, **kwargs):
        """Determine if this is the correct plugin; if so proceed with processing.

    Process() checks if the current bencode file being processed is a match for
    a plugin by comparing the PATH and KEY requirements defined by a plugin. If
    both match processing continues; else raise WrongBencodePlugin.

    This function also extracts the required keys as defined in
    self.BENCODE_KEYS from the file and stores the result in match[key]
    and calls self.GetEntries() which holds the processing logic implemented by
    the plugin.

    Args:
      top_level: Bencode data in dictionary form.

    Raises:
      WrongBencodePlugin: If this plugin is not able to process the given file.
      ValueError: If top level is not set.

    Returns:
      A generator of events processed by the plugin.
    """
        if top_level is None:
            raise ValueError(u'Top level is not set.')

        if not set(top_level.keys()).issuperset(self.BENCODE_KEYS):
            raise errors.WrongBencodePlugin(self.plugin_name)

        super(BencodePlugin, self).Process(**kwargs)

        logging.debug(u'Bencode Plugin Used: {}'.format(self.plugin_name))
        match = GetKeys(top_level, self.BENCODE_KEYS, 3)

        return self.GetEntries(data=top_level, match=match)
Exemple #3
0
    def Process(self, parser_context, top_level=None, **kwargs):
        """Determine if this is the correct plugin; if so proceed with processing.

    Process() checks if the current bencode file being processed is a match for
    a plugin by comparing the PATH and KEY requirements defined by a plugin. If
    both match processing continues; else raise WrongBencodePlugin.

    This function also extracts the required keys as defined in
    self.BENCODE_KEYS from the file and stores the result in match[key]
    and calls self.GetEntries() which holds the processing logic implemented by
    the plugin.

    Args:
      parser_context: A parser context object (instance of ParserContext).
      top_level: Bencode data in dictionary form.

    Raises:
      WrongBencodePlugin: If this plugin is not able to process the given file.
      ValueError: If top level is not set.
    """
        if top_level is None:
            raise ValueError(u'Top level is not set.')

        if not set(top_level.keys()).issuperset(self.BENCODE_KEYS):
            raise errors.WrongBencodePlugin(self.NAME)

        # This will raise if unhandled keyword arguments are passed.
        super(BencodePlugin, self).Process(parser_context, **kwargs)

        logging.debug(u'Bencode Plugin Used: {0:s}'.format(self.NAME))
        match = self._GetKeys(top_level, self.BENCODE_KEYS, 3)

        self.GetEntries(parser_context, data=top_level, match=match)
Exemple #4
0
    def GetEntries(self, parser_mediator, data=None, **unused_kwargs):
        """Extracts uTorrent active torrents.

    This is the main parsing engine for the plugin. It determines if
    the selected file is the proper file to parse and extracts current
    running torrents.

    interface.Process() checks for the given BENCODE_KEYS set, ensures
    that it matches, and then passes the bencoded data to this function for
    parsing. This plugin then parses the entire set of bencoded data to extract
    the variable file-name keys to retrieve their values.

    uTorrent creates a file, resume.dat, and a backup, resume.dat.old, to
    for all active torrents. This is typically stored in the user's
    application data folder.

    These files, at a minimum, contain a '.fileguard' key and a dictionary
    with a key name for a particular download with a '.torrent' file
    extension.

    Args:
      parser_mediator: A parser mediator object (instance of ParserMediator).
      data: Optional bencode data in dictionary form. The default is None.
    """
        # Walk through one of the torrent keys to ensure it's from a valid file.
        for key, value in data.iteritems():
            if not u'.torrent' in key:
                continue

            caption = value.get('caption')
            path = value.get('path')
            seedtime = value.get('seedtime')
            if not caption or not path or seedtime < 0:
                raise errors.WrongBencodePlugin(self.NAME)

        for torrent, value in data.iteritems():
            if not u'.torrent' in torrent:
                continue

            path = value.get('path', None)
            caption = value.get('caption', None)
            seedtime = value.get('seedtime', None)

            # Create timeline events based on extracted values.
            for event_key, event_value in value.iteritems():
                if event_key == 'added_on':
                    event_object = UTorrentEvent(
                        event_value, eventdata.EventTimestamp.ADDED_TIME, path,
                        caption, seedtime)
                    parser_mediator.ProduceEvent(event_object)

                elif event_key == 'completed_on':
                    event_object = UTorrentEvent(
                        event_value, eventdata.EventTimestamp.FILE_DOWNLOADED,
                        path, caption, seedtime)
                    parser_mediator.ProduceEvent(event_object)

                elif event_key == 'modtimes':
                    for modtime in event_value:
                        # Some values are stored as 0, skip those.
                        if not modtime:
                            continue

                        event_object = UTorrentEvent(
                            modtime,
                            eventdata.EventTimestamp.MODIFICATION_TIME, path,
                            caption, seedtime)
                        parser_mediator.ProduceEvent(event_object)
Exemple #5
0
    def GetEntries(self, parser_mediator, data=None, **unused_kwargs):
        """Extracts uTorrent active torrents.

    This is the main parsing engine for the plugin. It determines if
    the selected file is the proper file to parse and extracts current
    running torrents.

    interface.Process() checks for the given BENCODE_KEYS set, ensures
    that it matches, and then passes the bencoded data to this function for
    parsing. This plugin then parses the entire set of bencoded data to extract
    the variable file-name keys to retrieve their values.

    uTorrent creates a file, resume.dat, and a backup, resume.dat.old, to
    for all active torrents. This is typically stored in the user's
    application data folder.

    These files, at a minimum, contain a '.fileguard' key and a dictionary
    with a key name for a particular download with a '.torrent' file
    extension.

    Args:
      parser_mediator (ParserMediator): mediates interactions between parsers
          and other components, such as storage and dfvfs.
      data (Optional[dict[str, object]]): bencode data values.
    """
        # Walk through one of the torrent keys to ensure it's from a valid file.
        for key, value in iter(data.items()):
            if not u'.torrent' in key:
                continue

            caption = value.get(u'caption')
            path = value.get(u'path')
            seedtime = value.get(u'seedtime')
            if not caption or not path or seedtime < 0:
                raise errors.WrongBencodePlugin(self.NAME)

        for torrent, value in iter(data.items()):
            if not u'.torrent' in torrent:
                continue

            event_data = UTorrentEventData()
            event_data.caption = value.get(u'caption', None)
            event_data.path = value.get(u'path', None)

            # Convert seconds to minutes.
            seedtime = value.get(u'seedtime', None)
            event_data.seedtime, _ = divmod(seedtime, 60)

            # Create timeline events based on extracted values.
            for event_key, event_value in iter(value.items()):
                if event_key == u'added_on':
                    date_time = dfdatetime_posix_time.PosixTime(
                        timestamp=event_value)
                    event = time_events.DateTimeValuesEvent(
                        date_time, definitions.TIME_DESCRIPTION_ADDED)
                    parser_mediator.ProduceEventWithEventData(
                        event, event_data)

                elif event_key == u'completed_on':
                    date_time = dfdatetime_posix_time.PosixTime(
                        timestamp=event_value)
                    event = time_events.DateTimeValuesEvent(
                        date_time,
                        definitions.TIME_DESCRIPTION_FILE_DOWNLOADED)
                    parser_mediator.ProduceEventWithEventData(
                        event, event_data)

                elif event_key == u'modtimes':
                    for modtime in event_value:
                        # Some values are stored as 0, skip those.
                        if not modtime:
                            continue

                        date_time = dfdatetime_posix_time.PosixTime(
                            timestamp=modtime)
                        event = time_events.DateTimeValuesEvent(
                            date_time,
                            definitions.TIME_DESCRIPTION_MODIFICATION)
                        parser_mediator.ProduceEventWithEventData(
                            event, event_data)