Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert exe back to Python script

Recently I converted a .py file to a .exe file.

I lost the original .py file and I'm left with the exe file. I converted it with pyinstaller.

Is there anyway to reverse this to get my original .py file back?

like image 239
S. Known Avatar asked Jul 07 '18 21:07

S. Known


People also ask

Is it possible to convert exe to code?

Yes, easily. Anyone can decompile a . NET assembly and get source code which can be compiled again into the same assembly.


2 Answers

  1. Use pyinstxtractor.py:

         python pyinstxtractor.py yourFileName.exe
    

    This will extract .exe and create a folder named yourFileName.exe_extracted.

  2. Inside the yourFileName.exe_extracted folder, find the file without any extension.

  3. 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.

  4. Save and Rename the file with .pyc extension.

  5. Decompile the compiled bytecode (.pyc) to .py using any online tool, like https://www.toolnb.com/tools-lang-en/pyc.html

like image 119
Vasanth Parimalan Avatar answered Oct 01 '22 08:10

Vasanth Parimalan


You could try this python-exe-unpacker from In Ming Loh. Not guaranteed to work though.

like image 30
rinkert Avatar answered Oct 01 '22 10:10

rinkert