
    Xf^/                         d dl Z d dlZd dlmZmZmZmZ d dlmZm	Z	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 d dlmZ d d	lmZ  ej        e          Z G d
 de	j        j        ej                  ZdS )    N)CallableIterableListType)	renderers
interfaceslayers
exceptions	constants)requirements)utility)format_hints)intermed)pe)	timelinerc                      e Zd ZdZdZdZdZed             Zede	j
        j        dedede	j        j        d	ee	j        j                 d
e	j        j        fd            Ze	 ddee         ded
ee	j        j        gef         fd            Ze	 ddee         ded
ee	j        j        gef         fd            Zed fde	j
        j        dededee	j        j        gef         d
ee	j        j                 f
d            Zd Zd Zd ZdS )PsListzALists the processes present in a particular windows memory image.)   r   r   Fc           	          t          j        ddddg          t          j        dd| j        d	          t          j        d
t
          dd          t          j        dddd	          gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesphysicalz+Display physical offsets instead of virtualT)r   r   defaultoptionalpidz8Process ID to include (all other processes are excluded))r   element_typer   r   dumpzExtract listed processesF)r   ModuleRequirementBooleanRequirementPHYSICAL_DEFAULTListRequirementint)clss    ^/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/pslist.pyget_requirementszPsList.get_requirements   s     *,()4  
 +I,	   ( V	   +6	  %
 	
    contextkernel_table_namepe_table_nameprocopen_methodreturnc           
         d}d}	 |j         }|                                }|                    |t          j        z   dz   ||j                  }	|                    |t          j        z   dz   |	j        |          }
|j                            d|j        j	        j
        d	          } ||                    |j          d
| d
|	j        dd                    }|
                                D ]/\  }}|                    |           |                    |           0n7# t          $ r*}t                               d| d|            Y d}~nd}~ww xY w|S )ab  Extracts the complete data for a process as a FileHandlerInterface

        Args:
            context: the context to operate upon
            kernel_table_name: the name for the symbol table containing the kernel's symbols
            pe_table_name: the name for the symbol table containing the PE format symbols
            proc: the process object whose memory should be output
            open_method: class to provide context manager for opening the file

        Returns:
            An open FileHandlerInterface object containing the complete data for the process or None in the case of failure
        NzInvalid process object_PEB
