K6hdZddlZddlZddlZddlmZddlmZefdede defd Z dd ed ede fd Z d ededefdZ GddZdS)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)Optional) MAX_FILE_SIZE target_dirmax_sizereturnc#Ktj|D]p\}}}|D]g}tj||}tj||kr"tj||VhqdSN)oswalkpathjoingetsize)rrrootdirsfilesfiler s S/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/fs_scanner/utils.pydir_traverse_generatorrs WZ00//dE / /D7<<d++Dwt$$00gll4..... ////abs_pathroot_dirc|r"tj||pdnd}|tjtjfdt tDS)Nrc^g|])}tj|d*Sr )r sepr).0i path_partss r z/all_possible_relative_paths...s/ H H HABFKK 122 ' ' H H Hr)r r relpathstriprsplitrangelen)rrrel_pathr s @rall_possible_relative_pathsr((st>FMrwxS9992H''--bf55J H H H Hs:1G1G H H HHrr'c||std|d|d|dt| S)Nz rel_path 'z' is not a suffix of abs_path '')endswith ValueErrorr&)rr's r get_base_dirr-1s]   X & &  M M M( M M M    $s8}}n$ %%rceZdZejejdZdZej dZ ej dZ de fdZ ededefd Z dd e d edee fd ZdS)HashCalculator)md5sha256i s[ - ]+s [---]+ algorithmcb||_|j||_|dkr|jnd|_dS)Nr0c|Sr )xs rz)HashCalculator.__init__..Hsar)r2HASHING_ALGORITHMS_hasher_factory_normalize_data_for_md5 _normalizer)selfr2s r__init__zHashCalculator.__init__Ds>"#6yA,5,>,>D ( (KK rdatarct|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)clsr>s rr:z&HashCalculator._normalize_data_for_md5Ksd$&& JHII I-11#t<<*..tT::zz||rFfilepathapply_normalizationctj|sdSt|d5}|r'|n|}fdtdtj DD]}| | dddn #1swxYwY| S)Nrbc3<K|]}||jzVdSr ) BUFFER_SIZE)rrnormalized_datar<s r z+HashCalculator.calc_hash..hsI A(8$8 89rr) r r isfileopenr;readr9r%r&rNupdate hexdigest)r<rIrJrhasherchunkrOs` @r calc_hashzHashCalculator.calc_hash\sIw~~h''  F (D ! ! %T'!  ---YY[[  ))++Fq#o"6"68HII % % e$$$$  % % % % % % % % % % % % % % % %!!!sBCC"CN)F)__name__ __module__ __qualname__hashlibr0r1r8rNrecompilerFrDstrr= classmethodrBr:boolrrXr5rrr/r/;s{.K(bj)<==!+,M!N!N #    5U[":?"""26" #""""""rr/)r)__doc__r\r r]typingrconfigrr_intrlistr(r-r/r5rrrgs* !!!!!!&3///"/////II#IItIIII&3&#&#&&&&2"2"2"2"2"2"2"2"2"2"r