Python安全小工具之反编译pyc文件

本文介绍了如何使用uncompyle6库反编译Python的pyc文件,以便在没有py源码的情况下查看源代码内容。通过运行特定脚本,可以批量处理目录下的pyc文件,实现快速反编译。
摘要由CSDN通过智能技术生成

有时需要查看某个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) !
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值