
    i#                     8    S r SSKJr  S rS rS rS rS rS rg	)
z!
Utilities for Windows platform.
    )compatc                  f    [         R                  R                  5       n U (       d  [        S5      eU $ )z1
Return the Windows directory, e.g., C:\Windows.
z*ERROR: Cannot determine Windows directory!)r   win32apiGetWindowsDirectory
SystemExit)windirs    MC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller\utils\win32\winutils.pyget_windows_dirr
      s*     __002FEFFM    c                  V    [         R                  R                  5       n U [        5       /$ )z+
Return the required Windows system paths.
)r   r   GetSystemDirectoryr
   )sys_dirs    r	   get_system_pathr      s&     oo002G
 _&''r   c                     SSK nUR                  U SS9 nUR                  R                  sSSS5        $ ! , (       d  f       g= f)zD
Return the machine type code from the header of the given PE file.
r   NT	fast_load)pefilePEFILE_HEADERMachine)filenamer   pes      r	   get_pe_file_machine_typer   (   s2     	8t	,~~%% 
-	,	,s	   5
Ac                    SSK nUR                  U SS9 nUR                  5         [        U5      nXR                  l        [        US/ 5      nU H0  nUR                  R
                  (       d  M   XR                  l        M2     UR                  5       nSSS5        [        U S5       nUR                  W5        SSS5        g! , (       d  f       N5= f! , (       d  f       g= f)z_
Modifies the executable's build timestamp by updating values in the corresponding PE headers.
r   NTr   DIRECTORY_ENTRY_DEBUGwb)
r   r   	full_loadintr   TimeDateStampgetattrstructwriteopen)exe_path	timestampr   r   debug_entriesdebug_entrydatafps           r	   set_exe_build_timestampr*   2   s     	8t	, 	 	N	'0$  $;R@(K!!///3<""0 )
 xxz% 
-* 
h	
 
	+ 
-	,* 
	s   AC0$C(C
C
C"c                 b   SSK n [        U 5      nUR	                  U SS9 nX$R
                  l        UR                  5       nSSS5        [        U S5       nUR                  W5        SSS5        g! [         a  n[        S5      UeSnAff = f! , (       d  f       NS= f! , (       d  f       g= f)a  
Compute the executable's PE checksum, and write it to PE headers.

This optional checksum is supposed to protect the executable against corruption but some anti-viral software have
taken to flagging anything without it set correctly as malware. See issue #5579.
r   NzFailed to compute PE checksum!Tr   r   )	r   compute_exe_pe_checksum	ExceptionRuntimeErrorr   OPTIONAL_HEADERCheckSumr"   r#   )r$   r   checksumer   r(   r)   s          r	   update_exe_pe_checksumr3   Q   s     
D*84
 
8t	,&.# xxz	 
- 
h	
 
	  D;<!CD 
-	, 
	s.   A1 !BB 1
B;BB
B 
B.c           	      b   SSK nSSK JnJn  UR                  S5      R                  nUR                  R
                  R                  nSUl        UR                  Ul	        UR
                  R                  nUR                  4Ul        UR                  Ul	        UR
                  R                  nUR                  UR                  UR                  UR                  UR                  UR                  UR                  4Ul        UR                  Ul	        UR
                  R                  nUR                  UR                  UR                  UR                  UR                  UR                  4Ul        UR                  Ul	        UR
                  R                   n	UR                  UR                  UR                  UR                  UR                  4U	l        UR                  U	l	        UR
                  R"                  n
UR$                  4U
l        UR                  U
l	        UR
                  R&                  nUR                  UR(                  4Ul        UR*                  R,                  nUR                  UR                  UR.                  UR.                  4Ul        UR                  Ul	        U" UR1                  U 5      SSSSSS5      nX:X  a  U" 5       n[3        S	U  S
U 35      eUR5                  S5      nU" X5      S:X  a  U" 5       nU" U5        [3        SU 35      eUR                  nUS:  a  [3        S5      eU" USSSSS5      nU(       d  U" 5       nU" U5        [3        SU 35      eU	" USSSS5      nUS:X  a%  U" 5       nU" U5        U" U5        [3        SU 35      eUR                  S5      nUR                  S5      nU" UXR7                  U5      UR7                  U5      5      nUc  U" 5       nU
" U5        U" U5        U" U5        Uc  [3        SW 35      eUR                  $ )aV  
This is a replacement for the MapFileAndCheckSumW function. As noted in MSDN documentation, the Microsoft's
implementation of MapFileAndCheckSumW internally calls its ASCII variant (MapFileAndCheckSumA), and therefore
cannot handle paths that contain characters that are not representable in the current code page.
See: https://docs.microsoft.com/en-us/windows/win32/api/imagehlp/nf-imagehlp-mapfileandchecksumw

This function is based on Wine's implementation of MapFileAndCheckSumW, and due to being based entirely on
the pure widechar-API functions, it is not limited by the current code page.
r   N)windllwintypes l              zFailed to open file z! Error code: z,Failed to query file size file! Error code: l    zKExecutable size exceeds maximum allowed executable size on Windows (4 GiB)!   z Failed to map file! Error code:    z'Failed to create map view! Error code: z'CheckSumMappedFile failed! Error code: )ctypesr5   r6   HANDLEvaluekernel32GetLastErrorargtypesDWORDrestypeCloseHandleBOOLCreateFileWLPCWSTRLPVOIDCreateFileMappingWMapViewOfFileUnmapViewOfFileLPCVOIDGetFileSizeExPLARGE_INTEGERimagehlpCheckSumMappedFilePDWORD	c_wchar_pr.   LARGE_INTEGERbyref)r$   r=   r5   r6   INVALID_HANDLErA   rE   rG   rJ   rK   rL   rN   rQ   hFileerr
fileLengthhMappingbaseAddress	headerSumcheckSumrets                        r	   r,   r,   n   s    '__R(..N==))66LL#>>L//--KK #--K//--KK #//K;;# "*OO11MM %OOMoo55O O 'mmOOO11MM
  ;;	# "* "	E n1(>#OPP ''*JU'1,nEI#OPP!!JYhii "		H nE=cUCDD  				K anHEDSEJKK q!I~~a H
[*ll96Mv||\dOe
fC
{n K 
{DSEJKK>>r   N)	__doc__PyInstallerr   r
   r   r   r*   r3   r,   r8   r   r	   <module>ra      s.    	(&>:Sr   