Hacked By AnonymousFox

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

�

��g]"����dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZedd��Zej
e��ZGd�d��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>
�)�
namedtupleN)�sysctl�Event)�path�flags�cookie�name�wdc��eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZd�ej��dkrdnd��Zejed���Ze j!d��Z"e#d���Z$e#d���Z%e#d ���Z&e#d!���Z'e#d"���Z(e#d#���Z)d$S)%�InotifyzE
    Tiny wrapper for inotify api. See `man inotify` for details
    ������ �@��i�ii i@i�iiii i@lzlibc.{}�Darwinzso.6�dylibT)�	use_errno�iIIIc��ttj|��|�}|dkr5tj��}t|t
j|�����|S)a
        Wrapper to all calls to C functions. Raises OSError with appropriate
        errno as argument in case of error return value.
        :param method: method to call
        :param args: method args
        :return: called function return value in case of success
        ���)�getattrr�_libc�ctypes�	get_errno�OSError�os�strerror)�method�args�ret�errnos    �T/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/subsys/ainotify.py�_callz
Inotify._callIsR��-�g�g�m�V�,�,�d�3���"�9�9��$�&�&�E��%���U�!3�!3�4�4�4��
�c�6�t�d��S)z�
        Initialize an inotify instance.
        See `man inotify_init` for details
        :return: a file descriptor of new inotify instance
        �inotify_init�rr)�r*r(�initzInotify.initXs���}�}�^�,�,�,r*c�<�t�d|||��S)a�
        Add a watch to an initialized inotify instance. This method is
        idempotent. If called twice with the same :fd: and :path: and
        different mask, will change watch flags of current watch.
        See `man inotify_add_watch` for details
        :param fd: file descriptor returned by `init()`
        :param path: path to file or directory to watch
        :param mask: bitmask of events to monitor
        :return: file descriptor of watch
        �inotify_add_watchr-)�fdr�masks   r(�	add_watchzInotify.add_watchas���}�}�0�"�d�D�A�A�Ar*c�:�t�d||��S)z�
        Remove existing watch from inotify instance.
        :param fd: file descriptor of inotify instance
        :param wd: watch file descriptor, returned by `add_watch()`
        :return: zero
        �inotify_rm_watchr-)r2r
s  r(�rm_watchzInotify.rm_watchos���}�}�/��R�8�8�8r*c�@�tj�|��S)z�
        Unpacks prefix of event struct.
        See `man inotify` for details
        :param data: struct bytestring
        :return: tuple of (wd, flag, cookie, length)
        )r�event_prefix�unpack��datas r(�
unpack_prefixzInotify.unpack_prefixys���#�*�*�4�0�0�0r*c�~�tjdt|��z|��d�d��S)z�
        Unpack name field of inotify event struct
        See `man inotify` for details
        :param data: struct bytestring
        :return: name string
        z%dsr�)�structr:�len�rstripr;s r(�unpack_namezInotify.unpack_name�s4���}�U�S��Y�Y�.��5�5�a�8�?�?��H�H�Hr*N)*�__name__�
__module__�__qualname__�__doc__�ACCESS�MODIFY�ATTRIB�CLOSE_WRITE�
CLOSE_NOWRITE�OPEN�
MOVED_FROM�MOVED_TO�CREATE�DELETE�DELETE_SELF�	MOVE_SELF�UNMOUNT�
Q_OVERFLOW�IGNORED�ONLYDIR�DONT_FOLLOW�EXCL_UNLINK�MASK_ADD�ISDIR�ONESHOT�format�platform�system�_nr�CDLLrr@�Structr9�staticmethodr)r/r4r7r=rCr.r*r(rr's����������F�
�F�
�F��K��M��D��J��H�
�F�
�F��K��I��G��J��G��G��K��K��H��E��G�	�	�	�O�H�O�$5�$5��$A�$A�&�&�w�	O�	O�B��F�K��d�+�+�+�E� �6�=��(�(�L�����\���-�-��\�-��B�B��\�B��9�9��\�9��1�1��\�1��I�I��\�I�I�Ir*rc�Z�eZdZdZdZdZdZdZdd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�ZdS)�Watcherz1
    Asynchronous watcher for inotify events
    r�g�?zfs.inotify.max_user_watchesNc��||_t���|_t	j��|_|p|jj|_|j�	|j|j
��|���dS�N)�_looprr/�_fd�asyncio�Queue�_queue�put�	_callback�
add_reader�_read�_reset_state)�self�loop�
coro_callbacks   r(�__init__zWatcher.__init__�si����
��<�<�>�>����m�o�o���&�9�$�+�/����
���d�h��
�3�3�3��������r*c�0�i|_i|_d|_dS)Nr*)�paths�descriptors�buf�rss r(rrzWatcher._reset_state�s����
��������r*c�F�|xjtj|j|j��z
c_t
jj}t|j��|k�rIt
�	|jd|���\}}}}||z}t
�
|j||���}|j|d�|_||jvr��|j|}|t
jzr1t�d|��|�|����|t
jzrt�d����t%|||||��}	|j�|�|	����t|j��|k��GdSdS)Nz(Got IGNORED event for %s, cleaning watchzInotify queue overflow)rzr"�readrj�_CHUNK_SIZErr9�sizerAr=rCrxrV�logger�warning�_cleanup_watchrU�errorrri�create_taskro)
rs�struct_sizer
rr�length�
struct_endr	r�evs
          r(rqz
Watcher._read�s������B�G�D�H�d�&6�7�7�7����*�/���$�(�m�m�{�*�*�(/�(=�(=����+��&�)�)�%�B��v�v�%�v�-�J��&�&�t�x��J�0F�'G�H�H�D��x�
���,�D�H����#�#���:�b�>�D��w��&�
����>������#�#�D�)�)�)���w�)�)�
����5�6�6�6���t�U�F�D�"�5�5�B��J�"�"�4�>�>�"�#5�#5�6�6�6�/�$�(�m�m�{�*�*�*�*�*�*r*c���tj|j��}|t||jz��z}t
�d|j|��tj|j|��dS)NzRaising %s to %s)rr}�_MAX_USER_WATCHES�int�_WATCHERS_RAISE_COEFFr��info�write)rs�current_max_watches�new_max_watcherss   r(�_raise_user_watcheszWatcher._raise_user_watches�sx��$�k�$�*@�A�A��.���$�"<�<�2
�2
�
��	����� 6�8H�	
�	
�	
�	��T�+�-=�>�>�>�>�>r*c���|j�|j��	tj|j��|���d|_dS#|���d|_wxYw)za
        Close watcher. Close inotify fd, remove reader and reset state
        :return:
        N)ri�
