Encrypt Python .py file
python - How can I decode this bytecode into a regular .py script? - Stack Overflow
tools - Decompiling .pyc files - Reverse Engineering Stack Exchange
Python Newbie - Encryption and decryption help
Videos
Knowledge grows with sharing and I am truly believer. With same beliefs I shared my python script with my colleague because he wanted it. He shared with more people who made that program with commercial glaze and claimed some benefits which I found recently. Now they are asking more scripts because I have many programs to automate lots of tasks. How can I encrypt my scripts so people can use but not copy source code for own benefits.
What Python version you're decompiling? Py3k is not well supported, but there are quite a few decompilers for 2.x. One of the latest projects is this:
https://github.com/Mysterie/uncompyle2
It runs on Python 2.7 but supports decompiling 2.5 to 2.7.
Note that some commercial projects has been known to use modified Python interpreters. Modifications can include:
- bytecode files encryption
- changed opcode values or additional opcodes
- a heavily customized runtime (e.g. Stackless Python)
If you need to handle this, one approach is to convert non-standard bytecode to standard one and then use the usual decompilers (this apparently was used by the people from above project to decompile Dropbox code). Another is to change the decompiler to directly support the variations.
You might find pyREtic from Immunity to be useful. The presentation from BlackHat USA 2010 on pyREtic is here (YouTube).
pyREtic
Reverse Engineer Obfuscated Python Bytecode This toolkit allows you to take a object in memory back to source code, without needing access to the bytecode directly on disk. This can be useful if the applictions pyc's on disk are obfuscated in one of many ways.