
    Xf9                     T   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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mZ ddlmZ  G d	 d
          Z G d d          Z G d dej        j                  Z G d deej        e          Z G d de          Z  G d de!          Z"dS )z<Symbols provide structural information about a set of bytes.    N)ABCabstractmethod)AnyDictIterableListMappingOptionalTupleType)	constants
exceptions
interfaces)requirements)configurationobjects)RequirementInterfacec                      e Zd ZdZ	 	 ddededeej                 dee	         ddf
dZ
edefd	            Zedee         fd
            Zedeej                 fd            Zedefd            Zedee	         fd            ZdS )SymbolInterfacezBContains information about a named location in a program's memory.Nnameaddresstypeconstant_datareturnc                     || _         t          j        | j         v rt          dt          j         d          d| _        || _        || _        || _        dS )a  

        Args:
            name: Name of the symbol
            address: Numeric address value of the symbol
            type: Optional type structure information associated with the symbol
            constant_data: Potential constant data the symbol points at
        z7Symbol names cannot contain the symbol differentiator ()N)_namer   BANG
ValueError	_location_address_type_constant_data)selfr   r   r   r   s        Z/home/panchajanya/Development/work/volatility3/volatility3/framework/interfaces/symbols.py__init__zSymbolInterface.__init__   sa     
>TZ''[).[[[  
 
+    c                     | j         S )zReturns the name of the symbol.)r   r$   s    r%   r   zSymbolInterface.name.        zr'   c                 8    | j         dS | j         j        d         S )z8Returns the name of the type that the symbol represents.N	type_name)r   volr)   s    r%   r,   zSymbolInterface.type_name3   s      94y}[))r'   c                     | j         S )z,Returns the type that the symbol represents.)r"   r)   s    r%   r   zSymbolInterface.type;   r*   r'   c                     | j         S )zOReturns the relative address of the symbol within the compilation
        unit.)r!   r)   s    r%   r   zSymbolInterface.address@   s     }r'   c                     | j         S )z5Returns any constant data associated with the symbol.)r#   r)   s    r%   r   zSymbolInterface.constant_dataF   s     ""r'   NN)__name__
__module____qualname____doc__strintr
   r   Templatebytesr&   propertyr   r,   r   r   r    r'   r%   r   r      sJ       LL ,0)-, ,, , w'(	,
  , 
, , , ,6 c    X *8C= * * * X* hw/0    X     X
 #x # # # X# # #r'   r   c                   T   e Zd ZdZ	 	 ddedddeeeef                  deeeee	j
                 f                  ddf
d	Zdedefd
Zedee         fd            Zedee         fd            Zdede	j        fdZedee         fd            Zed d            Zej        d!d            Zdedee	j
                 ddfdZdedee	j
                 defdZdedee	j
                 fdZdeddfdZdedee	j                 fdZdedee         fdZd"dededee         fdZ d#dZ!dS )$BaseSymbolTableInterfacea  The base interface, inherited by both NativeTables and SymbolTables.

    native_types is a NativeTableInterface used for native types for the particular loaded symbol table
    table_mapping allows tables referenced by symbols to be remapped to a different table name if necessary

    Note: table_mapping is a rarely used feature (since symbol tables are typically self-contained)
    Nr   native_typesNativeTableInterfacetable_mappingclass_typesr   c                     || _         |i }|| _        || _        g | _        |r!|D ] }|                     |||                    dS dS )a  

        Args:
            name: Name of the symbol table
            native_types: The native symbol table used to resolve any base/native types
            table_mapping: A dictionary mapping names of tables (which when present within the table will be changed to the mapped table)
            class_types: A dictionary of types and classes that should be instantiated instead of Struct to construct them
        N)r   r@   _native_types_sort_symbolsset_type_class)r$   r   r>   r@   rA   
class_types         r%   r&   z!BaseSymbolTableInterface.__init__U   s     	 M*)46  	I) I I
##JJ0GHHHH	I 	II Ir'   c                      t          d          )z{Resolves a symbol name into a symbol object.

        If the symbol isn't found, it raises a SymbolError exception
        z9Abstract property get_symbol not implemented by subclass.NotImplementedErrorr$   r   s     r%   
get_symbolz#BaseSymbolTableInterface.get_symbolr   s    
 "G
 
 	
