
    Xf                        d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	m
Z
mZmZ ddlmZ  ej        e          Zdej        j        deej        j                 fdZd	eeej        j                          d
eej        j                 deeej        j                          fdZ	 dd	eej        j                 dej        j        deej        j        eej        j                 f         dedej        deej                 fdZdS )a0  Automagic modules allow the framework to populate configuration elements
that a user has not provided.

Automagic objects accept a `context` and a `configurable`, and will make appropriate changes to the `context` in an
attempt to fulfill the requirements of the `configurable` object (or objects upon which that configurable may rely).

Several pre-existing modules include one to stack layers on top of each other (allowing automatic detection and
loading of file format types) as well as a module to reconstruct layers based on their provided requirements.
    N)ListTypeUnion)class_subclassesimport_files
interfaces	constants)requirementscontextreturnc                      t          t          j        t                              t          j        t           fdt          t          j	        j
                  D             d           S )al  Returns an ordered list of all subclasses of
    :class:`~volatility3.framework.interfaces.automagic.AutomagicInterface`.

    The order is based on the priority attributes of the subclasses, in order to ensure the automagics are listed in
    an appropriate order.

    Args:
        context: The context that will contain any automagic configuration values.
    c           	      n    g | ]1} |t           j                            |j                            2S  )r   configuration	path_join__name__).0clazzconfig_pathr   s     Z/home/panchajanya/Development/work/volatility3/volatility3/framework/automagic/__init__.py
<listcomp>zavailable.<locals>.<listcomp>(   sQ     	
 	
 	
  E1;;KXX 	
 	
 	
    c                     | j         S N)priority)xs    r   <lambda>zavailable.<locals>.<lambda>.   s    aj r   )key)r   sysmodulesr   r	   AUTOMAGIC_CONFIG_PATHsortedr   r   	automagicAutomagicInterface)r   r   s   `@r   	availabler%      s}     X&'''1K	
 	
 	
 	
 	
 ***>*QRR		
 	
 	
 !    r   
automagicspluginc                    d}|j                             d          }t          |          }t          j        D ]C}	 |                    |          |k     r|                    |          }|}4# t          $ r Y @w xY w|t          j        vrt                              d           | S t                              d| d           g }| D ]}||j	        vr||gz  }|S )zOChooses which automagics to run, maintaining the order they were handed
    in.None.zNo plugin category detectedzDetected a z category plugin)

__module__splitlenr	   OS_CATEGORIESindex
ValueErrorvolloginfoexclusion_list)r&   r'   plugin_categoryplugin_categorieslowest_indexosoutputamagics           r   choose_automagicr:   2   s    O)//44())L%  	 &&r**\99066r::"$ 	 	 	D	 i5551222
KK?o???@@@F  &"777 vhFMs   0A,,
A98A9configurabler   progress_callbackc                    | D ]0}t          |t          j        j                  st	          d          1t          |t          j        j                  s.t          |t          j        j                  st	          d          t          |t          j        j                  r|j        }n|}t          j
        |j                  }|                                D ]}|                    |           g }	| D ]}	 t                              d|j        j                     |||||           9# t           $ r<}
|	                    t$          j                            |
                     Y d}
~
zd}
~
ww xY w|	S )av  Runs through the list of `automagics` in order, allowing them to make
    changes to the context.

    Args:
        automagics: A list of :class:`~volatility3.framework.interfaces.automagic.AutomagicInterface` objects
        context: The context (that inherits from :class:`~volatility3.framework.interfaces.context.ContextInterface`) for modification
        configurable: An object that inherits from :class:`~volatility3.framework.interfaces.configuration.ConfigurableInterface`
        config_path: The path within the `context.config` for options required by the `configurable`
        progress_callback: A function that takes a percentage (and an optional description) that will be called periodically

    This is where any automagic is allowed to run, and alter the context in order to satisfy/improve all requirements

    Returns a list of traceback objects that occurred during the autorun procedure

    Note:
        The order of the `automagics` list is important.  An `automagic` that populates configurations may be necessary
        for an `automagic` that populates the context based on the configuration information.
    z:Automagics must only contain AutomagicInterface subclassesz(Automagic operates on configurables only)namezRunning automagic: N)
isinstancer   r#   r$   	TypeErrorr   ConfigurableInterface
issubclass	__class__r
   MultiRequirementr   get_requirementsadd_requirementr1   r2   	Exceptionappend	tracebackTracebackExceptionfrom_exception)r&   r   r;   r   r<   r#   configurable_classrequirementreq
exceptionsexcps              r   runrQ   S   s   8    	)Z%9%LMM 	L  	
 j.D  Dz'?'UVVD BCCC
 ,
 8 NOO *)3)/5G5PQQQK,,.. ) )##C((((J Q Q		QKKLi.A.JLLMMMIg{K9JKKKK 	Q 	Q 	Qi:II$OOPPPPPPPP	Qs   75D--
E372E..E3r   ) __doc__loggingr   rI   typingr   r   r   volatility3.frameworkr   r   r   r	   #volatility3.framework.configurationr
   	getLoggerr   r1   r   ContextInterfacer#   r$   r%   pluginsPluginInterfacer:   r   rA   strProgressCallbackrJ   rQ   r   r   r   <module>r]      s     



     $ $ $ $ $ $ $ $ $ $ W W W W W W W W W W W W < < < < < <		8	$	$0	*

12   2T*.ABC#34 
$z#6
78   R 59: :Z)<=:0:  6Z%;<	>: : !1: 
)
&': : : : : :r   