
    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.                  j0                        Zy)    N)IteratorListTupleIterableOptional)	renderers
interfaces
exceptions)requirements)registry)format_hints)hivescanc                   >    e Zd ZdZdZddZd Zedee	   fd       Z
y)	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   c                 .    || _         || _        d | _        y 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                  j                  d| j
                        D ]3  }|j                         s|j                  j                  | _         y | 5 y w)NHiveListr   )	r   r   to_listvol	type_namer   is_validoffsetr   )r   hives     r   __iter__zHiveGenerator.__iter__   sl     LL))11LL&&
DMM 2 
 	D ==? $J	s   BB
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      s8    - #,
 #  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j2                  j4                     f
d       Zdej:                  fdZy	)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	 **(9(99 ++;	
 	
r   r;   c                     |j                  d      d   j                  dd      j                  dd      j                  dd      j                  dd      S )	N\ _. [])splitreplace)r   r;   s     r   _sanitize_hive_namezHiveList._sanitize_hive_nameH   sH    JJtR WS#WS"WS"WS"	
r   c           
   #     K   d}| j                   j                  | j                  d      }| j                  | j                   |j                  |j
                  | j                  j                  dd             D ]  }d}| j                  d   rt        | j                  | j                   | j                  |j                  |j
                  |j                  j                  g            }|j                  j                  d   j                  }| j                  |j!                               }| j#                  d	| d
t%        |j&                         d      }|5 }	|j(                  rK| j                   j*                  |j,                  d      j/                  |j                  j0                  d      }
nd}
|	j3                  |
       t5        d||      D ]6  }t7        |||z
        }|j/                  ||d      }|	j3                  |       8 	 d d d        |j8                  }dt;        j<                  |j                  j                        |j!                         xs d|ff  y # 1 sw Y   [xY ww)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   s8    
%%dkk(&;<11LL((11++//(D9	 2 
 0	K %K{{6"OO((#)#4#4%+%=%=&1oo&<&<%= $  ))++A.55 44T]]_E	"ii	{!C0@0@,A+B%H ! .I''$(LL$7$78I8I!8L$M$R$R II//%	 %7	OOI."1gz: .-0Wq[-I*#yy,>DyI!-.. *<<  $$[__%;%;<((*0b S0	0. .s    EI1B1I%AI1%I.	*I1NrX   base_config_pathrY   rZ   r[   r]   c           	   #     K   |6	 | j                  ||||      D cg c]  }|j                  j                   }}|D ]\  }| j                  |||||      }		 t        j                  ||	dt        |      z         }|j                  j                  |       | ^ yc c}w # t        $ r! t        j                  d       t        d      w xY w# t        j                  $ r% t        j                  dt        |       d       Y w xY ww)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
        NzFUnable 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   r"   r%   ImportErrorvollogwarning
ValueErrormake_subconfigr   RegistryHiverk   r
   InvalidAddressExceptionrn   	add_layer)
rI   rX   r   rY   rZ   r[   r]   r&   rl   reg_config_paths
             r   re   zHiveList.list_hives   s2    0  !$ 5 5\=!  HHOO    ( 	K!00!1'%' 1 O,,_6C<L3L NN$$T*J)	   \ !\ 	, 55 CCDTCUU_` 	sO   D
B" BB" D
$C;"D
B" "*CD
5DD
DD
c           	   #   (
  K   |j                   |   j                  d   }|j                  |||      }|j                  d      j                  }|j                  d|      }|j                  d      j                  d      }	|j                  d|j                  j                  |	z
  d	      }
t               }t        |
d
      }|D ]  }|j                  j                  |v rCt        j                  dj                  t        |j                  j                                      n|j!                  |j                  j                         |<|j#                         t%        |j'                         xs d      j#                         v s|j                   |   j)                  |j                  j                        s|  |j*                  }|rt        j                  dj                  t        |                   t        |
d
      }|D ]  }|j                  j                  |v rCt        j                  dj                  t        |j                  j                                      n|j!                  |j                  j                         |<|j#                         t%        |j'                         xs d      j#                         v s|j                   |   j)                  |j                  j                        s|  |j*                  }|r||k7  rt        j                  dj                  t        |                   t,        j.                  j1                  |||      D ]H  }	 |j2                  j4                  r-|j2                  j4                  |	z
  }|j                  d|d	      }dD ]  }|j2                  j7                  |j                  j8                  d|      D ]  }|j)                         r|j                  j                  |v r,|j!                  |j                  j                         |<|j#                         t%        |j'                         xs d      j#                         v s|j                   |   j)                  |j                  j                        s|   K yyyy# t:        j<                  $ rE t        j                  dj                  t        |j                  j                                     Y w xY ww)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   sF    * nnZ(//0GH>>,:c>R''(9:BB	__y_Q
""9-CCJO!*..*?*?&*HSW ! 

 u640 	Dxx$&AAGDHHOO,B HHTXX__%% &&(C0E2,F,L,L,NN>>*-66txxGJ	" **LLZaa(
 vu5B #88??d*LLOOUv0P )!)$**,DMMO4Ir0J0P0P0RR~~j1::488??K"
#"  "zzO7G$G AAG,-B %--88Z %D"==..040C0Cf0L- *2,5'8)- *9 *J
 ,9 >3=3F3F3N3N$(HH$6$6
G4" !>K -8,@,@,B+6??+A+AT+I(0$(HH[__-C-C$D(5(=+8+>+>+@+.{/C/C/E/K+L+R+R+T,U ,3>>*+E+N+N,7OO,B,B,* 3>,=#!>>% %H5 N &== gnn #DHHOO 4sR   FT2T9DT2T>A-T,DR752R7(R70T7ATTTTc                     t        j                  dt        j                  fdt        fdt        fg| j                               S )NOffsetFileFullPathzFile output)r   TreeGridr   rv   r   r   r*   s    r   runzHiveList.runH  s?    !!(()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   )   sq   HH"+
j&>&>&S&S!T 
 
0
 
 
4HU3c3h+?%@A 4l  (,"&;##44; ; 	;
 ;  }; 3i; 
(''	(; ;z  "@##44@ @ 	@
 @ 
*$$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      sX     < < C C < 1 8 9			8	$ 2c
z!!11 c
r   