
    Xf5                         d dl Z d dl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 d dlmZ d dlmZ  e j        e          Z G d d	          Z G d
 de	j        j                  ZdS )    N)IteratorListTupleIterableOptional)	renderers
interfaces
exceptions)requirements)registry)format_hints)hivescanc                   L    e Zd ZdZdZd	dZd Zedee	         fd            Z
dS )
HiveGeneratorzWalks the registry HiveList linked list in a given direction and stores an invalid offset
    if it's unable to fully walk the list   r   r   Tc                 0    || _         || _        d | _        d S N)_cmhive_forward_invalid)selfcmhiveforwards      i/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/registry/hivelist.py__init__zHiveGenerator.__init__   s        c              #      K   | j         j                            | j         j        j        d| j                  D ].}|                                s|j        j        | _         d S |V  /d S )NHiveListr   )	r   r   to_listvol	type_namer   is_validoffsetr   )r   hives     r   __iter__zHiveGenerator.__iter__   sy      L)11L&
DM 2 
 
 	 	D ==??  $ttJJJJ	 	r   returnc                     | j         S r   )r   r   s    r   invalidzHiveGenerator.invalid$   s
    }r   N)T)__name__
__module____qualname____doc___required_framework_versionr   r'   propertyr   intr+    r   r   r   r      st        - - #,   
   #    X  r   r   c                      e Zd ZdZdZdZedeej	        j
                 fd            ZdedefdZdeeeeeef         f                  fdZe	 	 dd
ej        j        dedededee         dee         deej                 fd            Ze	 dd
ej        j        dedededeej        j                 f
d            Zdej        fdZd	S )r   z>Lists the registry hives present in a particular memory image.   r   r   r   r(   c           	          t          j        ddddg          t          j        dddd 	          t          j        d
t          j        d          t          j        dddd          gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesfilterz$String to filter hive names returnedT)r;   r<   optionaldefaultr   r5   )r;   pluginversiondumpzExtract listed registry hivesF)r;   r<   r@   r?   )r   ModuleRequirementStringRequirementPluginRequirementr   HiveScanBooleanRequirement)clss    r   get_requirementszHiveList.get_requirements/   s     *,()4  
 *B	   *(99   +;	  
 	
r   r;   c                     |                     d          d                             dd                              dd                              dd                              dd          S )	N\ _. [])splitreplace)r   r;   s     r   _sanitize_hive_namezHiveList._sanitize_hive_nameH   sW    JJtR WS#WS"WS"WS"	
r   c           
   #   j  K   d}| j         j        | j        d                  }|                     | j         |j        |j        | j                            dd                     D ]}d}| j        d         rt          |                     | j         | j	        |j        |j        |j
        j        g                    }|j        j        d         j        }|                     |                                          }|                     d	| d
t%          |j                   d          }|5 }	|j        r<| j         j        |j        d                                      |j        j        d          }
nd}
|	                    |
           t5          d||          D ]B}t7          |||z
            }|                    ||d          }|	                    |           C	 d d d            n# 1 swxY w Y   |j        }dt;          j        |j
        j                  |                                pd|ffV  d S )Ni  P r8   r>   )context
layer_namesymbol_tablefilter_stringDisabledrC   )rY   rZ   hive_offsetsr   z	registry.rP   z.hivei   a                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   T)padrQ   )rX   modulesconfiglist_hive_objectsrY   symbol_table_namegetnext
list_hivesconfig_pathr"   r%   r&   StorageLengthrV   get_nameopenhexhive_offset_base_blocklayersdependenciesread	BaseBlockwriterangeminpreferred_filenamer   Hex)r   
chunk_sizer8   hive_objectfile_outputr&   maxaddr	hive_namefile_handle	file_data	hive_dataicurrent_chunk_sizedatas                 r   
_generatorzHiveList._generatorQ   s     
%dk(&;<11L(1+//(D99	 2 
 
 0	 0	K %K{6"  =OO(#)#4%+%=&1o&<%= $    )+A.5 44T]]__EE	"iiH	HHC0@,A,AHHH  ! .I' 7$(L$78I!8L$M$R$R I/% %		 %7	OOI..."1gz:: . .-0Wq[-I-I*#yy,>DyII!----.. . . . . . . . . . . . . . . *<  $[_%;<<((**0b    S0	 0	s   *B/G&&G*	-G*	NrX   base_config_pathrY   rZ   r[   r]   c           	   #     K   |[	 d |                      ||||          D             }n7# t          $ r* t                              d           t	          d          w xY w|D ]}|                     |||||          }	 t          j        ||dt          |          z             }	n@# t          j
        $ r. t                              dt          |           d           Y w xY w|j                            |	           |	V  dS )	a  Walks through a registry, hive by hive returning the constructed
        registry layer name.

        Args:
            context: The context to retrieve required elements (layers, symbol tables) from
            base_config_path: The configuration path for any settings required by the new table
            layer_name: The name of the layer on which to operate
            symbol_table: The name of the table containing the kernel symbols
            filter_string: An optional string which must be present in the hive name if specified
            offset: An optional offset to specify a specific hive to iterate over (takes precedence over filter_string)

        Yields:
            A registry hive layer name
        Nc                 &    g | ]}|j         j        S r3   )r"   r%   ).0r&   s     r   
<listcomp>z'HiveList.list_hives.<locals>.<listcomp>   s,           HO     r   zFUnable to import windows.hivelist plugin, please provide a hive offset)rX   r   rl   
base_layer
nt_symbolsr&   )r;   z-Couldn't create RegistryHive layer at offset z
, skipping)ra   ImportErrorvollogwarning
ValueErrormake_subconfigr   RegistryHiverk   r
   InvalidAddressExceptionrn   	add_layer)
