o
    àý°jSV  ã                   @   s²  d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
mZmZmZmZmZ d dlmZ d dlmZmZ edƒZedƒZG dd	„ d	eƒZeZG d
d„ deƒZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3d Z4dZ5d!Z6d"Z7d#Z8d$Z9d%Z:d&Z;dZ<dZ=d'Z>d(Z?d)Z@d*ZAd+ZBd,ZCd%ZDd#ZEd-ZFd.ZGd&ZHd$ZId/ZJd ZKd!ZLdZMd0ZNdZOd1ZPd2ZQd3ZRd4ZSd5ZTd6ZUdZVdZWd7ZXdZYdZZdZ[dZ\dZ]dZ^d8Z_d9Z`d ZadZbd!Zcd:Zdd4Zed Zfd ZgdZhdZidZjdZkdZldZmd;Znd<Zod9Zpd ZqG d=d>„ d>eƒZrG d?d@„ d@eƒZsG dAdB„ dBeƒZtG dCdD„ dDeƒZuG dEdF„ dFeƒZvG dGdH„ dHeƒZwG dIdJ„ dJeƒZxG dKdL„ dLeƒZyG dMdN„ dNeƒZzG dOdP„ dPeƒZ{G dQdR„ dReƒZ|G dSdT„ dTeƒZ}G dUdV„ dVeƒZ~G dWdX„ dXeƒZG dYdZ„ dZeƒZ€G d[d\„ d\eƒZ�G d]d^„ d^eƒZ‚G d_d`„ d`eƒZƒG dadb„ dbeƒZ„G dcdd„ ddeƒZ…G dedf„ dfeƒZ†G dgdh„ dheƒZ‡G didj„ djeƒZˆG dkdl„ dleƒZ‰G dmdn„ dneƒZŠG dodp„ dpeƒZ‹G dqdr„ dreƒZŒG dsdt„ dteƒZ�G dudv„ dveƒZŽG dwdx„ dxeƒZ�G dydz„ dzeƒZ�G d{d|„ d|eƒZ‘G d}d~„ d~eƒZ’G dd€„ d€eƒZ“G d�d‚„ d‚eƒZ”G dƒd„„ d„eƒZ•eŒe�feŽe�feŠe‹fe”e”fe�e‘fe’e“fd…œZ–d†d‡„ Z—dˆd‰„ Z˜e	e	e+e	fdŠd‹„Z™e	dfdŒd�„ZšdŽd�„ Z›d�d‘„ Zœd’d“„ Z�d”S )•é    )Úsystem_errors)Ú	ULONGLONGÚUINTÚUSHORTÚLPWSTRÚDWORDÚULONGÚNULL)ÚNDRCALLÚ	NDRSTRUCTÚNDRUNIONÚ
NDRPOINTERÚNDRUniConformantArray)ÚDCERPCException)Úuuidtup_to_binÚstring_to_bin)z$76F03F96-CDFD-44FC-A22C-64950A001209z1.0z$9940CA8E-512F-4C58-88A9-61098D6896BDc                   @   s   e Zd Zddd„Zdd„ ZdS )ÚDCERPCSessionErrorNc                 C   s   t  | |||¡ d S )N)r   Ú__init__)ÚselfÚerror_stringÚ
error_codeÚpacket© r   ú‰/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/impacket/dcerpc/v5/par.pyr   %   s   zDCERPCSessionError.__init__c                 C   sF   | j }|tjv rtj| d }tj| d }d| j ||f S d| j  S )Nr   é   z'RPRN SessionError: code: 0x%x - %s - %sz+RPRN SessionError: unknown error code: 0x%x)r   r   ÚERROR_MESSAGES)r   ÚkeyÚerror_msg_shortÚerror_msg_verboser   r   r   Ú__str__(   s   

