14

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?

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
S. Known
  • 195
  • 2
  • 2
  • 10

2 Answers2

7
  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

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
2

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

rinkert
  • 6,593
  • 2
  • 12
  • 31
  • How does it work? I came as far as `pyinstxtractor.py help.exe` and the result was `You can now use a python decompiler on the pyc files within the extracted directory` so what do I have to do now? – S. Known Jul 07 '18 at 21:40
  • Use a python decompiler on the`pyc`file. – hjpotter92 Jul 07 '18 at 21:53
  • @hjpotter92 there are 204 pyc files – S. Known Jul 07 '18 at 22:12
  • Yes Thanks for the info but still, there are 204 .pyc files. Do I just go over them 1 by 1?? @hjpotter92 – S. Known Jul 08 '18 at 08:04
  • @S.Known Did you bother clicking on any of provided alternatives for decompiling? Did you read its documentation? Did you search for "decompiling a directory of pyc files"? Have you heard of using `*` as wildcard? – hjpotter92 Jul 08 '18 at 08:11
  • @hjpotter92 I have searched for alternatives for decompiling but I think decompyle6 is the way to go. But now I dont need to decompyle all 204 files because the most of them are actualy the libraries I used with their components. I just need to decompyle the file I made, but I dont know wich one it is from the 204. – S. Known Jul 08 '18 at 08:37
  • @S.Known, we don't know either, but if you can exclude the libraries like you said, there should be a limited number left, which you can decompile in one batch. Then search for your file... – rinkert Jul 08 '18 at 16:35
  • @rickert I have made a little code in powershell that uncompyled everything and put everything into a folder I made. After that I searched trough all the .py files with notepad++ a couple times for a line of my code. But no luck. Couldnt find it. Is there a other way? – S. Known Jul 09 '18 at 09:57