简体   繁体   English

python中二进制数据的CRC32,没有最后4个字节

[英]CRC32 of binary data in python without last 4 bytes

I am trying to get the CRC32 of some binary data, except for the last 4 bytes. 我正在尝试获取一些二进制数据的CRC32,最后4个字节除外。

My code so far: 到目前为止,我的代码:

with open('filename.ext','rb') as f:
    fileContent = f.read()
    file_size, = struct.unpack("i",f.read(:4))
    print hex(file_size)

I know that the :4 is wrong and I am still looking for how not to read the last 4 bytes and then get the crc32 for the other data. 我知道:4是错误的,我仍在寻找如何不读取最后4个字节,然后获取其他数据的crc32。

You can use indexing like this: 您可以像这样使用索引:

fileContent[:-4]

to skip the last 4 bytes. 跳过最后4个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM