档案管理器能区分错误的密码和损坏的文件吗?

档案管理器能区分错误的密码和损坏的文件吗?

我有两个旧的加密 RAR 文件。我知道它们的密码,但发生了一些有趣的事情:

  1. 当我尝试在 File Roller(Ubuntu 的默认存档管理器)中打开每个文件并输入密码错误,它会显示消息“密码错误“,正如预期的那样。
  2. 当我尝试打开文件时使用正确的密码登录 File Roller,它显示错误“加载档案时发生错误/无法找到卷 a.r00“。 (注意:文件没有被分割成几部分,它们是单个完整的 RAR 文件。)
  3. 当我尝试打开文件时与其他工具,我总是得到这样的错误“加密文件 a.rar 的校验和错误。文件损坏或密码错误。“,我输入的密码是否正确。我尝试过 Unrar 和 7-zip。

从第 3 点开始,我假设我确实忘记了密码,但是第 2 点让我非常困惑,因为从消息来看,密码似乎正确,但由于其他原因文件无法提取(它期望档案有第二部分,但实际上没有)。

有很多问题与恢复损坏的 RAR 文件有关,所以我的问题与此无关。我想了解的是:为什么当密码正确时 File Roller 会显示不同的错误消息而其他工具则会显示一般消息“密码不正确”或“文件已损坏”?

我的最终目标是查明我是否输入了错误的密码或者文件是否损坏。

答案1

必须考虑到WinRAR.exe(Windows GUI 版本)和Rar.exe(Windows 控制台版本)在创建 RAR 存档时支持两种不同类型的加密:

  1. 文件数据加密和
  2. 真正加密所有数据,包括文件名、大小、属性、注释和其他块。

在第一种情况下,可以打开 RAR 存档文件以获取文件名列表、其原始文件大小、其打包大小、最后修改日期等,而无需密码,这意味着需要解密任何数据。

在第二种情况下,甚至需要密码才能获取存档文件内的文件和文件夹列表以及所有其他元数据。

还必须考虑 RAR 存档文件是否为 RAR 格式 4 或RAR 格式 5. 理由如下。

我在 Windows 上使用许可创建了三个 RAR 存档文件Rar.exe

  1. FileDataEncrypted.rar使用命令行加密的仅包含文件数据的RAR 文件:

    "%ProgramFiles%\WinRAR\Rar.exe" a -cfg- -ep -idq -m5 -ma5 -mt1 -psecret FileDataEncrypted.rar "%ProgramFiles%\WinRAR\Rar.txt"
    
  2. FullyEncrypted.rar使用命令行加密的RAR 文件及其所有数据:

    "%ProgramFiles%\WinRAR\Rar.exe" a -cfg- -ep -idq -m5 -ma5 -mt1 "-hpmore secret" FullyEncrypted.rar "%ProgramFiles%\WinRAR\Rar.txt"
    
  3. CorruptedArchive.rar首先使用命令行修复损坏的 RAR 文件:

    copy FileDataEncrypted.rar CorruptedArchive.rar
    

    然后我CorruptedArchive.rar在文本编辑器 UltraEdit 中以十六进制编辑模式打开该文件,将十六进制偏移量的 16 个字节修改2000为十六进制值FF,然后保存修改后的文件。

请参阅文本文件Rar.txt以了解使用开关的含义。

这三个 RAR 存档文件均为 RAR 格式 5(开关-ma5)。

然后我在 Windows 命令提示符窗口中执行了一个包含以下命令行的批处理文件:

@echo off
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ -psecret FileDataEncrypted.rar
echo Exit code of FileDataEncrypted.rar extraction with correct password is: %ERRORLEVEL%
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ -pwrong FileDataEncrypted.rar
echo Exit code of FileDataEncrypted.rar extraction with wrong password is: %ERRORLEVEL%
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ "-hpmore secret" FullyEncrypted.rar
echo Exit code of FullyEncrypted.rar extraction with correct password is: %ERRORLEVEL%
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ "-hpwrong secret" FullyEncrypted.rar
echo Exit code of FullyEncrypted.rar extraction with wrong password is: %ERRORLEVEL%
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ -psecret CorruptedArchive.rar
echo Exit code of CorruptedArchive.rar extraction with correct password is: %ERRORLEVEL%
"%ProgramFiles%\WinRAR\UnRAR.exe" x -idcdp -o+ -psecret CorruptedArchive.rar
echo Exit code of CorruptedArchive.rar extraction with wrong password is: %ERRORLEVEL%

输出为:

Extracting from FileDataEncrypted.rar

Extracting  Rar.txt                                                   OK
Exit code of FileDataEncrypted.rar extraction with correct password is: 0

