
    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
j0                  j2                        Zy)    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
j6                  j8                     dedee
j6                  j8                     fd       Zd Zd Z  xZ!S )VadInfozLists process memory ranges.)r   r   r   r   r   r   r   c                 2    t        |   |i | d | _        y )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 '';	 ((< 	 **fmmY ++:	 ''<++9#
 #	
r2   context
layer_namesymbol_tablec                     |j                   |   j                  d   }|j                  |||      }|j                  d      j                  }|j                  d||j                  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   sx    $ nnZ(//0GH>>,:c>R""#56>>h6G6G6NVX ! 
 r2   c                      yNF _s    r1   <lambda>zVadInfo.<lambda>t   s    r2   procfilter_funcNc              #   l   K   |j                         j                         D ]  } ||      r|  yw)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   s6     " $$&//1 	Cs#		s   *44ro   open_methodrC   c                 r   	 |j                         }|j                         }d|cxk  r|j                         k  r"n nt        j	                  d|dd|dd       yd}	 |j                  }|j                         }	|j                  |	   }d
| d|dd|dd}	  ||      }d}|}|j                         }|||z   k  rJt        |||z   |z
        }|j                  ||d      }|s	 |S |j!                  |       ||z  }|||z   k  rJ|S # t        $ r t        j	                  d       Y yw xY w# t        j                  $ rD}
t        j	                  d	j                  ||
j                  |
j                               Y d}
~
yd}
~
ww xY w# t"        $ r%}
t        j	                  d| d|
        Y d}
~
yd}
~
ww xY w)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kkmG
 w''LL 2a|;PQ 		**G"446O ^^O4
7)52a|4H		%i0K)JF||~H9x//j)h*>*GH!vwDA  !!$''! 9x// S  	LLHI	 11 	LL<CCT114??
 	.  	LL.ykD6BC	sH    D
  D. AF )F 
D+*D+.F:F  F	F6F11F6c              #   &   K    j                   j                   j                  d      } j                   j                  |j                     }dt
        j                  j                  dt        fd}|} j                  j                  dd       (dt
        j                  j                  dt        f fd}|}|D ]  }t        j                  |j                        } j                  ||      D ]  }	d	}
 j                  d
   rV j                   j                   ||	 j                   j                  d         }d}
|r|j!                          |j"                  }
d|j$                  |t'        j(                  |j+                  |	j,                  j.                              t'        j(                  |	j1                               t'        j(                  |	j3                               |	j5                         |	j7                   j9                   j                   |j                  |j:                        t<              |	j?                         |	jA                         t'        j(                  |	jC                               |	jE                         |
ff   y w)Nr5   rh   r3   c                      yre   rf   rg   s    r1   passthroughz'VadInfo._generator.<locals>.passthrough   s    r2   r;   xc                 z    | j                         j                  d   cxk  xr | j                         k   S c  S )Nr;   )rv   rZ   rw   )r   r-   s    r1   filter_functionz+VadInfo._generator.<locals>.filter_function   s4    KKMT[[-CRqyy{RSS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   s)    %%dkk(&;<||**6+<+<=	:--== 	$ 	 ";;??9d+7T:#5#5#E#E T$ T *K %	D"2243E3EFL~~d~D "(;;v&"&--dCDKK	<R#K #:K"#))+&1&D&D ,,$$(()B)B377>>)RS$((9$((7** // $ & 1 1 & 8 8
 . --/..0$(()9:))+#' "%	s   JJc                    | j                   j                  | j                  d      }t        j                  j                  | 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| j                  t        j                  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   %%dkk(&;<mm55dkkooeT6RS!!C <++,l../L,,-s#% #&<++,$ OO,, LL%00!'!9!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&S!T %
 %
N ##44  	
 
# 2    00 //0$6
 
:%%55tTA	B (  'A##44A   00A //	A
 *,,AABA A 
*$$99	:A AF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 C C < 1 8 .			8	$ ""&  x
j  00 x
r2   