
    Xf!                         d dl Z d dlmZmZmZ d dl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mZ  e j        e          Z G d dej        j                  ZdS )    N)ListIterable	Generator)	constants)
exceptions
interfaces)	renderers)requirements)format_hints)intermed)pe)pslistdlllistc                   d   e Zd ZdZdZdZedeej	        j
                 fd            Zd Ze	 ddej        j        d	ed
edee         deeddf         f
d            Zedej        j        dee         defd            Zedej        j        d	ed
edeej        j                 fd            Zd ZdS )Modulesz Lists the loaded kernel modules.   r   r   )   r   r   returnc           
         t          j        ddddg          t          j        dt          j        d          t          j        d	t
          j        d          t          j        d
ddd          t          j        dddd           gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesr   r   )r   	componentversionr   dumpzExtract listed modulesFT)r   r   defaultoptionalr   zmodule name/sub string)r   r   r!   r    )	r
   ModuleRequirementVersionRequirementr   PsListr   DllListBooleanRequirementStringRequirement)clss    _/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/modules.pyget_requirementszModules.get_requirements   s     *,()4  
 +	   +'/9   +4	   *4	  %
 	
    c              #   l  K   | j         j        | j        d                  }t          j                            | j         | j        ddt          j                  }| 	                    | j         |j
        |j                  D ]4}	 |j                                        }n# t          j        $ r d}Y nw xY w	 |j                                        }n# t          j        $ r d}Y nw xY w| j        d         r| j        d         |vrd}| j        d         rKt"          j                            | j         ||| j                  }d	}|r|                                 |j        }d
t/          j        |j        j                  t/          j        |j                  t/          j        |j                  |||ffV  6d S )Nr   windowsr   )class_types r   Disabledr   zError outputting filer   )contextmodulesconfigr   IntermediateSymbolTablecreateconfig_pathr   r.   list_modules
layer_namesymbol_table_nameBaseDllName
get_stringr   InvalidAddressExceptionFullDllNamer   r%   dump_peopenclosepreferred_filenamer   HexvoloffsetDllBaseSizeOfImage)selfr   pe_table_namemodr:   r=   file_outputfile_handles           r)   
_generatorzModules._generator5   s     %dk(&;< 8??L$*It @ 
 
 $$L&+V-E
 
 $	 $	C!!o88::5 ! ! ! !!!o88::5 ! ! ! ! {6" t{6':+'M'M$K{6" A%o55L-di  6 A%%'''"-"@K  $SW^44 $S[11 $S_55
 
 
 
 
5$	 $	s$   BB0/B04CC"!C"Nr1   r8   symbol_tablepidsc              #     K   g }t           j                            |pg           }t           j                            ||||          D ]}d}	 |j        }|                                }	|                    |t          j        z   dz   ||j	                  }
|
j
        |v rWnM# t          j        $ r; t                              t          j        d                    |                     Y w xY w|                    |
j
                   |	V  dS )aO  Build a cache of possible virtual layers, in priority starting with
        the primary/kernel layer. Then keep one layer per session by cycling
        through the process list.

        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
            pids: A list of process identifiers to include exclusively or None for no filter

        Returns:
            A list of session layer names
        )r1   r8   rM   filter_funcUnknown_MM_SESSION_SPACEr8   rD   zSProcess {} does not have a valid Session or a layer could not be constructed for itN)r   r$   create_pid_filterlist_processesUniqueProcessIdadd_process_layerobjectr   BANGSession	SessionIdr   r<   volloglogLOGLEVEL_VVVformatappend)r(   r1   r8   rM   rN   seen_idsrP   procproc_idproc_layer_namesession_spaces              r)   get_session_layerszModules.get_session_layersa   sR     * >@m55djbAAM00!%#	 1 
 
 !	" !	"D  G."&"8"8":": !( 9>14GG)< !/ ! ! !*h66 7 5   

*ipp     OOM3444!!!!!C!	" !	"s   AB!!AC+*C+session_layersbase_addressc                 X    |D ]&}|j         |                             |          r|c S 'dS )ag  Given a base address and a list of layer names, find a layer that
        can access the specified address.

        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
            session_layers: A list of session layer names
            base_address: The base address to identify the layers that can access it

        Returns:
            Layer name or None if no layers that contain the base address can be found
        N)layersis_valid)r(   r1   rg   rh   r8   s        r)   find_session_layerzModules.find_session_layer   sH    * ) 	" 	"J~j)22<@@ "!!!!" tr+   c              #   2  K   |j         |         j        d         }|                    |||          }	 |                    d          }n*# t          j        $ r |                    d          }Y nw xY w|j                            t          j	                  d         }|
                    d          j        }|                    d|          }	|                    d	          }
|                    ||	j        j        |
z
  d
          }|j        D ]}|V  dS )a  Lists all the modules in the primary layer.

        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

        Returns:
            A list of Modules as retrieved from PsLoadedModuleList
        kernel_virtual_offsetrS   _KLDR_DATA_TABLE_ENTRY_LDR_DATA_TABLE_ENTRYr   PsLoadedModuleList_LIST_ENTRY)object_typerD   InLoadOrderLinksT)rs   rD   absoluteN)rj   r3   moduleget_typer   SymbolError	type_namesplitr   rY   
get_symboladdressrX   relative_child_offsetrC   rD   rt   )r(   r1   r8   rM   kvontkrnlmpldr_entry_typery   	list_head
list_entryreloffrv   rI   s                r)   r7   zModules.list_modules   s<     $ nZ(/0GH>>,:c>RR	H%../GHHNN% 	H 	H 	H%../FGGNNN	H #,229>BB1E	''(<==E	__y_QQ
556HII!*.*?&*HSW ! 
 
 * 	 	CIIII	 	s   A
 
$A10A1c           	          t          j        dt          j        fdt          j        fdt          j        fdt          fdt          fdt          fg|                                           S )NOffsetBaseSizeNamePathzFile output)r	   TreeGridr   rB   strrL   )rG   s    r)   runzModules.run   sb    !<+,)*)*$ OO

 

 
	
r+   )N)__name__
__module____qualname____doc___required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer*   rL   r1   ContextInterfacer   intr   rf   r   rl   objectsObjectInterfacer7   r    r+   r)   r   r      s       **"+H
j&>&S!T 
 
 
 [
6* * *X  8" 8"#48" 8" 	8"
 3i8" 
3d?	#8" 8" 8" [8"t #4 ! 	   [4 $#4$ $ 	$
 
*$4	5$ $ $ [$L
 
 
 
 
r+   r   )loggingtypingr   r   r   volatility3.frameworkr   r   r   r	   #volatility3.framework.configurationr
   volatility3.framework.renderersr   volatility3.framework.symbolsr   0volatility3.framework.symbols.windows.extensionsr   volatility3.plugins.windowsr   r   	getLoggerr   r\   pluginsPluginInterfacer   r   r+   r)   <module>r      s     , , , , , , , , , , + + + + + + 8 8 8 8 8 8 8 8 + + + + + + < < < < < < 8 8 8 8 8 8 2 2 2 2 2 2 ? ? ? ? ? ? 7 7 7 7 7 7 7 7		8	$	$V
 V
 V
 V
 V
j 0 V
 V
 V
 V
 V
r+   