Extracting from FileDataEncrypted.rar

Incorrect password for Rar.txt
Exit code of FileDataEncrypted.rar extraction with wrong password is: 11

Extracting from FullyEncrypted.rar

Extracting  Rar.txt                                                   OK
Exit code of FullyEncrypted.rar extraction with correct password is: 0

Incorrect password for FullyEncrypted.rar
Exit code of FullyEncrypted.rar extraction with wrong password is: 11

Extracting from CorruptedArchive.rar

Extracting  Rar.txt
Rar.txt              - checksum error
Exit code of CorruptedArchive.rar extraction with correct password is: 3

Extracting from CorruptedArchive.rar

Extracting  Rar.txt
Rar.txt              - checksum error
Exit code of CorruptedArchive.rar extraction with wrong password is: 3

文本文件Rar.txt在底部解释了退出值:

   Code   Description   

    0     Successful operation.
    1     Non fatal error(s) occurred.
    2     A fatal error occurred.
    3     Invalid checksum. Data is damaged.
    4     Attempt to modify an archive locked by 'k' command.
    5     Write error.
    6     File open error.
    7     Wrong command line option.
    8     Not enough memory.
    9     File create error
   10     No files matching the specified mask and options were found.
   11     Wrong password.
   12     Read error.
  255     User stopped the process.

在命令行上对两个有效的 RAR 存档输入错误的密码,将导致输出Incorrect password for ...RAR 存档文件内的存档文件的错误消息(第一种情况)或整个 RAR 存档文件(第二种情况),并退出并显示值11

无论使用正确或错误的密码,错误消息始终为checksum error,退出代码始终3为 RAR 存档文件损坏。

RAR 存档格式 5 使得 RAR 提取代码能够确定解密密码是否错误或存档文件本身是否损坏。

我再次创建了三个 RAR 存档文件,但使用开关-ma4而不是-ma5在 RAR 存档格式 4 中创建两个有效的 RAR 存档文件和一个损坏的 RAR 存档文件。

接下来我执行了与之前相同的批处理文件进行提取。这次的输出是:

Extracting from FileDataEncrypted.rar

Extracting  Rar.txt                                                   OK
Exit code of FileDataEncrypted.rar extraction with correct password is: 0

Extracting from FileDataEncrypted.rar

Extracting  Rar.txt
Checksum error in the encrypted file Rar.txt. Corrupt file or wrong password.
Exit code of FileDataEncrypted.rar extraction with wrong password is: 3

Extracting from FullyEncrypted.rar

Extracting  Rar.txt                                                   OK
Exit code of FullyEncrypted.rar extraction with correct password is: 0

Checksum error in the encrypted file FullyEncrypted.rar. Corrupt file or wrong password.
No files to extract
Exit code of FullyEncrypted.rar extraction with wrong password is: 3

Extracting from CorruptedArchive.rar

Extracting  Rar.txt
Checksum error in the encrypted file Rar.txt. Corrupt file or wrong password.
Exit code of CorruptedArchive.rar extraction with correct password is: 3

Extracting from CorruptedArchive.rar

Extracting  Rar.txt
Checksum error in the encrypted file Rar.txt. Corrupt file or wrong password.
Exit code of CorruptedArchive.rar extraction with wrong password is: 3

从错误消息以及始终相同的退出代码可以看出,3提取代码无法确定密码是否错误,或者格式 4 的 RAR 存档文件中的存档文件数据是否损坏。

目前最新的 UnRAR C++ 源代码可以从WinRAR 和 RAR 归档插件页面,因为它是免费软件,请参阅license.txt源存档文件。同一页面上还有 UnRAR 二进制文件可供多个平台下载。

解压缩7-Zip在 Ubuntu 上使用时,输出与在 Windows 上相同的错误消息,当然UnRAR.exeRar.exe提取 RAR 格式 4 的 RAR 存档文件时也是如此,该文件要么已损坏,要么用户输入了错误的密码。如上所示,无法找出校验和错误的原因。解压缩7-Zip使用 UnRAR 源代码进行编译。

Ubuntu 文档页面锉刀滚筒在章节中支持的格式在本节中Ubuntu 中默认未安装格式信息压缩文件仅支持锉刀滚筒使用unrar(非免费)或 unrar-free 软件包,用于提取 .rar 档案。所以这取决于额外安装的解压包用于提取 RAR 存档文件以及 RAR 存档文件有多新。

标题中的问题是:

档案管理器能区分错误的密码和损坏的文件吗?

答案是:

是的,如果使用的 UnRAR 代码是最新的RAR 档案文件是 RAR 格式 5.
不,如果使用的 UnRAR 代码很旧或者RAR 存档文件为 RAR 格式 4。

相关内容