layer_nameoffset_IMAGE_DOS_HEADER)r5   r4   stringreplace
max_lengtherrors.z#xz.dmpzUnable to dump PE with pid z: )UniqueProcessIdadd_process_layerobjectr   BANGPebImageBaseAddressImageFileNamecastvolcountsanitize_filenamereconstructseekwrite	Exceptionvollogdebug)r'   r+   r,   r-   r.   r/   file_handleproc_idproc_layer_namepeb
dos_headerprocess_namer5   dataexcps                  r(   process_dumpzPsList.process_dump7   s   , *	J*G"4466O..!IN2V;*x !  C !	.1DD+* (  J  -22-17  3  L &+--+ZZlZZS=QZZZZ  K !+ 6 6 8 8 ( (  (((!!$''''(  	J 	J 	JLLHwHH$HHIIIIIIII	J s   DD 
E( EENpid_listexcludec                 L    d }|pg }d |D             r|rfd}nfd}|S )aw  A factory for producing filter functions that filter based on a list
        of process IDs.

        Args:
            pid_list: A list of process IDs that are acceptable, all other processes will be filtered out
            exclude: Accept only tasks that are not in pid_list

        Returns:
            Filter function for passing to the `list_processes` method
        c                     dS NF _s    r(   <lambda>z*PsList.create_pid_filter.<locals>.<lambda>        r*   c                     g | ]}||S Nr\   .0xs     r(   
<listcomp>z,PsList.create_pid_filter.<locals>.<listcomp>   s    <<<Qamqmmmr*   c                     | j         v S rb   r=   re   filter_lists    r(   r_   z*PsList.create_pid_filter.<locals>.<lambda>   s    (9[(H r*   c                     | j         vS rb   rh   ri   s    r(   r_   z*PsList.create_pid_filter.<locals>.<lambda>   s    (9(L r*   r\   )r'   rW   rX   filter_funcrj   s       @r(   create_pid_filterzPsList.create_pid_filterr   s^     &o>r<<(<<< 	M MHHHHLLLLr*   	name_listc                 L    d }|pg }d |D             r|rfd}nfd}|S )a|  A factory for producing filter functions that filter based on a list
        of process names.

        Args:
            name_list: A list of process names that are acceptable, all other processes will be filtered out
            exclude: Accept only tasks that are not in name_list
        Returns:
            Filter function for passing to the `list_processes` method
        c                     dS r[   r\   r]   s    r(   r_   z+PsList.create_name_filter.<locals>.<lambda>   r`   r*   c                     g | ]}||S rb   r\   rc   s     r(   rf   z-PsList.create_name_filter.<locals>.<listcomp>   s    ===Qq}q}}}r*   c                 :    t          j        | j                  v S rb   r   array_to_stringrC   ri   s    r(   r_   z+PsList.create_name_filter.<locals>.<lambda>   s    g5aoFF+U r*   c                 :    t          j        | j                  vS rb   rs   ri   s    r(   r_   z+PsList.create_name_filter.<locals>.<lambda>   s    g5aoFF&' r*   r\   )r'   rn   rX   rl   rj   s       @r(   create_name_filterzPsList.create_name_filter   sl     &oO	==)=== 		 UUUU 
' ' ' '  r*   c                     dS r[   r\   r]   s    r(   r_   zPsList.<lambda>   s    e r*   r4   symbol_tablerl   c              #     K   |j         |         j        d         }|                    |||          }|                    d          j        }|                    d|          }|                    d                              d          }	|                    d|j        j	        |	z
  d	          }
|
j
        D ]} ||          s|V  d
S )a[  Lists all the processes in the primary layer that are in the pid
        config option.

        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
            filter_func: A function which takes an EPROCESS object and returns True if the process should be ignored/filtered

        Returns:
            The list of EPROCESS objects from the `layer_name` layer's PsActiveProcessHead list after filtering
        kernel_virtual_offsetr3   PsActiveProcessHead_LIST_ENTRY)object_typer5   	_EPROCESSActiveProcessLinksT)r}   r5   absoluteN)r	   configmodule
get_symboladdressr?   get_typerelative_child_offsetrE   r5   r   )r'   r+   r4   rx   rl   kvontkrnlmpps_aph_offset
list_entryreloffeprocr.   s               r(   list_processeszPsList.list_processes   s      0 nZ(/0GH>>,:c>RR ++,ABBJ__}_UU
 "";//EE 
 
 #>(61   
 
 , 	 	D;t$$ 


	 	r*   c              #   p  K   | j         j        | j        d                  }t          j                            | j         | j        ddt          j                  }| j         j	        |j
                 }t          |t          j        j                  st          d          |                     | j         |j
        |j        |                     | j                            dd                               D ]}| j                            d| j                  s|j        j        }n:t-          |                    |j        j        d	
                    d	         \  }}}}}d}	 | j        d         rT|                     | j         |j        ||| j                  }d}|r(|                                 t7          |j                  }d	|j        |j        |j                             d|j        j        j!        d          tE          j#        |          |j$        |%                                |&                                |'                                |(                                |)                                |ffV  # tT          j+        $ r- tX          -                    d|j        j        dd           Y w xY wd S )Nr   windowsr   )class_typesz#Primary layer is not an intel layerr   )rl   r   r   )r5   lengthDisabledr!   zError outputting filer7   r8   r9   z"Invalid process found at address: re   z
. Skipping).r+   modulesr   r   IntermediateSymbolTablecreateconfig_pathr   r   r	   r4   
isinstanceintelIntel	TypeErrorr   symbol_table_namerm   getr$   rE   r5   listmappingrV   openclosestrpreferred_filenamer=   InheritedFromUniqueProcessIdrC   rD   rF   r   HexActiveThreadsget_handle_countget_session_idget_is_wow64get_create_timeget_exit_timer
   InvalidAddressExceptionrL   info)	selfr   r-   memoryr.   r5   r^   file_outputrN   s	            r(   
_generatorzPsList._generator   s     %dk(&;< 8??L$*It @ 
 
 $V%67&&,"455 	CABBB''L$..t{ud/K/KLL	 ( 
 
 5	 5	D ;??:t/DEE '+NN$(/!NDD( (($Avq! %K&;v& J"&"3"30%	# #K #:K" J#))+++&)+*H&I&I ,9*//$'+'9'='C#, 0  
 %(00*--//++--))++,,..**,,#    * 5   VVVVV    e5	 5	s   DI778J32J3c              #      K   |                                  D ]]}|\  }}d|d          d|d          d|d          d}|t          j        j        |d         fV  |t          j        j        |d	         fV  ^d S )
Nz	Process: r    r   z (   )   	   )r   r   TimeLinerTypeCREATEDMODIFIED)r   row_depthrow_datar   s        r(   generate_timelinezPsList.generate_timeline   s      ??$$ 	O 	OC"FHQhqkQQHQKQQ8A;QQQK	 7 ?!MMMM	 7 @(1+NNNNN		O 	Or*   c                 l   | j                             d| j                  sdnd}t          j        dt
          fdt
          fdt          fd| t          j        fdt
          fd	t
          fd
t
          fdt          fdt          j
        fdt          j
        fdt          fg|                                           S )Nr   z(V)z(P)PIDPPIDrC   OffsetThreadsHandles	SessionIdWow64
CreateTimeExitTimezFile output)r   r   r$   r   TreeGridr&   r   r   r   booldatetimer   )r   
offsettypes     r(   runz
PsList.run'  s    T5JKKVEEQV 	 ! #&&*&&(89C C c"$x01X./$ OO
 
 	
r*   r[   )__name__
__module____qualname____doc___required_framework_version_versionr$   classmethodr)   r   r+   ContextInterfacer   objectsObjectInterfacer   pluginsFileHandlerInterfacerV   r   r&   r   r   rm   rv   r   r   r   r   r   r\   r*   r(   r   r      s"       KK"+H
 
 [
6 8#48 8 	8
  08 *,AB8 
		08 8 8 [8t 9> Cy26	:%56<	=   [0 :? S	37	:%56<	=   [8  O3 3#43 3 	3
 /0$6
3 
*$4	53 3 3 [3j@ @ @DO O O
 
 
 
 
r*   r   ) r   loggingtypingr   r   r   r   volatility3.frameworkr   r   r	   r
   r   #volatility3.framework.configurationr   volatility3.framework.objectsr   volatility3.framework.renderersr   volatility3.framework.symbolsr   0volatility3.framework.symbols.windows.extensionsr   volatility3.pluginsr   	getLoggerr   rL   r   PluginInterfaceTimeLinerInterfacer   r\   r*   r(   <module>r      s.  
   1 1 1 1 1 1 1 1 1 1 1 1 V V V V V V V V V V V V V V < < < < < < 1 1 1 1 1 1 8 8 8 8 8 8 2 2 2 2 2 2 ? ? ? ? ? ? ) ) ) ) ) )		8	$	$g
 g
 g
 g
 g
Z/1M g
 g
 g
 g
 g
r*   