remove_readerrjr"�closerrr{s r(r�z
Watcher.close�st��
	
�
� � ���*�*�*�	��H�T�X�����������D�H�H�H��
�������D�H�O�O�O�Os�A�A4c��t|t��s
Jd���t�d|��d}		t�|j||��}||j|<||j|<dS#t$rz}||j
krN|jtjkr9|�
��|dz
}t�d|��Yd}~��t�d|���d}~wwxYw)	z�
        Add file to watch
        :param path: file or directory to watch
        :param mask: events mask for this watch
        zPath must be byteszWatching %rrTr
z-Inotify: not enough watches (%r), retrying...Nz Inotify failed while watching %r)�
isinstance�bytesr�r�rr4rjrxryr!�_MAX_WATCH_RETRIESr'�ENOSPCr�r�r�)rsrr3�retriesr
�es      r(�watchz
Watcher.watch�s���$��&�&�<�<�(<�<�<�&����M�4�(�(�(���	�
��&�&�t�x��t�<�<��!%��
�2��)+�� ��&�����
�
�
��d�5�5�5���5�<�/�/��,�,�.�.�.��q�L�G��N�N�G������H�H�H�H����?��F�F�F������
���s�5A6�6
C:�AC5�C5�5C:c�z�|j�|d��}|�|j�|d��dSdSrh)ry�poprx)rsr�
descriptors   r(r�zWatcher._cleanup_watch�sD���%�)�)�$��5�5�
��!��J�N�N�:�t�,�,�,�,�,�"�!r*c��||jvrdSt�d|��	t�|j|j|��|�|��dS#|�|��wxYw)zq
        Remove file or directory from watch
        :param path: file or directory to remove watch from
        NzStop watching %r)ryr�r�rr7rjr�)rsrs  r(�unwatchzWatcher.unwatch�s���
�t�'�'�'��F����&��-�-�-�	&����T�X�t�'7��'=�>�>�>�����%�%�%�%�%��D����%�%�%�%���s�+A*�*Bc��~K�|j����d{V��}t�d|��|S)zF
        Get watch event
        :return: `Event` named tuple
        NzInotify event: %s)rm�getr��debug)rs�events  r(�	get_eventzWatcher.get_eventsE����
�k�o�o�'�'�'�'�'�'�'�'�����(�%�0�0�0��r*rh)rDrErFrGr~r�r�r�rvrrrqr�r�r�r�r�r�r.r*r(rere�s����������K�����5���������
7�7�7�:?�?�?�
�
�
����:-�-�-�
&�&�&�����r*re)rG�collectionsrrkrr'�loggingr"r@r^�defence360agent.subsysrr�	getLoggerrDr�rrer.r*r(�<module>r�s����*#�"�"�"�"�"�����
�
�
�
���������	�	�	�	�
�
�
�
�����)�)�)�)�)�)��
�7�E�F�F��
��	�8�	$�	$��dI�dI�dI�dI�dI�dI�dI�dI�N@�@�@�@�@�@�@�@�@�@r*

Hacked By AnonymousFox1.0, Coded By AnonymousFox