Can EXE generated by cx_freeze be completely decompiled back to readable Python code?

前端 未结 2 1693
故里飘歌
故里飘歌 2020-12-17 19:14

I\'m new to python, and I\'m evaluating developing desktop programs with Python + PySide, and found that cx_freeze works very good in converting my python code into executab

相关标签:
2条回答
  • 2020-12-17 19:58

    In general - no. CX Freeze and py2exe store the PYC version of your code, the bytecode compiled from the PY files. Currently, if I am not mistaken, there are no working viable PYC decompilers. Some give you a more-or-less readable byte code with annotations, but none will give you the actual Python source code. So in that regard - no, it cannot be decompiled. You can also consider going the full native way and use Shed Skin

    0 讨论(0)
  • 2020-12-17 20:09

    It seems that the current accepted answer is no longer true.

    Here is how to recover the original source code from a project frozen with cx_freeze.

    Note: it is done here on a "Hello world" project, but, using the same method, I've been able to decompile a 1000+ lines-of-code source code from a project of mine frozen with cx_freeze, and recover nearly the original source code!

    1) Use cx_freeze

    Create a test.py file containing

    import time
    print('hello')
    time.sleep(2)
    print('world')
    

    Then create the executable with

    cxfreeze test.py --target-name=test.exe
    

    Then usually you'll distribute this to the final users:

    Now let's try to reverse engineer this!

    #2) Get the .pyc bytecode

    Open dist/lib/library.zip and extract the file test__main__.pyc.

    #3) Now use decompyle6 to get the source code

    import uncompyle6
    with open('test_main_reverse_eng.py', 'w') as f:
        uncompyle6.decompile_file('test__main__.pyc', f)
    

    #4) Surprise...

    Here is the original source code!

    # uncompyle6 version 3.7.1
    # Python bytecode 3.7 (3394)
    # Decompiled from: Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]
    # Embedded file name: test.py
    # Compiled at: 2020-06-16 21:02:17
    # Size of source mod 2**32: 58 bytes
    import time
    print('hello')
    time.sleep(2)
    print('world')
    
    0 讨论(0)
提交回复
热议问题