zDCERPCSessionError.__str__)NNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   $   s    
r   c                   @   ó   e Zd ZdeffZdS )ÚPSTRING_HANDLEÚDataN)r    r!   r"   ÚSTRING_HANDLEÚreferentr   r   r   r   r$   6   ó    ÿr$   é   é    i  i   i0  é   é   é@   i  i  r   é   i  i  i  iÿÿ  i   i   i   i   i   i   i   l        i   @i    i   éÿ   é   i   i   i   i ÿ  iÿÿwwiÿÿwi   pi   i    i  @ i  p i   i   i   i   i @  i €  i  € i   i    c                   @   s   e Zd ZdZdd„ ZdS )ÚPRINTER_HANDLE))r%   z20s=b""c                 C   s   | j du rdS dS )NTr,   r+   )Ú_isNDR64)r   r   r   r   ÚgetAlignment©   s   
zPRINTER_HANDLE.getAlignmentN)r    r!   r"   Ú	structurer3   r   r   r   r   r1   ¥   s    r1   c                   @   ó   e Zd ZdZdS )Ú
BYTE_ARRAYÚcN©r    r!   r"   Úitemr   r   r   r   r6   °   ó    r6   c                   @   r#   )ÚPBYTE_ARRAYr%   N)r    r!   r"   r6   r'   r   r   r   r   r;   ³   r(   r;   c                   @   ó   e Zd ZdefdeffZdS )ÚDEVMODE_CONTAINERÚcbBufÚpDevModeN)r    r!   r"   r   r;   r4   r   r   r   r   r=   ¸   ó    þr=   c                   @   s:   e Zd ZdefdefdefdefdefdefdeffZdS )	ÚSPLCLIENT_INFO_1ÚdwSizeÚpMachineNameÚ	pUserNameÚ
dwBuildNumÚdwMajorVersionÚdwMinorVersionÚwProcessorArchitectureN)r    r!   r"   r   r   r   r4   r   r   r   r   rA   ¿   s    ùrA   c                   @   r#   )ÚPSPLCLIENT_INFO_1r%   N)r    r!   r"   rA   r'   r   r   r   r   rI   Ê   r(   rI   c                   @   r#   )ÚSPLCLIENT_INFO_2ÚnotUsedN)r    r!   r"   r   r4   r   r   r   r   rJ   Ð   r(   rJ   c                   @   r#   )ÚPSPLCLIENT_INFO_2r%   N)r    r!   r"   rJ   r'   r   r   r   r   rL   Õ   r(   rL   c                   @   sL   e Zd Zdefdefdefdefdefdefdefdefdefd	eff
Zd
S )ÚSPLCLIENT_INFO_3ÚcbSizeÚdwFlagsrC   rD   rE   rF   rG   rH   ÚhSplPrinterN)	r    r!   r"   r   r   r   r   r   r4   r   r   r   r   rM   Ú   s    örM   c                   @   r#   )ÚPSPLCLIENT_INFO_3r%   N)r    r!   r"   rM   r'   r   r   r   r   rQ   è   r(   rQ   c                   @   r#   )ÚDRIVER_INFO_1ÚpNameN)r    r!   r"   r&   r4   r   r   r   r   rR   î   r(   rR   c                   @   r#   )ÚPDRIVER_INFO_1r%   N)r    r!   r"   rR   r'   r   r   r   r   rT   ò   r(   rT   c                   @   s4   e Zd ZdefdefdefdefdefdeffZdS )ÚDRIVER_INFO_2ÚcVersionrS   ÚpEnvironmentÚpDriverPathÚ	pDataFileÚpConfigFileN)r    r!   r"   r   r   r4   r   r   r   r   rU   ø   ó    úrU   c                   @   r#   )ÚPDRIVER_INFO_2r%   N)r    r!   r"   rU   r'   r   r   r   r   r\     r(   r\   c                   @   s(   e Zd ZdeffZdefdefdœZdS )ÚDRIVER_INFO_UNIONÚtagÚpNotUsedÚLevel2)r   r.   N)r    r!   r"   r   Ú	commonHdrrT   r\   Úunionr   r   r   r   r]     s    ÿ
þr]   c                   @   r<   )ÚDRIVER_CONTAINERÚLevelÚ
DriverInfoN)r    r!   r"   r   r]   r4   r   r   r   r   rc     r@   rc   c                   @   s.   e Zd ZdeffZdefdefdefdœZdS )ÚCLIENT_INFO_UNIONr^   ÚpClientInfo1Ú	pNotUsed1Ú	pNotUsed2)r   r.   é   N)	r    r!   r"   r   ra   rI   rL   rQ   rb   r   r   r   r   rf     s    ÿ
ýrf   c                   @   r<   )ÚSPLCLIENT_CONTAINERrd   Ú
ClientInfoN)r    r!   r"   r   rf   r4   r   r   r   r   rk   !  r@   rk   c                   @   r5   )ÚUSHORT_ARRAYz<HNr8   r   r   r   r   rm   (  r:   rm   c                   @   r#   )ÚPUSHORT_ARRAYr%   N)r    r!   r"   rm   r'   r   r   r   r   rn   +  r(   rn   c                   @   s4   e Zd ZdefdefdefdefdefdeffZdS )ÚRpcAsync_V2_NOTIFY_OPTIONS_TYPEÚTypeÚ	Reserved0Ú	Reserved1Ú	Reserved2ÚCountÚpFieldsN)r    r!   r"   r   r   rn   r4   r   r   r   r   ro   0  r[   ro   c                   @   r#   )Ú!PRPC_V2_NOTIFY_OPTIONS_TYPE_ARRAYr%   N)r    r!   r"   ro   r'   r   r   r   r   rv   :  r(   rv   c                   @   s(   e Zd ZdefdefdefdeffZdS )ÚRpcAsync_V2_NOTIFY_OPTIONSÚVersionÚReservedrt   ÚpTypesN)r    r!   r"   r   rv   r4   r   r   r   r   rw   @  ó    ürw   c                   @   r#   )ÚPRPC_V2_NOTIFY_OPTIONSr%   N)r    r!   r"   rw   r'   r   r   r   r   r|   H  r(   r|   c                   @   s2   e Zd ZdZdefdefdefdefdeffZdS )ÚRpcAsyncEnumPrintersé&   ÚFlagsÚNamerd   ÚpPrinterEnumr>   N)r    r!   r"   Úopnumr   r&   r;   r4   r   r   r   r   r}   R  ó    ûr}   c                   @   ó(   e Zd ZdefdefdefdeffZdS )ÚRpcAsyncEnumPrintersResponser�   Ú	pcbNeededÚ
pcReturnedÚ	ErrorCodeN©r    r!   r"   r;   r   r   r4   r   r   r   r   r…   \  r{   r…   c                   @   s2   e Zd ZdZdefdefdefdefdeffZ	dS )ÚRpcAsyncOpenPrinterr   ÚpPrinterNameÚ	pDatatypeÚpDevModeContainerÚAccessRequiredÚpClientInfoN)
r    r!   r"   r‚   r&   r   r=   r   rk   r4   r   r   r   r   rŠ   e  rƒ   rŠ   c                   @   r<   )ÚRpcAsyncOpenPrinterResponseÚpHandlerˆ   N©r    r!   r"   r1   r   r4   r   r   r   r   r�   o  r@   r�   c                   @   s   e Zd ZdZdeffZdS )ÚRpcAsyncClosePrinteré   Ú	phPrinterN)r    r!   r"   r‚   r1   r4   r   r   r   r   r“   v  s    ÿr“   c                   @   r<   )ÚRpcAsyncClosePrinterResponser•   rˆ   Nr’   r   r   r   r   r–   |  r@   r–   c                   @   ó2   e Zd ZdZdefdefdefdefdeffZdS )ÚRpcAsyncEnumPrinterDriversé(   rS   rW   rd   ÚpDriversr>   N©	r    r!   r"   r‚   r&   r   r   r;   r4   r   r   r   r   r˜   ƒ  rƒ   r˜   c                   @   r„   )Ú"RpcAsyncEnumPrinterDriversResponserš   r†   r‡   rˆ   Nr‰   r   r   r   r   rœ   �  r{   rœ   c                   @   r—   )Ú!RpcAsyncGetPrinterDriverDirectoryé)   rS   rW   rd   ÚpDriverDirectoryr>   Nr›   r   r   r   r   r�   –  rƒ   r�   c                   @   s"   e Zd ZdefdefdeffZdS )Ú)RpcAsyncGetPrinterDriverDirectoryResponserŸ   r†   rˆ   Nr‰   r   r   r   r   r       s
    ýr    c                   @   s&   e Zd ZdZdefdefdeffZdS )ÚRpcAsyncAddPrinterDriveré'   rS   ÚpDriverContainerÚdwFileCopyFlagsN)r    r!   r"   r‚   r&   rc   r   r4   r   r   r   r   r¡   ¨  s    ýr¡   c                   @   r#   )Ú RpcAsyncAddPrinterDriverResponserˆ   N)r    r!   r"   r   r4   r   r   r   r   r¥   °  r(   r¥   )r   r”   r~   r¢   r™   rž   c                 C   s(   | t kr| S | dd … dkr| d S | S )Néÿÿÿÿú )r	   )Ústringr   r   r   ÚcheckNullStringÅ  s
   r©   c                 C   s   t ƒ }||d< |  |t¡S )a±  
    RpcClosePrinter closes a handle to a printer object, server object, job object, or port object.
    Full Documentation: https://msdn.microsoft.com/en-us/library/cc244768.aspx

    :param DCERPC_v5 dce: a connected DCE instance.
    :param PRINTER_HANDLE phPrinter: A handle to a printer object, server object, job object, or port object.

    :return: a RpcClosePrinterResponse instance, raises DCERPCSessionError on error.
    r•   )r“   ÚrequestÚMSRPC_UUID_WINSPOOL)Údcer•   rª   r   r   r   ÚhRpcAsyncClosePrinterÎ  s   
