a
   2볣'#                   @   s   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 zddl
ZW n eyb   ddlZY n0 ddlmZ dZdZd	Zd
d Zdd Ze d dkrejZnejZG dd dejZdd ZG dd deZdS )zP
Functions for communicating with Pageant, the basic windows ssh agent program.
    N)	zero_byte)b   )_winapil   P  i    J   c                   C   s   t jjddS )Ns   Pageant)ctypeswindlluser32ZFindWindowA r
   r
   8/usr/lib/python3.9/site-packages/paramiko/win_pageant.py_get_pageant_window_object.   s    r   c                   C   s
   t t S )z
    Check to see if there is a "Pageant" agent we can talk to.

    This checks both if we have the required libraries (win32all or ctypes)
    and if there is a Pageant currently running.
    )boolr   r
   r
   r
   r   can_talk_to_agent2   s    r   Z64bitc                   @   s,   e Zd ZdZdefdejjfdejfgZ	dS )COPYDATASTRUCTzy
    ctypes implementation of
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms649010%28v=vs.85%29.aspx
    Znum_data	data_sizeZdata_locN)
__name__
__module____qualname____doc__	ULONG_PTRr   ZwintypesZDWORDZc_void_pZ_fields_r
   r
   r
   r   r   B   s
   
r   c              	   C   s   t  }|sdS dt  }t|tt }| ||  tdt	|t
 }| \}}tt||}tjj|tt|t|}|dkr|d |d}	td|	d }
|	||
 W  d   S W d   dS 1 s0    Y  dS )za
    Communication with the Pageant process is done through a shared
    memory-mapped file.
    NzPageantRequest%08xr   r      z>I)r   thread	get_identr   Z	MemoryMap_AGENT_MAX_MSGLENZ get_security_attributes_for_userwritearrayr   r   Zbuffer_infor   _AGENT_COPYDATA_IDr   r   r	   ZSendMessageAwin32con_WM_COPYDATAZsizeofZbyrefseekreadstructunpack)msgZhwndZmap_nameZpymapZchar_bufferZchar_buffer_addressZchar_buffer_sizeZcdsZresponseZdatalenZretlenr
   r
   r   _query_pageantO   s.    



r#   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )PageantConnectiona  
    Mock "connection" to an agent which roughly approximates the behavior of
    a unix local-domain socket (as used by Agent).  Requests are sent to the
    pageant daemon via special Windows magick, and responses are buffered back
    for subsequent reads.
    c                 C   s
   d | _ d S N	_responseselfr
   r
   r   __init__}   s    zPageantConnection.__init__c                 C   s   t || _d S r%   )r#   r'   )r)   datar
   r
   r   send   s    zPageantConnection.sendc                 C   s@   | j d u rdS | j d | }| j |d  | _ | j dkr<d | _ |S )N r&   )r)   nretr
   r
   r   recv   s    

zPageantConnection.recvc                 C   s   d S r%   r
   r(   r
   r
   r   close   s    zPageantConnection.closeN)r   r   r   r   r*   r,   r0   r1   r
   r
   r
   r   r$   u   s
   	r$   )r   r   Zctypes.wintypesr   platformr    Zparamiko.commonr   Zparamiko.py3compatr   _threadr   ImportErrorr-   r   r   r   r   r   r   ZarchitectureZc_uint64r   Zc_uint32Z	Structurer   r#   objectr$   r
   r
   r
   r   <module>   s,   
&