有时需要查看某个Python Web目录内Python源码,但dump下来只有pyc文件而没有py文件,这时需要我们反编译pyc文件为py文件。为了方便就写个脚本遍历目录内的pyc文件并进行反编译。
主要应用Python的第三方uncompyle6库,安装:pip install uncompyle6
#coding=utf-8
import os
import sys
import uncompyle6
def Decompile(path):
if os.path.exists(path):
for parent,dirs,files in os.walk(path):
for file in files:
file_name,ext = os.path.splitext(file)
if ext == ".pyc":
file_path = os.path.join(parent,file)
print "[*]Decompiling:", file_path
cmd = "uncompyle6 " + file_path + " > " + parent + "\\" + file_name + ".py"
try:
os.system(cmd)
print "[+]Decompile successful.\n"
except Exception as e:
print e
print "[*]Finished."
else:
print "[-]Wrong Directory Path."
def main():
if len(sys.argv) !