ZIP文件解密[Termux,Python]
################### 目錄 ###################
#PATH_home = '/storage/emulated/0' ?#以'/storage/emulated/0'為初始目錄
PATH_home = '' ? #以__file__的上一級目錄為初始目錄
################### 目錄 ###################
import os
os.system('pip list > pip_list.txt')
PIP = ['textual','pyzipper']
with open('pip_list.txt','r') as f :
? ?pip_list = f.read().split()
for i in PIP :
? ?if i not in pip_list :
? ? ? ?os.system(f'pip install {i} -i https://pypi.tuna.tsinghua.edu.cn/simple')
? ? ? ?
import pyzipper
from sys import argv
from textual.app import App
from textual.screen import Screen
from textual.widgets import DirectoryTree,Header,Button
pwd_path = None
file_path = None
out_path = os.path.dirname(os.path.realpath(argv[0]))
if PATH_home[-1:] != '/' and len(PATH_home) > 1 :
? ?PATH_home+='/'
if not os.path.exists(PATH_home) :
? ?PATH_home = out_path
def pwd_list() :
? ?if os.path.isfile(pwd_path) :
? ? ? ?pwd_L = [pwd_path]
? ?else :
? ? ? ?pwd_L = os.listdir(pwd_path)
? ? ? ?pwd_L = [str(pwd_path)+'/'+i for i in pwd_L]
? ?for i in pwd_L :
? ? ? ?print('\n當(dāng)前字典 : ',i,end='\n')
? ? ? ?with open(i,'r') as f:
? ? ? ? ? ?for line in f:
? ? ? ? ? ? ? ?yield line.strip()
? ? ? ?
def zip_pwd(a) :
? ?_s = 0
? ?zip_file = pyzipper.AESZipFile(file_path, 'r')
? ?while True :
? ? ? ?try :
? ? ? ? ? ?passwd = next(a)
? ? ? ? ? ?zip_file.extractall(path=out_path,pwd=passwd.encode())
? ? ? ? ? ?zip_file.close()
? ? ? ? ? ?print('\r',_s, end='\n')
? ? ? ? ? ?print('密碼是 : ',passwd)
? ? ? ? ? ?return passwd
? ? ? ?except RuntimeError :
? ? ? ? ? ?print('\r',_s, end='')
? ? ? ?except StopIteration :
? ? ? ? ? ?print('\r',_s, end='\n')
? ? ? ? ? ?print('未能匹配到密碼')
? ? ? ? ? ?return None
? ? ? ?except Exception as e :
? ? ? ? ? ?pass
? ? ? ? ? ?#print('\n異常值 : "',passwd,'"\n',e,end='\n')
? ? ? ?_s+=1
? ? ? ?
class zipp_1(Screen):
? ?def compose(self) :
? ? ? ?yield Header()
? ? ? ?yield DirectoryTree(PATH_home)
? ? ? ?self.notify('選擇一個加密的ZIP文件',title='選擇文件',timeout=10)
? ? ? ?
class zipp_2(Screen):
? ?def compose(self) :
? ? ? ?yield Header()
? ? ? ?yield DirectoryTree(PATH_home)
? ? ? ?yield Button('R U N',variant='success')
? ? ? ?self.notify('''
選擇一個字典文件,
或者含有多個字典
文件的文件夾,點(diǎn)
擊RUN開始任務(wù)。
''', ? ?
? ? ? ?title='選擇字典',timeout=30)
? ? ? ? ? ?
class zipp(App):
? ?CSS = '''
? ?Header {height: 3 ;background: $error;text-style:bold}
? ?Button {width: 50}
? ?'''
? ?
? ?TITLE = '選擇需要破解的ZIP文件'
? ?
? ?SCREENS = {
? ?'zip': zipp_1(),
? ?'dic': zipp_2()
? ?}
? ?
? ?def on_mount(self) :
? ? ? ?self.push_screen('zip')
? ? ? ?
? ?def on_tree_node_highlighted(self,event) :
? ? ? ?global pwd_path,file_path
? ? ? ?if not file_path :
? ? ? ? ? ?return
? ? ? ?pwd_path = event.node.data.path
? ?
? ?def on_directory_tree_file_selected(self,event) :
? ? ? ?global file_path
? ? ? ?if file_path :
? ? ? ? ? ?return
? ? ? ?if str(event.path)[-4:].lower() == '.zip' :
? ? ? ? ? ?file_path = event.path
? ? ? ? ? ?self.title = '選擇一個字典文件'
? ? ? ? ? ?self.switch_screen('dic')
? ?
? ?def on_button_pressed(self) :
? ? ? ?self.exit()
? ? ? ?
if __name__ == '__main__' :
? ?zipp().run()
? ?PWD = pwd_list()
? ?os.system('clear')
? ?zip_pwd(PWD)
標(biāo)簽: