Decompiling Python files

Hello All

I was working on my module in OpenERP and some unfortunate thing happened to eclipse and I lost all my source. I checked that file with gedit and it showed me an empty file. Luckily the pyc (complied python file) was present so I reversed and got my Source back. Here is how I did it

I cloned the source of https://github.com/zrax/pycdc using the command

git clone https://github.com/zrax/pycdc

then

cd pycdc

To compile the source code. first install cmake as there is no MAKEFILE inside and you will have to make one from the CMAKEList file. To Do so. follow the following steps

sudo apt-get install cmake

Now in source directory type

cmake .

This will create the MAKEFILE. Now to compile the source code type

make

This will compile all the source code. Now to get your lost source code from pyc just type the following command in pycdc source folder

./pycdc </path/to/yourSource.pyc>

This will echo out all the source code. To save the code to a file, Type the command

./pycdc /path/to/your/file.pyc >  file.py

And all of your source will get saved to file.py

Advertisements

One thought on “Decompiling Python files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s