閒聊

[Python]反編譯pyc文件

因為一些原因 拿到了一個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) != 2:
		print ("[*]Usage: python decompile.py [Directory Path]")
	else:
		path = sys.argv[1]
		Decompile(path)
 
if __name__ == "__main__":
	main()


C:\Users\david\Desktop\>python ./de.py C:\Users\david\Desktop\

他會幫你把那個資料夾內的所有pyc的檔案都反編譯好丟到你指定的資料夾內

Be the First to comment.

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。

(若看不到驗證碼,請重新整理網頁。)