
    *1f{3                         d Z ddlZddlZddlmZmZ ddlmZmZm	Z	m
Z
mZ ddlmZmZ  G d de          Z G d	 d
ej        j                  Z G d dej        j                  ZdS )a  Defines an interface for contexts, which hold the core components that a
plugin will operate upon when running.

These include a `memory` container which holds a series of forest of
layers, and a `symbol_space` which contains tables of symbols that can
be used to interpret data in a layer.  The context also provides some
convenience functions, most notably the object constructor function,
`object`, which will construct a symbol on a layer at a particular
offset.
    N)ABCMetaabstractmethod)OptionalUnionDictListIterable)
interfaces
exceptionsc                   P   e Zd ZdZddZeed d                        Zeed!d                        Zeed"d
                        Z	d#dZ
eed$d                        Zd%dZe	 d&deedf         dedededdf
d            Zd'dZ	 	 d(dedededee         dee         ddfdZdS ))ContextInterfacezAll context-like objects must adhere to the following interface.

    This interface is present to avoid import dependency cycles.
    returnNc                     dS )z,Initializes the context with a symbol_space.N selfs    Z/home/panchajanya/Development/work/volatility3/volatility3/framework/interfaces/context.py__init__zContextInterface.__init__             )interfaces.configuration.HierarchicalDictc                     dS )z2Returns the configuration object for this context.Nr   r   s    r   configzContextInterface.config!   r   r   'interfaces.symbols.SymbolSpaceInterfacec                     dS )zReturns the symbol_space for the context.

        This object must support the :class:`~volatility3.framework.interfaces.symbols.SymbolSpaceInterface`
        Nr   r   s    r   symbol_spacezContextInterface.symbol_space&   r   r   ModuleContainerc                      t          d          )*Returns the memory object for the context.z)ModuleContainer has not been implemented.NotImplementedErrorr   s    r   moduleszContextInterface.modules0   s     ""MNNNr   module"interfaces.context.ModuleInterfacec                 :    | j                             |           dS )a%  Adds a named module to the context.

        Args:
            module: The module to be added to the module object collection

        Raises:
            volatility3.framework.exceptions.VolatilityException: if the module is already present, or has
                unmet dependencies
        N)r"   
add_moduler   r#   s     r   r&   zContextInterface.add_module6   s      	'''''r    interfaces.layers.LayerContainerc                      t          d          )r   z(LayerContainer has not been implemented.r    r   s    r   layerszContextInterface.layersB   s     ""LMMMr   layer$interfaces.layers.DataLayerInterfacec                 :    | j                             |           dS )zAdds a named translation layer to the context memory.

        Args:
            layer: Layer object to be added to the context memory
        N)r*   	add_layer)r   r+   s     r   r.   zContextInterface.add_layerH   s      	e$$$$$r   object_typeinterfaces.objects.Template
