zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
U
X±d1ã@szdZddlZddlZddlmZddlmZe e    ¡Z
dd„Z dd„Z dd    „Z d
d „Zd d „Zdd„Zdd„Zdd„ZdS)z!
Utilities for Windows platform.
éN©ÚcompatcCs&ddlm}|j ¡}|s"tdƒ‚|S)z9
    Return the Windows directory, e.g., C:\Windows.
    rrz*Error: Cannot determine Windows directory!)Ú PyInstallerrÚwin32apiZGetWindowsDirectoryÚ
SystemExit)rÚwindir©rúWd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\PyInstaller/utils/win32/winutils.pyÚget_windows_dirs
 
r
cCs(ddlm}g}|j ¡}|tƒg}|S)z3
    Return the required Windows system paths.
    rr)rrrZGetSystemDirectoryr
)rZ_bpathÚsys_dirrrr    Úget_system_path$s
 
 
r cCs>ddlm}| dd¡}| |¡tj |¡}| d|¡dS)z
    Add new paths at the beginning of environment variable PATH.
 
    Some hooks might extend PATH where PyInstaller should look for dlls.
    rrÚPATHÚN)rrÚgetenvÚappendÚosÚpathsepÚjoinZsetenv)ÚpathsrÚold_pathÚnew_pathrrr    Úextend_system_path4s
 
 rc Csþd}zt|iidgd}WnÞtk
rø}zÀt|ƒ d¡rÞttdƒ}ttddƒ}dt_tj    rdtj
}nt  ¡}|D]\}t j
  |d¡}t j
 |¡rptj
 |¡zt|iidgd}WqÎWqptk
rÊYqpXqp|rÚ|t_nt`|dkrè‚W5d}~XYnX|S)    aé
    Import and return the PyWin32 module with the passed name.
 
    When imported, the `pywintypes` and `pythoncom` modules both internally import dynamic libraries
    (e.g., `pywintypes.py` imports `pywintypes34.dll` under Python 3.4). The Anaconda Python distribution for Windows
    installs these libraries to non-standard directories, resulting in
    `"ImportError: No system module 'pywintypes' (pywintypes34.dll)"`
    exceptions. This function catches these exceptions, searches for these libraries, adds their directories to
    `sys.path`, and retries.
 
    Parameters
    ----------
    module_name : str
        Fully-qualified name of this module.
 
    Returns
    ----------
    types.ModuleType
        The desired module.
    Nr)ÚglobalsÚlocalsÚfromlistzNo system moduleÚfrozenz
|_|GLYH@CKZpywin32_system32)Únamerrr)Ú
__import__Ú ImportErrorÚstrÚ
startswithÚhasattrÚsysÚgetattrrrZis_venvÚpathÚgetsitepackagesrrÚisdirr)Ú module_nameÚmoduleÚexcZ is_sys_frozenZ
sys_frozenZ    sys_pathsÚsys_pathZpywin32_dll_dirrrr    Úimport_pywin32_moduleBs4
 
r+cCst|tƒrt|ddS|SdS)z}
    Convert dll names from 'bytes' to 'str'.
 
    Latest pefile returns type 'bytes'.
    :param dll_name:
    :return:
    zUTF-8)ÚencodingN)Ú
isinstanceÚbytesr)Zdll_namerrr    Úconvert_dll_name_to_strˆs    
 r/c    CsŒddl}|j|ddL}| ¡t|ƒ}||j_t|dgƒ}|D]}|jjr@||j_q@| ¡}W5QRXt    |dƒ}| |¡W5QRXdS)zg
    Modifies the executable's build timestamp by updating values in the corresponding PE headers.
    rNT©Z    fast_loadZDIRECTORY_ENTRY_DEBUGÚwb)
ÚpefileÚPEZ    full_loadÚintZ FILE_HEADERZ TimeDateStampr#ÚstructÚwriteÚopen)Úexe_pathÚ    timestampr2ÚpeZ debug_entriesZ debug_entryÚdataÚfprrr    Úset_exe_build_timestamp—s 
 r=c
Csddl}z t|ƒ}Wn,tk
r@}ztdƒ|‚W5d}~XYnX|j|dd}||j_| ¡}W5QRXt|dƒ}| |¡W5QRXdS)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.
    rNzFailed to compute PE checksum!Tr0r1)    r2Úcompute_exe_pe_checksumÚ    ExceptionÚ RuntimeErrorr3ZOPTIONAL_HEADERZCheckSumr6r7)r8r2ZchecksumÚer:r;r<rrr    Úupdate_exe_pe_checksum¶s  rBcCs¨ddl}ddlm}m}| d¡j}|jjj}d|_|j|_    |jj
}|jf|_|j |_    |jj }|j |j|j|j|j|j|jf|_|j|_    |jj}|j|j|j|j|j|j f|_|j|_    |jj}    |j|j|j|j|jf|    _|j|    _    |jj}
|jf|
_|j |
_    |jj} |j|jf| _|jj} |j|j|j|jf| _|j| _    || |¡ddddddƒ} | |krt|ƒ}td    |›d
|›ƒ‚| d¡}| | |ƒdkrª|ƒ}|| ƒtd |›ƒ‚|j}|d krÂtd ƒ‚|| dddddƒ}|sö|ƒ}|| ƒtd|›ƒ‚|    |ddddƒ}|dkr4|ƒ}||ƒ|| ƒtd|›ƒ‚| d¡}| d¡}| ||| |¡| |¡ƒ}|dkrr|ƒ}|
|ƒ||ƒ|| ƒ|dkr¢td|›ƒ‚|jS)ar
    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.
    rN)ÚwindllÚwintypeséÿÿÿÿrléé€zFailed 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: )ÚctypesrCrDÚHANDLEÚvalueÚkernel32Ú GetLastErrorÚargtypesÚDWORDÚrestypeÚ CloseHandleÚBOOLÚ CreateFileWÚLPCWSTRÚLPVOIDÚCreateFileMappingWÚ MapViewOfFileÚUnmapViewOfFileÚLPCVOIDÚ GetFileSizeExÚPLARGE_INTEGERZimagehlpÚCheckSumMappedFileÚPDWORDÚ    c_wchar_pr@Ú LARGE_INTEGERÚbyref)r8rJrCrDZINVALID_HANDLErNrRrTrWrXrYr[r]ZhFileÚerrZ
fileLengthZhMappingZ baseAddressZ    headerSumZcheckSumÚretrrr    r>ÓsÖ  
ÿù    úûÿþüù    
 
 
úû
 
 
 
 
r>)Ú__doc__rr"ZPyInstaller.logÚlogÚloggingrrÚ    getLoggerÚ__name__Úloggerr
r rr+r/r=rBr>rrrr    Ú<module> s  
 F