如何计算WinRAR文件的CRC? [英] How to calculate CRC of a WinRAR file?

查看:410
本文介绍了如何计算WinRAR文件的CRC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Wikipedia 了解CRC计算算法.关于RAR文件的结构,我在此处阅读.例如,其中写道:

I know CRC calculation algorithm from Wikipedia. About structure of RAR file I read here. For example, there was written:

文件的魔术数为:

The file has the magic number of:

   0x 52 61 72 21 1A 07 00

以下是描述存档标题的细分:

Which is a break down of the following to describe an Archive Header:

   0x6152 - HEAD_CRC
   0x72   - HEAD_TYPE
   0x1A21 - HEAD_FLAGS
   0x0007 - HEAD_SIZE

如果我理解正确,则HEAD_CRC(0x6152)是标记块(MARK_HEAD)的CRC值.在我读过的某个地方,WinRAR文件的CRC是使用标准多项式0xEDB88320计算的,但是当CRC的大小小于4个字节时,有必要使用较小的有效字节.在这种情况下(当然,如果我无法正确理解的话),CRC值是0x6152,所以它有2个字节.现在我不知道,我必须减少哪些字节的重要性.从标准多项式(0xEDB88320)开始?那么0x8320可能是此多项式的较低有效字节.接下来,如果我们已经有正确的多项式,那么如何计算标记块的CRC(即从以下字节:0x 52 61 72 21 1A 07 00)?

If I understand correctly, the HEAD_CRC (0x6152) is CRC value of Marker Block (MARK_HEAD). Somewhere I read, that CRC of a WinRAR file is calculated with standard polynomial 0xEDB88320, but when size of CRC is less than 4 bytes, it's necessary to use less significant bytes. In this case (of course if I undestand correctly) CRC value is 0x6152, so it has 2 bytes. Now I don't know, which bytes I have to take as less significant. From the standard polynomial (0xEDB88320)? Then 0x8320 probably are less significant bytes of this polynomial. Next, how to calculate CRC of the Marker Block (i. e. from the following bytes: 0x 52 61 72 21 1A 07 00), if we have already right polynomial?

推荐答案

可能是对不是源自32位CRC的较旧格式进行了16位检查. zip和rar使用的标准32位CRC应用于标头的最后五个字节,其任何部分均不等于前两个字节.波兰语页面似乎错误地声称两字节校验是32位CRC的低两位字节.

There was likely a 16-bit check for an older format that is not derived from a 32-bit CRC. The standard 32-bit CRC, used by zip and rar, applied to the last five bytes of the header has no portion equal to the first two bytes. The Polish page appears to be incorrect in claiming that the two-byte check is the low two-bytes of a 32-bit CRC.

从文档中确实可以看出,该标头与其他格式的旧模块一样以标准方式构造,因此,出于娱乐目的,作者安排了他的格式以提供校验值"Ra",以便拼出"Rar!"然后是文本终止控件Z.

It does appear from the documentation that that header is constructed in a standard way as other blocks in the older format, so that the author, for fun, arranged for his format to give the check value "Ra" so that it could spell out "Rar!" followed by a text-terminating control-Z.

我在unrar源代码中发现了另一个16位校验,但是该校验也不会导致这些值.

I found another 16-bit check in the unrar source code, but that check does not result in those values either.

哦,不,您不能参加CRC多项式,并希望它对于较小的检查是一个很好的CRC多项式.波兰语页面的意思是,您将计算完整的32位CRC,然后 then 占用结果的低2个字节.但是,这不适用于幻数标头.

Oh, and no, you can't take part of a CRC polynomial and expect that to be a good CRC polynomial for a smaller check. What the page in Polish is saying is that you would compute the full 32-bit CRC, and then take the low two bytes of the result. However that doesn't work for the magic number header.

这篇关于如何计算WinRAR文件的CRC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