r­   c                 C   sd   t ƒ }t|ƒ|d< ||d< |tu rt|d d< n||d< ||d< |tu r(tdƒ‚||d< |  |t¡S )a+  
    RpcOpenPrinterEx retrieves a handle for a printer, port, port monitor, print job, or print server
    Full Documentation: https://msdn.microsoft.com/en-us/library/cc244809.aspx

    :param DCERPC_v5 dce: a connected DCE instance.
    :param string printerName: A string for a printer connection, printer object, server object, job object, port
    object, or port monitor object. This MUST be a Domain Name System (DNS), NetBIOS, Internet Protocol version 4
    (IPv4), Internet Protocol version 6 (IPv6), or Universal Naming Convention (UNC) name that remote procedure
    call (RpcAsync) binds to, and it MUST uniquely identify a print server on the network.
    :param string pDatatype: A string that specifies the data type to be associated with the printer handle.
    :param DEVMODE_CONTAINER pDevModeContainer: A DEVMODE_CONTAINER structure. This parameter MUST adhere to the specification in
    DEVMODE_CONTAINER Parameters (section 3.1.4.1.8.1).
    :param int accessRequired: The access level that the client requires for interacting with the object to which a
    handle is being opened.
    :param SPLCLIENT_CONTAINER pClientInfo: This parameter MUST adhere to the specification in SPLCLIENT_CONTAINER Parameters.

    :return: a RpcOpenPrinterExResponse instance, raises DCERPCSessionError on error.
    r‹   rŒ   r�   r?   rŽ   zpClientInfo cannot be NULLr�   )rŠ   r©   r	   Ú	Exceptionrª   r«   )r¬   ÚprinterNamerŒ   r�   ÚaccessRequiredr�   rª   r   r   r   ÚhRpcAsyncOpenPrinterÝ  s   r±   c              
   C   s¾   t ƒ }||d< ||d< t|d< ||d< d}z|  |t¡ W n" ty? } zt|ƒ d¡dk r/‚ | ¡ d }W Y d}~nd}~ww t ƒ }||d< ||d< ||d< ||d	< d