layer_nameoffsetnative_layer_name"interfaces.objects.ObjectInterfacec                     dS )a  Object factory, takes a context, symbol, offset and optional
        layer_name.

        Looks up the layer_name in the context, finds the object template based on the symbol,
        and constructs an object using the object template on the layer at the offset.

        Args:
            object_type: Either a string name of the type, or a Template of the type to be constructed
            layer_name: The name of the layer on which to construct the object
            offset: The address within the layer at which to construct the object
            native_layer_name: The layer this object references (should it be a pointer or similar)

        Returns:
             A fully constructed object
        Nr   )r   r/   r1   r2   r3   	argumentss         r   objectzContextInterface.objectR   r   r   c                 *    t          j        |           S )a'  Produce a clone of the context (and configuration), allowing
        modifications to be made without affecting any mutable objects in the
        original.

        Memory constraints may become an issue for this function
        depending on how much is actually stored in the context
        )copydeepcopyr   s    r   clonezContextInterface.clonek   s     }T"""r   module_namesizeModuleInterfacec                     dS )aA  Create a module object.

        A module object is associated with a symbol table, and acts like a context, but offsets locations by a known value
        and looks up symbols, by default within the associated symbol table.  It can also be sized should that information
        be available.

        Args:
            module_name: The name of the module
            layer_name: The layer the module is associated with (which layer the module lives within)
            offset: The initial/base offset of the module (used as the offset for relative symbols)
            native_layer_name: The default native_layer_name to use when the module constructs objects
            size: The size, in bytes, that the module occupies from offset location within the layer named layer_name

        Returns:
            A module object
        Nr   )r   r<   r1   r2   r3   r=   s         r   r#   zContextInterface.moduleu   r   r   )r   Nr   r   )r   r   )r   r   )r#   r$   )r   r(   )r+   r,   N)r   r   )NN)__name__
__module____qualname____doc__r   propertyr   r   r   r"   r&   r*   r.   r   strintr7   r;   r   r#   r   r   r   r   r      s        
; ; ; ;
 A A A ^ XA    ^ X O O O ^ XO
( 
( 
( 
( N N N ^ XN% % % %  "& 3 ==>  	
  
.   ^0# # # # ,0"   	
 $C= sm 
     r   r   )	metaclassc                   v    e Zd ZdZdedededdf fdZedefd            Zede	fd	            Z
edefd
            Zedefd            Zd) fdZedefd            Zede	fd            Zedefd            Zedefd            Zedefd            Ze	 	 	 d*dede	dee         deddf
d            Ze	 	 	 d+dedee         dedeeedf                  ddf
d            Zdede	fdZdeddfdZdeddfd Zdeddfd!Zdedefd"Zdedefd#Zdedefd$Zde fd%Z!d,de	d'e	de e         fd(Z" xZ#S )-r>   ziMaintains state concerning a particular loaded module in memory.

    This object is OS-independent.
    contextconfig_pathnamer   Nc                 Z    t                                          ||           || _        dS )zConstructs a new os-independent module.

        Args:
            context: The context within which this module will exist
            config_path: The path within the context's configuration tree
            name: The name of the module
        N)superr   _module_name)r   rK   rL   rM   	__class__s       r   r   zModuleInterface.__init__   s-     	+... r   c                     | j         d         S )Nr1   r   r   s    r   _layer_namezModuleInterface._layer_name   s    {<((r   c                     | j         d         S )Nr2   rS   r   s    r   _offsetzModuleInterface._offset   s    {8$$r   c                 B    | j                             d| j                  S )Nr3   )r   getrT   r   s    r   _native_layer_namez"ModuleInterface._native_layer_name   s    {2D4DEEEr   c                 B    | j                             d| j                  S )Nsymbol_table_name)r   rX   rP   r   s    r   _symbol_table_namez"ModuleInterface._symbol_table_name   s    {2D4EFFFr   r   c                    t                                                      }| j        d         |d<   | j        j        | j                                                 | j        j        | j                                                 d}| j        | j        k    r,| j        j        | j                                                 |d<   |D ]<}||         D ]1}||         |         |t          j
                            ||          <   2=|S )z<Builds the configuration dictionary for this specific Moduler2   )r[   r1   r3   )rO   build_configurationr   rK   r   r[   r*   r1   rY   r
   configuration	path_join)r   r   
subconfigs	subconfigreqrQ   s        r   r^   z#ModuleInterface.build_configuration   s    ,,..;x0x!%!:&"!!##,-do>RRTT	
 

 ?d555.2l.A'/!!## *+ $ 	 	I!),  MWNNz/99)SIIJJ
 r   c                     | j         S )z#The name of the constructed module.)rP   r   s    r   rM   zModuleInterface.name   s       r   c                     | j         S )zRReturns the offset that the module resides within the layer of
        layer_name.)rV   r   s    r   r2   zModuleInterface.offset   s     |r   c                     | j         S )z'Layer name in which the Module resides.)rT   r   s    r   r1   zModuleInterface.layer_name   s     r   c                     | j         S )zContext that the module uses.)_contextr   s    r   rK   zModuleInterface.context   s     }r   c                     | j         S )z8The name of the symbol table associated with this module)r\   r   s    r   r[   z!ModuleInterface.symbol_table_name   s     &&r   Fr/   r2   r3   absoluter4   c                     dS )av  Returns an object created using the symbol_table_name and layer_name
        of the Module.

        Args:
            object_type: The name of object type to construct (using the module's symbol_table)
            offset: the offset (unless absolute is set) from the start of the module
            native_layer_name: The native layer for objects that reference a different layer (if not the default provided during module construction)
            absolute: A boolean specifying whether the offset is absolute within the layer, or relative to the start of the module

        Returns:
            The constructed object
        Nr   )r   r/   r2   r3   rj   kwargss         r   r7   zModuleInterface.object   r   r   symbol_namec                     dS )a  Returns an object created using the symbol_table_name and layer_name
        of the Module.

        Args:
            symbol_name: The name of a symbol (that must be present in the module's symbol table).  The symbol's associated type will be used to construct an object at the symbol's offset.
            native_layer_name: The native layer for objects that reference a different layer (if not the default provided during module construction)
            absolute: A boolean specifying whether the offset is absolute within the layer, or relative to the start of the module
            object_type: Override for the type from the symobl to use (or if the symbol type is missing)

        Returns:
            The constructed object
        Nr   )r   rm   r3   rj   r/   rl   s         r   object_from_symbolz"ModuleInterface.object_from_symbol   r   r   c                 J    |                      |          }| j        |j        z   S )z=Returns the absolute address of the symbol within this module)
get_symbolr2   address)r   rM   symbols      r   get_absolute_symbol_addressz+ModuleInterface.get_absolute_symbol_address  s"    &&{V^++r   r0   c                     dS )z.Returns a type from the module's symbol table.Nr   r   rM   s     r   get_typezModuleInterface.get_type  r   r   z"interfaces.symbols.SymbolInterfacec                     dS )z7Returns a symbol object from the module's symbol table.Nr   rv   s     r   rq   zModuleInterface.get_symbol  r   r   c                     dS )z6Returns an enumeration from the module's symbol table.Nr   rv   s     r   get_enumerationzModuleInterface.get_enumeration  r   r   c                     dS )zBDetermines whether a type is present in the module's symbol table.Nr   rv   s     r   has_typezModuleInterface.has_type  r   r   c                     dS )zDDetermines whether a symbol is present in the module's symbol table.Nr   rv   s     r   
has_symbolzModuleInterface.has_symbol!  r   r   c                     dS )zJDetermines whether an enumeration is present in the module's symbol table.Nr   rv   s     r   has_enumerationzModuleInterface.has_enumeration$  r   r   c                     dS )z?Lists the symbols contained in the symbol table for this moduleNr   r   s    r   symbolszModuleInterface.symbols'  r   r   r   r=   c                     dS )zReturns the symbols within table_name (or this module if not specified) that live at the specified
        absolute offset provided.Nr   )r   r2   r=   s      r    get_symbols_by_absolute_locationz0ModuleInterface.get_symbols_by_absolute_location*  r   r   r@   )NNF)NFN)r   )$rB   rC   rD   rE   r   rG   r   rF   rT   rH   rV   rY   r\   r^   rM   r2   r1   rK   r[   r   r   boolr7   r   ro   rt   rw   rq   rz   r|   r~   r   r   r   r   __classcell__)rQ   s   @r   r>   r>      s'        
	! 0 	!s 	!# 	!RV 	! 	! 	! 	! 	! 	! )S ) ) ) X) % % % % X% FC F F F XF GC G G G XG     4 !c ! ! ! X!     X
  C       X  )    X '3 ' ' ' X'  +/   $C=	
  
.   ^*  ,0RV  $C= 	
 eC)M$MNO 
.   ^*, , , , , ,
=S =%B = = = =Fs F'K F F F FEC E,I E E E EQS QT Q Q Q QSs St S S S SYC YD Y Y Y YN N N N N% %s %# %dSVi % % % % % % % %r   r>   c                       e Zd ZdZddeee                  ddfdZd ZdeddfdZ	d	e
ddfd
Zd	e
defdZdefdZd Zdde
de
fdZde
dee
         fdZdS )r   z&Container for multiple layers of data.Nr"   r   c                 P    i | _         ||D ]}|                     |           d S d S rA   )_modulesr&   )r   r"   r#   s      r   r   zModuleContainer.__init__2  sE    46! ( ('''' ( (r   c                 B    t          |           t          |          k    S rA   )dict)r   others     r   __eq__zModuleContainer.__eq__8  s    DzzT%[[((r   r#   c                 x    |j         | j        v rt          j        d|j                    || j        |j         <   dS )zAdds a module to the module collection

        This will throw an exception if the required dependencies are not met

        Args:
            module: the module to add to the list of modules (based on module.name)
        zModule already exists: N)rM   r   r   VolatilityExceptionr'   s     r   r&   zModuleContainer.add_module;  sK     ;$-''07&+77   &,fk"""r   rM   c                     | j         |= dS )z%Removes a module from the module listNr   rv   s     r   __delitem__zModuleContainer.__delitem__I  s    M$r   c                     | j         |         S )z$Returns the layer of specified name.r   rv   s     r   __getitem__zModuleContainer.__getitem__M  s    }T""r   c                 *    t          | j                  S rA   )lenr   r   s    r   __len__zModuleContainer.__len__Q  s    4=!!!r   c                 *    t          | j                  S rA   )iterr   r   s    r   __iter__zModuleContainer.__iter__T  s    DM"""r   prefixc                     dS )zaReturns an unused table name to ensure no collision occurs when
        inserting a symbol table.Nr   )r   r   s     r   free_module_namez ModuleContainer.free_module_nameW  r   r   symbol_tablec              #   V   K   | j         D ]}| j         |         }|j        |k    r|V  dS )z=Returns the modules which use the specified symbol table nameN)r   r[   )r   r   r<   r#   s       r   get_modules_by_symbol_tablesz,ModuleContainer.get_modules_by_symbol_tables[  sH      = 	" 	"K];/F'<77!!!!	" 	"r   rA   )r#   )rB   rC   rD   rE   r   r   r>   r   r   r&   rG   r   r   rH   r   r   r   r	   r   r   r   r   r   r   /  s7       00( (o)> ? (4 ( ( ( () ) ), ,T , , , ,           # # # # # #" " " " "# # #% %s %# % % % %" "# " " " " " "r   r   )rE   collectionsr9   abcr   r   typingr   r   r   r   r	   volatility3.frameworkr
   r   r   r_   ConfigurableInterfacer>   Mappingr   r   r   r   <module>r      s+  	 	      ' ' ' ' ' ' ' ' 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8v v v v v v v v vr]% ]% ]% ]% ]%j.D ]% ]% ]%@1" 1" 1" 1" 1"ko- 1" 1" 1" 1" 1"r   