Python 解壓還密碼的壓縮文件 LookupError: Couldn't find path to unrar library.

Python 解壓還密碼的壓縮文件(rar zip)
image

安裝包

pip install unrar -i https://pypi.tuna.tsinghua.edu.cn/simple

from unrar import rarfile
from tqdm import tqdm
import itertools


def rar_attack(file_name):
    file_handle = rarfile.RarFile(file_name)
    for length in range(1, 9):
        # 思路是這樣,但實際運行過程中,會消耗大量資源,耗時較長
        # for combination in tqdm(itertools.product('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()', repeat=length)):
        for combination in tqdm(itertools.product('0123456789', repeat=length)):
            password = ''.join(combination)
            try:
                file_handle.extractall(pwd=password)
                print('Password found: ', password)
                return
            except:
                pass


if __name__ == '__main__':
    # 壓縮包,需要和代碼同級
    file_name = '123.rar'
    rar_attack(file_name)

image
image

問題

如果報LookupError: Couldn't find path to unrar library.
解決方案如下:

  1. 官網下載
    RARLab官方下載庫文件 下載地址: https://www.rarlab.com/rar/unrardll-624.exe
  2. 安裝路徑
    執行 UnRARDLL.exe 文件 ,路徑選擇默認 ,一般是C:\Program Files (x86)\UnrarDLL\ 目錄下

image

image

unrar.rarfile.BadRarFile: Invalid RAR file.
解決方案:

  1. 下載 UnRAR.exe https://www.rarlab.com/rar/unrarw64.exe
    將 UnRAR.exe 複製到代碼同級目錄下,或者添加環境變量
    image
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章