
    vf
                         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 d dlmZ  e j                  e      Z G d dej"                        Zy)    N)ListOptionalType)	renderers
interfaces	constants
exceptions)requirements)pluginsc                   "   e Zd ZdZdZdZdZedee	j                  j                     fd       Ze	 	 dde	j                  j                  d	ed
edeej$                     dee   deej,                     deej$                     fd       Zd Zd Zd Zy)LayerWriterzMRuns the automagics and writes out the primary layer produced by the stacker.i  P )   r   r   )r   r      returnc           
          t        j                  dd      t        j                  dd| j                  d      t        j                  dd	d
d      t        j
                  dt        dd d      gS )NprimaryzMemory layer for the kernel)namedescription
block_sizezSize of blocks to copy overT)r   r   defaultoptionallistzList available layersFlayerszCNames of layers to write (defaults to the highest non-mapped layer))r   element_typer   r   r   )r
   TranslationLayerRequirementIntRequirementdefault_block_sizeBooleanRequirementListRequirementstr)clss    [/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/layerwriter.pyget_requirementszLayerWriter.get_requirements   s     44,I ''!9..	 ++3	 (( a!
 	
    Ncontext
layer_namepreferred_nameopen_method
chunk_sizeprogress_callbackc                    ||j                   vrt        j                  d      |j                   |   }|| j                  } ||      }t	        d|j
                  |      D ]b  }	t        ||j
                  dz   |	z
        }
|j                  |	|
d      }|j                  |       |sG ||	|j
                  z  dz  d|        d |S )aY  Produces a FileHandler from the named layer in the provided context or None on failure

        Args:
            context: the context from which to read the memory layer
            layer_name: the name of the layer to write out
            preferred_name: a string with the preferred filename for hte file
            chunk_size: an optional size for the chunks that should be written (defaults to 0x500000)
            open_method: class for creating FileHandler context managers
            progress_callback: an optional function that takes a percentage and a string that displays output
        zLayer not foundr   r   T)padd   zWriting layer )	r   r	   LayerExceptionr   rangemaximum_addressminreadwrite)r!   r%   r&   r'   r(   r)   r*   layerfile_handleicurrent_chunk_sizedatas               r"   write_layerzLayerWriter.write_layer2   s    * W^^+++,=>>z*//J!.1q%//< 	A!$Z1F1F1JQ1N!O::a!3:>Dd# !...#5
|7T	 r$   c              #   F  K   | j                   d   r#| j                  j                  D ]	  }d|ff  y | j                   d   s`g | j                   d<   | j                  j                  D ]8  }d| j                  j                  |   j                  vs)|g| j                   d<   : | j                   d   D ]  }|| j                  j                  vrdd| dff '| d}| j                   j	                  d|      }	 | j                  | j                  ||| j                  | j                   j	                  d	| j                        | j                  
      }|j                          |j                  }dd| ff  y # t        $ r}dd| d| ff Y d }~(d }~ww xY ww)Nr   r   r   mappedzLayer Name z does not existz.rawoutputr   )r*   zLayer cannot be written to z: zLayer has been written to )configr%   r   metadatagetr9   openr   _progress_callbackclosepreferred_filenameIOError)selfr   default_output_nameoutput_namer5   excps         r"   
_generatorzLayerWriter._generatorY   s    ;;v++ !$j ! ;;x((*H% LL// 7Dt||':':4'@'I'II15H-7 H- Kt||222D6ACCC-1F$-'"&++//(<O"PKX&*&6&6 LL ' II KKOOL$:Q:QR.2.E.E '7 ' $))+ '2&D&D  :;-HJJJ1K* # X$?}Btf"U!WWWXs8   BF!A)F!<A5E>1F!>	FFF!FF!c              #      K   | j                   j                  D ]5  }d|| j                   j                  |   j                  j                  ff 7 yw)zList layer names from this runr   N)r%   r   	__class____name__)rE   r   s     r"   _generate_layerszLayerWriter._generate_layers   sL     LL'' 	LDtT\\006@@IIJKK	Ls   AAc                     | j                   d   r2t        j                  dt        fdt        fg| j	                               S t        j                  dt        fg| j                               S )Nr   z
Layer namez
Layer typeStatus)r=   r   TreeGridr    rM   rI   )rE   s    r"   runzLayerWriter.run   sa    ;;v%%$|S&9:D<Q<Q<S  !!Hc?"3T__5FGGr$   )NN)rL   
__module____qualname____doc__r   _required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer#   r%   ContextInterfacer    r   r   FileHandlerInterfacer   intr   ProgressCallbackr9   rI   rM   rQ    r$   r"   r   r      s    W!"+H
j&>&>&S&S!T 
 
4  %)BF$##44$ $ 	$
 '667$ SM$ $I$>$>?$ 
'..	/$ $L$KLL
Hr$   r   )loggingtypingr   r   r   volatility3.frameworkr   r   r   r	   #volatility3.framework.configurationr
    volatility3.framework.interfacesr   	getLoggerrL   vollogPluginInterfacer   r^   r$   r"   <module>rg      sD   
  ' ' N N < 4			8	$zH')) zHr$   