rI   rX   r   rY   rZ   r[   r]   rl   reg_config_pathr&   s
             r   re   zHiveList.list_hives   s     0     # 5 5\=! !         \   !\  	 ( 	 	K!00!1'%' 1  O,_6C<L<L3L   5   `CDTDT```   	
 N$$T***JJJJ)	 	s   ") 4A?'B'':C$#C$c           	   #   	  K   |j         |         j        d         }|                    |||          }|                    d          j        }|                    d|          }|                    d                              d          }	|                    d|j        j	        |	z
  d	          }
t                      }t          |
d
          }|D ]}|j        j	        |v rFt                              d                    t          |j        j	                                        n|                    |j        j	                   |I|                                t%          |                                pd                                          v r.|j         |                             |j        j	                  r|V  |j        }|r%t                              d                    t          |                               t          |
d
          }|D ]}|j        j	        |v rFt                              d                    t          |j        j	                                        n|                    |j        j	                   |I|                                t%          |                                pd                                          v r.|j         |                             |j        j	                  r|V  |j        }|r||k    rt                              d                    t          |                               t,          j                            |||          D ]}	 |j        j        r|j        j        |	z
  }|                    d|d	          }dD ]}|j                            |j        j        d|          D ]}|                                r|j        j	        |v r%|                    |j        j	                   |I|                                t%          |                                pd                                          v r.|j         |                             |j        j	                  r|V  ## t:          j        $ rH t                              d                    t          |j        j	                                       Y yw xY wdS dS dS dS )a  Lists all the hives 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
            filter_string: A string which must be present in the hive name if specified

        Returns:
            The list of registry hives from the `layer_name` layer as filtered against using the `filter_string`
        kernel_virtual_offset)rY   r%   CmpHiveListHead_LIST_ENTRY)object_typer%   _CMHIVEr   T)r   r%   absoluter    zYHivelist found an already seen offset {} while traversing forwards, this should not occurNrQ   zHHivelist failed traversing the list forwards at {}, traversing backwardsFzcHivelist found an already seen offset {} while traversing backwards, list walking met in the middlezbHivelist failed traversing backwards at {}, a different location from forwards, revert to scanning)TFzIInvalidAddressException when traversing hive {} found from scan, skipping)rn   r`   module
get_symboladdressobjectget_typerelative_child_offsetr"   r%   setr   r   debugformatrk   addlowerstrri   r$   r+   r   rG   
scan_hivesr   Flinkr!   r#   r
   r   )rI   rX   rY   rZ   r[   kvontkrnlmp	list_head
list_entryreloffr   seenhgr&   forward_invalidbackward_invalidstart_hive_offset
start_hiver   linked_hives                       r   ra   zHiveList.list_hive_objects   s5     * nZ(/0GH>>,:c>RR''(9::B	__y_QQ
""9--CCJOO!*.*?&*HSW ! 
 

 uu64000 	 	Dx$&&AAGDHO,,B B   HHTX_%%%% &&((C0E2,F,F,L,L,N,NNN>*-66txGG JJJ* L	LLZaa((   
 vu555B # #8?d**LLOOUv00P P   E)))!)$**,,DMMOO4Ir0J0J0P0P0R0RRR~j1::48?KK #"


!z 2O7G$G$G AAG,--B B   %-88Z  % %D"=. >040Cf0L- *2,5'8)- *9 * *J
 ,9 > >3=3F3N3N$(H$6
G4" 4" !> !>K -8,@,@,B,B%1+6?+AT+I+I(0$(HH[_-C$D$D$D(5(=+8+>+>+@+@+.{/C/C/E/E/K+L+L+R+R+T+T,U ,U ,3>*+E+N+N,7O,B,* ,* )> 3>,=,=,=#!>$ &=   gnn #DHO 4 4     OL	 L	42 2$G$G% %s   7DRAS-,S-c                     t          j        dt          j        fdt          fdt          fg|                                           S )NOffsetFileFullPathzFile output)r   TreeGridr   rv   r   r   r*   s    r   runzHiveList.runH  sA    !()NC+@=RUBVWOO
 
 	
r   )NNr   )r,   r-   r.   r/   _versionr0   classmethodr   r	   configurationRequirementInterfacerJ   r   rV   r   r   r2   r   rX   ContextInterfacer   r   r   r   re   objectsObjectInterfacera   r   r   r   r3   r   r   r   r   )   s       HHH"+
j&>&S!T 
 
 
 [
0
 
 
 
 
 
4HU3c3h+?%@A 4 4 4 4l  (,"&; ;#4; ; 	;
 ;  }; 3i; 
('	(; ; ; [;z  "@ @#4@ @ 	@
 @ 
*$4	5@ @ @ [@D
Y' 
 
 
 
 
 
r   r   )loggingtypingr   r   r   r   r   volatility3.frameworkr   r	   r
   #volatility3.framework.configurationr   volatility3.framework.layersr   volatility3.framework.renderersr   $volatility3.plugins.windows.registryr   	getLoggerr,   r   r   pluginsPluginInterfacer   r3   r   r   <module>r      s    < < < < < < < < < < < < < < C C C C C C C C C C < < < < < < 1 1 1 1 1 1 8 8 8 8 8 8 9 9 9 9 9 9		8	$	$       2c
 c
 c
 c
 c
z!1 c
 c
 c
 c
 c
r   