Как я могу перекомпилировать некоторые .pyc файлы, созданные Python 2.5 с Python 2.7?
У меня нет исходных файлов, и я не могу его получить.
Я ищу бесплатное решение.
Ответ 1
Вам понадобятся 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)