
    "fu                         d dl Z d dlmZmZmZ d dl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 d d	lmZ  e j        e          Ze G d
 d                      Ze G d d                      Z G d dej                  ZdS )    N)	dataclassastuplefields)IterableListTuple)
interfaces	renderers
exceptions)requirements)plugins)utility)
extensions)pslistc                   F    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   dS )TaskDataz%Stores basic information about a taskcommpidtgidppideuidN)__name__
__module____qualname____doc__str__annotations__int     b/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/linux/capabilities.pyr   r      sC         //
III	HHH
III
III
IIIIIr    r   c                       e Zd ZU dZej        j        ed<   ej        j        ed<   ej        j        ed<   ej        j        ed<   ej        j        ed<   defdZ	d	S )
CapabilitiesDataz)Stores each set of capabilties for a taskcap_inheritablecap_permittedcap_effectivecap_bsetcap_ambientreturnc                 T     t           fdt                     D                       S )zReturns a shallow copy of the capability sets in a tuple.

        Otherwise, when dataclasses.astuple() performs a deep-copy recursion on
        ObjectInterface will take a substantial amount of time.
        c              3   B   K   | ]}t          |j                  V  d S N)getattrname).0fieldselfs     r!   	<genexpr>z+CapabilitiesData.astuple.<locals>.<genexpr>.   s/      II5WT5:..IIIIIIr    )tupler   )r1   s   `r!   r   zCapabilitiesData.astuple(   s.     IIIIF4LLIIIIIIr    N)
r   r   r   r   r	   objectsObjectInterfacer   r   r   r   r    r!   r#   r#      s         33'7777%5555%5555 0000#3333J J J J J J Jr    r#   c                      e Zd ZdZdZdZedeej	        j
                 fd            Zdej        j        defdZed	ej        j        defd
            Zedej        j        deeef         fd            Zedeej        j                 deeeef                  fd            Zdeej        j                 deeeef                  fdZd ZdS )CapabilitieszLists process capabilities   r   r   )   r   r   r)   c                     t          j        ddg d          t          j        dt          j        d          t          j        dd	t          d
          gS )NkernelzLinux kernel)Intel32Intel64AArch64)r.   descriptionarchitecturesr   r8   )r.   pluginversionpidszFilter on specific process IDs.T)r.   r@   element_typeoptional)r   ModuleRequirementPluginRequirementr   PsListListRequirementr   )clss    r!   get_requirementszCapabilities.get_requirements8   su     **???  
 *fmY   (= 	  
 	
r    contextvmlinux_module_namec                     |j         |         }	 |                    d          }n# t          j        $ r Y dS w xY wt          j                                        }||k    rt                              d           dS dS )zChecks that the framework supports at least as much capabilities as
        the kernel being analysed. Otherwise, it shows a warning for the
        developers.
        cap_last_cap)symbol_nameNzXDevelopers: The supported Linux capabilities of this plugin are outdated for this kernel)	modulesobject_from_symbolr   SymbolErrorr   kernel_cap_structget_last_cap_valuevollogwarning)r1   rM   rN   vmlinuxkernel_cap_last_capvol2_last_caps         r!   _check_capabilities_supportz(Capabilities._check_capabilities_supportK   s     /"56	")"<"<"<"X"X% 	 	 	44	 #4GGII..NNj     /.s   & 99capc                     t          | t          j                  r| S |                                 }|sdS ||                                 k    rdS d                    |                                           S )a  Returns a textual representation of the capability set.
        The format is a comma-separated list of capabilitites. In order to
        summarize the output and if all the capabilities are enabled, instead of
        the individual capabilities, the special name "all" will be shown.

        Args:
            cap: Kernel capability object. Usually a 'kernel_cap_struct' struct

        Returns:
            str: A string with a comma separated list of decoded capabilities
         allz, )
isinstancer
   NotAvailableValueget_capabilitiesget_kernel_cap_fulljoinenumerate_capabilities)r]   	cap_values     r!   _decode_capzCapabilities._decode_capc   sv     c9677 	J((**	 	2//11115yy3355666r    taskc           	         t          t          j        |j                  t	          |j                  t	          |j                  t	          |j        j                  t	          |j        j	                            }|j
        }t          |j        |j        |j        |j        t!          j                              }|                    d          r|j        |_        ||fS )zReturns a tuple with the task basic information along with its capabilities

        Args:
            task: A task object from where to get the fields.

        Returns:
            A tuple with the task basic information and its capabilities
        )r   r   r   r   r   )r$   r%   r&   r'   r(   r(   )r   r   array_to_stringr   r   r   r   parentcredr   	real_credr#   r$   r%   r&   r'   r
   rb   
has_memberr(   )rK   ri   	task_data	task_credcapabilities_datas        r!   get_task_capabilitiesz"Capabilities.get_task_capabilities|   s     (33DHTYT[_%%TY^$$
 
 
	 N	,%5#1#1'!355
 
 
 .. 	B,5,A)+++r    tasksc              #   B   K   |D ]}|                      |          V  dS )a"  Yields a tuple for each task containing the task's basic information along with its capabilities

        Args:
            tasks: An iterable with the tasks to process.

        Yields:
            A tuple for each task containing the task's basic information and its capabilities
        N)rs   )rK   rt   ri   s      r!   get_tasks_capabilitiesz#Capabilities.get_tasks_capabilities   s>        	2 	2D++D111111	2 	2r    c              #       K                         |          D ]J\  }}t          |          }t           fd|                                D                       }d||z   fV  Kd S )Nc              3   B   K   | ]}                     |          V  d S r,   )rh   )r/   r]   r1   s     r!   r2   z*Capabilities._generator.<locals>.<genexpr>   sB       & &*-  %%& & & & & &r    r   )rv   r   r3   )r1   rt   task_fieldscapabilities_fieldscapabilities_texts   `    r!   
