K6h#@dZddlZddlZddlZddlmZddlmZmZddl m Z m Z ddl m Z mZmZddlmZmZGd d e ZeGd d ZeGd dZGddejZGddeZGddeZdS)u  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see N) defaultdict) dataclassfield) NamedTupleOptional)DBPatchDependencyMatch VersionMatch)HashCalculator get_base_dircXeZdZUeed<eed<dZeeed<dZeeed<dS)FileIdentifierrel_pathhashNvuln_id vuln_type) __name__ __module__ __qualname__str__annotations__rrintrU/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/fs_scanner/matcher.pyrr!sLMMM III!GXc]!!!#Ix}#####rrc\eZdZUeed<eed<eeed<ee Z e ed<dS)VersionIdentifieridrfile_identifiers)default_factorymatched_base_dirsN) rrrrrrlistrrsetr"rrrrr(sS GGG III>****"U3777s77777rrc&eZdZUeeed<dS)PatchDependencyfilesN)rrrr#rrrrrr&r&1s#  rr&c`eZdZdefdZejdedeeee ffdZ dS)Matcher input_filec:|||_dSN) _parse_inputdict_of_identifiers)selfr*s r__init__zMatcher.__init__7s#'#4#4Z#@#@   r file_pathreturncdSr,r)r/r1s rr-zMatcher._parse_input:s rN) rrrrr0abcabstractmethoddictr#tupler-rrrr)r)6stA3AAAA  c d3U 3C.D      rr)ceZdZededeefdZdedee fdZ dede eee ffdZ de d ed e defd Zd ed eded e fdZdS)VersionsMatcher file_hashesr2c|d}dt|ddd|dddDS)N|c4g|]\}}t||Srr).0rhash_s r z:VersionsMatcher._parse_path_hash_pairs..Es6   % 8U + +   rr)stripsplitzip)r:partss r_parse_path_hash_pairsz&VersionsMatcher._parse_path_hash_pairs@sb!!##))#..  #&uQTT{E##A#J#?#?    rlinec|d\}}}}|dkrdSt||||S)N:+)rCrDrrG)r/rHstateid_r@r:s r _parse_linezVersionsMatcher._parse_lineJs]*.););C)@)@&sE; C<<4 33K@@   rr1ctt}t|d5}|D]D}||x}r+||jdj|E dddn #1swxYwY|S)Nrr)rr#openrNr rappend)r/r1plugins_identifiers_by_pathfilerHnew_identifiers rr-zVersionsMatcher._parse_inputTs    $)S ! ! -T - -%)%5%5d%;%;;>-/&7:Cf^,,,  - - - - - - - - - - - - - - - - +*sAA::A>A>plugin_identifierbase_dirhash_calculatorcD|jD]G}tjtj||jsdSH|jD]H}|tj||jd|jkrdSIdS)NFT)apply_normalization)r ospathisfilejoinr calc_hashr)r/rVrWrXfile_identifiers rhas_full_matchzVersionsMatcher.has_full_matchds 1A  O7>> X'?@@ uu  1A  O))GLL?+CDD(,*#' (( uu (tr full_path relative_pathdbcFd}|j|gD]}t||}||jvrg||||rP|j||jt|j ||j d}|S)NF)rr\rT) r.getr r"raaddversions_matchesbuffered_insertr rr)r/rbrcrdrX is_matchedrVrWs rmatch_and_savezVersionsMatcher.match_and_save|s !%!9!=!= 2" "  " " $I}==H 1 CCC''%xD "377AAA#33 ,/%.3" rN)rrr staticmethodrr#rrGrrrNr6r-r boolrar rkrrrr9r9?s C D4H   \   1B(C    ++ c4)** +++++ ,(   0   ( rr9cReZdZdedeeeeffdZdededede fdZ d S) PatchDependenciesMatcherr1r2chtt}t|d5}|D]q}|d|dd}}|dkrtdt j|D}|jD]"}||j|#r dddn #1swxYwY|S)NrPrrrKc dg|]-}t|d|d|d|d.S)filenamervulnerability_idvulnerability_type)rrrrr>)r?_s rrAz9PatchDependenciesMatcher._parse_input..sY '%&z]!"6$%&8$9&'(<&= r)r') rr#rQr&jsonloadsr'rrR) r/r1 patch_depsrTrHrLdatapatch_dependencyr`s rr-z%PatchDependenciesMatcher._parse_inputs/8C47H7H )S ! ! T  "1gtABBxtC<<#2"&D!1!1 $ $ $ (8'=O78??(                (sA5B''B+.B+rbrcrdrXc d}|j|gD]Ԋ t||}g jD]}|j|kr|t j||j|j krM t j||j|j |j |j fd} fdDfdD|S)NFTc ng|]1}t|dttjki2S)dependencies_met)r lenr')r?rowmatches_to_insertrzs rrAz;PatchDependenciesMatcher.match_and_save..s\!!! %-..#6F6L2M2MM!!!rcDg|]}j|Sr)patch_dependenciesri)r?matchrds rrAz;PatchDependenciesMatcher.match_and_save..s:   %55e<<   r) r.rfr r'rr_r[r\r^rrRrr) r/rbrcrdrXrjrWr`rrzs ` @@rrkz'PatchDependenciesMatcher.match_and_saves_ $ 8 < < 2! ! ' '  $I}==H!# #3#9 & &#, =='11 X/GHH'+,,&,,GLL?3KLL+0+3+5 "&J!!!!!-!!!     .     rN) rrrrr6r#r&r-r r rkrrrroroscd3_8M3M.N>000  0 ( 000000rro)__doc__r4rvr[ collectionsr dataclassesrrtypingrrrdr r r utilsr r rrr&ABCr)r9rorrrrs* ######((((((((''''''''6666666666////////$$$$$Z$$$ 8888888 8               cg   ZZZZZgZZZzPPPPPwPPPPPr