HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/pkg/__pycache__/win.cpython-310.pyc
o

�N�g"��@stdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZdZ
zddlZddlZddlZddlZddlZddlZWneyXedkrWed���wedkrze��Ze�e�d��e�e�Ze�e�e�ej�ne�e�Zzddlm Z Wney�ddlm Z Ynwdd	l!m"Z"Gd
d�d�Z#Gdd
�d
�Z$dd�Z%edkr�e%�dSdS)aK
Collect information about software installed on Windows OS
================

:maintainer: Salt Stack <https://github.com/saltstack>
:codeauthor: Damon Atkins <https://github.com/damon-atkins>
:maturity: new
:depends: pywin32
:platform: windows

Known Issue: install_date may not match Control Panel\Programs\Programs and Features
�N)�
cmp_to_keyz0.1�__main__z Please install pywin32/pypiwin32z[%(levelname)s]: %(message)s)�OrderedDict��Versionc@sLeZdZdZe�d�Ze�d�Ze�d�ZiZ	iZ
ejej
fejejejejfejd�Ze��ddkrEe��r?dejd�Zndd	d�Znejdd�Zd+dd�Zd
d�Zedd��Zedd��Ze dd��Z!d,dd�Z"dd�Z#d,dd�Z$e dd��Z%e dd��Z&e dd ��Z'e d!d"��Z(e d#d$��Z)e d%d&��Z*e d'd(��Z+e d)d*��Z,d	S)-�RegSoftwareInfoz�
    Retrieve Registry data on a single installed software item or component.

    Attribute:
        None

    :codeauthor: Damon Atkins <https://github.com/damon-atkins>
    zO^\{(\w{8})-(\w{4})-(\w{4})-(\w\w)(\w\w)-(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)\}$zG^(\w{8})(\w{4})(\w{4})(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)$z$\d+\.\d+\.\d+[\w.-]*|\d+\.\d+[\w.-]*)�str�list�int�bytesr�32bit�TFNFc
CsJ||_d|_d|_d|_d|_|j�|�}|dur0tdd�D]}|j|�|�ddd�7_q|r\d|_	d|_
d|_d	�||�|_
|jr[d
�||j�|_|�d�|_d�||j�|_n&d
|_	||_
|j||_d�|�|_
|jr�d|j��|_d|_d�|j�|_zt�tt|j	�|j
dtj|jB�|_Wntjy�}z|jtjkr�t�d|||��d}~wwd|_|jr�zt�tt|j	�|jdtj|jB�|_Wn&tjy�}z|jtjkr�t�d|||�d|_n�WYd}~nd}~wwd|_t�|j��dd�}|�r!t |d��rt!�"|�#��|_dSt |d��r#t$|�|_dSdSdS)a(
        Initialise against a software item or component.

        All software has a unique "Identifer" within the registry. This can be free
        form text/numbers e.g. "MySoftware" or
        GUID e.g. "{0EAF0D8F-C9CF-4350-BD9A-07EC66929E04}"

        Args:
            key_guid (str): Identifer.
            sid (str): Security IDentifier of the User or None for Computer/Machine.
            use_32bit (bool):
                Regisrty location of the Identifer. ``True`` 32 bit registry only
                meaning fully on 64 bit OS.
        �N������
