gpt4 book ai didi

python - 如何将 Python 2.5 字节码重新编译为 2.7?

转载 作者:太空狗 更新时间:2023-10-29 17:50:52 26 4
gpt4 key购买 nike

如何用 Python 2.7 重新编译 Python 2.5 生成的一些 .pyc 文件?

我没有源文件,无法获取。

我正在寻找一个免费的解决方案。

最佳答案

您需要安装 Python 2.5 和 2.7 以及 byteplay (http://code.google.com/p/byteplay/)。

diz.py:

#!/usr/bin/env python
import byteplay, marshal, sys
if __name__ == '__main__':
sys.stdin.read(8)
c = byteplay.Code.from_code(marshal.load(sys.stdin)).code
labels = set([ x for l in c for x in l if isinstance(x, byteplay.Label) ])
labels = dict([(l,i) for (i,l) in enumerate(labels)])
byteplay.Label.__repr__ = lambda self: "labels[%d]" % labels[self]
print repr(c)

az.py:

#!/usr/bin/env python
import byteplay, sys, imp, struct, marshal, time
if __name__ == '__main__':
byteplay.labels = dict([(i, byteplay.Label()) for i in xrange(10000)])
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
asm = sys.stdin.read()
c = eval(asm, byteplay.__dict__)
c = byteplay.Code(c, (), (), 0, 0, 0, '', '', 0, '').to_code()
sys.stdout.write(imp.get_magic())
sys.stdout.write(struct.pack('<L', time.time()))
marshal.dump(c, sys.stdout)

用法:

python2.5 diz.py < foo.pyc > foo.az
python2.7 az.py < foo.az > foo.2.7.pyc

关于python - 如何将 Python 2.5 字节码重新编译为 2.7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7664189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com