结构解包(…)在x64机器上工作不同

2024-06-11 05:24:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力 key = struct.unpack('L', bytes_key)[0]其中bytes\u key是b'\xa6\x0b\xddE',它在我的x32机器上运行良好,但是每当我试图在x64机器上执行它时,它就会出错。你知道吗

Traceback (most recent call last):
File "unpacker.py", line 42, in <module> decompile(obj[1]) File "unpacker.py", line 13, in decompile f.write(decrypt_record(arg).content) File "crypt.py", line 61, in crypt.decrypt_record (crypt.c:2447) record.checksum = decrypt(record.checksum, checksum_key)
File "crypt.py", line 36, in crypt.decrypt (crypt.c:1821) key = struct.unpack('L', bytes_key)[0] struct.error: unpack requires a bytes object of length 8


Tags: keyinpy机器byteslinerecordstruct
1条回答
网友
1楼 · 发布于 2024-06-11 05:24:39

您可以尝试在“L”之前使用“=”:

...
struct.unpack("=L", bytes_key)[0]
...

根据documentation,它说:

Standard size depends only on the format character; see the table in the Format Characters section. Note the difference between '@' and '=': both use native byte order, but the size and alignment of the latter is standardized.

相关问题 更多 >