
    *1fO"                         d dl mZmZmZmZmZ d dl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  G d	 d
ej        j                  ZdS )    )AnyCallableIterableListTuple)
interfaces	renderers)requirements)utility)format_hints)intermed)elf)elfsc                      e Zd ZdZdZdZedeej	        j
                 fd            Zeddee         deegef         fd            Ze	 dd
ej        j        dedeeeeef         fd            Zd
ej        j        defdZ	 	 	 ddeegef         dededefdZed d	fdej        j        dedeegef         dedeej        j                 f
d            Zd ZdS )PsListz?Lists the processes present in a particular linux memory image.   r   r   )r   r      returnc                 8   t          j        ddg d          t          j        dt          j        d          t          j        dd	t          d
          t          j        ddd
d          t          j        ddd
d          t          j        ddd
d          gS )NkernelzLinux kernel)Intel32Intel64AArch64)namedescriptionarchitecturesr   r   )r   pluginversionpidzFilter on specific process IDsT)r   r   element_typeoptionalthreadszInclude user threadsF)r   r   r"   defaultdecorate_commzXShow `user threads` comm in curly brackets, and `kernel threads` comm in square bracketsdumpzExtract listed processes)r
   ModuleRequirementPluginRequirementr   ElfsListRequirementintBooleanRequirement)clss    \/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/linux/pslist.pyget_requirementszPsList.get_requirements   s     **???  
 *DIy   (< 	   +2	   +$v	   +6	  7!
 !	
    Npid_listc                 <    |pg }d |D             rfd}|S d S )a/  Constructs a filter function for process IDs.

        Args:
            pid_list: List of process IDs that are acceptable (or None if all are acceptable)

        Returns:
            Function which, when provided a process object, returns True if the process is to be filtered out of the list
        c                     g | ]}||S N ).0xs     r.   
<listcomp>z,PsList.create_pid_filter.<locals>.<listcomp>G   s    <<<Qamqmmmr0   c                     | j         vS r4   )r    )r7   filter_lists    r.   filter_funcz-PsList.create_pid_filter.<locals>.filter_funcJ   s    uK//r0   c                     dS NFr5   _s    r.   <lambda>z*PsList.create_pid_filter.<locals>.<lambda>O   s    U r0   r5   )r-   r1   r;   r:   s      @r.   create_pid_filterzPsList.create_pid_filter;   sR     >r<<(<<< 	#0 0 0 0 0 "?"r0   Ftaskr%   c                     |j         }|j        }|j        r|j        j         nd}t          j        |j                  }|r|j        rd| d}n|j        rd| d}|j        j	        ||||f}|S )a  Extract the fields needed for the final output

        Args:
            task: A task object from where to get the fields.
            decorate_comm: If True, it decorates the comm string of user threads in curly brackets,
                           and of Kernel threads in square brackets.
                           Defaults to False.
        Returns:
            A tuple with the fields to show in the plugin output.
        r   []{})
tgidr    parentr   array_to_stringcommis_kernel_threadis_user_threadvoloffset)r-   rB   r%   r    tidppidr   task_fieldss           r.   get_task_fieldszPsList.get_task_fieldsQ   s     ih#';5t{A&ty11 	%$ %"4{{{$ %$D}}}xS$=r0   c           	         t           j                            | j        | j        ddt
          j                  }|                                }|st          j	                    S d}|j
                                        D ]q}|j        |j
        j        k    rZt          j                            | j        ||||| j                  }|r(t%          |j                  }|                                  nr|S )zExtract the elf for the process if requested
        Args:
            task: A task object to extract from.
        Returns:
            A string showing the results of the extraction, either
            the filename used or an error.
        linuxr   )class_typeszError outputting file)r   IntermediateSymbolTablecreatecontextconfig_pathr   rV   add_process_layerr	   NotApplicableValuemmget_vma_itervm_start
