S. Known
S. Known

Reputation: 195

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?

Upvotes: 14

Views: 64156

Answers (2)

Vasanth Parimalan
Vasanth Parimalan

Reputation: 89

  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

Upvotes: 7

rinkert
rinkert

Reputation: 6863

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

Upvotes: 2

Related Questions