Hacked By AnonymousFox

Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/__pycache__/scanner.cpython-311.pyc

�

��g�����dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZmZmZmZeje��ZGd
�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)�Dict�Iterator�List�Optional�Tuple)�ScanFailedError)�Core)�MessageType�)�AiBolit)�
DirectAiBolit�PrepareFileList�
ScanResult�
event_hookc��eZdZdd�Zd�Zd�Zd�Zd�Zd�Zd	�Z	d
�Z
d�Zdee
d
eeeeee
ffd�ZdS)�MalwareScannerNFc���|ptj|_||_||_d|_d|_tj��|_	||_d|_
d|_tj��|_
dS�N)�Config�TMPDIR�_tmpdir�_sink�_hooks�aibolit�_task�asyncio�get_event_loop�_loop�
_current_task�_future_result�Lock�_is_running)�self�tmpdir�sink�hookss    �Q/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/scanner.py�__init__zMalwareScanner.__init__'sg���.�������
���������
��+�-�-��
����!���"���"�<�>�>�����c��tj��|_|j�|j|g|�Ri|����|_|jSr)r�Futurer r�create_task�_startr)r#�path�args�kwargss    r'�startzMalwareScanner.start4sM��%�n�.�.����Z�+�+�K�D�K��,N�t�,N�,N�,N�v�,N�,N�O�O��
��z�r)c��|j�tj�d���|j�|j��|j���S�NzNeed to start action)r r�
exceptions�InvalidStateErrorr�run_until_complete�result�r#s r'�waitzMalwareScanner.wait9sQ����&��$�6�6�7M�N�N�N��
�%�%�d�&9�:�:�:��"�)�)�+�+�+r)c��K�|j�tj�d���|j�d{V��|j���Sr3)r rr4r5r7r8s r'�
async_waitzMalwareScanner.async_wait@sW������&��$�6�6�7M�N�N�N��!�!�!�!�!�!�!�!��"�)�)�+�+�+r)c�d�|���r|j���dSdSr)�statusr�cancelr8s r'�stopzMalwareScanner.stopGs6���;�;�=�=�	 ��J��������	 �	 r)c�4�|j���Sr)r"�lockedr8s r'r=zMalwareScanner.statusKs����&�&�(�(�(r)c���K�|j4�d{V��	|j}|jrt|j��|��}||g|�Ri|���d{V��}|j�|��n[#tj$r|j�d��Yn0t$r$}|j�
|��Yd}~nd}~wwxYwddd���d{V��dS#1�d{V��swxYwYdSr)r"�
_execute_scanrrrr �
set_resultr�CancelledError�	Exception�
set_exception)r#r.r/r0�execute_scanr7�es       r'r-zMalwareScanner._startNs������#�	7�	7�	7�	7�	7�	7�	7�	7�

