Example #1
0
    def testSetTimeZone(self):
        """Tests the SetTimeZone function."""
        knowledge_base_object = knowledge_base.KnowledgeBase()

        time_zone_artifact = artifacts.TimeZoneArtifact(
            localized_name='Eastern (standaardtijd)',
            mui_form='@tzres.dll,-112',
            name='Eastern Standard Time')

        knowledge_base_object.AddAvailableTimeZone(time_zone_artifact)

        # Set an IANA time zone name.
        knowledge_base_object.SetTimeZone('Europe/Zurich')
        self.assertEqual(knowledge_base_object._time_zone.zone,
                         'Europe/Zurich')

        # Set a Windows time zone name.
        knowledge_base_object.SetTimeZone('Eastern Standard Time')
        self.assertEqual(knowledge_base_object._time_zone.zone,
                         'America/New_York')

        # Set a localized Windows time zone name.
        knowledge_base_object.SetTimeZone('Eastern (standaardtijd)')
        self.assertEqual(knowledge_base_object._time_zone.zone,
                         'America/New_York')

        # Set a MUI form Windows time zone name.
        knowledge_base_object.SetTimeZone('@tzres.dll,-112')
        self.assertEqual(knowledge_base_object._time_zone.zone,
                         'America/New_York')

        with self.assertRaises(ValueError):
            knowledge_base_object.SetTimeZone('Bogus')
Example #2
0
    def _ParseKey(self, mediator, registry_key, value_name):
        """Parses a Windows Registry key for a preprocessing attribute.

    Args:
      mediator (PreprocessMediator): mediates interactions between preprocess
          plugins and other components, such as storage and knowledge base.
      registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
      value_name (str): name of the Windows Registry value or None if not
          specified.

    Raises:
      errors.PreProcessFail: if the preprocessing fails.
    """
        std_value = registry_key.GetValueByName('Std')
        if std_value:
            localized_name = std_value.GetDataAsObject()
        else:
            localized_name = registry_key.name

        mui_std_value = registry_key.GetValueByName('MUI_Std')
        if mui_std_value:
            mui_form = std_value.GetDataAsObject()
        else:
            mui_form = None

        tzi_value = registry_key.GetValueByName('TZI')
        if not tzi_value:
            mediator.ProducePreprocessingWarning(
                self.ARTIFACT_DEFINITION_NAME,
                'TZI value missing from Windows Registry key: {0:s}'.format(
                    registry_key.key_path))
            return

        time_zone_artifact = artifacts.TimeZoneArtifact(
            localized_name=localized_name,
            mui_form=mui_form,
            name=registry_key.name)

        try:
            self._ParseTZIValue(tzi_value.data, time_zone_artifact)

        except (ValueError, errors.ParseError) as exception:
            mediator.ProducePreprocessingWarning(
                self.ARTIFACT_DEFINITION_NAME,
                'Unable to parse TZI record value in Windows Registry key: {0:s} '
                'with error: {2!s}'.format(registry_key.key_path, exception))
            return

        try:
            mediator.AddTimeZoneInformation(time_zone_artifact)
        except KeyError:
            mediator.ProducePreprocessingWarning(
                self.ARTIFACT_DEFINITION_NAME,
                ('Unable to add time zone information: {0:s} to knowledge '
                 'base.').format(registry_key.name))
Example #3
0
    def _ParseKey(self, knowledge_base, registry_key, value_name):
        """Parses a Windows Registry key for a preprocessing attribute.

    Args:
      knowledge_base (KnowledgeBase): to fill with preprocessing information.
      registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
      value_name (str): name of the Windows Registry value.

    Raises:
      errors.PreProcessFail: if the preprocessing fails.
    """
        time_zone_artifact = artifacts.TimeZoneArtifact(name=registry_key.name)

        try:
            knowledge_base.AddAvailableTimeZone(time_zone_artifact)
        except KeyError:
            # TODO: add and store preprocessing errors.
            pass