Python程序编译后是pyc文件,使用本文件放于任意目录下,修改directory值,然后使用python运行即可批量破解反编译pyc文件 。
import uncompyle6
import os
def decompile_pyc_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.pyc'):
pyc_file = os.path.join(root, file)
py_file = os.path.splitext(pyc_file)[0] + '.py' # 使用同名的.py文件名
# 反编译.pyc文件为.py文件
with open(py_file, 'w', encoding='utf-8') as f: # 指定编码方式为utf-8
uncompyle6.decompile_file(pyc_file, f)
print(f"Decompiled: {pyc_file} -> {py_file}")
# 指定包含.pyc文件的目录
directory = r"D:\source\"
# 执行批量反编译
decompile_pyc_files(directory)