CRC32 Mpeg 校验和不匹配?

CRC32 Mpeg checksums don't match?

我一直在尝试对 crc32 校验和进行逆向工程。我无法访问原始的 J# 代码,因为它是编译的,反编译它没有帮助。我通过 运行 10 个有效负载 reveng 返回:

width=32 poly=0x04c11db7 init=0xFFFFFFFF refin=false refout=false xorout=0x00000000 check=0x0376e6e7 name="CRC-32/MPEG-2"

我通过两个不同的 python 库尝试了 运行 包,甚至构建了一个 objective-c 算法来尝试获得已知的校验和。重新创建的所有内容都相互匹配,但它们与原始校验和不匹配。有什么想法吗?

这是原始的和计算出的 crc32 校验和:

original  -> calculated

1.  0x99c93052 -> 0x13bc2c5c
2.  0xb5cea403 -> 0x1fd00c8e
3.  0xc7e4f40c -> 0xf9698bd6
4.  0xabe5ad28 -> 0x6be300d6
5.  0x2dacbf16 -> 0x43b2c356
6.  0xf321c2E9 -> 0xacb5981a
7.  0x01430cb6 -> 0x2f9e64ee
8.  0xa1028afb -> 0x44c7182b
9.  0xe73118e6 -> 0xd6c1ffa5
10. 0x5f366305 -> 0x84961d17

感谢任何和所有建议!

编辑:

根据请求,这里是原始有效负载及其 CRC-32/MPEG-2 校验和及其计算的校验和:

1. Payload = d3b09900005500005469746c653a090954657374207469746c652020202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000
   Orig = 0xf9297a54
   Calc = 0xebcc0d91
2. Payload = d3b09900004300005469746c653a090954657374207469746c652032202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000
   Orig = 0xb518dad0
   Calc = 0x45e4e895
3. Payload = d3b09900004300005469746c653a090954657374207469746c652033202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000
   Orig = 0xe367073b
   Calc = 0x5db5800c
4. Payload = d3b09900004300005469746c653a090954657374207469746c652034202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000
   Orig = 0x44d90b1d
   Calc = 0x14039bc3

这是我计算这些校验和的一种方法(尽管 pycrc 和我实现的 objective-c 代码都给出了相同的结果):

>>> import crcmod.predefined
>>> s = 'd3b09900004300005469746c653a090954657374207469746c652034202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000'
>>> crc32_func = crcmod.predefined.mkCrcFun('crc-32-mpeg')
>>> print hex(crc32_func(s))
0x14039bc3

以上代码使用了负载示例 4。如您所见,计算出的校验和 (0x14039bc3) 与负载 (0x44d90b1d) 附带的原始校验和不匹配。

我可以使用我的 Pascal Rocksoft 实现来验证您所有的原始 CRC,并且 来自 http://reveng.sourceforge.net/crc-catalogue/ 的 CRC-32/MPEG-2 具有这些参数

width=32 
poly=0x04c11db7 
init=0xffffffff 
refin=false 
refout=false 
xorout=0x00000000 
check=0x0376e6e7 
name="CRC-32/MPEG-2"

如果对实现有疑问,请参阅 Rocksoft document. You find a Python implementation at https://pycrc.org/models.html 中包含的 C 源代码(尽管我没有对此进行测试)。

看起来很清楚(从你自己的报复性回答,从 Marc 的 post,从我的 确认)给定的参数对于您的问题是正确的。但是因为 你确实展示了任何代码,我能给你的唯一建议是你应该 通过逐步与经过验证的 C 实现进行比较来调试您的代码。

所以事实证明只是将十六进制作为字符串传递并不会通过 python 库以正确的校验和结束 crcmod. 它也不会采用字节数组,这似乎是计算准确校验和的更有可能的方法。您需要做的是将字节数组作为缓冲区传递,然后计算出正确的校验和。

使用问题中的例子:

>>> import crcmod.predefined
>>> s = 'd3b09900004300005469746c653a090954657374207469746c652034202020202020202020202020202020202020202020202020202020200a4172746973743a09095465737420617274697374202020202020202020202020202020202020200a43443a0909095465737420434420202020202020202020202020202020202020202020200a4c6162656c3a0954657374204c626c202000'
>>> h = s.decode("hex")
>>> b = bytearray(h)
>>> crc32_func = crcmod.predefined.mkCrcFun('crc-32-mpeg')
>>> print hex(crc32_func(buffer(b)))
0x44d90b1d

好了。我猜这主要是对 CRC 校验和的计算方式缺乏了解。希望这最终能帮助到其他人。