r'   c                      t          d          )z(Returns an iterator of the Symbol names.z6Abstract property symbols not implemented by subclass.rH   r)   s    r%   symbolsz BaseSymbolTableInterface.symbols{   s     "D
 
 	
r'   c                      t          d          )z-Returns an iterator of the Symbol type names.z4Abstract property types not implemented by subclass.rH   r)   s    r%   typeszBaseSymbolTableInterface.types   s     "B
 
 	
r'   c                      t          d          )z}Resolves a symbol name into an object template.

        If the symbol isn't found it raises a SymbolError exception
        z5Abstract method get_type not implemented by subclass.rH   rJ   s     r%   get_typez!BaseSymbolTableInterface.get_type   s    
 "C
 
 	
r'   c                      t          d          )z-Returns an iterator of the Enumeration names.z;Abstract property enumerations not implemented by subclass.rH   r)   s    r%   enumerationsz%BaseSymbolTableInterface.enumerations   s     "I
 
 	
r'   c                     | j         S )zOReturns None or a NativeTable for handling space specific native
        types.rC   r)   s    r%   nativesz BaseSymbolTableInterface.natives   s     !!r'   valuec                     || _         dS )zChecks the natives value and then applies it internally.

        WARNING: This allows changing the underlying size of all the other types referenced in the SymbolTable
        NrU   r$   rW   s     r%   rV   z BaseSymbolTableInterface.natives   s     #r'   clazzc                      t          d          )a  Overrides the object class for a specific Symbol type.

        Name *must* be present in self.types

        Args:
            name: The name of the type to override the class for
            clazz: The actual class to override for the provided type name
        z3Abstract method set_type_class not implemented yet.rH   r$   r   rZ   s      r%   rE   z'BaseSymbolTableInterface.set_type_class   s     ""WXXXr'   c                 V    	 |                      ||           dS # t          $ r Y dS w xY w)a$  Calls the set_type_class function but does not throw an exception.
        Returns whether setting the type class was successful.
        Args:
            name: The name of the type to override the class for
            clazz: The actual class to override for the provided type name
        TF)rE   r   r\   s      r%   optional_set_type_classz0BaseSymbolTableInterface.optional_set_type_class   sD    	e,,,4 	 	 	55	s    
