
    vf                         d Z 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 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 ddlmZ  ej4                  e      Z G d dej:                        Zy)zkA module containing a collection of plugins that produce data typically
found in Linux's /proc file system.    N)ListOptionalType)	constants
interfaces	renderers)requirements)plugins)utility)format_hints)intermed)elf)ELF_MAX_EXTRACTION_SIZE)pslistc                   j   e Zd ZdZdZdZedeej                  j                     fd       Zedej                  j                  deded	ej                  j                   d
ej                  j                   deej$                  j&                     deej$                  j&                     fd       Zd Zd Zy)Elfsz4Lists all memory mapped ELF files for all processes.   r   r   )r   r      returnc           	          t        j                  ddg d      t        j                  dt        j                  d      t        j
                  dd	t        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dumpzExtract listed processesF)r   r   defaultr#   )r	   ModuleRequirementPluginRequirementr   PsListListRequirementintBooleanRequirement)clss    Z/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/linux/elfs.pyget_requirementszElfs.get_requirements   sx     ***?
 **fmmY ((< 	 ++6	
 	
    context
layer_nameelf_table_namevmataskopen_methodc           	         |j                   |   }d}|j                  |t        j                  z   dz   |j                  |      }	|	j                         st        j                  d       yi }
|	j                         D ]  }	 |j                  j                  dk7  r	 |j                  }|j                  }||z   }||j                   z  r||j"                  z  }||j                   z  r||j"                  z  |j                   z   }||z
  }|dk  s	|t$        kD  rt        d|       ||
|<    d	}t'        |
j)                               D ]-  }|
|   }|j+                  |j                  |z   |d
      }||z   }/  |d|j,                   dt/        j0                  |j2                         d|j                  dd      }|j5                  |       |S # t        $ r5 t        j                  t        j                  d|j                          Y w xY w)a]  Extracts an ELF as a FileHandlerInterface
        Args:
            context: the context to operate upon
            layer_name: The name of the layer on which to operate
            elf_table_name: the name for the symbol table containing the symbols for ELF-files
            vma: virtual memory allocation of ELF
            task: the task 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 task or None in the case of failure
        NElf)offsetr1   z$ELF object to be dumped is not validPT_LOADz*Skipping unknown ELF program header type: r   z(The claimed size of the ELF is invalid: r/   Tpadzpid..z#xz.dmp)layersobjectr   BANGvm_startis_validvollogdebugget_program_headersp_typer   
ValueErrorlogLOGLEVEL_VVVVp_vaddrp_memsz	page_size	page_maskr   sortedkeysreadr!   r   array_to_stringcommwrite)r,   r0   r1   r2   r3   r4   r5   
proc_layerfile_handle
elf_objectsectionsphdrstartsizeend	real_sizeelf_datasection_start	read_sizebufs                       r-   elf_dumpzElfs.elf_dump7   s   , ^^J/
^^Y^^+e3<<! $ 

 ""$LL?@224 	(D;;**i7 8 LLE<<D$,C
 z+++
 4 44Z)))Z111Z5I5IIeI 1}	,C C #KI;!WXX'HUO=	(@ #HMMO4 	&M /I//#,,">	t/TC#~H		& "488*Ag55dii@A3<<PRBSSWX
 	(#Q  

++@N s    G:H	H	c           
   #   f  K   t         j                  j                  | j                  | j                  ddt
        j                        }|D ]a  }|j                         }|s| j                  j                  |   }t        j                  |j                        }|j                  j                         D ]  }|j                  |j                  dd      }|dk7  r'|j!                  | j                  |      }	d}
| j"                  d	   rS| j%                  | j                  ||||| j&                        }d
}
|r%|j)                          t+        |j,                        }
d|j.                  |t1        j2                  |j                        t1        j2                  |j4                        |	|
ff  d y w)Nlinuxr   )class_types   Tr:   s   ELFDisabledr$   zError outputting filer   )r   IntermediateSymbolTablecreater0   config_pathr   rc   add_process_layerr=   r   rP   rQ   mmget_vma_iterrO   r@   get_nameconfigr`   openclosestrpreferred_filenamer!   r   Hexvm_end)selftasksr2   r4   proc_layer_namerS   r   r3   hdrpathfile_outputrT   s               r-   
_generatorzElfs._generator   s    !99@@LL$**GU A 
  )	D"446O",,_=J**4995Dww++-   oocllA4o@*$||DLL$7(;;v&"&--'&		#K #:K"#))+&)+*H*H&I $((6$((4#
 
- )	s   F/F1c           
         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        fdt        fg| j                  t         j                  j                  | j                  | j                  d   |	                  S )
Nr!   PIDProcessStartEndz	File PathzFile Outputr   )filter_func)r   r(   create_pid_filterrm   getr   TreeGridr*   rp   r   rr   rz   
list_tasksr0   )rt   r   s     r-   runzElfs.run   s    mm55dkkooeT6RS!!C ,**+(()c"$ OO((LL$++h"7[ ) 
 	
r/   N)__name__
__module____qualname____doc___required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer.   r0   ContextInterfacerp   objectsObjectInterfacer   r
   FileHandlerInterfacer   r`   rz   r    r/   r-   r   r      s    >"+H
j&>&>&S&S!T 
 
0 P##44P P 	P
 //P   00P *,,AABP 
*$$99	:P Pd-^
r/   r   )r   loggingtypingr   r   r   volatility3.frameworkr   r   r   #volatility3.framework.configurationr	    volatility3.framework.interfacesr
   volatility3.framework.objectsr   volatility3.framework.renderersr   volatility3.framework.symbolsr   .volatility3.framework.symbols.linux.extensionsr   %volatility3.framework.constants.linuxr   volatility3.plugins.linuxr   	getLoggerr   rB   PluginInterfacer   r   r/   r-   <module>r      s[   '  ' ' B B < 4 1 8 2 > I , 
		8	$r
7"" r
r/   