CVS deleted one of my files when I updated my project before commit. All that I've got now is a .pyc file compiled by Python 2.7. How can I decompile it?
This is old but may still work: http://www.crazy-compilers.com/decompyle/
A newer tool can be found here: http://www.depython.net/
Your can also try this one (but it doesn't work on iterators): http://sourceforge.net/projects/unpyc/
You may try Easy Python Decompiler. It's based on Decompyle++ and Uncompyle2.
Note: I am the author of the above tool.
Related
I am developing a paid application in Python. I do not want the users to see the source code or decompile it. How can I accomplish this task of hiding the source code from the user, but running the code perfectly with the same performance?
You may distribute the compiled .pyc files which is a byte code that the Python interpreter compiles your .py files to.
More info on this found here on stackoverflow.
How to compile all your project files.
This will somewhat hide your actual code into bytecode, but it can be disassembled. To prevent from disassembling you need to use obfuscation. Pyarmor might be something you're looking for.
You will definitely see the code if you're running it as a Python file. Maybe try using pyinstaller to make a executable binary for the respective Operating System that you're building for.
The best way would be to turn your python code into an executable file.
When u take a look here, there is a nice Tutorial on how to do it:
Install pyinstall via pip3 install pyinstaller
Pack your excecutable with pyinstaller main.py
There is a lot of options to tweak the output of your application, the docs can be found under https://pyinstaller.org/en/stable/
So I've found a few resources on the internet, but I'm running into trouble with the version numbers. Apparently there were some "major" changes to some aspects of Python between versions 3.7 and 3.10? Since the file I'm attempting to decompile back into readable code is some years old (just happened to run across it and wanted to improve on it now that I've progressed my Python knowledge somewhat).
I'm not entirely sure there's a way around this or not, but perhaps I'm doing something wrong. I attempted to use decompyle6 ... which is where I'm running into the version issue. I suppose the most obvious answer would be to go back through the archives, install the older Python version, and decompile from IT?
I want to decompile PYC file in Python 3.9. I tried decompyle3, uncompyle6, but output was like this:
Error: decompyle3 requires Python 3.7-3.8
What I should use?
If you really have to support 3.9, you're going to have to do it yourself.
Clone the repo locally, Change the line which requires 3.7-8, have a go, and fix it where it starts breaking (and do submit a PR when you're done). The changes between 3.8 and 3.9 are not enormous, so it likely won't be too much work. If the code you're trying to decompile is <3.9 anyway, you won't actually have to implement 3.9isms, so it may run straight off---code written in 3.8 will likely run in 3.9, as AFAIK the APIs haven't changed noticeable. I haven't looked at how compiling works, though, so I could be wrong.
I've noticed this question several times on SO, but none of the answers seems to be applicable to a Python 3.6 version. As most cases when this is asked, I accidentally deleted my .py source file but I still have a .exe built with pyinstaller (passing only the --onefile and --icon arguments).
I managed to reach the following point:
Ran pyinstxtractor.py on the .exe I mentioned above. This gave me a bunch of files including one with no extension which is actually the .pyc of the source file missing the magic number.
Renamed the file with no extension in order to have the .pyc extension
Used a hex editor to append the magic number to the .pyc file, using the header from another .pyc file (used __future__ for this example). It looks like this.
Ran uncompyle6 on the .pyc file that now has the correct magic number, but the operations fails as seen here. Some of the code is retrieved(about 15%) but this important part is just obfuscated byte-code.
Any other tools I managed to come across do not work on Python 3.6 such as Easy Python Decompiler, unpyclib, pyREtic.
I did not manage to use pycdc/Decompyle++ or Maynard as I don't understand how they work, but they still don't seem to support 3.6.
Anything else I might try?
PS: My OS is Win7 and I did try file recovery software and system rollbacks, none of which worked.
I've created an app using py2app, which works fine, but if I zip/unzip it, the newly unzipped version can't access standard python modules like traceback, or os. The manpage for zip claims that it preserves resource forks, and I've seen other applications packaged this way (I need to be able to put this in a .zip file). How do I fix this?
This is caused by building a semi-standalone version that contains symlinks to the natively installed files and as you say, the links are lost when zipping/unzipping unless the "-y" option is used.
An alternate solution is to build for standalone instead, which puts (public domain) files inside the application and so survives zipping/unzipping etc. better. It also means the app is more resilient to changes in the underlying OS. The downside is that it is bigger, of course, and is more complicated to get it set up.
To build a stand alone version, you need to install the python.org version which can be repackaged.
An explanation of how to do this is here, but read the comments as there have been some changes since the blog post was written.
use zip -y ... to create the file whilst preserving symlinks.
You probably need to give it your full PYTHONPATH.
Depends on your os. Here's how to find out:
import os [or any other std module]
os.file()