HKEY_USERSFrz9{}\Software\Microsoft\Windows\CurrentVersion\Uninstall\{}z){}\Software\Classes\Installer\Products\{}z*\Software\Microsoft\Installer\UpgradeCodeszSSoftware\Microsoft\Windows\CurrentVersion\Installer\UserData\{}\Products\{}\Patches�HKEY_LOCAL_MACHINEz6Software\Microsoft\Windows\CurrentVersion\Uninstall\{}z$Software\Classes\Installer\Products\z'Software\Classes\Installer\UpgradeCodeszYSoftware\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\{}\PatcheszISoftware/Component Not Found  key_guid: '%s', sid: '%s' , use_32bit: '%s'zgSoftware/Component Not Found in Products section of registry key_guid: '%s', sid: '%s', use_32bit: '%s'Z
LastWriteTime�utctimetuple�__int__)%�_RegSoftwareInfo__reg_key_guid�_RegSoftwareInfo__squidZ#_RegSoftwareInfo__reg_products_path�&_RegSoftwareInfo__reg_upgradecode_path�_RegSoftwareInfo__patch_list�_RegSoftwareInfo__guid_pattern�match�range�group�_RegSoftwareInfo__reg_hive�_RegSoftwareInfo__reg_32bit�"_RegSoftwareInfo__reg_32bit_access�format�$_RegSoftwareInfo__reg_uninstall_path�"_RegSoftwareInfo__reg_patches_path�"_RegSoftwareInfo__use_32bit_lookup�win32api�RegOpenKeyEx�getattr�win32con�KEY_READ�&_RegSoftwareInfo__reg_uninstall_handle�
pywintypes�error�winerror�ERROR_FILE_NOT_FOUND�log�%_RegSoftwareInfo__reg_products_handle�debug�_RegSoftwareInfo__mod_time1970ZRegQueryInfoKeyW�get�hasattr�time�mktimerr
)�selfZkey_guid�sid�	use_32bitZ
guid_match�index�excZmod_win_time�r<�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/pkg/win.py�__init__fs� �����
����
���


����


�����
��zRegSoftwareInfo.__init__cCs�|sdS|j�|�}d}|durdd|�d�ddd�d|�d�ddd�d|�d�ddd�d|�d	�ddd�|�d
�ddd�d}tdd�D]}||�|�ddd�7}qQ|d
7}|S)a
        Squished GUID (SQUID) to GUID.

        A SQUID is a Squished/Compressed version of a GUID to use up less space
        in the registry.

        Args:
            squid (str): Squished GUID.

        Returns:
            str: the GUID if a valid SQUID provided.
        rN�{rr�-�����r�})�_RegSoftwareInfo__squid_patternrrr)r7�squidZsquid_match�guidr:r<r<r=Z__squid_to_guid�s:
��������	��zRegSoftwareInfo.__squid_to_guidcCsPt|t�r|dkrdSt|t�r&tjd|tjtjd�dur&t|�dkr&dSdS)z�
        Test for ``1`` as a number or a string and return ``True`` if it is.

        Args:
            value: string or number or None.

        Returns:
            bool: ``True`` if 1 otherwise ``False``.
        rT�\d+��flagsN�1F)�
isinstancer
r�rer�
IGNORECASE�UNICODE)�valuer<r<r=Z__one_equals_true
s�z!RegSoftwareInfo.__one_equals_truecCs2t�||�\}}|tjkrt�|�tj}||fS)ak
        Calls RegQueryValueEx

        If PY2 ensure unicode string and expand REG_EXPAND_SZ before returning
        Remember to catch not found exceptions when calling.

        Args:
            handle (object): open registry handle.
            value_name (str): Name of the value you wished returned

        Returns:
            tuple: type, value
        )r%�RegQueryValueExr(�
REG_EXPAND_SZZExpandEnvironmentStrings�REG_SZ)�handle�
value_name�
item_value�	item_typer<r<r=Z__reg_query_values�

