
    Xfx.                         d dl Z 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mZmZ d dlmZ d dlmZmZ d dlmZmZmZ d dlmZ d dlmZ  ej        e          Z G d	 d
ej        j                  Z dS )    N)ListSequenceIterableTupleUnion)objects	renderers
exceptions
interfaces	constants)requirements)RegistryHiveRegistryFormatException)TreeGrid
conversionformat_hints)RegValueTypes)hivelistc                   B   e Zd ZdZdZdZedeej	        j
                 fd            Ze	 	 dded	eej                 d
edeeeeej        eeej        j        f                  fd            Z	 	 dded	eej                 d
efdZ	 	 	 ddededee         ded
ef
dZd ZdS )PrintKeyz;Lists the registry keys under a hive or specific key value.)   r   r      r   r   returnc           
          t          j        ddddg          t          j        dt          j        d          t          j        d	d
d 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   pluginversionoffsetHive OffsetT)r   r    defaultoptionalkeyzKey to start fromrecursezRecurses through keysF)r   ModuleRequirementPluginRequirementr   HiveListIntRequirementStringRequirementBooleanRequirement)clss    i/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/registry/printkey.pyget_requirementszPrintKey.get_requirements   s     *,()4  
 *(99   '=$QU   *(;TTX   +3	  
 	
    NFhive	node_pathr)   c              #     K   |s|                     |j                  g}t          |t                    rt	          |          dk     rt
                              d           dS |d         }|g|dd         z   }d                    d |D                       }|j        j	        
                    t          j        dz             rt          |j        d          t          j        |j        j                  }|                                D ]}t	          |          d	|||                                |f}	|	V  |r|j        j        d
 |D             vrn	 |                                 n6# t.          j        $ r$}
t
                              |
           Y d}
~
d}
~
ww xY w|                     |||gz   |          E d{V  |                                D ]-}t	          |          d|||                                |f}	|	V  .dS )a  Walks through a set of nodes from a given node (last one in
        node_path). Avoids loops by not traversing into nodes already present
        in the node_path.

        Args:
            hive: The registry hive to walk
            node_path: The list of nodes that make up the
            recurse: Traverse down the node tree or stay only on the same level

        Yields:
            A tuple of results (depth, is_key, last write time, path, volatile, and the node).
        r   z6Hive walker was not passed a valid node_path (or None)N\c                 6    g | ]}|                                 S  )get_name).0ks     r1   
<listcomp>z)PrintKey.key_iterator.<locals>.<listcomp>P   s     CCCqajjllCCCr3   
_CELL_DATAz.Encountered _CELL_DATA instead of _CM_KEY_NODETc                 &    g | ]}|j         j        S r:   )volr$   )r<   xs     r1   r>   z)PrintKey.key_iterator.<locals>.<listcomp>c   s    .O.O.Oqu|.O.O.Or3   r)   F)get_noderoot_cell_offset
isinstancelistlenvollogwarningjoinrA   	type_nameendswithr   BANGr   r   r   wintime_to_datetimeLastWriteTimeQuadPartget_subkeysget_volatiler$   r;   r
   InvalidAddressExceptiondebugkey_iterator
get_values)r0   r4   r5   r)   nodekey_path_itemskey_pathlast_write_timekey_noderesultexcp
value_nodes               r1   rV   zPrintKey.key_iterator2   sl     .  	?t'<==>I)T** 	c)nnq.@.@NNSTTT4})ABB-/99CCNCCCDD8&&y~'DEE 	)	K   %89K9TUU((** 	 	HI%%''F LLL 
<&.O.OY.O.O.OOO! ))++++%= ! ! !T*** !  #//i8*4g  0            //++ 		 		JI!!##F LLLL		 		s   E))F8FFc           	   #     K   |                      |||          D ]?\  }}}}}}	|r	 |	                                }
nP# t          j        t          f$ r7}t
                              |           t          j                    }
Y d}~nd}~ww xY wt          j
        |	j        j                  }||t          j                            |j                  d||
t          j                    |ffV  	 |	                                pd}nP# t          j        t          f$ r7}t
                              |           t          j                    }Y d}~nd}~ww xY w	 t#          |	j                  j        }nP# t          j        t          f$ r7}t
                              |           t          j                    }Y d}~nd}~ww xY wt)          |t          j                  r/t
                              d           t          j                    }n!	 |	                                }t)          |t,                    rt          j        |d          }nt#          |	j                  t"          j        k    rt          j        |d          }nPt#          |	j                  t"          j        k    rt          j        |d	d
          }nt          j        |d	          }nV# t4          t          j        t          f$ r7}t
                              |           t          j                    }Y d}~nd}~ww xY w||t          j                            |j                  |||||ff}|V  AdS )a  Method that wraps the more generic key_iterator, to provide output
        for printkey specifically.

        Args:
            hive: The registry hive to walk
            node_path: The list of nodes that make up the
            recurse: Traverse down the node tree or stay only on the same level

        Yields:
            The depth, and a tuple of results (last write time, hive offset, type, path, name, data and volatile)
        NKeyz	(Default)z8Couldn't read registry value type, so data is unreadablezutf-8)encodingT)show_hexz	utf-16-le)rb   split_nulls)rV   r;   r
   rT   r   rI   rU   r	   UnreadableValuer   rO   rP   rQ   r   Hexhive_offsetNotApplicableValuer   Typer   rF   decode_dataintMultiTypeData
