
    "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j8                        Zy)    N)	dataclassastuplefields)IterableListTuple)
interfaces	renderers
exceptions)requirements)plugins)utility)
extensions)pslistc                   D    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   y)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      s    /
I	H
I
I
Ir    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	y	)
CapabilitiesDataz)Stores each set of capabilties for a taskcap_inheritablecap_permittedcap_effectivecap_bsetcap_ambientreturnc                 >     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   J   K   | ]  }t        |j                          y wN)getattrname).0fieldselfs     r!   	<genexpr>z+CapabilitiesData.astuple.<locals>.<genexpr>.   s     I5WT5::.Is    #)tupler   )r1   s   `r!   r   zCapabilitiesData.astuple(   s     IF4LIIIr    N)
r   r   r   r   r	   objectsObjectInterfacer   r   r   r   r    r!   r#   r#      sm    3''777%%555%%555  000##333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y)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   s\     ***?
 **fmmY ((= 	
 	
r    contextvmlinux_module_namec                     |j                   |   }	 |j                  d      }t        j
                  j                         }||kD  rt        j                  d       yy# t        j                  $ r Y yw xY w)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   sx     //"56	")"<"<"<"X
 #44GGI.NNj / %% 		s   A A32A3capc                     t        | t        j                        r| S | j                         }|sy|| j	                         k(  rydj                  | j                               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   sY     c9667J((*	//11yy335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"                               }|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DHHTYYT[[__%TYY^^$
	 NN	,%55#11#11''!335
 .,5,A,A)+++r    tasksc              #   @   K   |D ]  }| j                  |        yw)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(       	2D++D11	2s   c              #       K    j                  |      D ];  \  }}t        |      }t         fd|j                         D              }d||z   f = y w)Nc              3   @   K   | ]  }j                  |        y wr,   )rh   )r/   r]   r1   s     r!   r2   z*Capabilities._generator.<locals>.<genexpr>   s!      &*-  %&s   r   )rv   r   r3   )r1   rt   task_fieldscapabilities_fieldscapabilities_texts   `    r!   
_generatorzCapabilities._generator   sg      150K0KE0R 	5,K,!+.K % &1D1L1L1N& ! [#4444	5s   AAc                    | j                  | j                  | j                  d          | j                  j                  d      }t        j
                  j                  |      }t        j
                  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                  || 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{{v&]]44T:
((LL$++h/Z ) 

 SMCLCLSMSM$c"c"S!C 
 !!'4??5+A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   sF   $"+H
j&>&>&S&S!T 
 
$##44 !0 7++;; 7 7 70  ,%%55 ,	x))	* ,  ,D 2++;;<2	%"223	42 2
5j00@@A
5	%U
#	$
5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 ( ( C C < 4 1 : ,			8	$    J J J$_C7** _Cr    