z!RegSoftwareInfo.__reg_query_valuec
Cs�|j}zt�|jd�\}}Wntjy*}z|jtjkr%|WYd}~S�d}~ww|tj	krLzt
j
�|d�}t�
|���}W|StyKY|Sw|S)a�
        Return the install time, or provide an estimate of install time.

        Installers or even self upgrading software must/should update the date
        held within InstallDate field when they change versions. Some installers
        do not set ``InstallDate`` at all so we use the last modified time on the
        registry key.

        Returns:
            int: Seconds since 1970 UTC.
        ZInstallDateNz%Y%m%d)r2r%rSr*r+r,r-r.r(rU�datetime�strptimer5r6�	timetuple�
ValueError)r7Ztime1970Zdate_stringrYr;Zdate_objectr<r<r=�install_time8s*
���
��zRegSoftwareInfo.install_timec
Cshz|�|j|�\}}Wntjy&}z|jtjkr!WYd}~dS�d}~ww|r2||j|vr2d}|S)a�
        For the uninstall section of the registry return the name value.

        Args:
            value_name (str): Registry value name.
            wanted_type (str):
                The type of value wanted if the type does not match
                None is return. wanted_type support values are
                ``str`` ``int`` ``list`` ``bytes``.

        Returns:
            value: Value requested or None if not found.
        N)�!_RegSoftwareInfo__reg_query_valuer*r+r,r-r.�_RegSoftwareInfo__reg_types)r7rW�wanted_typerXrYr;r<r<r=�get_install_valueZs���z!RegSoftwareInfo.get_install_valuecCs|�|�|��S)z�
        For the uninstall section check if name value is ``1``.

        Args:
            value_name (str): Registry value name.

        Returns:
            bool: ``True`` if ``1`` otherwise ``False``.
        )�!_RegSoftwareInfo__one_equals_truerb)r7�keyr<r<r=�is_install_truews
zRegSoftwareInfo.is_install_truec	
Cs�|jsdStj�|�\}}z(|r+t�|j|dtj|jB�}|�	||�\}}t�
|�n	t�|j|�\}}Wntj
yP}z|jtjkrKWYd}~dS�d}~ww|r\||j|vr\d}|S)a�
        For the product section of the registry return the name value.

        Args:
            value_name (str): Registry value name.
            wanted_type (str):
                The type of value wanted if the type does not match
                None is return. wanted_type support values are
                ``str`` ``int`` ``list`` ``bytes``.

        Returns:
            value: Value requested or ``None`` if not found.
        Nr)r0�os�path�splitr%r&r(r)r r_�RegCloseKeyrSr+r,r-r.r`)	r7rWraZsubkeyZsearch_value_namerVrXrYr;r<r<r=�get_product_value�s8
������z!RegSoftwareInfo.get_product_valuec

Cs�|jsdSd�|j|j|j�}|jr|j|jvr�zt�t	t
|j�|jdt
j|jB�}Wn&t
jyQ}z|jtjkrLt�d|j|j|j�WYd}~dS�d}~wwtt�|��\}}}}||jvrs|j|||fkrst�d|�dSt�d|�|D]9}|�|�}t�||dt
j|jB�}	t�|	�\}}
}t|
�D]}|�t�|	|�d�}|r�||j|<q�t�|	�q{t�|�||f|j|<|j�|jd�S)z�
        For installers which follow the Microsoft Installer standard, returns
        the ``Upgrade code``.

        Returns:
            value (str): ``Upgrade code`` GUID for installed software.
        rz{}\{}\{}r�Not Found %s\%s 32bit %sNz/Scan skipped for upgrade codes, no changes (%s)z-Scan for upgrade codes (%s) for product codes)rr!rrr�_RegSoftwareInfo__upgrade_codesrr%r&r'r(r)r r+r,r-r.r/�warning�zip�RegEnumKeyEx�(_RegSoftwareInfo__upgrade_code_have_scanr1�_RegSoftwareInfo__squid_to_guid�RegQueryInfoKeyrZRegEnumValuerir3)
r7Z
have_scan_keyZ	uc_handler;Zsquid_upgrade_code_all�_Z
suc_pytimeZupgrade_code_squidZupgrade_code_guidZ	pc_handleZpc_val_countZ
item_indexZproduct_code_guidr<r<r=�upgrade_code�s~	�

�����
���

�
��
�

�zRegSoftwareInfo.upgrade_codec
Cs�|jsgS|jdur�zt�tt|j�|jdtj|j	B�}Wn't
jyD}z|jtj
kr?t�d|j|j|j�gWYd}~S�d}~wwt�|�\}}}|sQgStt�|��\}}}}g}|D]_}z=t�||dtj|j	B�}|�|d�\}	}
|�|d�\}}|tjks�t|t�r�|dks�|
tjkr�Wq`t�|�|�|	�Wq`t
jy�}z|jtj
kr�t�d|�WYd}~q`�d}~ww|S)z�
        For installers which follow the Microsoft Installer standard, returns
        a list of patches applied.

        Returns:
            value (list): Long name of the patch.
        Nrrk�DisplayName�Staterzskipped patch, not found %s)rrr%r&r'r(rr#r)r r+r,r-r.r/rmrrrrnror_�	REG_DWORDrNr
