Repack PyInstaller exe after extracting - python

Is it possible to repack/rebuild a PyInstaller exe file after extracting the files from it using PyInstaller Extractor? I also decomplied most of the files with Easy Python Decomplier. I modified one .py file and I want the new exe file to contain this modified file. How can I repack the application?

You may leave all not modified files as *.pyc.
Once you have full modules structure ready, just find the original entrypoint and pack the bundle again, it should work.

Related

Stop Python exe script from converting back

For example, I have a Python file like this:
print("Hello World")
Now I am converting it to an .exe file using pyinstaller.
But I found a method to convert it back:
Use pyinstxtractor.py:
python pyinstxtractor.py yourFileName.exe
This will extract .exe and create a folder named yourFileName.exe_extracted.
Inside the yourFileName.exe_extracted folder, find the file without
any extension.
Edit it with HxD editor and from any pycache file created with the
same version of Python, copy the first row and insert it into your
file.
Save and Rename the file with .pyc extension.
Decompile the compiled bytecode (.pyc) to .py using any online tool,
like https://www.toolnb.com/tools-lang-en/pyc.html
Is there any way to prevent converting the .exe file converting back to his .py file?
Thanks.
You can use an obfuscation tool such as PyArmor and add at-least some level of code-protection to your original python script.
The official documentation of PyArmor has more info on this here https://pyarmor.readthedocs.io/en/latest/advanced.html#bundle-obfuscated-scripts-to-one-executable-file

how to change bundled data file pyinstaller on execute

I'm making onefile executables with pyinstaller on windows 10. I'm including data files (pickle files) by editing the .spec file...
How can I store changes made to these files during run time? My understanding is that the data files are copied to a temp directory during execution. I can read from the files using the path I get from sys._MEIPASS but the changes I write are lost after restarting the program.
Is there a way to write to pickle files stored inside the exe?
Do not mention the pickle file to pyinstaller and put the pickle file in the same folder than the bundled onefile. For me this works even if you have two files in the folder instead of one.

My exe doesn't execute after I decompiled and changed the code

I have an .exe file where file compiled by py2exe in my .exe folder I have some .dll files, one .exe file and library.zip file and inside this zip I have to many .pyccompiled files.
I have decompiled this files from library.zip using Easy Python Decompiler and that program created me new file where I can see and change my code.
I have opened this file where I needed and I changed my code using python editor and finaly I saved as new script code with the some name and extension .pyc
with purpose to replace first .pyc.
zip again library folder and I tried to run .exe prgram but after the changes the program doesn't execute.
What have I done wrong in my task? Do I need to re-compile again in some way?
pyc and py file are NOT the same. While they represent the same code, they are totally different :
the py file represents the code you are typing, can be interpreted by the python interpreter, is not native, and is portable
the pyc file is a compiled version of the py file, that is not portable, not intended to be modified by an human, but faster
You cannot swap them and expect it to work. You will need to compile it to pyc before. You will find more information here : How can I manually generate a .pyc file from a .py file

Py2exe (Python Pygame) - Is there not an easier way?

I just checked the wiki and realized you need to input a tonne of code to change a python file containing pygame code to an exe. Is there not an easier way? Shouldn't it just be an exe file that you just open and imput what you want to change and where to save the exe to?
I am not sure I completely understand your question, but I would recommend using PyInstaller. All you have to do it go into the pyinstaller directory, and then run:
python pyinstaller.py /link/to/your/program
which should then make a directory in the pyinstaller directory named after your .py file. In that file you will have a build folder and a dist folder. The dist is the one of interest and will have your .exe in it.

How does Python package installer exe work?

The setuptools installer for Windows 7 x86 is named an exe file, but can be opened as a zip file. When I peek into it, there are two top level folders: PURELIB and SCRIPTS. What are these, and how is it that when I double click on this exe, Windows runs it for me, although it's a zip file? That is, how does Windows know what to run inside this zip/exe? Thanks.
It's a self-extracting archive.
A self-extracting archive is a computer application which contains a
file archive, as well as programming to extract this information. Such
file archives do not require a second executable file or program to
extract from the archive, as archive files usually require. The files
in an archive can thus be extracted by anyone, whether they possess
the appropriate decompression program or not, as long as the program
can run on their computer platform.
It is an executable, it's just that your extraction software knows to look for self-extracting archives, and treats it as a normal archive.
What are these, and how is it that when I double click on this exe,
Windows runs it for me, although it's a zip file?
From http://zziplib.sourceforge.net/sfx-make.html
The basic scheme goes like this: the final file will have an EXE
starting at offset null, followed by the data entries of a ZIP
archive. The last part of the ZIP archive is the ZIP central-directory
which ends at the end of the file.
The magic is possible because exe format allows any data to be appended to the executable and zip format allows any data to be prepended to the archive.

Categories