
    Xft                         d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ  ej        e          Z G d dej        j        e	          Z G d
 de	          ZdS )zDefines the automagic interfaces for populating the context before a plugin
runs.

Automagic objects attempt to automatically fill configuration values
that a user has not filled.
    N)ABCMeta)AnyListOptionalTupleTypeUnion)	constants
interfaces)requirementsc                       e Zd ZdZdZ	 g Z	 dej        j        de	ddf fdZ
	 ddej        j        de	dej        j        d	ej        deee                  f
d
Z	 ddej        j        de	dej        j        deeeej        j                 df         eej        j                 f         dedeee	ej        j        f                  fdZ xZS )AutomagicInterfacea  Class that defines an automagic component that can help fulfill
    `Requirements`

    These classes are callable with the following parameters:

    Args:
        context: The context in which to store configuration data that the automagic might populate
        config_path: Configuration path where the configurable's data under the context's config lives
        configurable: The top level configurable whose requirements may need satisfying
        progress_callback: An optional function accepting a percentage and optional description to indicate
            progress during long calculations

    .. note::

        The `context` provided here may be different to that provided during initialization.  The `context` provided at
        initialization should be used for local configuration of the automagic itself, the `context` provided during
        the call is to be populated by the automagic.
    
   contextconfig_pathreturnNc                    t                                          ||           |                                 D ]R}t          |t          j        j        t          j        t          j	        t          j
        f          st          d          Sd S )NzpAutomagic requirements must be a SimpleTypeRequirement, ChoiceRequirement, ListRequirement or VersionRequirement)super__init__get_requirements
isinstancer   configurationSimpleTypeRequirementr   ChoiceRequirementListRequirementVersionRequirement	TypeError)selfr   r   argskwargsrequirement	__class__s         \/home/panchajanya/Development/work/volatility3/volatility3/framework/interfaces/automagic.pyr   zAutomagicInterface.__init__0   s     	+...0022 	 	K,B 2 0 3	     G  	 	    r!   progress_callbackc                     g S )z)Runs the automagic over the configurable. )r   r   r   r!   r%   s        r#   __call__zAutomagicInterface.__call__F   s	     	r$   Trequirement_rootrequirement_type.shortcutc           	      R   t           j                            ||j                  }g }| }t	          ||          r0|s|                    ||          r|                    ||f           nd}|r8|j                                        D ]}	|| 	                    |||	||          z  }|S )a  Determines if there is actually an unfulfilled `Requirement`
        waiting.

        This ensures we do not carry out an expensive search when there is no need for a particular `Requirement`

        Args:
            context: Context on which to operate
            config_path: Configuration path of the top-level requirement
            requirement_root: Top-level requirement whose subrequirements will all be searched
            requirement_type: Type of requirement to find
            shortcut: Only returns requirements that live under unsatisfied requirements

        Returns:
            A list of tuples containing the config_path, sub_config_path and requirement identifying the unsatisfied `Requirements`
        T)
r   r   	path_joinnamer   unsatisfiedappendr   valuesfind_requirements)
r   r   r   r)   r*   r+   sub_config_pathresultsrecursesubreqs
             r#   r2   z$AutomagicInterface.find_requirementsS   s    4 %2<<).
 
 TV,&(899 	 D*66wLL D1ABCCCG 	*7>>@@  411_f6F   r$   N)T)__name__
__module____qualname____doc__priorityexclusion_listr   r   ContextInterfacestrr   r   RequirementInterfacer
   ProgressCallbackr   r   r   r(   r	   r   r   boolr2   __classcell__)r"   s   @r#   r   r      s        & HGNh#4  
     6 9= #4   -B	
 %5 
$s)	   , ) )#4) ) %2G	)
  $z/DEsJK)>?A
) ) 
eC1FFG	H) ) ) ) ) ) ) )r$   r   )	metaclassc                       e Zd ZU dZdZ	 g Zee         ed<   	 e		 dde
j        j        dedej        dee
j        j                 fd	            Ze	d
             ZdS )StackerLayerInterfacezClass that takes a lower layer and attempts to build on it.

    stack_order determines the order (from low to high) that stacking
    layers should be attempted lower levels should have lower
    `stack_orders`
    r   r=   Nr   
layer_namer%   r   c                     dS )a  Method to determine whether this builder can operate on the named
        layer.  If so, modify the context appropriately.

        Returns the name of any new layer stacked on top of this layer or None.  The stacking is therefore strictly
        linear rather than tree driven.

        Configuration options provided by the context are ignored, and defaults are to be used by this method
        to build a space where possible.

        Args:
           context: Context in which to construct the higher layer
           layer_name: Name of the layer to stack on top of
           progress_callback: A callback function to indicate progress through a scan (if one is necessary)
        Nr'   )clsr   rG   r%   s       r#   stackzStackerLayerInterface.stack   s      r$   c                 :    t                               d           d S )NzgReads to this layer are slow, it's recommended to use the layerwriter plugin once to produce a raw file)vollogwarning)rI   s    r#   stacker_slow_warningz*StackerLayerInterface.stacker_slow_warning   s%    u	
 	
 	
 	
 	
r$   r7   )r8   r9   r:   r;   stack_orderr=   r   r?   __annotations__classmethodr   r   r>   r
   rA   r   layersDataLayerInterfacerJ   rN   r'   r$   r#   rF   rF      s           KG "NDI"""b
 9=	 #4  %5	
 
*#6	7   [* 
 
 [
 
 
r$   rF   )r;   loggingabcr   typingr   r   r   r   r   r	   volatility3.frameworkr
   r   #volatility3.framework.configurationr   	getLoggerr8   rL   r   ConfigurableInterfacer   rF   r'   r$   r#   <module>r[      s           : : : : : : : : : : : : : : : : 7 7 7 7 7 7 7 7 < < < < < <		8	$	$h h h h h2gh h h hV'
 '
 '
 '
 '
g '
 '
 '
 '
 '
 '
r$   