
    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.                  j0                     deeej(                  j*                        fdZ	 dd	eej(                  j*                     dej$                  j&                  deej4                  j6                  eej4                  j6                     f   dedej:                  deej<                     fdZy)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                 D   t        t        j                  t                  t        j
                  }t        t        t        j                  j                        D cg c]3  } || t        j                  j                  ||j                              5 c}d       S c c}w )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                     | j                   S N)priority)xs    Z/home/panchajanya/Development/work/volatility3/volatility3/framework/automagic/__init__.py<lambda>zavailable.<locals>.<lambda>.   s
    ajj     )key)r   sysmodules__name__r	   AUTOMAGIC_CONFIG_PATHsortedr   r   	automagicAutomagicInterfaceconfiguration	path_join)r   config_pathclazzs      r   	availabler!      s     X&'11K
 ***>*>*Q*QR		
  11;;KX	
 ! 	
s   8B
automagicspluginc                    d}|j                   j                  d      }t        |      }t        j                  D ]*  }	 |j                  |      |k  r|j                  |      }|}, |t        j                  vrt        j                  d       | S t        j                  d| d       g }| D ]  }||j                  vs||gz  } |S # t        $ r Y w xY w)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_automagicr6   2   s     O))//4()L%% 	 &&r*\9066r:"$	 i55512
KK+o..>?@F &"7"77 vhF	
 M  		s   'C	CCconfigurabler   progress_callbackc                    | D ]1  }t        |t        j                  j                        r(t	        d       t        |t        j
                  j                        s/t        |t        j
                  j                        st	        d      t        |t        j
                  j                        r|j                  }n|}t        j                  |j                        }|j                         D ]  }|j                  |        g }	| D ]:  }	 t        j                  d|j                  j                           |||||       < |	S # t         $ r8}
|	j#                  t$        j&                  j)                  |
             Y d}
~
{d}
~
ww xY w)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_requirementr-   r.   	Exceptionappend	tracebackTracebackExceptionfrom_exception)r"   r   r7   r   r8   r   configurable_classrequirementreq
exceptionsexcps              r   runrM   S   si   8   	)Z%9%9%L%LML  j..DDz'?'?'U'UVBCC
 ,
 8 8 N NO)33)//5G5P5PQK,,. )##C() J Q		QKK-i.A.A.J.J-KLMg{K9JKQ   	Qi::II$OPP	Qs   7E	F.FFr   ) __doc__loggingr   rE   typingr   r   r   volatility3.frameworkr   r   r   r	   #volatility3.framework.configurationr
   	getLoggerr   r-   r   ContextInterfacer   r   r!   pluginsPluginInterfacer6   r   r=   strProgressCallbackrF   rM    r   r   <module>rZ      sb    
  $ $ W W <			8	$00	*


1
122T*..AABC##334 
$z##66
78R 59:Z))<<=:00:   66Z%%;;<	>: : !11: 
)
&
&':r   