o
    Žõ±j-
  ã                   @   s:   d dl Z d dlZd dlmZ d dlmZ G dd„ dƒZdS )é    N)Úlogger)ÚUniversalEncoderc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚRegistryCMDHelperc                 C   s   dg| _ dg| _d S )NÚregistry)Úlive_keywordsÚkeywords)Úself© r	   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pypykatz/registry/cmdhelper.pyÚ__init__   s   zRegistryCMDHelper.__init__c                 C   s˜   |j ddd}|jdddd |jdd	d
d |j ddd}|jddd |jddd |jddd |jddd |jdd	d
d |jdddd d S )Nr   zGet all secrets from registry)Úhelpz--jsonÚ
store_truez Print credentials in JSON format)Úactionr   z-oz	--outfilez[Save results to file (you can specify --json for json file, or text format will be written)zGet secrets from registry filesÚsystemz path to the SYSTEM registry hivez--samzpath to the SAM registry hivez
--securityz"path to the SECURITY registry hivez
--softwarez"path to the SOFTWARE registry hive)Ú
add_parserÚadd_argument)r   ÚparserÚlive_parserÚ
live_groupÚgroupr	   r	   r
   Úadd_args   s   zRegistryCMDHelper.add_argsc                 C   sb   t | jƒdkr|j| jv r|  |¡ t | jƒdkr+|jdkr-|j| jv r/|  |¡ d S d S d S d S )Nr   Úlive)Úlenr   ÚcommandÚrunr   ÚmoduleÚrun_live)r   Úargsr	   r	   r
   Úexecute!   s
   
$ÿzRegistryCMDHelper.executec                 C   sN   |j r| |j |j¡ d S |jrttj| ¡ tdddƒ d S tt|ƒƒ d S )Né   T)ÚclsÚindentÚ	sort_keys)ÚoutfileÚto_fileÚjsonÚprintÚdumpsÚto_dictr   Ústr)r   Úresultsr   r	   r	   r
   Úprocess_results(   s
   z!RegistryCMDHelper.process_resultsc                 C   sÈ   ddl m} d }z| ¡ }W nC tyQ } z7t ¡  t dt|ƒ ¡ zddl	m
} | ¡ }W n tyF } zt d¡ W Y d }~nd }~ww W Y d }~nd }~ww |d ur^|  ||¡ d S tdƒ d S )Nr   )ÚLiveRegistryzPFailed to obtain registry secrets via direct registry reading method. Reason: %s©ÚOffineRegistryz5Failed to obtain registry secrets via filedump methodzRegistry parsing failed!)Úpypykatz.registry.live_parserr,   Úgo_liveÚ	ExceptionÚ	tracebackÚ	print_excr   Údebugr)   Ú pypykatz.registry.offline_parserr.   Úfrom_live_systemr+   r&   )r   r   r,   ÚlrÚer.   r	   r	   r
   r   1   s&   €ÿ€ú	zRegistryCMDHelper.run_livec                 C   s4   ddl m} | |j|j|j|j¡}|  ||¡ d S )Nr   r-   )r5   r.   Ú
from_filesr   ÚsamÚsecurityÚsoftwarer+   )r   r   r.   Úpor	   r	   r
   r   D   s   zRegistryCMDHelper.runN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r+   r   r   r	   r	   r	   r
   r      s    	r   )r%   r2   Úpypykatzr   Úpypykatz.commons.commonr   r   r	   r	   r	   r
   Ú<module>   s
   