
    [
#g%                         d dl Z d dlmZmZmZ d dlmZ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mZ  e j*                  e      Z G d	 d
ej0                  j2                        Zy)    N)ListIterable	Generator)
exceptions
interfaces	constants	renderers)requirements)format_hints)intermed)pe)pslistpedumpc                       e Zd ZdZdZdZ fdZedee	j                  j                     fd       Z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.                  j0                     fd       Zd Z xZS )Modulesz Lists the loaded kernel modules.   r   r   c                 F    t        |   |i | | j                  | _        y N)super__init__list_modules_enumeration_method)selfargskwargs	__class__s      _/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/modules.pyr   zModules.__init__   s#    $)&)#'#4#4     returnc           
      Z   t        j                  ddddg      t        j                  dt        j                  d      t        j
                  d	d
dd      t        j                  ddd      t        j                  dddd       t        j                  dt        j                  d      gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesr   r   )r%   	componentversiondumpzExtract listed modulesFT)r%   r&   defaultoptionalbasez)Extract a single module with BASE address)r%   r&   r,   r%   zmodule name/sub string)r%   r&   r,   r+   r   )   r   r   )
r
   ModuleRequirementVersionRequirementr   PsListBooleanRequirementIntRequirementStringRequirementr   PEDump)clss    r   get_requirementszModules.get_requirements   s     **,()4
 ++	 ++4	 ''G
 **4	 ++	5
 	
r   c                     | j                  | j                  ||j                        }d|j                  d}|r<t        j                  j                  | j                  ||| j                  |      }|sd}|S )Nz'Cannot find a viable session layer for z#x)
layer_namezError outputting file)find_session_layercontextDllBaser   r5   dump_ldr_entryopen)r   session_layerspe_table_namemodsession_layer_namefile_outputs         r   dump_modulezModules.dump_module<   s{    !44LL.#++
 @B?OP --66		- 7 K 5r   c              #     K   | j                   j                  | j                  d      }d }d }| j                  d   rt        j                  j                  | j                   | j                  ddt        j                        }t        | j                  | j                   |j                  |j                              }| j                  | j                   |j                  |j                        D ]  }| j                  d   r| j                  d   |j                  k7  r0	 |j                  j!                         }| j                  d   r| j                  d   |vrl	 |j,                  j!                         }d}| j                  d   r| j/                  |||      }d	t1        j2                  |j4                  j6                        t1        j2                  |j                        t1        j2                  |j8                        |||ff  y # t"        j$                  $ r" t&        j(                  j+                         }Y w xY w# t"        j$                  $ r" t&        j(                  j+                         }Y w xY ww)
Nr"   r*   windowsr   )class_typesr-   r%   Disabledr   )r;   modulesconfigr   IntermediateSymbolTablecreateconfig_pathr   rG   listget_session_layersr9   symbol_table_namer   r<   BaseDllName
get_stringr   InvalidAddressExceptionr   r	   BaseAbsentValueFullDllNamerD   r   HexvoloffsetSizeOfImage)r   r"   r@   r?   rA   rQ   rU   rC   s           r   
_generatorzModules._generatorN   s    %%dkk(&;<;;v$<<CC  NN D M "''LL&"3"3V5M5MN ++LL&++V-E-E
C {{6"t{{6':ckk'IE!oo88: {{6"t{{6':+'ME!oo88: %K{{6""..~}cR  0  -  1  /
 55 E(22BBDE 55 E(22BBDEsO   DI9H	8!I9I4BI9	1H>:I9=H>>I91I62I95I66I9Nr;   r9   symbol_tablepidsc              #   >  K   g }t         j                  j                  |xs g       }t         j                  j                  ||||      D ]  }d}	 |j                  }|j                         }	|j                  |t        j                  z   dz   ||j                        }
|
j                  |v rc	 |j#                  |
j                         |	  y# t        j                  $ r6 t        j                  t        j                  dj!                  |             Y w xY ww)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
        )r;   r9   r[   filter_funcUnknown_MM_SESSION_SPACEr9   rX   zSProcess {} does not have a valid Session or a layer could not be constructed for itN)r   r1   create_pid_filterlist_processesUniqueProcessIdadd_process_layerobjectr   BANGSession	SessionIdr   rS   volloglogLOGLEVEL_VVVformatappend)r6   r;   r9   r[   r\   seen_idsr^   procproc_idproc_layer_namesession_spaces              r   rO   zModules.get_session_layers   s    * >@mm55djbAMM00!%#	 1 
D  G.."&"8"8": !( 9>>14GG)<< !/ ! !**h6 7 OOM334!!C
, 55 

**ipp s,   ADAC-$DADDDDr?   base_addressc                 V    |D ]$  }|j                   |   j                  |      s"|c S  y)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)r6   r;   r?   rt   r9   s        r   r:   zModules.find_session_layer   s0    * )J~~j)22<@!! ) r   c              #   :  K   |j                   |   j                  d   }|j                  |||      }	 |j                  d      }|j                  j                  t        j                        d   }|j                  d      j                  }|j                  d|      }	|j                  d	      }
|j                  ||	j                  j                  |
z
  d
      }|j                   D ]  }|  y# t        j
                  $ r |j                  d      }Y w xY ww)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_offsetra   _KLDR_DATA_TABLE_ENTRY_LDR_DATA_TABLE_ENTRYr.   PsLoadedModuleList_LIST_ENTRY)object_typerX   InLoadOrderLinksT)r~   rX   absoluteN)rv   rJ   moduleget_typer   SymbolError	type_namesplitr   rg   
get_symboladdressrf   relative_child_offsetrW   rX   r   )r6   r;   r9   r[   kvontkrnlmpldr_entry_typer   	list_head
list_entryreloffr   rA   s                r   r   zModules.list_modules   s    $ nnZ(//0GH>>,:c>R	H%../GHN #,,229>>B1E	''(<=EE	__y_Q
556HI!*..*?*?&*HSW ! 
 **CI + %% 	H%../FGN	Hs)   1DC1 B,D1$DDDD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| j                               S )NOffsetBaseSizeNamePathzFile output)r	   TreeGridr   rV   strrZ   )r   s    r   runzModules.run   sf    !!<++,))*))*$ OO

 
	
r   r   )__name__
__module____qualname____doc___required_framework_version_versionr   classmethodr   r   configurationRequirementInterfacer7   rD   rZ   r;   ContextInterfacer   intr   rO   r   r:   objectsObjectInterfacer   r   __classcell__)r   s   @r   r   r      sP   *"+H5 
j&>&>&S&S!T 
 
@$3j  8"##448" 8" 	8"
 3i8" 
3d?	#8" 8"t ##44 ! 	 4 $##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   rj   pluginsPluginInterfacer    r   r   <module>r      sQ     , , N N < 8 2 ? 6			8	$z
j  00 z
r   