
    Xfd)                         d dl Z d dlmZmZmZmZmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ  e j        e          Zdd	d
ddddddddddZ G d de
j        j                  ZdS )    N)CallableList	GeneratorIterableTypeOptional)	renderers
interfaces
exceptions)requirements)utility)format_hints)pslist                   @         i   i      @)PAGE_NOACCESSPAGE_READONLYPAGE_READWRITEPAGE_WRITECOPYPAGE_EXECUTEPAGE_EXECUTE_READPAGE_EXECUTE_READWRITEPAGE_EXECUTE_WRITECOPY
PAGE_GUARDPAGE_NOCACHEPAGE_WRITECOMBINEPAGE_TARGETS_INVALIDc                       e Zd ZdZdZdZdZ fdZede	e
j        j                 fd            Zede
j        j        d	ed
edee         fd            Zed fde
j        j        dee
j        j        gef         dee
j        j        ddf         fd            Zeefde
j        j        de
j        j        de
j        j        dee
j        j                 dedee
j        j                 fd            Zd Zd Z  xZ!S )VadInfozLists process memory ranges.)r   r   r   r   r   r   r   c                 H     t                      j        |i | d | _        d S )N)super__init___protect_values)selfargskwargs	__class__s      _/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/vadinfo.pyr+   zVadInfo.__init__(   s-    $)&)))#    returnc                 @   t          j        ddddg          t          j        ddd	          t          j        d
dt          d          t          j        dt          j        d          t          j        dddd          t          j        dd| j	        d          gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesaddresszRProcess virtual memory address to include (all other address ranges are excluded).T)r8   r9   optionalpidzFilter on specific process IDs)r8   r9   element_typer<   r   r(   )r8   pluginversiondumpzExtract listed memory rangesF)r8   r9   defaultr<   maxsizezNMaximum size for dumped VAD sections (all the bigger sections will be ignored))
r   ModuleRequirementIntRequirementListRequirementintPluginRequirementr   PsListBooleanRequirementMAXSIZE_DEFAULT)clss    r1   get_requirementszVadInfo.get_requirements,   s     *,()4   ';	   (< 	   *fmY   +:	   '<+  9#
 #	
r2   context
layer_namesymbol_tablec                     |j         |         j        d         }|                    |||          }|                    d          j        }|                    d||                    d          d          }|S )a  Look up the array of memory protection constants from the memory
        sample. These don't change often, but if they do in the future, then
        finding them dynamically versus hard-coding here will ensure we parse
        them properly.

        Args:
            context: The context to retrieve required elements (layers, symbol tables) from
            layer_name: The name of the layer on which to operate
            symbol_table: The name of the table containing the kernel symbols
        kernel_virtual_offset)rO   offsetMmProtectToValuearrayrG   r   )object_typerS   subtypecount)layersconfigmodule
get_symbolr;   objectget_type)rL   rN   rO   rP   kvontkrnlmpaddrvaluess           r1   protect_valueszVadInfo.protect_valuesT   s~    $ nZ(/0GH>>,:c>RR""#566>h6G6G6N6NVX ! 
 
 r2   c                     dS NF _s    r1   <lambda>zVadInfo.<lambda>t   s    e r2   procfilter_funcNc              #   z   K   |                                                                 D ]} ||          s|V  dS )a  Lists the Virtual Address Descriptors of a specific process.

        Args:
            proc: _EPROCESS object from which to list the VADs
            filter_func: Function to take a virtual address descriptor value and return True if it should be filtered out

        Returns:
            A list of virtual address descriptors based on the process and filtered based on the filter function
        N)get_vad_roottraverse)rL   rj   rk   vads       r1   	list_vadszVadInfo.list_vadsn   sU      " $$&&//11 	 	C;s## 				 	r2   ro   open_methodrC   c                    	 |                                 }|                                }n+# t          $ r t                              d           Y dS w xY wd|cxk     r|                                k     r(n n%t                              d|dd|dd           dS d}	 |j        }|                                }	nV# t          j	        $ rD}
t                              d	
                    ||
j        |
j                             Y d}
~
dS d}
~
ww xY w|j        |	         }d
| d|dd|dd}	  ||          }d}|}|                                }|||z   k     rTt          |||z   |z
            }|                    ||d          }|sn#|                    |           ||z  }|||z   k     Tn8# t"          $ r+}
t                              d| d|
            Y d}
~
dS d}
~
ww xY w|S )a/  Extracts the complete data for Vad as a FileInterface.

        Args:
            context: The context to retrieve required elements (layers, symbol tables) from
            proc: an _EPROCESS instance
            vad: The suspected VAD to extract (ObjectInterface)
            open_method: class to provide context manager for opening the file
            maxsize: Max size of VAD section (default MAXSIZE_DEFAULT)

        Returns:
            An open FileInterface object containing the complete data for the process or None in the case of failure
        z-Unable to find the starting/ending VPN memberNr   zSkip VAD dump z#x-z due to maxsize limitUnknownz*Process {}: invalid address {} in layer {}zpid.z.vad.z.dmpi   T)padzUnable to dump VAD z: )	get_startget_endAttributeErrorvollogdebugget_sizeUniqueProcessIdadd_process_layerr   InvalidAddressExceptionformatinvalid_addressrO   rY   minreadwrite	Exception)rL   rN   rj   ro   rq   rC   	vad_startvad_endproc_idproc_layer_nameexcp
