
    XfL                         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dS )    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dS )LayerWriterzMRuns the automagics and writes out the primary layer produced by the stacker.i  P )   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,I   '!9.	   +3	   ( a  !
 	
    Ncontext
layer_namepreferred_nameopen_method
chunk_sizeprogress_callbackc                 v   ||j         vrt          j        d          |j         |         }|| j        } ||          }t	          d|j        |          D ]c}	t          ||j        |	z
            }
|                    |	|
d          }|                    |           |r ||	|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 foundNr   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!k.11q%/<< 	 	A!$Z1F1J!K!K::a!3:>>Dd###  !!..#57T
7T7T   r#   c              #     K   | j         d         r| j        j        D ]	}d|ffV  
d S | j         d         sOg | j         d<   | j        j        D ]8}| j        j        |         j                            dd          s|g| j         d<   9| j         d         D ]}|| j        j        vrdd| dffV  | j                             dd	                    |d
g                    }	 |                     | j        ||| j        | j                             d| j                  | j	                  }|
                                 n/# t          $ r"}dd| j         d          d| ffV  Y d }~nd }~ww xY wdd| ffV  d S )Nr   r   r   mappedFzLayer Name z does not existoutput.rawr   )r)   zLayer cannot be written to output_namez: zLayer has been written to )configr$   r   metadatagetjoinr8   openr   _progress_callbackcloseIOError)selfr   r>   r4   excps        r!   
_generatorzLayerWriter._generatorY   s     ;v  	K+ ! !$j    ! ! ;x( 7(*H% L/ 7 7D<.t4=AA(ERR 715H-H- K Kt|222ADAAACCCCCC"&+//(CHHdE]<S<S"T"TK&*&6&6 L ' I KOOL$:QRR.2.E '7 ' ' $))++++"   ^$+m:T^^X\^^"         
 H;HHJJJJJJ+K Ks   AD;;
E'E""E'c              #   l   K   | j         j        D ]$}d|| j         j        |         j        j        ffV  %dS )zList layer names from this runr   N)r$   r   	__class____name__)rG   r   s     r!   _generate_layerszLayerWriter._generate_layers|   sQ      L' 	L 	LDtT\06@IJKKKKK	L 	Lr#   c                     | j         d         r7t          j        dt          fdt          fg|                                           S t          j        dt          fg|                                           S )Nr   z
Layer namez
Layer typeStatus)r?   r   TreeGridr   rM   rI   )rG   s    r!   runzLayerWriter.run   sl    ;v 	%$|S&9:D<Q<Q<S<S   !Hc?"3T__5F5FGGGr#   )NN)rL   
__module____qualname____doc__r   _required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer"   r$   ContextInterfacer   r   r   FileHandlerInterfacer   intr   ProgressCallbackr8   rI   rM   rQ    r#   r!   r   r      s(       WW!"+H
j&>&S!T 
 
 
 [
4  %)BF$ $#4$ $ 	$
 '67$ SM$ $I$>?$ 
'.	/$ $ $ [$L!K !K !KFL L L
H H H H 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      s   
  ' ' ' ' ' ' ' ' ' ' N N N N N N N N N N N N < < < < < < 4 4 4 4 4 4		8	$	$wH wH wH wH wH') wH wH wH wH wHr#   