rUri�appendr1)
r7Zpat_all_handler;Zpc_sub_key_cntrsZsquid_patch_all�retZpatch_squidZpatch_squid_handleZpatch_display_nameZpatch_display_name_typeZpatch_stateZpatch_state_typer<r<r=�list_patchess�	


����
��
��
��
�����zRegSoftwareInfo.list_patchescCs|j�d|j��S)z�
        Returns the uninstall path this object is associated with.

        Returns:
            str: <hive>\<uninstall registry entry>
        �\�rr"�r7r<r<r=�registry_path_textWsz"RegSoftwareInfo.registry_path_textcCs|j|jfS)z�
        Returns the uninstall path this object is associated with.

        Returns:
            tuple: hive, uninstall registry entry path.
        r|r}r<r<r=�
registry_pathaszRegSoftwareInfo.registry_pathcC�|jS)zT
        Return GUID or Key.

        Returns:
            str: GUID or Key
        )rr}r<r<r=rIk�zRegSoftwareInfo.guidcCr�)zc
        Return SQUID of the GUID if a valid GUID.

        Returns:
            str: GUID
        )rr}r<r<r=rHur�zRegSoftwareInfo.squidcCs|�|�d��S)z^
        Return package code of the software.

        Returns:
            str: GUID
        ZPackageCode)rqrjr}r<r<r=�package_codeszRegSoftwareInfo.package_codec
Cs�z|�|jd�\}}Wn tjy+}z|jtjkr!WYd}~dSWYd}~nd}~wwd}d}|rp|tjkrWt|t	�r>|}|rSd�
|d?d@|d?d@|d	@�}d
}||fS|tjkrpt|t�rp|j
�|�durp|�d�}d}||fS)
z�
        Return version number which is stored in binary format.

        Returns:
            str: <major 0-255>.<minior 0-255>.<build 0-65535> or None if not found
        �versionN)rrrz{}.{}.{}���i��zbinary-version� zbinary-version (string))r_r*r+r,r-r.r(rwrNr
r!rUr�!_RegSoftwareInfo__version_patternr�strip)r7rXrYr;Zversion_binary_text�version_srcZversion_binary_rawr<r<r=�version_binary�s>����



�
��
zRegSoftwareInfo.version_binary)NF�N)-�__name__�
__module__�__qualname__�__doc__rO�compilerrGr�rlrpr(rTrUZREG_MULTI_SZrwZREG_DWORD_BIG_ENDIANZ	REG_QWORDZ
REG_BINARYr`�platform�architecture�win32process�IsWow64Process�KEY_WOW64_64KEYr$�KEY_WOW64_32KEYr>rq�staticmethodrcr_�propertyr^rbrerjrtrzr~rrIrHr�r�r<r<r<r=r>sb
��

�
#



!
,
U
Q
	
	
	
	
	rc
@s|eZdZdZe�d�Zejdejd�Zddgd�fdd	d
dgfddd
gfdddgfdddgfdddgfdddgfdddgfdddgfdddgfdddgfgZ	dd	dgfd d	d!gfd"d	d#gfd$dd%gfgZ
dNd(d)�Zed*d+��Z
ed,d-��Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�ZdOd8d9�Zed:d;��Zed<d=��Zd>d?�Zd@dA�ZdBdC�ZedDdE��ZdFdG�ZdHdI�ZdJdK�ZdLdM�Zd'S)P�WinSoftwarez�
    Point in time snapshot of the software and components installed on
    a system.

    Attributes:
        None

    :codeauthor: Damon Atkins <https://github.com/damon-atkins>
    z+^S-\d-\d-\d+$|^S-\d-\d-\d+-\d+-\d+-\d+-\d+$z^\s*$rK�urlr)ZURLInfoAboutZHelpLinkZMoreInfoUrlZ
UrlUpdateInfo�sizer
ZSizeZ
EstimatedSizeZwin_commentsZCommentsZwin_release_type�ReleaseTypeZwin_product_idZ	ProductIDZwin_product_codesZProductCodesZwin_package_refsZPackageRefsZwin_install_locationZInstallLocationZwin_install_src_dirZ
InstallSourceZwin_parent_pkg_uidZ
ParentKeyNameZwin_parent_nameZParentDisplayNameZwin_advertise_flagsZAdvertiseFlagsZwin_redeployment_flagsZDeploymentFlagsZwin_instance_typeZInstanceTypeZwin_package_namezSourceList\PackageNameFNcCs4||_||_i|_|j|d�t|j�|_d|_dS)a

        Point in time snapshot of the software and components installed on
        a system.

        Args:
            version_only (bool): Provide list of versions installed instead of detail.
            user_pkgs (bool): Include software/components installed with user space.
            pkg_obj (object):
                If None (default) return default package naming standard and use
                default version capture methods (``DisplayVersion`` then
                ``Version``, otherwise ``0.0.0.0``)
        )�	user_pkgsN)�_WinSoftware__pkg_obj�_WinSoftware__version_only�_WinSoftware__reg_software�"_WinSoftware__get_software_details�len�_WinSoftware__pkg_cnt�_WinSoftware__iter_list)r7�version_onlyr�Zpkg_objr<r<r=r>�s

zWinSoftware.__init__cCr�)z�
        Returns the raw data

        Returns:
            dict: contents of the dict are dependent on the parameters passed
                when the class was initiated.
        )r�r}r<r<r=�data�s	zWinSoftware.datacCr�)z�
        Returns True if class initiated with ``version_only=True``

        Returns:
            bool: The value of ``version_only``
        )r�r}r<r<r=r��r�zWinSoftware.version_onlycCr�)z�
        Returns total number of software/components installed.

        Returns:
            int: total number of software/components installed.
        )r�r}r<r<r=�__len__szWinSoftware.__len__cCs||jvr
|j|St|��)z�
        Returns information on a package.

        Args:
            pkg_id (str): Package Id of the software/component

        Returns:
            dict or list: List if ``version_only`` is ``True`` otherwise dict
        )r��KeyError�r7�pkg_idr<r<r=�__getitem__s


zWinSoftware.__getitem__cCs,|jdur	td��t�t|j����|_|S)zT
        Standard interation class initialisation over package information.
        Nz#Can only perform one iter at a time)r��RuntimeError�collections�deque�sortedr��keysr}r<r<r=�__iter__ s
zWinSoftware.__iter__cCs&z|j��WStyd|_t�w)�X
        Returns next Package Id.

        Returns:
            str: Package Id
        N)r��popleft�
IndexError�
StopIterationr}r<r<r=�__next__)s�zWinSoftware.__next__cCst|�S)r�)�nextr}r<r<r=r�6szWinSoftware.nextcCs|j�||�S)a/
        Returns information on a package.

        Args:
            pkg_id (str): Package Id of the software/component.
            default_value: Value to return when the Package Id is not found.

        Returns:
            dict or list: List if ``version_only`` is ``True`` otherwise dict
        )r�r3)r7r��
default_valuer<r<r=r3?�zWinSoftware.getcCst|�t|�kr
dSdS)zC
        Used for sorting version numbers oldest to latest
        rrr�Zver1Zver2r<r<r=Z__oldest_to_latest_versionL�z&WinSoftware.__oldest_to_latest_versioncCst|�t|�kr
dSdS)zD
        Used for sorting version numbers, latest to oldest
        rrrr�r<r<r=Z__latest_to_oldest_versionSr�z&WinSoftware.__latest_to_oldest_versioncCsH|j�|d�}|sgSt|t�r|St|�d����}t|t|j�d�S)z�
        Returns information on a package.

        Args:
            pkg_id (str): Package Id of the software/component.

        Returns:
            list: List of version numbers installed.
        Nr�)rd)r�r3rNr	r�r�r�&_WinSoftware__oldest_to_latest_version)r7r�Zpkg_dataZinstalled_versionsr<r<r=�pkg_version_listZs


�zWinSoftware.pkg_version_listcC�|�|�dS)a
        Returns a package latest version installed out of all the versions
        currently installed.

        Args:
            pkg_id (str): Package Id of the software/component.

        Returns:
            str: Latest/Newest version number installed.
        r�r�r�r<r<r=�pkg_version_latestrr�zWinSoftware.pkg_version_latestcCr�)a
        Returns a package oldest version installed out of all the versions
        currently installed.

        Args:
            pkg_id (str): Package Id of the software/component.

        Returns:
            str: Oldest version number installed.
        rr�r�r<r<r=�pkg_version_oldestr�zWinSoftware.pkg_version_oldestc
Cs4|dus|dkr
dSzt�|�}Wntjy)}ztd�||j|j���d}~wwzt�d|�\}}}|�d|��}Wn&tjyb}z|jtj	krS|WYd}~Std�||j|j���d}~wwzt�
|tjtj
�}W|Stjy�}z|jtjtjtj	fvr�|���d|����WYd}~S�d}~ww)a
        Provided with a valid Windows Security Identifier (SID) and returns a Username

        Args:
            sid (str): Security Identifier (SID).

        Returns:
            str: Username in the format of username@realm or username@computer.
        Nrz/pkg: Software owned by {} is not valid: [{}] {}r{z,Failed looking up sid '{}' username: [{}] {}�@)�
win32securityZGetBinarySidr+r,r]r!r-�strerrorZLookupAccountSidZERROR_NONE_MAPPEDZ
TranslateNamer%ZNameSamCompatibleZNameUserPrincipalZERROR_NO_SUCH_DOMAINZERROR_INVALID_DOMAINNAME�lower)r8Zsid_binr;�name�domainZ
_account_typeZ	user_nameZuser_principalr<r<r=Z__sid_to_username�sX
����
�
�������"��zWinSoftware.__sid_to_usernamec
Cs�|r|�dd���}nd}|r|�dd���}nd}|rd}nd}|r'|d7}|d|d|}|jrGt|jd�rG|j�||||�}	|	rG|	S|S)	a
        Determine the Package ID of a software/component using the
        software/component ``publisher``, ``name``, whether its a software or a
        component, and if its 32bit or 64bit archiecture.

        Args:
            publisher (str): Publisher of the software/component.
            name (str): Name of the software.
            is_component (bool): True if package is a component.
            is_32bit (bool): True if the software/component is 32bit architecture.

        Returns:
            str: Package Id
        �,rZNoValue�compZsoftZ32z\\�	to_pkg_id)�replacer�r�r4r�)
r7�	publisherr�Zis_componentZis_32bitZpub_lcZname_lcZ	soft_typeZdefault_pkg_idr�r<r<r=Z__software_to_pkg_id�s"z WinSoftware.__software_to_pkg_idcCs�|jr4t|jd�r4|j�||||�\}}}|dkr"|r"|r"|||fS|dkr4td�t|j�||||���|rItjd|tjtj	d�durI|}d}n|r^tjd|tjtj	d�dur^|}d}nd	}d
}|||fS)a,
        This returns the version and where the version string came from, based on instructions
        under ``version_capture``, if ``version_capture`` is missing, it defaults to
        value of display-version.

        Args:
            pkg_id (str): Publisher of the software/component.
            version_binary (str): Name of the software.
            version_display (str): True if package is a component.
            display_name (str): True if the software/component is 32bit architecture.

        Returns:
            str: Package Id
        �version_capturezuse-defaultzUversion capture within object '{}' failed for pkg id: '{}' it returned '{}' '{}' '{}'rJrKNzdisplay-versionzversion-binaryZnonez	0.0.0.0.0)
r�r4r�r]r!rrOrrPrQ)r7r�r��version_display�display_nameZversion_str�srcZversion_user_strr<r<r=Z__version_capture_slp�sD
�
������
z!WinSoftware.__version_capture_slpc'Csbt|||�}|jddd�}|dus|j�|�rdS|jddd�}|jddd�}tjd|tjtjd�dusB|r<|�d	�sB|rJ|d
vrJt�	d|�dS|�
d�}|�d
�}	|�d�}
|�d�}|�
d�}|�
d�}
|jddd�}|	dur|
dur|dur|sdS|r�|�|�}nd}|�|||
|�}|j
\}}|jddd�}|�||||�\}}}|s�|}|r�d�||�}n|}|jr�||jvr�||j|vr�d}|j|D]}t|�t|�kr�n|d7}q�|j|�||�dSt�	d|||�dS|g|j|<dS||jv�r|j|}nt�}|j|<|�r|�ddi�n|�rdnd}d|v�r2|d|k�r1d|d<n|�d|i�|�rUd|v�rQ|d��|��k�rPd|d<n||d<d|v�rf|d|
k�red|d<n|
|d<|�d|i�|�d i�||d v�r�d!|d |v�r�|d |d!d7<nd"|d |d!<nt�|d |<|d |}|�d#|i�|	�r�|�d$|	i�|
�r�|�d%|
i�|�r�|�d&|i�|�d'|i�|�r�|�d(|i�|�r�|�d)|i�|�r�|�d*|i�|�s|	�rtjd+|	tjtjd��r|�d,d-i�nit�d.|tj�du�s;|	�rCtjd/|	tjtjd�du�s;tjd0|	tjtjd�du�rC|�d,d1i�n5|�d2��rY|jd3dd��rY|�d,d4i�n|	�rqtjd5|	tjtjd��rq|�d,d6i�n|�d,di�|�d7�}t|t��r�|tjv�r�|�d8tj|i�|j}|�r�|�d9|i�|j}|�r�|�d:|i�|�
d;�}|�r�|�d<|i�|j } | �r�|�d=t!j!�"| ��#�i�|�d>t| �i�|j$D]\}!}"}#|#D]}$|j|$|"d�}%|%�r�|�|!|%i�n�q�q�|j%D]!\}!}"}#|#D]}$|j&|$|"d�}|du�r|�|!|i�n�q�q�|j'}&|&�r/|�d?|&i�dSdS)@z:
        Update data with the next software found
        rur)raNrr�z^{.*\}\.KB\d{6,}$rK)ZKBZkbZKb)ZHotfixz
Update RollupzSecurity UpdateZServicePackz&skipping hotfix/update/service pack %sZNoRemoveZUninstallStringZQuietUninstallStringZ
ModifyPathZWindowsInstallerZSystemComponentZ	PublisherZDisplayVersionz{};{}rrzHFound extra entries for '%s' with same version '%s', skipping entry '%s'�arch�unknown�x86Zx64�many�vendorZwin_system_componentZwin_version_srcr�Zwin_install_countrAZwin_display_nameZwin_uninstall_cmdZwin_uninstall_quiet_cmdZwin_uninstall_no_removeZwin_product_codeZwin_version_displayZwin_version_binaryZwin_version_userzMsiExec.exe\s|MsiExec\sZwin_installer_typeZwinmsiZInstallShield_Z
InstallShieldzisuninst\.exe.*\.isuZ
installshieldZ_is1zInno Setup: Setup VersionZinnoz .*\\uninstall.exe|.*\\uninst.exeZnsisZLanguageZwin_languageZwin_package_codeZwin_upgrade_codeZIsMinorUpgradeZwin_is_minor_upgradeZinstall_dateZinstall_date_time_tZwin_patches)(rrb� _WinSoftware__whitespace_patternrrOrPrQ�
startswithr/r1re�_WinSoftware__sid_to_username� _WinSoftware__software_to_pkg_idr��!_WinSoftware__version_capture_slpr!r�r�r�insertr�updater��
setdefault�search�endswithrNr
�locale�windows_localer�rtr^rZ�
fromtimestamp�	isoformat�#_WinSoftware__uninstall_search_list�"_WinSoftware__products_search_listrjrz)'r7r8Zkey_softwarer9Z
reg_soft_infor�r�Zrelease_typeZuninstall_no_removeZuninstall_stringZuninstall_quiet_stringZuninstall_modify_pathZwindows_installerZsystem_componentr��usernamer�r�r�r�Zversion_textZuser_versionZdict_keyZinsert_pointZver_itemr�Zarch_strZversion_dataZlanguage_numberr�rtZis_minor_upgrader^ZinfokeyZinfotypeZ
regfield_listZregfieldZstrvalueZ
patch_listr<r<r=Z__collect_software_info6s�������





��
�
��

��
�
�
�
��
�����
���

�
��
������
���z#WinSoftware.__collect_software_infocCst��ddkr t��rdtjd�}ddg}nddd�}dg}n
tjdd�}ddg}|D]4}d}t�d|�t	�
tj|dtj||B�}t
t	�|��\}}}}t	�|�|D]	}	|�d|	|�qVq,|sedSt�d	�t	�
tjd
dtj�}
g}tt	�|
�d�D]}|�t	�|
|��q|D]k}
|j�|
�dur�d�|
�}zt	�
|
|dtj�}Wn tjy�}z|jtjkr�t�d|�WYd}~q��d}~wwz
t
t	�|��\}}}}Wnty�t�d
|�g}Ynwt	�|�|D]	}	|�|
|	d�q�q�t	�|
�dS)a5
        This searches the uninstall keys in the registry to find
        a match in the sub keys, it will return a dict with the
        display name as the key and the version as the value
        .. sectionauthor:: Damon Atkins <https://github.com/damon-atkins>
        .. versionadded:: 2016.11.0
        rrr
TFNz3Software\Microsoft\Windows\CurrentVersion\UninstallzSYSTEM processing 32bit:%sz'Processing user software... please waitrz6{}\Software\Microsoft\Windows\CurrentVersion\UninstallzNot Found %szNo Entries Found %s)r�r�r�r�r(r�r�r/r1r%r&rr)rnrori�#_WinSoftware__collect_software_inforrrrrxZ
RegEnumKey�_WinSoftware__sid_patternrr!r+r,r-r.r])r7r�Zuse_32bit_lookupZ	arch_listZ	arch_flagZ
key_searchrVZreg_key_allrsZreg_keyZ
handle_sidZsid_allr:r8Zuser_uninstall_pathr;r<r<r=Z__get_software_detailsAs�

��
�
��
��
�����
�
z"WinSoftware.__get_software_details)FFNr�) r�r�r�r�rOr�r�rQr�r�r�r>r�r�r�r�r�r�r�r�r3r�r�Z&_WinSoftware__latest_to_oldest_versionr�r�r�r�r�r�r�r�r<r<r<r=r��s^










�



�



			
	



=0<
r�cs�ttj�dkrtj�dtjd�d��t�d�d�d�ttjd�dkr(d	�ttjd
�dkr3d	�ddl}ddl����fd
d�}t	d|j|dd����dS)z�This module can also be run directly for testing
    Args:
        detail|list : Provide ``detail`` or version ``list``.
        system|system+user: System installed and System and User installs.
    rBzusage: rz$ <detail|list> <system|system+user>
�@Frr	TrAzsystem+userNcs<t��d�}t�jjj|jddd��tdt|����dS)zA
        Main run code, when this module is run directly
        )r�r�TrC)�	sort_keys�indentzTotal: N)r��print�utils�json�dumpsr�r�)Zpkg_list��saltr�r�r<r=�run�s
�z__main.<locals>.runzTime Taken: )�number)
r��sys�argv�stderr�write�exitr�timeitZsalt.utils.jsonr�)r�r�r<r�r=�__main�s

�r�)&r�r�rZr��loggingZos.pathrfr�rOr�r5�	functoolsr�__version__r+r%r(r�r�r-�ImportErrorr��
StreamHandlerZLOG_CONSOLE�setFormatter�	Formatter�	getLoggerr/�
addHandler�setLevel�DEBUGZsalt.utils.odictrZsalt.utils.versionsrrr�r�r<r<r<r=�<module>sj
�


�g"