((c                      t          d          )z0Returns the class associated with a Symbol type.z3Abstract method get_type_class not implemented yet.rH   rJ   s     r%   get_type_classz'BaseSymbolTableInterface.get_type_class       !"WXXXr'   c                      t          d          )zARemoves the associated class override for a specific Symbol type.z3Abstract method del_type_class not implemented yet.rH   rJ   s     r%   del_type_classz'BaseSymbolTableInterface.del_type_class   ra   r'   c                 h    |                      |          j        }|dS |                     |          S )zQResolves a symbol name into a symbol and then resolves the symbol's
        type.N)rK   r,   rQ   )r$   r   r,   s      r%   get_symbol_typez(BaseSymbolTableInterface.get_symbol_type   s5     OOD))3	4}}Y'''r'   r,   c              #      K   | j         D ]Y}|                     |          }|j        ;|j        |k    s'|j                            t          j        |z             r	|j        V  ZdS )zXReturns the name of all symbols in this table that have type
        matching type_name.N)rM   rK   r,   endswithr   r   r   )r$   r,   symbol_namesymbols       r%   get_symbols_by_typez,BaseSymbolTableInterface.get_symbols_by_type   s~        < 	" 	"K __[11F+ I--$--iny.HII . k!!!	" 	"r'   r   offsetsizec              #      K   |dk     rt          d           j        s%t           fd j        D                        _         j        }t	          j        ||df          }|t          |          k     rx||         d         |k    rj||         d         ||z   k    rW||         d         V  |dz  }|t          |          k     r+||         d         |k    r||         d         ||z   k    OdS dS dS dS dS dS )zWReturns the name of all symbols in this table that live at a
        particular offset.r   z"Size must be strictly non-negativec                 H    g | ]}                     |          j        |fS r;   )rK   r   ).0snr$   s     r%   
<listcomp>zDBaseSymbolTableInterface.get_symbols_by_location.<locals>.<listcomp>   s-    JJJr$//"%%-r2JJJr'       N)r   rD   sortedrM   bisectbisect_leftlen)r$   rk   rl   sort_symbolsresults   `    r%   get_symbols_by_locationz0BaseSymbolTableInterface.get_symbols_by_location   sB      !88ABBB! 	!'JJJJT\JJJ" "D )#L62,??s<(((( #v--V$Q'6D=88v&q))))aKF s<(((( #v--V$Q'6D=8888 )(((--88 .-r'   c                     dS )z-Clears the symbol cache of this symbol table.Nr;   r)   s    r%   clear_symbol_cachez+BaseSymbolTableInterface.clear_symbol_cache   s    r'   r1   )r   r?   )rW   r?   r   N)r   )r   N)"r2   r3   r4   r5   r6   r
   r   r	   r   r   ObjectInterfacer&   r   rK   r:   r   rM   rO   r8   rQ   r   rS   rV   setterrE   boolr^   r`   rc   re   rj   r7   rz   r|   r;   r'   r%   r=   r=   L   s         37MQI II -I  S#X/	I
 gc40G+H&HIJI 
I I I I:
s 
 
 
 
 
 
# 
 
 
 X
 
x} 
 
 
 X

S 
W%5 
 
 
 
 
hsm 
 
 
 X
 " " " X"
 ^# # # ^#	Y3 	YtG4K/L 	YQU 	Y 	Y 	Y 	Y $W%< =	    Y3 Y40G+H Y Y Y YY3 Y4 Y Y Y Y(C (HW5E,F ( ( ( ("S "Xc] " " " " c  Xc]    $     r'   r=   c                      e Zd ZdZddedefdZededdfd            Zed	edee         fd
            Z	e	 dde
de
dee         dee         fd            Zed	edej        fd            Zededefd            Zededej        fd            Zededefd            Zededefd            Zededefd            Zededdfd            ZdS )SymbolSpaceInterfacezhAn interface for the container that holds all the symbol-containing
    tables for use within a context.layerprefixr   c                     dS )zaReturns an unused table name to ensure no collision occurs when
        inserting a symbol table.Nr;   )r$   r   s     r%   free_table_namez$SymbolSpaceInterface.free_table_name        r'   
table_nameNc                     dS )zClears the symbol cache for the specified table name. If no table
        name is specified, the caches of all symbol tables are cleared.Nr;   )r$   r   s     r%   r|   z'SymbolSpaceInterface.clear_symbol_cache  r   r'   r,   c                     dS )z4Returns all symbols based on the type of the symbol.Nr;   r$   r,   s     r%   rj   z(SymbolSpaceInterface.get_symbols_by_type  r   r'   r   rk   rl   c                     dS )z>Returns all symbols that exist at a specific relative address.Nr;   )r$   rk   rl   r   s       r%   rz   z,SymbolSpaceInterface.get_symbols_by_location  r   r'   c                     dS )z;Look-up a type name across all the contained symbol tables.Nr;   r   s     r%   rQ   zSymbolSpaceInterface.get_type  r   r'   rh   c                     dS )z=Look-up a symbol name across all the contained symbol tables.Nr;   )r$   rh   s     r%   rK   zSymbolSpaceInterface.get_symbol  r   r'   	enum_namec                     dS )z>Look-up an enumeration across all the contained symbol tables.Nr;   )r$   r   s     r%   get_enumerationz$SymbolSpaceInterface.get_enumeration  r   r'   r   c                     dS )z@Determines whether a type exists in the contained symbol tables.Nr;   rJ   s     r%   has_typezSymbolSpaceInterface.has_type#  r   r'   c                     dS )zJDetermines whether a symbol exists in the contained symbol
        tables.Nr;   rJ   s     r%   
has_symbolzSymbolSpaceInterface.has_symbol'  r   r'   c                     dS )zWDetermines whether an enumeration choice exists in the contained
        symbol tables.Nr;   rJ   s     r%   has_enumerationz$SymbolSpaceInterface.has_enumeration,  r   r'   rW   c                     dS )z+Adds a symbol_list to the end of the space.Nr;   rY   s     r%   appendzSymbolSpaceInterface.append1  r   r'   )r   )r   N)r2   r3   r4   r5   r6   r   r   r|   r   rj   r7   r
   rz   r   r8   rQ   r   rK   r   r   r   r   r   r=   r   r;   r'   r%   r   r      sk       ( (% %c % % % % % KS KT K K K ^K CS CXc] C C C ^C FJM MM!$M6>smM	#M M M ^M
 J# J'*: J J J ^J Lc Lo L L L ^L M M1A M M M ^M OS OT O O O ^O s t    ^ C D    ^ :4 : : : : ^: : :r'   r   c                        e Zd ZdZ	 	 ddddededdd	eeeef                  d
eeeee	j
                 f                  ddfdZd fdZedee         f fd            Z xZS )SymbolTableInterfacezHandles a table of symbols.Ncontextz#interfaces.context.ContextInterfaceconfig_pathr   r>   r?   r@   rA   r   c                     t           j                            | ||           t                              | ||||           dS )a  Instantiates an SymbolTable based on an IntermediateSymbolFormat JSON file.  This is validated against the
        appropriate schema.

        Args:
            context: The volatility context for the symbol table
            config_path: The configuration path for the symbol table
            name: The name for the symbol table (this is used in symbols e.g. table!symbol )
            isf_url: The URL pointing to the ISF file location
            native_types: The NativeSymbolTable that contains the native types for this symbol table
            table_mapping: A dictionary linking names referenced in the file with symbol tables in the context
            class_types: A dictionary of type names and classes that override StructType when they are instantiated
        )rA   N)r   ConfigurableInterfacer&   r=   )r$   r   r   r   r>   r@   rA   s          r%   r&   zSymbolTableInterface.__init__<  sQ    * 	+44T7KPPP ))$m 	* 	
 	
 	
 	
 	
r'   configuration.HierarchicalDictc                     t                                                      }| j        j        dz   | j        j        z   |d<   |S )N.class)superbuild_configuration	__class__r3   r2   )r$   configr   s     r%   r   z(SymbolTableInterface.build_configurationV  s<    ,,.. .3c9DN<SSwr'   c                 x    t                                                      t          j        dddd          gz   S )Nsymbol_maskzAddress mask for symbolsTr   )r   descriptionoptionaldefault)r   get_requirementsr   IntRequirement)clsr   s    r%   r   z%SymbolTableInterface.get_requirements]  sF    ww''))'"6	  -
 
 	
r'   r1   )r   r   )r2   r3   r4   r5   r6   r
   r   r	   r   r   r}   r&   r   classmethodr   r   r   __classcell__)r   s   @r%   r   r   6  s        &% 37MQ
 
6
 
 	

 -
  S#X/
 gc40G+H&HIJ
 

 
 
 
4      
&:!; 
 
 
 
 
 [
 
 
 
 
r'   r   c                       e Zd ZdZdedefdZedee         fd            Z	dede
j        fdZedee         fd            ZdS )	r?   z?Class to distinguish NativeSymbolLists from other symbol lists.r   r   c                 8    t          j        || j        d          )NzNativeTables never hold symbolsr   SymbolErrorr   rJ   s     r%   rK   zNativeTableInterface.get_symboll  s    $T496WXXXr'   c                     g S Nr;   r)   s    r%   rM   zNativeTableInterface.symbolso      	r'   c                 8    t          j        || j        d          )Nz$NativeTables never hold enumerationsr   rJ   s     r%   r   z$NativeTableInterface.get_enumerations  s!    $$)C
 
 	
r'   c                     g S r   r;   r)   s    r%   rS   z!NativeTableInterface.enumerationsx  r   r'   N)r2   r3   r4   r5   r6   r   rK   r:   r   rM   r   r8   r   rS   r;   r'   r%   r?   r?   i  s        IIYs Y Y Y Y Y #    X
C 
G,< 
 
 
 

 hsm    X  r'   r?   c                   "    e Zd ZdZdeddfdZdS )MetadataInterfacez>Interface for accessing metadata stored within a symbol table.	json_datar   Nc                     || _         dS )z#Constructor that accepts json_data.N)
_json_data)r$   r   s     r%   r&   zMetadataInterface.__init__  s    #r'   )r2   r3   r4   r5   r   r&   r;   r'   r%   r   r   }  s<        HH$$ $4 $ $ $ $ $ $r'   r   )#r5   ru   collections.abccollectionsabcr   r   typingr   r   r   r   r	   r
   r   r   volatility3.frameworkr   r   r   #volatility3.framework.configurationr    volatility3.framework.interfacesr   r   .volatility3.framework.interfaces.configurationr   r   r=   r   r   r   r?   objectr   r;   r'   r%   <module>r      s   C B      # # # # # # # # L L L L L L L L L L L L L L L L L L L L C C C C C C C C C C < < < < < < C C C C C C C C O O O O O O9# 9# 9# 9# 9# 9# 9# 9#xq q q q q q q qh3: 3: 3: 3: 3:;?2 3: 3: 3:l0
 0
 0
 0
 0
mA30
 0
 0
f    3   ($ $ $ $ $ $ $ $ $ $r'   