7�#�1���;�H�#9�:�d�j�#9�#9�,�#G�#G�L�+�|�D�B�4�B�B�B�6�B�B�B�B�B�B�B�B���#�.�.�v�6�6�6�6���)�
5�
5�
5��#�.�.�t�4�4�4�4�4��
5�
5�
5��#�1�1�!�4�4�4�4�4�4�4�4�����
5����	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7sF�C�=A*�C�*)C�C�	C�B=�8C�=C�C�
C"�%C"c���K�|jr�	tj��}|jj|d<t|t��rG|j|d<|j|d<|j	|d<|j
|d<|j|d<|j|d<|j
|d<nt|��|d<|j�|���d{V��dS#t j$r�t$$rt&�d	��YdSwxYwdS)
N�	exception�return_code�command�out�err�messager.�scan_idz*Exception while sending ScanFailed message)rr
�
ScanFailed�	__class__�__name__�
isinstancerrLrMrNrOrPr.rQ�str�process_messagerrErF�loggerrK)r#rI�msgs   r'�_send_scan_failed_messagez(MalwareScanner._send_scan_failed_message\s4�����:�	O�
O�!�,�.�.��#$�;�#7��K� ��a��1�1�	,�)*��C�
�&�%&�Y�C�	�N�!"��C��J�!"��C��J�%&�Y�C�	�N�"#�&�C��K�%&�Y�C�	�N�N�%(��V�V�C�	�N��j�0�0��5�5�5�5�5�5�5�5�5�5�5���)�
�
�
���
O�
O�
O�� � �!M�N�N�N�N�N�N�
O����'	O�	Os�B0B=�=3C4�3C4c��|K�t�d��t|t��rtnt
}||j��}tj��|d<||j��}||g|�Ri|���d{V��}t|t��sJ�|�
��rdntj��}|�|���|�
��r|���S|j
r|j
jr|j
j|_|���S)NzScan started�
begin_time)�end_time)rX�inforUrVr
rr�time�_run_aibolitr�is_detached�set_start_stop�to_dict_initialr�cmdr/�to_dict)	r#r.r/r0�files_provider�prepare_file_listrHr7r]s	         r'rCzMalwareScanner._execute_scanssB�������N�#�#�#�(��c�2�2�G�M�M��	�+�N�4�<�8�8��#�y�{�{��|��(�(��):�;�;��#�|�D�:�4�:�:�:�6�:�:�:�:�:�:�:�:���&�*�-�-�-�-�-�!�-�-�/�/�@�4�4�T�Y�[�[�����x��0�0�0������	$��)�)�+�+�+��|�
/��� 0�
/�"�l�.����>�>�#�#�#r)�file�returnc��~K�g}d}t��|_|jj}	||_	||fi|���d{V��}n�#tj$r�t$rH}|�|���d{V��t�	d��g}|j
}Yd}~n`d}~wt$rP}|�|���d{V��t�	d��g}t|��}Yd}~nd}~wwxYwtj|��\}}	|�|��d|_n#d|_wxYw||fS)z�
        :param file: file with list of files, that should be scanned
        :param scan_options: some options for the scan
        :return: parse report iterator and error
        Nz%Scan failed with ScanFailed exceptionz#Scan failed with ordinary exception)rr�scanrrrErrZrXrKrPrF�repr�	itertools�tee�append)
r#rh�scan_options�	iterators�errorrk�iteratorrIr7�_s
          r'r`zMalwareScanner._run_aibolit�s������	����y�y����|� ��	&�!%�D��
 �!%��d�!;�!;�l�!;�!;�;�;�;�;�;�;�����)�
�
�
��"�
"�
"�
"��4�4�Q�7�7�7�7�7�7�7�7�7�� � �!H�I�I�I����	������������
 �
 �
 ��4�4�Q�7�7�7�7�7�7�7�7�7�� � �!F�G�G�G����Q�������������	
 ����"�
�h�/�/�I�F�A����V�$�$�$�!%�D�����D��%�%�%�%��%��sD�D/�?�D/�C8�>B�D/�
C8�(AC3�.D/�3C8�8/D/�/	D8)NNF)rT�
__module__�__qualname__r(r1r9r;r?r=r-rZrCrrVrrrrr`�r)r'rr&s�������*�*�*�*����
,�,�,�,�,�,� � � �)�)�)�7�7�7�O�O�O�.$�$�$�0& ��S�M�& �	�t�H�T�N�#�X�c�]�2�	3�& �& �& �& �& �& r)r)�__doc__rrm�loggingr_�typingrrrrr�imav.malwarelib.scanr� defence360agent.contracts.configr	r�"defence360agent.contracts.messagesr
�ai_bolit.scannerr�scan_resultr
rrr�	getLoggerrTrXrrwr)r'�<module>r�s����*����������������8�8�8�8�8�8�8�8�8�8�8�8�8�8�0�0�0�0�0�0�;�;�;�;�;�;�:�:�:�:�:�:�%�%�%�%�%�%�O�O�O�O�O�O�O�O�O�O�O�O�	��	�8�	$�	$��K �K �K �K �K �K �K �K �K �K r)

Hacked By AnonymousFox1.0, Coded By AnonymousFox