}gdZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZddlmZdd lmZmZmZmZejeZGd 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 . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see N)DictIteratorListOptionalTuple)ScanFailedError)Core) MessageType)AiBolit) DirectAiBolitPrepareFileList ScanResult event_hookceZdZddZdZdZdZdZdZd Z d Z d Z d e e d eeeee e ffdZdS)MalwareScannerNFc|p tj|_||_||_d|_d|_tj|_ ||_d|_ d|_ tj |_ dSN)ConfigTMPDIR_tmpdir_sink_hooksaibolit_taskasyncioget_event_loop_loop _current_task_future_resultLock _is_running)selftmpdirsinkhookss Q/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/scan/scanner.py__init__zMalwareScanner.__init__'sg.     +--  !""<>>ctj|_|j|j|g|Ri||_|jSr)rFuturer r create_task_startr)r#pathargskwargss r'startzMalwareScanner.start4sM%n..Z++KDK,Nt,N,N,Nv,N,NOO zr)c|jtjd|j|j|jSNzNeed to start action)r r exceptionsInvalidStateErrorrrun_until_completeresultr#s r'waitzMalwareScanner.wait9sQ   &$667MNN N %%d&9:::"))+++r)cK|jtjd|jd{V|jSr3)r rr4r5r7r8s r' async_waitzMalwareScanner.async_wait@sW   &$667MNN N!!!!!!!!"))+++r)cd|r|jdSdSr)statusrcancelr8s r'stopzMalwareScanner.stopGs6 ;;== J         r)c4|jSr)r"lockedr8s r'r=zMalwareScanner.statusKs&&(((r)cK|j4d{V |j}|jrt|j|}||g|Ri|d{V}|j|n[#tj$r|jdYn0t$r$}|j |Yd}~nd}~wwxYwdddd{VdS#1d{VswxYwYdSr) r" _execute_scanrrrr set_resultrCancelledError Exception set_exception)r#r.r/r0 execute_scanr7es r'r-zMalwareScanner._startNs# 7 7 7 7 7 7 7 7 7#1 ;H#9:dj#9#9,#G#GL+|DB4BBB6BBBBBBBB #..v6666 ) 5 5 5#..t44444 5 5 5#11!44444444 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 7sFC=A*C*)CC CB=8C=CC C"%C"cK|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{VdS#t j$rt$$rt&d YdSwxYwdS) N exception return_codecommandouterrmessager.scan_idz*Exception while sending ScanFailed message)rr ScanFailed __class____name__ isinstancerrLrMrNrOrPr.rQstrprocess_messagerrErFloggerrK)r#rImsgs r'_send_scan_failed_messagez(MalwareScanner._send_scan_failed_message\s4 : O O!,..#$;#7K a11 ,)*C &%&YC N!"CJ!"CJ%&YC N"#&CK%&YC NN%(VVC Nj0055555555555)    O O O  !MNNNNNN O' O OsB0B==3C43C4c|Ktdt|trtnt }||j}tj|d<||j}||g|Ri|d{V}t|tsJ| rdntj}| || r| S|j r|j jr|j j|_|S)Nz Scan started begin_time)end_time)rXinforUrVr rrtime _run_aibolitr is_detachedset_start_stopto_dict_initialrcmdr/to_dict) r#r.r/r0files_providerprepare_file_listrHr7r]s r'rCzMalwareScanner._execute_scanssB N###(c22 GMM +N4<88#y{{|(():;; #|D:4:::6::::::::&*-----!--//@44TY[[x000      $))++ +| / 0 /"l. >>## #r)filereturnc~Kg}d}t|_|jj} ||_ ||fi|d{V}n#tj$rt $rH}||d{Vt dg}|j }Yd}~n`d}~wt$rP}||d{Vt dg}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 rscanrrrErrZrXrKrPrFrepr itertoolsteeappend) r#rh scan_options iteratorserrorrkiteratorrIr7_s r'r`zMalwareScanner._run_aibolits yy |  &!%D  !%d!;!;l!;!;;;;;;;)   " " " "44Q777777777  !HIII    44Q777777777  !FGGGQ  " h//IFA   V $ $ $!%D  D  % % % %%sDD/?D/C8>BD/ C8(AC3.D/3C88/D// D8)NNF)rT __module__ __qualname__r(r1r9r;r?r=r-rZrCrrVrrrrr`r)r'rr&s * * * * ,,,,,,   ))) 7 7 7OOO.$$$0& SM& tHTN#Xc]2 3& & & & & & r)r)__doc__rrmloggingr_typingrrrrrimav.malwarelib.scanr defence360agent.contracts.configr r"defence360agent.contracts.messagesr ai_bolit.scannerr scan_resultr rrr getLoggerrTrXrrwr)r'rs* 88888888888888000000;;;;;;::::::%%%%%%OOOOOOOOOOOO  8 $ $K K K K K K K K K K r)