관리-도구
편집 파일: utils.cpython-311.pyc
� ����x�O�E��������������������������d�Z�ddlZddlZddlZddlmZ�ddlmZ�efdede defd �Z ddededefd �Zdededefd�Z �G�d��d������������ZdS�)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 <https://www.gnu.org/licenses/>. Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see <https://www.imunify360.com/legal/eula> �����N)�Optional����)� MAX_FILE_SIZE� target_dir�max_size�returnc��������������#������K����t����������j��������|�������������D�]p\��}}}|D�]g}t�����������j�����������������������������||������������}t�����������j�����������������������������|������������|k����r"t�����������j�����������������������������||������������V����h�qd�S��N)�os�walk�path�join�getsize)r���r����root�dirs�files�filer ���s��� �S/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/fs_scanner/utils.py�dir_traverse_generatorr������s������������ �W�Z�0�0��/��/���d�E��� /�� /�D��7�<�<��d�+�+�D��w���t�$�$��0�0��g�l�l�4��.�.�.�.�.�� /�/��/������/�abs_path�root_dirc�����������������������|�r"t�����������j�����������������������������|�|pd������������nd}|���������������������t�����������j�����������������������������������������t�����������j����������������������fd�t ����������t�����������������������������������D���������������S�)Nr�����c������������������^������g�|�])}t�����������j������������������������������|d�������������������������*S�r ���)r����sepr���)�.0�i� path_partss��� �r���� <listcomp>z/all_possible_relative_paths.<locals>.<listcomp>.���s/�������H�H�H�A�B�F�K�K� �1�2�2��'�'�H�H�Hr���)r���r ����relpath�stripr����split�range�len)r���r����rel_pathr ���s��� @r����all_possible_relative_pathsr(���(���st��������>F�M�r�w���x���S�9�9�9�2�H������'�'�-�-�b�f�5�5�J�H�H�H�H��s�:���1G�1G�H�H�H�Hr���r'���c�����������������������|�����������������������|������������st����������d|��d|���d��������������|�d�t����������|�����������������������S�)Nz rel_path 'z' is not a suffix of abs_path '�')�endswith� ValueErrorr&���)r���r'���s��� r����get_base_dirr-���1���s]����������X�&�&�� ��M��M�M�(�M�M�M� �� �� ���$�s�8�}�}�n�$�%�%r���c�������������������������e�Zd�Zej��������ej��������d�ZdZ�ej ��������d������������Z �ej ��������d������������Zdefd�Z ededefd ���������������Z �ddededee���������fd �ZdS�)�HashCalculator)�md5�sha256i� ��s���[ - ]+s���[�---�]+� algorithmc������������������b�����||�_���������|�j��������|���������|�_��������|dk����r|�j��������nd��|�_��������d�S�)Nr0���c�����������������������|�S�r �����)�xs��� r����<lambda>z)HashCalculator.__init__.<locals>.<lambda>H���s������a��r���)r2����HASHING_ALGORITHMS�_hasher_factory�_normalize_data_for_md5�_normalizer)�selfr2���s��� r����__init__zHashCalculator.__init__D���s>������"���#�6�y�A���,5��,>�,>�D�(�(�K�K�� ���r����datar���c������������������������t����������|t����������������������st����������d�������������|�j�����������������������������d|������������}|�j�����������������������������d|������������}|�����������������������������������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������� )� isinstance�bytes� TypeError�_remove_control_characters�sub�_consolidate_whitespace�lower)�clsr>���s��� r���r:���z&HashCalculator._normalize_data_for_md5K���sd��������$��&�&�� J��H�I�I�I��-�1�1�#�t�<�<���*�.�.�t�T�:�:���z�z�|�|�r���F�filepath�apply_normalizationc��������������������������t�����������j�����������������������������|������������sd�S�t����������|d������������5�}|r'�����������������������|�����������������������������������������������n|�������������������������������������������������������������������������}���fd�t����������dt�������������������������j ��������������������D���������������D�]}|� ��������������������|�������������� �d�d�d��������������n#�1�swxY�w�Y���|�����������������������������������S�)N�rbc��������������3����<����K����|�]}�||�j���������z�������������V����d�S�r ���)�BUFFER_SIZE)r���r����normalized_datar<���s��� ��r���� <genexpr>z+HashCalculator.calc_hash.<locals>.<genexpr>h���sI����������������� ��A��(8�$8� 8�9�����������r���r���)r���r ����isfile�openr;����readr9���r%���r&���rN����update� hexdigest)r<���rI���rJ���r����hasher�chunkrO���s���` @r���� calc_hashzHashCalculator.calc_hash\���sI���������w�~�~�h�'�'�� ��F� �(�D� !� !�� %�T��'�!�� � ������-�-�-��Y�Y�[�[�� � ��)�)�+�+�F�����������q�#�o�"6�"6��8H�I�I������� %�� %���� � �e�$�$�$�$� %� %�� %�� %�� %�� %�� %�� %�� %�� %�� %�� %����� %�� %�� %�� %�����!�!�!s����BC�C�"CN)F)�__name__� __module__�__qualname__�hashlibr0���r1���r8���rN����re�compilerF���rD����strr=����classmethodrB���r:����boolr���rX���r5���r���r���r/���r/���;���s����������������{��.�������K�(�b�j�)<�=�=��!+���,M�!N�!N�� �#�� �� �� �� ����5���U���������[��"�:?�"��"��"�26�"� �#��"��"��"��"��"��"r���r/���)r���)�__doc__r\���r���r]����typingr����configr���r_����intr����listr(���r-���r/���r5���r���r����<module>rg������s�������*������ � � � �� � � � ��������������!��!��!��!��!��!��&3�/��/��/�"�/��/��/��/��/�I��I�#��I���I�t��I��I��I��I�&�3��&�#��&�#��&��&��&��&�2"��2"��2"��2"��2"��2"��2"��2"��2"��2"r���