proc_layer	file_namefile_handle
chunk_sizerS   vad_sizeto_readdatas                      r1   vad_dumpzVadInfo.vad_dump   s|   ,	IkkmmGG 	 	 	LLHIII44	 w'''''''''LLQQQQQQQQ   4		*G"4466OO1 	 	 	LL<CCT14?   
 44444	 ^O4
H7HHHHHHHHH		%+i00K)JF||~~H9x///j)h*>*GHH!vwDAA !!$''''! 9x///  	 	 	LLByBBDBBCCC44444	 s@   (+ $AA B< <D9D

D.B F/ /
G$9 GG$c              #      K    j         j         j        d                  } j         j        |j                 }dt
          j        j        dt          fd}|} j        	                    dd            dt
          j        j        dt          f fd}|}|D ]}t          j        |j                  }                     ||          D ]}	d	}
 j        d
         rM                      j         ||	 j         j        d                   }d}
|r|                                 |j        }
d|j        |t'          j        |                    |	j        j                            t'          j        |	                                          t'          j        |	                                          |	                                |	                                          j         |j        |j                  t<                    |	                                |	                                 t'          j        |	!                                          |	"                                |
ffV  d S )Nr5   rh   r3   c                     dS re   rf   rg   s    r1   passthroughz'VadInfo._generator.<locals>.passthrough   s    5r2   r;   xc                     |                                  j        d         cxk    o|                                 k    nc  S )Nr;   )rv   rZ   rw   )r   r-   s    r1   filter_functionz+VadInfo._generator.<locals>.filter_function   s?    KKMMT[-CRRRRqyy{{RRRRSSr2   )rk   DisabledrA   rC   zError outputting filer   )#rN   modulesrZ   rY   rO   r
   objectsObjectInterfaceboolgetr   array_to_stringImageFileNamerp   r   openclosepreferred_filenamer|   r   HexcanonicalizevolrS   rv   rw   get_tagget_protectionrc   symbol_table_namewinnt_protectionsget_commit_chargeget_private_memory
get_parentget_file_name)r-   procsr5   kernel_layerr   rk   r   rj   process_namero   file_outputr   s   `           r1   
_generatorzVadInfo._generator   sv     %dk(&;<|*6+<=	:-= 	$ 	 	 	 	 ";??9d++7T:#5#E T$ T T T T T T *K %	 %	D"243EFFL~~d~DD " "(;v& E"&--dCDK	<R# #K #:K" E#))+++&1&D ,$$()B)B37>)R)RSS$(99$(77** // $ & 1 & 8 
 .  --//..00$()9)9::))++#'    "%	 %	r2   c                 D   | j         j        | j        d                  }t          j                            | j                            dd                     }t          j        dt          fdt          fdt          j        fdt          j        fdt          j        fdt          fd	t          fd
t          fdt          fdt          j        fdt          fdt          fg|                     t          j                            | j         |j        |j        |                              S )Nr5   r=   PIDProcessOffsetz	Start VPNzEnd VPNTag
ProtectionCommitChargePrivateMemoryParentFilezFile output)rN   rO   rP   rk   )rN   r   rZ   r   rI   create_pid_filterr   r	   TreeGridrG   strr   r   r   list_processesrO   r   )r-   r5   rk   s      r1   runzVadInfo.run   s   %dk(&;<m55dkooeT6R6RSS!C <+,l./L,-s#% #&<+,$ OO,, L%0!'!9 +	 -   
 
 	
r2   )"__name__
__module____qualname____doc___required_framework_version_versionrK   r+   classmethodr   r
   configurationRequirementInterfacerM   rN   ContextInterfacer   r   rG   rc   r   r   r   r   r   rp   r   pluginsFileHandlerInterfacer   r   r   r   __classcell__)r0   s   @r1   r'   r'   !   s       &&"+H(O$ $ $ $ $ %
j&>&S!T %
 %
 %
 [%
N #4  	
 
#   [2  O  0 /0$6
 
:%5tTA	B   [(  'A A#4A  0A /	A
 *,ABA A 
*$9	:A A A [AF4 4 4l
 
 
 
 
 
 
r2   r'   )loggingtypingr   r   r   r   r   r   volatility3.frameworkr	   r
   r   #volatility3.framework.configurationr   volatility3.framework.objectsr   volatility3.framework.renderersr   volatility3.plugins.windowsr   	getLoggerr   ry   r   r   PluginInterfacer'   rf   r2   r1   <module>r      s/  
  F F F F F F F F F F F F F F F F C C C C C C C C C C < < < < < < 1 1 1 1 1 1 8 8 8 8 8 8 . . . . . .		8	$	$ ""&   x
 x
 x
 x
 x
j 0 x
 x
 x
 x
 x
r2   