
    Xf              	       v   d dl Z d dlZd dlZd dlZd dlmZmZmZmZ d dl	m
Z
  ej                  e      Zej                  j                  e
j                   d      Zdee   fdZdee   ddfdZ e       Zdd	eeef   d
edefdZ	 dd	eeef   deeeef      dee   fdZ	 dd	eeef   deeef   d
edefdZy)    N)AnyDictOptionalSet)	constantszvalid_isf.hashcachereturnc                      t               } t        j                  j                  t              r?t        t        d      5 }| j                  t        j                  |             ddd       | S | S # 1 sw Y   | S xY w)z_Loads up the list of successfully cached json objects, so we don't need
    to revalidate them.rN)	setospathexistscached_validation_filepathopenupdatejsonload)validhashesfs     N/home/panchajanya/Development/work/volatility3/volatility3/schemas/__init__.pyload_cached_validationsr      s`     uK	ww~~01,c2 	-atyy|,	-;	-s   %A//A9validationsc                     t        t        d      5 }t        j                  t	        |       |       ddd       y# 1 sw Y   yxY w)zQRecord the cached validations, so we don't need to revalidate them in
    future.wN)r   r   r   dumplist)r   r   s     r   record_cached_validationsr      s9     
(#	. (!		${#Q'( ( (s	    :Ainput	use_cachec                 8   | j                  di       j                  dd      }|st        j                  d       yt        j                  j                  t        j                  j                  t                    }t        j                  j                  |d|z   dz         }t        j                  j                  |      st        j                  d|        yt        |d	      5 }t        j                  |      }ddd       t        | |      S # 1 sw Y   xY w)
z(Validates an input JSON file based upon.metadataformatNNo schema format definedFschema-.jsonSchema for format not found: r
   )getvollogdebugr   r   abspathdirname__file__joinr   r   r   r   valid)r   r   r"   basepathschema_pathsschemas          r   validater3   &   s    YYz2&**8T:F/0wwrwwx89H'',,xV);g)EFK77>>+&4[MBC	k3	 11	** s   %DDr2   c                    || j                  di       j                  dd      }|st        j                  d       yt        j                  j                  t        j                  j                  t                    }t        j                  j                  |d|z   dz         }t        j                  j                  |      st        j                  d|        yt        |d      5 }t        j                  |      }ddd       t        j                  t        t        j                   | |fd	
      d            j#                         S # 1 sw Y   MxY w)ziConstructs the hash of the input and schema to create a unique
    identifier for a particular JSON file.Nr!   r"   r#   r$   r%   r&   r
   T)	sort_keyszutf-8)r'   r(   r)   r   r   r*   r+   r,   r-   r   r   r   r   hashlibsha1bytesdumps	hexdigest)r   r2   r"   r/   r0   r1   s         r   create_json_hashr;   6   s    
 ~:r*..x>LL3477??277??8#<=ggll8Y-?'-IJww~~k*LL8FG+s# 	"qYYq\F	"<<djj%D97Cik	" 	"s   (E

Ec                    t        | |      }|t        v r|ry	 ddl}	 t        j                  d       |j                  | |       t        j                  |       t        j                  d       t        t               y# t        $ r- t        j                  d       t        j                  d       Y yw xY w# |j                  j                  $ r t        j                  dd	       Y y
w xY w)zValidates a json schema.Tr   Nz1Dependency for validation unavailable: jsonschemaz>All validations will report success, even with malformed inputz!Validating JSON against schema...z-JSON validated against schema (result cached)zSchema validation error)exc_infoF)r;   cached_validations
jsonschemaImportErrorr(   infor)   r3   add
exceptionsSchemaErrorr   )r   r2   r   
input_hashr?   s        r   r.   r.   L   s     "%0J''I89E6*z*DE
 01  GHUV   ,, .>s#   A? AB8 ?3B54B580C+*C+)T)N)r6   r   loggingr   typingr   r   r   r   volatility3.frameworkr   	getLogger__name__r(   r   r-   
CACHE_PATHr   strr   r   r>   boolr3   r;   r.        r   <module>rP      s  
    	 + + +			8	$WW\\)*>*>@UV S (3s8 ( ( -. +DcN +t +t +" ?CS>#+DcN#;c]. FJS>#'S>>B	rO   