start_coder   r)   elf_dumpopenstrpreferred_filenameclose)selfrB   elf_table_nameproc_layer_namefile_outputvfile_handles          r.   _get_file_outputzPsList._get_file_outputl   s    "9@@L A 
 
 0022 	 /111 2KW))++  :!333"&)"4"4'&	# #K # ,&)+*H&I&I#))+++E 4 r0   
pid_filterinclude_threadsr&   c              #     K   |                      | j        | j        d         ||          D ]V}|r|                     |          }nd}|                     ||          \  }}}	}
}dt          j        |          ||	|
||ffV  WdS )a  Generates the tasks list.

        Args:
            pid_filter: A function which takes a process object and returns True if the process should be ignored/filtered
            include_threads: If True, the output will also show the user threads
                             If False, only the thread group leaders will be shown
                             Defaults to False.
            decorate_comm: If True, it decorates the comm string of
                            - User threads: in curly brackets,
                            - Kernel threads: in square brackets
                           Defaults to False.
            dump: If True, the main executable of the process is written to a file
                  Defaults to False.
        Yields:
            Each rows
        r   Disabledr   N)
list_tasksrY   configrl   rS   r   Hex)rf   rm   rn   r%   r&   rB   ri   rO   r    rP   rQ   r   s               r.   
_generatorzPsList._generator   s      . OOL$+h/_
 
 	 	D  )"33D99(+/+?+?m+T+T(FCdD ((     	 	r0   c                     dS r=   r5   r>   s    r.   r@   zPsList.<lambda>   s    u r0   rY   vmlinux_module_namer;   c              #      K   |j         |         }|                    d          }|j        D ].} ||          r|V  |r|                                E d{V  /dS )a  Lists all the tasks in the primary layer.

        Args:
            context: The context to retrieve required elements (layers, symbol tables) from
            vmlinux_module_name: The name of the kernel module on which to operate
            filter_func: A function which takes a process object and returns True if the process should be ignored/filtered
            include_threads: If True, it will also return user threads.
        Yields:
            Task objects
        	init_task)symbol_nameN)modulesobject_from_symboltasksget_threads)r-   rY   rv   r;   rn   vmlinuxrx   rB   s           r.   rq   zPsList.list_tasks   s      $ /"56..;.GG	 O 	. 	.D{4   JJJ .++---------	. 	.r0   c           	         | j                             d          }| j                             d          }| j                             d          }| j                             d          }|                     |          }dt          j        fdt
          fdt
          fdt
          fd	t          fd
t          fg}t          j        || 	                    ||||                    S )Nr    r#   r%   r&   z
OFFSET (V)PIDTIDPPIDCOMMzFile output)
rr   getrA   r   rs   r+   rc   r	   TreeGridrt   )rf   pidsrn   r%   r&   r;   columnss          r.   runz
PsList.run   s    {u%%+//)4488{v&&,,T22 <+,CLCLSMSMC 
 !T__[/=RVWW
 
 	
r0   r4   )F)FFF)__name__
__module____qualname____doc___required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer/   r+   r   r   boolrA   objectsObjectInterfacer   rc   rS   rl   rt   rY   ContextInterfacer   rq   r   r5   r0   r.   r   r      s       II"+H"
j&>&S!T "
 "
 "
 ["
H # #c #hud{>S # # # [#* MR %5FJ	sCc!	"   [4%Z%7%G %C % % % %T !&#( (cUD[)( ( 	(
 ( ( ( (T 
 .=_ %. .#4. !. seTk*	.
 . 
*$4	5. . . [.>
 
 
 
 
r0   r   N)typingr   r   r   r   r   volatility3.frameworkr   r	   #volatility3.framework.configurationr
   volatility3.framework.objectsr   volatility3.framework.renderersr   volatility3.framework.symbolsr   .volatility3.framework.symbols.linux.extensionsr   volatility3.plugins.linuxr   pluginsPluginInterfacer   r5   r0   r.   <module>r      s    8 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 < < < < < < 1 1 1 1 1 1 8 8 8 8 8 8 2 2 2 2 2 2 > > > > > > * * * * * *_
 _
 _
 _
 _
Z/ _
 _
 _
 _
 _
r0   