Share some tips and experiences here.Keep the author's information and article links for sharing, reprinting or citing your hard work.
Author's environment:
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. Help keeping PyInstaller alive: Maintaining PyInstaller is a huge amount of work. PyInstaller development can only continue if users and companies provide sustainable.
- Hidden-import=Pillow -hidden-import='PIL' -hidden-import='Pillow' My script uses the following line of code in regards to the PIL module: from PIL import Image, ImageTk Everything works fine in the script, it is only when I use pyinstaller that I have a problem.
- On Module imports like for example 1 import PyQt5.QtCore the pyinstaller seems to find automatically the corresponding hooks during analysis and does not add anymore errors to the log.
- 17980 INFO: Removing import of PyQt4 from module PIL.ImageQt 17981 INFO: Excluding import 'PyQt5' 17984 INFO: Removing import of PyQt5 from module PIL.ImageQt 17986 INFO: Excluding import 'tkinter' 17991 INFO: Removing import of tkinter from module PIL.ImageTk 17991 INFO: Import to be excluded not found: 'FixTk'.
win7+python3.5(anaconda3)
Theoretically, systems with win7 and above and any version of python are available.
1. Basic scripts
First, we build a simple script, such as output a series of numbers, text, and so on. Here we output a series of words and calculate the power of three times at the same time.
Save this script as mylib.py and run it:
As you can see, the script is working correctly.
For demonstration purposes, we create a new script into the main.py script file and import the test function from mylib.
2. Package as exe using PyInstaller
Package it as a single exe using the following command (remove-F is not a single exe)
The packaging process is as follows:
Finally, build, disk folders are generated in the directory.Where exe file is in disk.It is working properly.As follows:
3. Decompiled Pyinstaller packaged exe
Such exe s can already be migrated to other computers for use, and this is the end if it is for the convenience of other computers.Sometimes, however, we may use this feature for many people, but if you don't want to open source or be cracked by others, this is not enough.
Because at this point exe can be decompiled by others.
Tools used here:
Pyinstaller Key
exe decompile tool: pyinstxtractor.py: Click here to download
pyc decompile tool: Easy Python Decompiler Or decompile pyc online.
Place pyinstxtractor.py in the same directory as the exe file and execute the following cmd command:
If executed successfully, a new decompiled folder, main.exe_extracted, will be generated in the same directory, as shown below:
At the same time, we can find the mylib module, which was introduced by exe at that time, in pyc format, in the path circled below.
pyc format file, decompile is very simple.Using the tools provided in the previous section or finding an online minute decompile on the web, let's look at the results of the decompilation:
As you can see, the source code is basically decompiled perfectly.Where Chinese is involved, coding problems will change.But the non-Chinese part is almost the same.
Ask you if you are afraid!!!
4. Compile scripts as pyd to prevent decompiling
Fear, hath.
How to solve this problem, consider compiling the module py file into a dynamic link library, which makes cracking more difficult.In python, the pyd format is a dynamic link library.Use cython to compile, and if anaconda comes with it, some pythons may not have cython, just install it:
We create a new py file in the folder where main.py is located. Here I name it build_pyd.py, which reads as follows:
Pyinstaller Hidden Imports
Then execute the following cmd command:
The process and results are illustrated below, with the red-box PYD file compiled.Since I am a 64-bit system and python, an amd64 suffix is generated, so we can rename this deletion to mylib.pyd.
Note: When both mylib.pyd and mylib.py exist, the import priority is pyd>py, so PYD is the default import without removing the PY file.
At this point, we delete the build, disk folders, repeat Step 2, and compile to exe again.
Note: Compilation requires a relevant VC environment, as Python 3.5 is based on the VS14 version, so I installed it here as well.It cannot be compiled without installation.
You can verify that:
After decompiling main.exe again, mylib.pyc could not be found under the original path E:tdistmain.exe_extractedout00-PYZ.pyz_extracted.
Because he is no longer a file that can be decompiled directly.
Where is he? He exists in the upper directory as a pyd.As follows:
pyd's decompilation is quite difficult, so you're done!
Reference link: https://www.lizenghai.com/archives/898.html
https://blog.csdn.net/zy841958835/article/details/79446871
https://blog.csdn.net/HW140701/article/details/93494869 (pyinstaller-F--key=***encrypted pyc prevents decompilation) pycropto needs to be installed during this process, which is cumbersome to install: https://www.cnblogs.com/xiohao/p/11216271.html)
Added by friday_13 on Fri, 02 Aug 2019 03:46:14 +0300