python3 decompilation, pyc file decompilation to py

Table of contents

1 uncompyle6

2 decompyle3

3 pycdc

3.1 windows use

3.2 Use of linux


1 uncompyle6

pip install uncompyle6
uncompyle6 -o 生成的文件名.py 想反编译的文件名.pyc

Source code address ( rocky/python-uncompyle6: cross-version Python bytecode decompiler (github.com)

2 decompyle3

pip install decompyle3
decompyle3 -o 生成的文件名.py 想反编译的文件名.pyc

源码地址(rocky/python-decompile3: Python decompiler for 3.7-3.8 Stripped down from uncompyle6 so we can refactor and start to fix up some long-standing problems (github.com)

uncompyle6 and decompyle3 are the same author, and decompyle3 is a branch of uncompyle6, which is lighter and supports python3.7 and python3.8 better.

uncompyle6 supports earlier versions of python3. Since the author's energy issues are no longer maintained, these two commands are the most convenient python decompilation methods, which can be downloaded and used directly through pip

3 pycdc

Source address ( zrax/pycdc: C++ python bytecode disassembler and decompiler (github.com)

I compiled the exe ( https://download.csdn.net/download/weixin_44382736/87698967?spm=1001.2014.3001.5501 )

3.1 windows use

Reference (https://blog.csdn.net/qq_63585949/article/details/127080253)

(1) Download the source code

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

(2) The compilation of the program needs to use CMake,

CMake Installation Tutorial ( CMake Installation Tutorial_cmake Download and Installation Tutorial_Xiaoaogou's Blog-CSDN Blog

(3) Or use the CMake extension of vscode. I personally recommend this method, which is more foolish

Download the CMake extension

(4) CMake install pycdc

(5) Then you can find pycdas.exe and pycdc.exe under build/debug, pycdas is a disassembly tool, just use pycdc here

(6) Move pycdc to the same level directory as the file to be decompiled pycdc.exe file name.pyc

Then you can copy the decompiled code into the .py file

3.2 Use of linux

(1) It is recommended to upgrade gcc to the latest version. For centos system, it is recommended to install gcc manually. The gcc version of yum install is too low. Refer to (Linux upgrade gcc to the latest version gcc-11.2.0_Dan faint heart blog-CSDN blog )

The version is too low and the following error may be reported when making in step (2)

Linux make error · Issue #229 · zrax/pycdc (github.com)

(2) After installing gcc, enter cmake CMakeLists.txt in the download directory, a Makefile will be generated in the current directory and then enter make to compile and install

Because my disk is insufficient and it is very troublesome to clean up, I got stuck at (1),

It is still recommended to use the 3.1 method to compile with windows vscode

The function of pycdc is more powerful. It currently supports python3.11 and is still being updated. However, according to actual measurements, uncompyle6 and decompyle3 can decompile Chinese characters. After decompilation by pycdc, Chinese characters will become garbled characters.

In addition, python2.7 can also refer to ( wibiti/uncompyle2: Python 2.7 decompiler (github.com)

Python3.3 can also refer to ( figment/unpyc3: Decompiler for Python 3.3 (forked from https://code.google.com/p/unpyc3) (github.com)

Versions 2.7 and 3.3 are not mainstream now, so they will not be introduced anymore.

It is recommended to try all the above tools. A certain tool may only decompile a part of the code. It is possible that all tools in a certain part cannot be successfully decompiled, but it is much better than losing all the source code.

Guess you like

Origin blog.csdn.net/weixin_44382736/article/details/130203729