Python文件反编译,还原代码(xxd、uncompyle6)

这里有难度的就是如何复制文件的完整内容,如果能直接下载既下载,否则就要用方法完整拷贝内容

首先复制文件的十六进制的内容

xxd命令转换二进制文件为十六进制文件

xxd .configuration.cpython-38.pyc

然后把显示出的东西都复制放在kali文件里,再就是十六进制转换成二进制

xxd -r configure.pyc >> configure1.pyc

再进行还原文件

这里要提前在下一个python还原文件的工具uncompyle6

uncompyle6可将python字节码转换回等效的python源代码,它接受python 1.3版到3.8版的字节码,这其中跨越了24年的python版本,此外还包括Dropbox的Python 2.5字节码和一些PyPy字节码。

github项目:GitHub - rocky/python-uncompyle6: A cross-version Python bytecode decompiler

pip install uncompyle6

(事实上,pip install uncompyle2 也会跳到安装uncompyle6) 

uncompyle6 configuration1.pyc > configuration.py

configuration.cpython-38.pyc 

# uncompyle6 version 3.8.0
# Python bytecode 3.8.0 (3413)
# Decompiled from: Python 3.9.12 (main, Mar 24 2022, 13:02:21) 
# [GCC 11.2.0]
# Embedded file name: configuration.py
# Compiled at: 2020-06-04 10:49:49
# Size of source mod 2**32: 1343 bytes
import os, sys, json
from glob import glob
from datetime import datetime as dt
 
class ConfigReader:
    config = None
 
    @staticmethod
    def read_config(path):
        """Reads the config file
        """
        config_values = {}
        try:
            with open(path, 'r') as (f):
                config_values = json.load(f)
        except Exception as e:
            try:
                print("Couldn't properly parse the config file. Please use properl")
                sys.exit(1)
            finally:
                e = None
                del e
 
        else:
            return config_values
 
    @staticmethod
    def set_config_path():
        """Set the config path
        """
        files = glob('/home/saint/*.json')
        other_files = glob('/tmp/*.json')
        files = files + other_files
        try:
            if len(files) > 2:
                files = files[:2]
            else:
                file1 = os.path.basename(files[0]).split('.')
                file2 = os.path.basename(files[1]).split('.')
                if file1[(-2)] == 'config':
                    if file2[(-2)] == 'config':
                        a = dt.strptime(file1[0], '%d-%m-%Y')
                        b = dt.strptime(file2[0], '%d-%m-%Y')
                if b < a:
                    filename = files[0]
                else:
                    filename = files[1]
        except Exception:
            sys.exit(1)
        else:
            return filename
# okay decompiling configuration1.pyc

猜你喜欢

转载自blog.csdn.net/u012206617/article/details/126217743