
    !hi                     ~    d Z ddlmZ ddlmZmZ  ej                  e      Z	dZ
dZdZdZdZd	Zdd
ZddZddZd Zy)z2
Read and write resources from/to Win32 PE files.
    N)
pywintypeswin32api      i  i  i  i  c           	      l   |t        |      ndh}|t        |      ndh}|t        |      ndh}i }t        t        t        t        h}t        j                  | dt              }	 t        j                  |      }d|vr|D 	cg c]	  }	|	|v s|	 }}	|D ]  }		 t        j                  ||	      }
d|vr|
D cg c]	  }||v s| }
}|
D ]u  }	 t        j                  ||	|      }d|vr|D cg c]	  }||v s| }}|D ]>  }	 t        j                  ||	||      }|	|vri ||	<   |||	   vri ||	   |<   |||	   |   |<   @ w  t        j                  |       |S # t        j                  $ r}|j                  d   |vr g }Y d}~d}~ww xY wc c}	w # t        j                  $ r}|j                  d   |vr Y d}~*d}~ww xY wc c}w # t        j                  $ r}|j                  d   |vr Y d}~.d}~ww xY wc c}w # t        j                  $ r}|j                  d   |vr Y d}~1d}~ww xY w)a  
    Retrieve resources from the given PE file.

    filename: path to the PE file.
    types: a list of resource types (integers or strings) to search for (None = all).
    names: a list of resource names (integers or strings) to search for (None = all).
    languages: a list of resource languages (integers) to search for (None = all).

    Returns a dictionary of the form {type: {name: {language: data}}}, which might also be empty if no matching
    resources were found.
    N*r   )setERROR_RESOURCE_DATA_NOT_FOUNDERROR_RESOURCE_TYPE_NOT_FOUNDERROR_RESOURCE_NAME_NOT_FOUNDERROR_RESOURCE_LANG_NOT_FOUNDr   LoadLibraryExLOAD_LIBRARY_AS_DATAFILEEnumResourceTypesr   errorargsEnumResourceNamesEnumResourceLanguagesLoadResourceFreeLibrary)filenametypesnames	languagesoutput_IGNORE_EXCEPTIONSmodule_handleavailable_typeseres_typeavailable_namesres_nameavailable_languagesres_langdatas                  OC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/utils/win32/winresource.pyget_resourcesr'      s     +CJ#E+CJ#E"+"7IcUIF 	&%%%	 **8Q8PQM"44]C %4CYxSXGX8YY# %<	&88QO e8G]H8W\K\x]O]' 	<H&.&D&D]T\^f&g# )#@S&mHW_clWlx&m#&m/ <#00(T\]D 6)')F8$6(#3313F8$X.7;x *84<	<%<P 'Me  66!9.. Z  	vvay 22	 ^ ## 66!9$66 'n "'' vvay(::s   %E 	FFF6	G GG+	G>5G>HF,FFG&F>>GG;G66G;H3	H.	.H3	c           	         |dk(  rt        d      |t        |      ndh}|t        |      ndh}t        | |g||      }|j                  |i       }|D ].  }|dk(  r	||vri ||<   |D ]  }|dk(  r	|||   vsd||   |<    0 t	        j
                  | d      }|j                         D ]3  }||   j                         D ]  }t	        j                  |||||        5 t	        j                  |d       y)a  
    Update or add a single resource in the PE file with the given binary data.

    filename: path to the PE file.
    data: binary data to write to the resource.
    res_type: resource type to add/update (integer or string).
    names: a list of resource names (integers or strings) to update (None = all).
    languages: a list of resource languages (integers) to update (None = all).
    r   z"res_type cannot be a wildcard (*)!Nr   )	
ValueErrorr	   r'   getr   BeginUpdateResourcekeysUpdateResourceEndUpdateResource)	r   r%   r    r   r   	resourcesr"   r$   r   s	            r&   add_or_update_resourcer0   q   s4    3=>>+CJ#E"+"7IcUI h
E9EI h+I 
5s?9$"$Ih! 	5H3y2204	(#H-		5
5 001=MNN$ W!(+002 	WH##M8XtXV	WW }a0    c           
      h   |t        |      ndh}|t        |      ndh}|t        |      ndh}t        ||||      }|j                         D ]a  \  }}d|vr||vr|j                         D ]@  \  }}	d|vr||vr|	j                         D ]  \  }
}d|vr|
|vrt        | |||g|
g       ! B c y)a  
    Update or add resources in the given PE file by copying them over from the specified source PE file.

    filename: path to the PE file.
    src_filename: path to the source PE file.
    types: a list of resource types (integers or strings) to add/update via copy for (None = all).
    names: a list of resource names (integers or strings) to add/update via copy (None = all).
    languages: a list of resource languages (integers) to add/update via copy (None = all).
    Nr   )r	   r'   itemsr0   )r   src_filenamer   r   r   r/   r    resources_for_typer"   resources_for_type_namer$   r%   s               r&   copy_resources_from_pe_filer7      s      +CJ#E+CJ#E"+"7IcUI lE5)DI(1(9 	Y$$e 51C1I1I1K 	Y-H-%HE$9"9"?"?"A Y$i'HI,E&xx(hZXY	Y	Yr1   c                 \    t        j                  | d      }t        j                  |d       y)z6
    Remove all resources from the given PE file:
    TFN)r   r+   r.   )r   r   s     r&   remove_all_resourcesr9      s&     004@M}e4r1   )NNN)NN)__doc__PyInstaller.loglogloggingPyInstaller.compatr   r   	getLogger__name__loggerr   ERROR_BAD_EXE_FORMATr
   r   r   r   r'   r0   r7   r9    r1   r&   <module>rD      s`    " 3			8	$   $  $  $  $ Rj'1TY:5r1   