目录
依赖库的安装
pip install uncompyle6
测试过的支持文件
.pyc ,.pyo
反编译文件夹下所有文件
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Time : 14:09
# Email : spirit_az@foxmail.com
# File : pycToPy.py
__author__ = "ChenLiang.Miao"
# import --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ #
import os
import sys
# function +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ #
def run(folder, flag='.pyc'):
unPath = sys.executable
unPath = unPath[0: unPath.rfind(os.sep)]
for r, dirs, fs in os.walk(folder):
for f in fs:
fileName, oldFlag = os.path.splitext(f)
if oldFlag == flag:
oldPath = os.path.join(r, f)
newname = oldPath[0:oldPath.rfind('.')] + '.py'
print oldPath
print newname
command = "python -u " + unPath + "\Scripts\uncompyle6.exe " + oldPath + " > " + newname
os.system(command)
# +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ #
if __name__ == "__main__":
fp = r'E:\MCL\python\demo\tsm3'
run(fp)
知识点:
获取编译器所在路径
unPath = sys.executable
unPath = unPath[0: unPath.rfind(os.sep)]
与主程序同步执行shell命令
command = "python -u " + unPath + "\Scripts\uncompyle6.exe " + oldPath + " > " + newname
os.system(command)