REG_BINARYREG_MULTI_SZ
ValueError)selfr4   r5   r)   depthis_keyr[   rZ   volatilerX   key_node_namer^   value_node_name
value_type
value_datar]   s                   r1   _printkey_iteratorzPrintKey._printkey_iteratory   s     0 tY88e	 e	 
 ]@$(MMOOMM6+ @ @ @ LL&&&$-$=$?$?MMMMMM@ #-"@&/# #
 '!.2243CDD %!466     B&*mmoo&DOO6+ B B B LL&&&&/&?&A&AOOOOOOB=!.ty!9!9!>JJ6+ = = = LL&&&!*!:!<!<JJJJJJ= j)*CDD !ALLR   "133 JA%)%5%5%7%7
%j#66 )5)C *W* * *JJ +49559QQQ)5)C *T* * *JJ +49559SSS)5)C *[d* * *JJ *6)C *[* * *J #":/ A A A
 T***%.%>%@%@





A '!.2243CDD" '"  Ke	 e	s^   <B	-BB	,DE-EEE..F;-F66F;C	KL%.-L  L%
layer_namesymbol_tablehive_offsetsr(   c              #     K   t           j                            | j        | j        |||          D ]}	 ||                    |d          }n|                    |j                  g}|                     |||          D ]\  }}	|t          |          z
  |	fV  n# t          j        t          t          f$ r<}
t          |
t                    r4t                              d| dt#          |j                   d           nyt          |
t                    rt                              |
           nIt          |
t          j                  r/t                              dt#          |
j                              d	t)          j                    t-          j        |j                  d
d|pdz   t)          j                    t)          j                    t)          j                    ff}|V  Y d }
~
d }
~
ww xY wd S )N)ry   rz   r{   T)return_listrC   zKey 'z' not found in Hive at offset .z$Invalid address identified in Hive: r   ra   z?\ )r   r,   
list_hivescontextconfig_pathget_keyrD   rE   rx   rH   r
   rT   KeyErrorr   rF   rI   rU   hexrg   invalid_addressr	   re   r   rf   )rp   ry   rz   r{   r(   r)   r4   r5   rB   yr^   r]   s               r1   _registry_walkerzPrintKey._registry_walker   s1      %00L!%% 1 
 
 *	 *	D#? $Sd C CII!%t/D!E!E FI 33D)W3UU 2 2DAqs9~~-q111112 2'   
 dH-- 	LL[[[3tGWCXCX[[[     &=>> LL&&&&j&HII LLZs4CW?X?XZZ   !133$()9::+!133!133!133 7*	 *	s   A)BG8<D1G33G8c                    | j                             dd           }| j        j        | j         d                  }t	          dt
          j        fdt          j        fdt          fdt          fdt          fdt          j	        fd	t          fg|                     |j        |j        |d n|g| j                             d
d           | j                             dd                               S )Nr$   r   zLast Write Timer%   ri   ra   NameDataVolatiler(   r)   )r{   r(   r)   )columns	generator)configgetr   modulesr   datetimer   rf   strrl   boolr   ry   symbol_table_name)rp   r$   r   s      r1   runzPrintKey.run%  s    400%dk(&;<"H$56 0134T" ++!(%+^TT&KOOE400	488 ,  
 
 
 	
r3   )NF)NNF)__name__
__module____qualname____doc___required_framework_version_versionclassmethodr   r   configurationRequirementInterfacer2   r   r   r   
StructTyper   r   r   rk   r   r   ObjectInterfacerV   rx   r   r   r:   r3   r1   r   r      s       EE"+H
j&>&S!T 
 
 
 [
0  37	D DD G./D 	D
 
x(#tZ5G5WW	

D D D [DR 37	v vv G./v 	v v v vx #'2 22 2 3i	2
 2 2 2 2 2h
 
 
 
 
r3   r   )!r   loggingtypingr   r   r   r   r   volatility3.frameworkr   r	   r
   r   r   #volatility3.framework.configurationr   %volatility3.framework.layers.registryr   r   volatility3.framework.renderersr   r   r   9volatility3.framework.symbols.windows.extensions.registryr   $volatility3.plugins.windows.registryr   	getLoggerr   rI   pluginsPluginInterfacer   r:   r3   r1   <module>r      s/  
   9 9 9 9 9 9 9 9 9 9 9 9 9 9 W W W W W W W W W W W W W W < < < < < < W W W W W W W W N N N N N N N N N N S S S S S S 9 9 9 9 9 9		8	$	$g
 g
 g
 g
 g
z!1 g
 g
 g
 g
 g
r3   