| |d< |  |t¡S )aÇ  
    RpcEnumPrinters enumerates available printers, print servers, domains, or print providers.
    Full Documentation: https://msdn.microsoft.com/en-us/library/cc244794.aspx

    :param DCERPC_v5 dce: a connected DCE instance.
    :param int flags: The types of print objects that this method enumerates. The value of this parameter is the
    result of a bitwise OR of one or more of the Printer Enumeration Flags (section 2.2.3.7).
    :param string name: NULL or a server name parameter as specified in Printer Server Name Parameters (section 3.1.4.1.4).
    :param level: The level of printer information structure.

    :return: a RpcEnumPrintersResponse instance, raises DCERPCSessionError on error.
    r   r€   r�   rd   r   ÚERROR_INSUFFICIENT_BUFFERr†   Nr>   ó   a)r}   r	   rª   r«   r   ÚstrÚfindÚ
get_packet)r¬   ÚflagsÚnameÚlevelrª   ÚbytesNeededÚer   r   r   ÚhRpcAsyncEnumPrinters  s*   €ýr¼   c                 C   s.   t ƒ }t|ƒ|d< ||d< ||d< |  |t¡S )a~  
    RpcAddPrinterDriverEx installs a printer driver on the print server
    Full Documentation: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/b96cc497-59e5-4510-ab04-5484993b259b

    :param DCERPC_v5 dce: a connected DCE instance.
    :param pName
    :param pDriverContainer
    :param dwFileCopyFlags

    :return: raises DCERPCSessionError on error.
    rS   r£   r¤   )r¡   r©   rª   r«   )r¬   rS   r£   r¤   rª   r   r   r   ÚhRpcAsyncAddPrinterDriver%  s
   r½   c              
   C   óÊ   t ƒ }t|ƒ|d< ||d< ||d< t|d< d|d< z|  |t¡ W n" tyC } zt|ƒ d¡dk r3‚ | ¡ d }W Y d	}~nd	}~ww t ƒ }t|ƒ|d< ||d< ||d< d
