
    *1f                         d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZmZ  ej        e          Z G d dej                  Z G d d	ej        j        ej        j        e
          ZdS )zPlugins are the `functions` of the volatility framework.

They are called and carry out some algorithms on data stored in layers
using objects constructed from symbols.
    N)ABCMetaabstractmethod)ListTupleType)
exceptions	constants
interfacesc                        e Zd ZdZdeddf fdZed             Zej        defd            Ze	d             Z
ededefd	            Zd
 Zd Z xZS )FileHandlerInterfacezClass for storing Files in the plugin as a means to output a file when necessary.

    This can be used as ContextManager that will close/produce the file automatically when exiting the context block
    filenamereturnNc                 d    d| _         || _        t                                                       dS )zsCreates a FileHandler

        Args:
            filename: The requested name of the filename for the data
        N)_preferred_filenamepreferred_filenamesuper__init__)selfr   	__class__s     Z/home/panchajanya/Development/work/volatility3/volatility3/framework/interfaces/plugins.pyr   zFileHandlerInterface.__init__   s1     $( "*    c                     | j         S )zThe preferred filename to save the data to.
        Until this file has been written, this value may not be the final filename the data is written to.
        )r   r   s    r   r   z'FileHandlerInterface.preferred_filename&   s    
 ''r   c                     | j         rt          d          t          |t                    st	          d          t
          j        j        |v rt          d          || _	        dS )zSets the preferred filenamez.FileHandler name cannot be changed once closedz/FileHandler preferred filenames must be stringsz4FileHandler filenames cannot contain path separatorsN)
closedIOError
isinstancestr	TypeErrorospathsep
ValueErrorr   )r   r   s     r   r   z'FileHandlerInterface.preferred_filename-   sl     ; 	LJKKK(C(( 	OMNNN7;(""STTT#+   r   c                     dS )zAMethod that commits the file and fixes the final filename for useN r   s    r   closezFileHandlerInterface.close8         r   c                 6    d}d}| D ]}||v r||z  }|dz  }|S )z]Sanititizes the filename to ensure only a specific whitelist of characters is allowed throughzSabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]{}!$%^:#~?<>,| ?r%   )r   allowedresultchars       r   sanitize_filenamez&FileHandlerInterface.sanitize_filename<   sB     h 	 	Dw$#r   c                     | S Nr%   r   s    r   	__enter__zFileHandlerInterface.__enter__H   s    r   c                     ||||                                   d S t                              d| j         dt	          |                      |                                   d S )NzFile z could not be written: )r&   vollogwarningr   r   )r   exc_type	exc_value	tracebacks       r   __exit__zFileHandlerInterface.__exit__K   sh    	 1i6GJJLLLLLNNY0YYYYY   JJLLLLLr   )__name__
__module____qualname____doc__r   r   propertyr   setterr   r&   staticmethodr.   r1   r8   __classcell__r   s   @r   r   r      s        
        ( ( X( ,3 , , , , P P ^P 	C 	C 	 	 	 \	        r   r   c            	           e Zd ZU dZdZeeeef         ed<   	 	 ddej	        j
        dedej        ddf fd	Zed
             Zdee         ddfdZedeej        j                 f fd            Zedej        j        fd            Z xZS )PluginInterfaceaU  Class that defines the basic interface that all Plugins must maintain.

    The constructor must only take a `context` and `config_path`, so
    that plugins can be launched automatically.  As such all
    configuration information must be provided through the requirements
    and configuration information in the context it is passed.
    )r   r   r   _required_framework_versionNcontextconfig_pathprogress_callbackr   c                 r   t                                          ||           |pd | _        |                     ||          r.t                              d           t          j        d          |                                 D ]$}|j	        | j
        vr|j        | j
        |j	        <   %t          | _        dS )a  

        Args:
            context: The context that the plugin will operate within
            config_path: The path to configuration data within the context configuration data
            progress_callback: A callable that can provide feedback at progress points
        c                     d S r0   r%   )fss     r   <lambda>z*PluginInterface.__init__.<locals>.<lambda>   s    T r   zPlugin failed validationz+The plugin configuration failed to validateN)r   r   _progress_callbackunsatisfiedr3   r4   r   PluginRequirementExceptionget_requirementsnameconfigdefaultr   _file_handler)r   rE   rF   rG   requirementr   s        r   r   zPluginInterface.__init__t   s     	+..."3"J8I8I G[11 	NN56667=    0022 	D 	DKt{220;0CK,-9Mr   c                     | j         S )z:Returns a context manager and thus can be called like open)rT   r   s    r   openzPluginInterface.open   s     !!r   handlerc                 \    t          |t                    st          d          || _        dS )z0Sets the file handler to be used by this plugin.z6FileHandler must be a subclass of FileHandlerInterfaceN)
issubclassr   r#   rT   )r   rX   s     r   set_open_methodzPluginInterface.set_open_method   s3    '#788 	WUVVV$r   c                 D    t                                                      S )z6Returns a list of Requirement objects for this plugin.)r   rP   )clsr   s    r   rP   z PluginInterface.get_requirements   s     ww'')))r   c                     dS )a  Executes the functionality of the code.

        .. note:: This method expects `self.validate` to have been called to ensure all necessary options have been provided

        Returns:
            A TreeGrid object that can then be passed to a Renderer.
        Nr%   r   s    r   runzPluginInterface.run   r'   r   r0   )r9   r:   r;   r<   rD   r   int__annotations__r
   rE   ContextInterfacer   r	   ProgressCallbackr   r=   rW   r   r   r[   classmethodr   configurationRequirementInterfacerP   r   	renderersTreeGridr_   r@   rA   s   @r   rC   rC   c   s[        
  9BsC}!5AAA{ 9=	N N#4N N %5	N
 
N N N N N N: " " X"%t,@'A %d % % % % *j&>&S!T * * * * * [* Z)2    ^    r   rC   )	metaclass)r<   iologgingr    abcr   r   typingr   r   r   volatility3.frameworkr   r	   r
   	getLoggerr9   r3   	RawIOBaser   re   ConfigurableInterfaceVersionableInterfacerC   r%   r   r   <module>rs      s    
			  				 ' ' ' ' ' ' ' ' $ $ $ $ $ $ $ $ $ $ C C C C C C C C C C		8	$	$< < < < <2< < < <ZF F F F F21F F F F F Fr   