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ZG d[d\ d\eZG d]d^ d^eZG d_d` d`eZG dadb dbeZG dcdd ddeZG dedf dfeZG dgdh dheZG didj djeZG dkdl dleZG dmdn dneZG dodp dpeZG dqdr dreZG dsdt dteZG dudv dveZG dwdx dxeZG dydz dzeZG d{d| d|eZG d}d~ d~eZG dd deZG dd deZG dd deZeefeefeefeefeefeefdZdd Zdd Ze	e	e+e	fddZe	dfddZdd Zdd Zdd ZdS )    )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   iwwiw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,  $		



	

	
		
$$)