| |d< ||d< |  |t¡S )aØ  
    RpcEnumPrinterDrivers enumerates the printer drivers installed on a specified print server.
    Full Documentation: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/857d00ac-3682-4a0d-86ca-3d3c372e5e4a

    :param DCERPC_v5 dce: a connected DCE instance.
    :param pName
    :param pEnvironment
    :param Level
    :param pDrivers
    :param cbBuf
    :param pcbNeeded
    :param pcReturned

    :return: raises DCERPCSessionError on error.
    rS   rW   rd   rš   r   r>   r²   r†   Nr³   )	r˜   r©   r	   rª   r«   r   r´   rµ   r¶   ©r¬   rS   rW   rd   rª   r»   rº   r   r   r   ÚhRpcAsyncEnumPrinterDrivers:  s*   €ýrÀ   c              
   C   r¾   )aÃ  
    RpcAsyncGetPrinterDriverDirectory retrieves the path of the printer driver directory.
    Full Documentation: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-par/92206fb2-dd31-47f4-8d12-4cd239b71d78

    :param DCERPC_v5 dce: a connected DCE instance.
    :param pName
    :param pEnvironment
    :param Level
    :param pDriverDirectory
    :param cbBuf
    :param pcbNeeded

    :return: raises DCERPCSessionError on error.
    rS   rW   rd   rŸ   r   r>   r²   r†   Nr³   )	r�   r©   r	   rª   r«   r   r´   rµ   r¶   r¿   r   r   r   Ú"hRpcAsyncGetPrinterDriverDirectoryc  s*   €ýrÁ   N)žÚimpacketr   Úimpacket.dcerpc.v5.dtypesr   r   r   r   r   r   r	   Úimpacket.dcerpc.v5.ndrr
   r   r   r   r   Úimpacket.dcerpc.v5.rpcrtr   Úimpacket.uuidr   r   ÚMSRPC_UUID_PARr«   r   r&   r$   ÚJOB_ACCESS_ADMINISTERÚJOB_ACCESS_READÚJOB_EXECUTEÚJOB_READÚ	JOB_WRITEÚJOB_ALL_ACCESSÚPRINTER_ACCESS_ADMINISTERÚPRINTER_ACCESS_USEÚPRINTER_ACCESS_MANAGE_LIMITEDÚPRINTER_ALL_ACCESSÚPRINTER_EXECUTEÚPRINTER_READÚPRINTER_WRITEÚSERVER_ACCESS_ADMINISTERÚSERVER_ACCESS_ENUMERATEÚSERVER_ALL_ACCESSÚSERVER_EXECUTEÚSERVER_READÚSERVER_WRITEÚSPECIFIC_RIGHTS_ALLÚSTANDARD_RIGHTS_ALLÚSTANDARD_RIGHTS_EXECUTEÚSTANDARD_RIGHTS_READÚSTANDARD_RIGHTS_REQUIREDÚSTANDARD_RIGHTS_WRITEÚSYNCHRONIZEÚDELETEÚREAD_CONTROLÚ	WRITE_DACÚWRITE_OWNERÚGENERIC_READÚGENERIC_WRITEÚGENERIC_EXECUTEÚGENERIC_ALLÚPRINTER_CHANGE_SET_PRINTERÚPRINTER_CHANGE_DELETE_PRINTERÚPRINTER_CHANGE_PRINTERÚPRINTER_CHANGE_ADD_JOBÚPRINTER_CHANGE_SET_JOBÚPRINTER_CHANGE_DELETE_JOBÚPRINTER_CHANGE_WRITE_JOBÚPRINTER_CHANGE_JOBÚ!PRINTER_CHANGE_SET_PRINTER_DRIVERÚPRINTER_CHANGE_TIMEOUTÚPRINTER_CHANGE_ALLÚPRINTER_CHANGE_ALL_2Ú!PRINTER_CHANGE_ADD_PRINTER_DRIVERÚ$PRINTER_CHANGE_DELETE_PRINTER_DRIVERÚPRINTER_CHANGE_PRINTER_DRIVERÚPRINTER_CHANGE_ADD_FORMÚPRINTER_CHANGE_DELETE_FORMÚPRINTER_CHANGE_SET_FORMÚPRINTER_CHANGE_FORMÚPRINTER_CHANGE_ADD_PORTÚPRINTER_CHANGE_CONFIGURE_PORTÚPRINTER_CHANGE_DELETE_PORTÚPRINTER_CHANGE_PORTÚ"PRINTER_CHANGE_ADD_PRINT_PROCESSORÚ%PRINTER_CHANGE_DELETE_PRINT_PROCESSORÚPRINTER_CHANGE_PRINT_PROCESSORÚPRINTER_CHANGE_ADD_PRINTERÚ(PRINTER_CHANGE_FAILED_CONNECTION_PRINTERÚPRINTER_CHANGE_SERVERÚPRINTER_ENUM_LOCALÚPRINTER_ENUM_CONNECTIONSÚPRINTER_ENUM_NAMEÚPRINTER_ENUM_REMOTEÚPRINTER_ENUM_SHAREDÚPRINTER_ENUM_NETWORKÚPRINTER_ENUM_EXPANDÚPRINTER_ENUM_CONTAINERÚPRINTER_ENUM_ICON1ÚPRINTER_ENUM_ICON2ÚPRINTER_ENUM_ICON3ÚPRINTER_ENUM_ICON8ÚPRINTER_ENUM_HIDEÚPRINTER_NOTIFY_CATEGORY_2DÚPRINTER_NOTIFY_CATEGORY_ALLÚPRINTER_NOTIFY_CATEGORY_3DÚAPD_STRICT_UPGRADEÚAPD_STRICT_DOWNGRADEÚAPD_COPY_ALL_FILESÚAPD_COPY_NEW_FILESÚAPD_COPY_FROM_DIRECTORYÚAPD_DONT_COPY_FILES_TO_CLUSTERÚAPD_COPY_TO_ALL_SPOOLERSÚAPD_INSTALL_WARNED_DRIVERÚAPD_RETURN_BLOCKING_STATUS_CODEr1   r6   r;   r=   rA   rI   rJ   rL   rM   rQ   rR   rT   rU   r\   r]   rc   rf   rk   rm   rn   ro   rv   rw   r|   r}   r…   rŠ   r�   r“   r–   r˜   rœ   r�   r    r¡   r¥   ÚOPNUMSr©   r­   r±   r¼   r½   rÀ   rÁ   r   r   r   r   Ú<module>   s,  $		



	

	
	ù	
ÿ$$)