Beispiel #1
0
    def stack(
        cls,
        context: interfaces.context.ContextInterface,
        layer_name: str,
        progress_callback: constants.ProgressCallback = None
    ) -> Optional[interfaces.layers.DataLayerInterface]:
        """Attempt to stack this based on the starting information."""
        memlayer = context.layers[layer_name]
        if not isinstance(memlayer, physical.FileLayer):
            return None
        location = memlayer.location
        if location.endswith(".vmem"):
            vmss = location[:-5] + ".vmss"
            vmsn = location[:-5] + ".vmsn"
            current_layer_name = context.layers.free_layer_name(
                "VmwareMetaLayer")
            current_config_path = interfaces.configuration.path_join(
                "automagic", "layer_stacker", "stack", current_layer_name)

            vmss_success = False
            try:
                _ = resources.ResourceAccessor().open(vmss).read(10)
                context.config[interfaces.configuration.path_join(
                    current_config_path, "location")] = vmss
                context.layers.add_layer(
                    physical.FileLayer(context, current_config_path,
                                       current_layer_name))
                vmss_success = True
            except IOError:
                pass

            vmsn_success = False
            if not vmss_success:
                try:
                    _ = resources.ResourceAccessor().open(vmsn).read(10)
                    context.config[interfaces.configuration.path_join(
                        current_config_path, "location")] = vmsn
                    context.layers.add_layer(
                        physical.FileLayer(context, current_config_path,
                                           current_layer_name))
                    vmsn_success = True
                except IOError:
                    pass

            vollog.log(
                constants.LOGLEVEL_VVVV,
                f"Metadata found: VMSS ({vmss_success}) or VMSN ({vmsn_success})"
            )

            if not vmss_success and not vmsn_success:
                return None
            new_layer_name = context.layers.free_layer_name("VmwareLayer")
            context.config[interfaces.configuration.path_join(
                current_config_path, "base_layer")] = layer_name
            context.config[interfaces.configuration.path_join(
                current_config_path, "meta_layer")] = current_layer_name
            new_layer = VmwareLayer(context, current_config_path,
                                    new_layer_name)
            return new_layer
        return None
Beispiel #2
0
    def load_pdb_layer(
            cls, context: interfaces.context.ContextInterface,
            location: str) -> Tuple[str, interfaces.context.ContextInterface]:
        """Loads a PDB file into a layer within the context and returns the
        name of the new layer.

        Note: the context may be changed by this method
        """
        physical_layer_name = context.layers.free_layer_name("FileLayer")
        physical_config_path = interfaces.configuration.path_join(
            "pdbreader", physical_layer_name)

        # Create the file layer
        # This must be specific to get us started, setup the config and run
        new_context = context.clone()
        new_context.config[interfaces.configuration.path_join(
            physical_config_path, "location")] = location

        physical_layer = physical.FileLayer(new_context, physical_config_path,
                                            physical_layer_name)
        new_context.add_layer(physical_layer)

        # Add on the MSF format layer
        msf_layer_name = context.layers.free_layer_name("MSFLayer")
        msf_config_path = interfaces.configuration.path_join(
            "pdbreader", msf_layer_name)
        new_context.config[interfaces.configuration.path_join(
            msf_config_path, "base_layer")] = physical_layer_name
        msf_layer = msf.PdbMultiStreamFormat(new_context, msf_config_path,
                                             msf_layer_name)
        new_context.add_layer(msf_layer)

        msf_layer.read_streams()

        return msf_layer_name, new_context
Beispiel #3
0
 def load_file(self, location: str):
     """Loads a file into a Filelayer and returns the name of the layer"""
     layer_name = self.context.layers.free_layer_name()
     location = volshell.VolShell.location_from_file(location)
     current_config_path = 'volshell.layers.' + layer_name
     self.context.config[interfaces.configuration.path_join(current_config_path, "location")] = location
     layer = physical.FileLayer(self.context, current_config_path, layer_name)
     self.context.add_layer(layer)
     return layer_name
Beispiel #4
0
 def load_file(self, location: str):
     """Loads a file into a Filelayer and returns the name of the layer"""
     layer_name = self.context.layers.free_layer_name()
     if not parse.urlparse(location).scheme:
         location = "file:" + request.pathname2url(location)
     current_config_path = 'volshell.layers.' + layer_name
     self.context.config[interfaces.configuration.path_join(
         current_config_path, "location")] = location
     layer = physical.FileLayer(self.context, current_config_path,
                                layer_name)
     self.context.add_layer(layer)
     return layer_name
Beispiel #5
0
    def stack(self, context: interfaces.context.ContextInterface,
              config_path: str,
              requirement: interfaces.configuration.RequirementInterface,
              progress_callback: constants.ProgressCallback) -> None:
        """Stacks the various layers and attaches these to a specific
        requirement.

        Args:
            context: Context on which to operate
            config_path: Configuration path under which to store stacking data
            requirement: Requirement that should have layers stacked on it
            progress_callback: Function to provide callback progress
        """
        # If we're cached, find Now we need to find where to apply the stack configuration
        if self._cached:
            top_layer_name, subconfig = self._cached
            result = self.find_suitable_requirements(context, config_path,
                                                     requirement,
                                                     [top_layer_name])
            if result:
                appropriate_config_path, layer_name = result
                context.config.merge(appropriate_config_path, subconfig)
                context.config[appropriate_config_path] = top_layer_name
                return
            self._cached = None

        new_context = context.clone()
        location = self.config.get('single_location', None)

        # Setup the local copy of the resource
        current_layer_name = context.layers.free_layer_name("FileLayer")
        current_config_path = interfaces.configuration.path_join(
            config_path, "stack", current_layer_name)

        # This must be specific to get us started, setup the config and run
        new_context.config[interfaces.configuration.path_join(
            current_config_path, "location")] = location
        physical_layer = physical.FileLayer(new_context, current_config_path,
                                            current_layer_name)
        new_context.add_layer(physical_layer)

        stacked_layers = self.stack_layer(new_context, current_layer_name,
                                          self.create_stackers_list(),
                                          progress_callback)

        if stacked_layers is not None:
            # Applies the stacked_layers to each requirement in the requirements list
            result = self.find_suitable_requirements(new_context, config_path,
                                                     requirement,
                                                     stacked_layers)
            if result:
                path, layer = result
                # splice in the new configuration into the original context
                context.config.merge(
                    path, new_context.layers[layer].build_configuration())

                # Call the construction magic now we may have new things to construct
                constructor = construct_layers.ConstructionMagic(
                    context,
                    interfaces.configuration.path_join(self.config_path,
                                                       "ConstructionMagic"))
                constructor(context, config_path, requirement)

                # Stash the changed config items
                self._cached = context.config.get(
                    path, None), context.config.branch(path)
        vollog.debug("Stacked layers: {}".format(stacked_layers))