Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
windivert.cpython-313.pyc156 linesDownload Raw Back to __pycache__
1�

2��j�$���SSKrSSKrSSKJrJrJrJrJr SSKJ	r	 SSK3JrJrJ
r
 SSKJr SSKJr Sr"SS	\5rg)4�N)�byref�c_uint64�c_uint�c_char�c_char_p)�
windivert_dll)�Layer�	Direction�Flag)�Packet)�PY2i�c�,�\rSrSrSrS\RS\R4Sjr	Sr5SrSrS	r
S6r\R S:a\r\S5r\S
5r\S5r\\R4Sj5rSr\S5rSr\4SjrSSjrSrSrSr g)�	WinDivert�a7A WinDivert handle that can be used to capture packets.8The main methods are `.open()`, `.recv()`, `.send()` and `.close()`.9 10Use it like so::11 12    with pydivert.WinDivert() as w:13        for packet in w:14            print(packet)15            w.send(packet)16 17�truerc�`�SUlUR5UlX lX0lX@lg�N)�_handle�encode�_filter�_layer�	_priority�_flags)�self�filter�layer�priority�flagss     �XD:\code\apps\devtools\python\user_packages\Python313\site-packages\pydivert/windivert.py�__init__�WinDivert.__init__*s%������}�}������!����c��SRURbSOSURR5URUR18UR5$)NzH<WinDivert state="{}" filter="{}" layer="{}" priority="{}" flags="{}" />�open�closed)�formatrr�decoderrr�rs r�__repr__�WinDivert.__repr__1sH��Y�`�`��l�l�.�F�H��L�L���!��K�K��N�N��K�K�19�	20r"c�&�UR5 U$r)r$r(s r�	__enter__�WinDivert.__enter__:s���	�	���r"c�$�UR5 gr)�close)r�argss  r�__exit__�WinDivert.__exit__>s���21�22�r"c��U$r�r(s r�__iter__�WinDivert.__iter__As���r"c�"�UR5$r)�recvr(s r�__next__�WinDivert.__next__Ds���y�y�{�r")�rc�P�[S5 SSS5 g!,(df   g=f)z�23An utility method to register the service the first time.24It is usually not required to call this function, as WinDivert will register itself when opening a handle.25�falseN)rr4r"r�register�WinDivert.registerJs���w�
�� �
�
�s��26%c�l�[R"S[R[RS9S:H$)zF27Check if the WinDivert service is currently installed on the system.28zsc query WinDivert1.3��stdout�stderrr)�29subprocess�call�PIPEr4r"r�
is_registered�WinDivert.is_registeredSs-��30���6�z���&0�o�o�7�:;�<�	<r"c�h�[R"S[R[RS9 g)z�31Unregisters the WinDivert service.32This function only requests a service stop, which may not be processed immediately if there are still open33handles.34zsc stop WinDivert1.3rAN)rD�35check_callrFr4r"r�36unregister�WinDivert.unregister[s"��	���4�Z�_�_�%/�_�_�	6r"c��S[5[5pCn[R"UR	5U[U5[U55nX#RURR54$![a N2f=f)a$37Checks if the given packet filter string is valid with respect to the filter language.38 39The remapped function is WinDivertHelperCheckFilter::40 41    BOOL WinDivertHelperCheckFilter(42        __in const char *filter,43        __in WINDIVERT_LAYER layer,44        __out_opt const char **errorStr,45        __out_opt UINT *errorPos46    );47 48See: https://reqrypt.org/windivert-doc.html#divert_helper_check_filter49 50:return: A tuple (res, pos, msg) with check result in 'res' human readable description of the error in 'msg' and the error's position in 'pos'.51F)	rrr�WinDivertHelperCheckFilterrr�OSError�valuer')rr�res�pos�msgs     r�check_filter�WinDivert.check_filterest��$�v�x���#��	��:�:�6�=�=�?�E�SX�Y\�S]�_d�eh�_i�j�C��I�I�s�y�y�/�/�1�1�1���	��	�s�9A6�652B�Bc���UR(a[S5e[R"URUR53URUR5Ulg)a�54Opens a WinDivert handle for the given filter.55Unless otherwise specified by flags, any packet that matches the filter will be diverted to the handle.56Diverted packets can be read by the application with receive().57 58The remapped function is WinDivertOpen::59 60    HANDLE WinDivertOpen(61        __in const char *filter,62        __in WINDIVERT_LAYER layer,63        __in INT16 priority,64        __in UINT64 flags65    );66 67For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_open68z!WinDivert handle is already open.N)	�is_open�RuntimeErrorr�
WinDivertOpenrrrrrr(s rr$�WinDivert.open~sC��"�<�<��B�C�C�$�2�2�4�<�<����d�n�n�37�;�;�@��r"c�,�[UR5$)z169Indicates if there is currently an open handle.70)�boolrr(s rrW�WinDivert.is_open�s��71�D�L�L�!�!r"c��UR(d[S5e[R"UR5 SUlg)z�72Closes the handle opened by open().73 74The remapped function is WinDivertClose::75 76    BOOL WinDivertClose(77        __in HANDLE handle78    );79 80For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_close81zWinDivert handle is not open.N)rWrXr�WinDivertCloserr(s rr/�WinDivert.close�s0���|�|��>�?�?��$�$�T�\�\�2���r"c	��URc[S5e[U5n[U-R	U5n[82R"5n[S5n[83R"URX1[U5[U55 [[U5SURURUR4[UR55$)a�84Receives a diverted packet that matched the filter.85 86The remapped function is WinDivertRecv::87 88    BOOL WinDivertRecv(89        __in HANDLE handle,90        __out PVOID pPacket,91        __in UINT packetLen,92        __out_opt PWINDIVERT_ADDRESS pAddr,93        __out_opt UINT *recvLen94    );95 96For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_recv97 98:return: The return value is a `pydivert.Packet`.99NzWinDivert handle is not openr)rrX�	bytearrayr�from_bufferr�WinDivertAddressr�
WinDivertRecvrr�100memoryviewrP�IfIdx�SubIfIdxr101)r�bufsize�packet�packet_�address�recv_lens      rr8�WinDivert.recv�s���$�<�<���=�>�>��7�#���G�#�0�0��8���0�0�2���!�9���#�#�D�L�L�'�E�'�N�TY�Zb�Tc�d���v������/�
�]�]�G�,�,�-��g�'�'�(�102�	103r"c	��U(aUR5 [S5n[(a[UR5nOURn[104[
UR5-RU5n[R"URU[
UR5[UR5[U55 U$)a�105Injects a packet into the network stack.106Recalculates the checksum before sending unless recalculate_checksum=False is passed.107 108The injected packet may be one received from recv(), or a modified version, or a completely new packet.109Injected packets can be captured and diverted again by other WinDivert handles with lower priorities.110 111The remapped function is WinDivertSend::112 113    BOOL WinDivertSend(114        __in HANDLE handle,115        __in PVOID pPacket,116        __in UINT packetLen,117        __in PWINDIVERT_ADDRESS pAddr,118        __out_opt UINT *sendLen119    );120 121For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_send122 123:return: The return value is the number of bytes actually sent.124r)
�recalculate_checksumsrr
rb�rawr�lenrcr�
WinDivertSendrr�wd_addr)rrj�recalculate_checksum�send_len�buffs     r�send�WinDivert.send�s���, ��(�(�*��!�9���3��V�Z�Z�(�D��:�:�D���V�Z�Z��(�5�5�d�;���#�#�D�L�L�$��F�J�J���v�~�~�I^�$)�(�O�	5��r"c��[S5n[R"URU[	U55 UR125$)at126Get a WinDivert parameter. See pydivert.Param for the list of parameters.127 128The remapped function is WinDivertGetParam::129 130    BOOL WinDivertGetParam(131        __in HANDLE handle,132        __in WINDIVERT_PARAM param,133        __out UINT64 *pValue134    );135 136For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_get_param137 138:return: The parameter value.139r)rr�WinDivertGetParamrrrP�r�namerPs   r�	get_param�WinDivert.get_param�s1�� �����'�'����d�E�%�L�I��{�{�r"c�D�[R"URX5$)aO140Set a WinDivert parameter. See pydivert.Param for the list of parameters.141 142The remapped function is DivertSetParam::143 144    BOOL WinDivertSetParam(145        __in HANDLE handle,146        __in WINDIVERT_PARAM param,147        __in UINT64 value148    );149 150For more info on the C call visit: http://reqrypt.org/windivert-doc.html#divert_set_param151)r�WinDivertSetParamrr|s   r�	set_param�WinDivert.set_params���.�.�t�|�|�T�I�Ir")rrrrrN)T)!�__name__�152__module__�__qualname__�__firstlineno__�__doc__r	�NETWORKr�DEFAULTr r)r,r1r5r9�sys�version_info�next�staticmethodr>rGrKrTr$�propertyrWr/�DEFAULT_PACKET_BUFFER_SIZEr8rxr~r��__static_attributes__r4r"rrrs����%�E�M�M�A�T�\�\��153��������&� ��������<��<��6��6��#(�=�=�2��2�0@�,�"��"��"6�154�@"�H�(Jr"r)rDr��ctypesrrrrr�pydivertr�pydivert.constsr	r155r�pydivert.packetr�
pydivert.utilr
r��objectrr4r"r�<module>r�s8�� �156�<�<�"�2�2�"��!��vJ��vJr"
codekingpro/portable-devtools · Team Ai