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
posted @ 2024-01-26 08:32  VipSoft  阅读(230)  评论(0)    收藏  举报