_generatorzCapabilities._generator   s       150K0KE0R0R 	5 	5,K,!+..K % & & & &1D1L1L1N1N& & & ! ! [#4444444	5 	5r    c                    |                      | j        | j        d                    | j                            d          }t          j                            |          }t          j                            | j        | j        d         |          }dt          fdt          fdt          fdt          fdt          fd	t          fd
t          fdt          fdt          fdt          fg
}t          j        ||                     |                    S )Nr<   rD   )filter_funcNameTidPidPPidEUIDr$   r%   r&   cap_boundingr(   )r\   rM   configgetr   rI   create_pid_filter
list_tasksr   r   r
   TreeGridr|   )r1   rD   
pid_filterrt   columnss        r!   runzCapabilities.run   s    ((t{87LMMM{v&&]44T::
((L$+h/Z ) 
 

 SMCLCLSMSM$c"c"S!C 
 !'4??5+A+ABBBr    N)r   r   r   r   _required_framework_version_versionclassmethodr   r	   configurationRequirementInterfacerL   rM   ContextInterfacer   r\   staticmethodr4   r5   rh   r   r   r#   rs   r   rv   r   r|   r   r   r    r!   r7   r7   1   s       $$"+H
j&>&S!T 
 
 
 [
$#4 !   0 7+; 7 7 7 7 \70  ,%5 ,	x))	* ,  ,  , [ ,D 2+;<2	%"223	42 2 2 [2
5j0@A
5	%U
#	$
5 
5 
5 
5C C C C Cr    r7   )loggingdataclassesr   r   r   typingr   r   r   volatility3.frameworkr	   r
   r   #volatility3.framework.configurationr    volatility3.framework.interfacesr   volatility3.framework.objectsr   #volatility3.framework.symbols.linuxr   volatility3.plugins.linuxr   	getLoggerr   rW   r   r#   PluginInterfacer7   r   r    r!   <module>r      s  
  2 2 2 2 2 2 2 2 2 2 ( ( ( ( ( ( ( ( ( ( C C C C C C C C C C < < < < < < 4 4 4 4 4 4 1 1 1 1 1 1 : : : : : : , , , , , ,		8	$	$         J J J J J J J J$_C _C _C _C _C7* _C _C _C _C _Cr    