ȏ4JdZddlZddlZddlZddlZddlmZmZddlm Z ej e Z e fde dedee fd Zdd e d e defd Zd e de de fdZGddZdS)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)IteratorOptional) MAX_FILE_SIZE target_dirmax_sizereturnc#|Ktj|D]\}}}|D]}tj||} tj||kr"tj||Vi#t $r&}t d||Yd}~d}~wwxYwdS)Nz+Error occurred while processing file %s: %s)oswalkpathjoingetsize Exceptionloggerwarning)rrrootdirsfilesfiler es S/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/fs_scanner/utils.pydir_traverse_generatorr!s WZ00  dE  D7<<d++D 7??4((H44',,tT22222   A4     sAB B8B33B8/abs_pathroot_dirc|r"tj||pdnd}|tjtjfdt tDS)Nrc^g|])}tj|d*SN)r sepr).0i path_partss r z/all_possible_relative_paths..6s/ H H HABFKK 122 ' ' H H H)r r relpathstripr!splitrangelen)rrrel_pathr$s @rall_possible_relative_pathsr-0st>FMrwxS9992H''--bf55J H H H Hs:1G1G H H HHr&r,c||std|d|d|dt| S)Nz rel_path 'z' is not a suffix of abs_path '')endswith ValueErrorr+)rr,s r get_base_dirr29s]   X & &  M M M( M M M    $s8}}n$ %%r&ceZdZejejdZdZej dZ ej dZ de fdZ ededefd Z dd e d edee fd ZdS)HashCalculator)md5sha256i s[ - ]+s [---]+ algorithmcb||_|j||_|dkr|jnd|_dS)Nr5c|Sr )xs rz)HashCalculator.__init__..Psar&)r7HASHING_ALGORITHMS_hasher_factory_normalize_data_for_md5 _normalizer)selfr7s r__init__zHashCalculator.__init__Ls>"#6yA,5,>,>D ( (KK r&datar ct|tstd|jd|}|jd|}|S)a This method normalizes binary data by: - Removing the special control characters: 0x00-0x08, 0x0E-0x1F, 0x7F-0xFF; - 0x00-0x08, 0x0E-0x1F are ASCII control characters minus TAB, LF, VT, FF and CR; - 0x7F-0xFF are unicode control characters (DEL from C0 and C1 set). - Consolidating the clusters of whitespace characters (0x20, 0x09-0x0D) into single space character (0x20); - Turns all uppercase ASCII characters to lowercase. z*Normalization function expects bytes inputr& ) isinstancebytes TypeError_remove_control_characterssub_consolidate_whitespacelower)clsrCs rr?z&HashCalculator._normalize_data_for_md5Ssd$&& JHII I-11#t<<*..tT::zz||r&Ffilepathapply_normalizationctj|sdSt|d5}|r'|n|}fdtdtj DD]}| | dddn #1swxYwY| S)Nrbc3<K|]}||jzVdSr ) BUFFER_SIZE)r"r#normalized_datarAs r z+HashCalculator.calc_hash..psI A(8$8 89r&r) r r isfileopenr@readr>r*r+rSupdate hexdigest)rArNrOrhasherchunkrTs` @r calc_hashzHashCalculator.calc_hashdsIw~~h''  F (D ! ! %T'!  ---YY[[  ))++Fq#o"6"68HII % % e$$$$  % % % % % % % % % % % % % % % %!!!sBCC"CN)F)__name__ __module__ __qualname__hashlibr5r6r=rSrecompilerKrIstrrB classmethodrGr?boolrr]r:r&rr4r4Cs{.K(bj)<==!+,M!N!N #    5U[":?"""26" #""""""r&r4)r)__doc__raloggingr rbtypingrrconfigr getLoggerr^rrdintrlistr-r2r4r:r&rrns<* %%%%%%%%!!!!!!  8 $ $&3   "  c]    II#IItIIII&3&#&#&&&&2"2"2"2"2"2"2"2"2"2"r&