My question is how decompile .pyc file to python code. In first place I had exe file, i extracted .pyz file from it. From .pyz file i extracted .pyc files with this http://www.pyinstaller.org/browser/project/PyInstaller/cliutils/archive_viewer.py
However when i try to decompile .pyc files I receive erro that magic number is invalid. I looked it up, and its 63 (hex) and 99 in decimal. I guess Pyinstaller makes some changes to pyc files, my question is how to decompile this .pyc file.
I have created some tools which will help in dealing with pyinstaller.
There are many ways you can go.
If you just want to extract the exe to get all the embedded files, including the ones inside the pyz use this script.
Afterwards use Easy Python Decompiler to decompile the pyc files.
If you want to dig deeper and recompile the exe then use Pyinstaller exe rebuilder tool.
Related
This question is related to differential update of pyinstaller executable (modify embedded PYZ-00.pyz)
I would like to create a pyinstaller distributable, that can easily be hot fixed without wasting too much bandwidth.
The standard pyinstaller approach for embedding python code .pyc files seems to be to put them into a PYZ file (ZLIB archive), adding the PYZ file into a CARchive and append the CArchive to the end of the executable.
I thought, that following solution might help me, tough it will penalize startup time of the program, but this is acceptable.
If possible I would like, that all collected .pyc files will not be added tot he .PYZ file but into a normal .zip file and that this normal zip file will then be added ('collected') into the dist folder.
How could I achieve this?
The answer https://stackoverflow.com/a/68754754/858675 to the other question is almost there and one could just pack up all .pyc files into a .zip file.
However the value of __file__ would be different for the modules and I guess, this might break some existing code if the depend on __file__
I have decompiled a .exe compiled.
I got a .pyz file and some other files:
Extracted them and got this:
How am I able to get the .py file from all those .pyc files?
You can decompile .pyc files yes - see these similar questions:
Is it possible to decompile a compiled .pyc file into a .py file?
https://reverseengineering.stackexchange.com/questions/1701/decompiling-pyc-files
The short of it is that you can use a tool to generate .py files from .pyc:
https://github.com/rocky/python-uncompyle6/
Is it possible to do a two steps decompression with PyInstaller?
e.g. it can decompress archived files from itself as needed, like InnoSetup, Nullsoft Installer (NSIS).
For --onefile exe generated with PyInstaller, everything is decompressed at invocation runtime, and it takes a lot of time, if there's a lot of bundled datafile.
What I trying to do is to replicate InnoSetup with PyInstaller+PyQt. Any ideas?
Yes you can. You can bundle installer files by appending to a.data in your spec file. Then at runtime your data files will be in the MEIPASS folder and you can copy them wherever you want. https://stackoverflow.com/a/20088482/259538
I had a python program written which I converted to an exe binary using py2exe. I have all of the files generated in the dist folder but due to a system crash, I lost the source code.
Is there a way to get the .py source code file back from .exe or other supporting files generated by py2exe?
According to the following links, you can extract your .pyc files from library.zip and then use decompyle to obtain .py files similar to what you started with.
http://bytes.com/topic/python/answers/101743-py2exe-there-way-go-backwards-exe2py
http://sourceforge.net/projects/decompyle/
Hope it works, and I hope you use github or bitbucket next time.
I'm using cx_Freeze to freeze my python program. On running cx_Freeze, a bunch of PYD files are created, a whole bunch of PYC files are put into a archive named library.zip and a few DLL files are there too.
Could someone tell me the difference between the PYC and the PYD files?
What's the reason for the PYD files not in the library.zip?
Is it possible to put the PYD files into the archive as well?
Thanks.
Disclaimer: I haven't used cx_Freeze in awhile......
.PYD files are DLL machine-code files that contain specific python-required functions.
.PYC files are .py files that have been compiled into bytecode.
so PYDs are machine code and PYCs are bytecode
Now as for why the PYDs aren't in the .zip....I'd imagine it's because those .PYDs are needed by the python interpreter to run the program. What cx_Freeze does is basically this:
compile all .py files and throw the .pyc files in a zip
put all needed .pyd files in the zip
create a stub .py file and put it in the output directory
copy the python.exe and rename to myprogram.exe
copy all .pyd files needed to open the .zip and run the contents
So you're not actually compiling your python file, you're instead renaming the interpeter and freezing all the source files.
I hope this helps.