我不小心丢失了所有项目的源代码,但我仍然拥有我的 .pyc 文件。我需要帮助对它们进行反编译。我下载了可以反编译Python 3.2文件的unpyc3脚本,并进行了更改以使其正确读取Python 3.3 pyc文件:
def read_code(stream):
# This helper is needed in order for the PEP 302 emulation to
# correctly handle compiled files
# Note: stream must be opened in "rb" mode
import marshal
magic = stream.read(4)
if magic != imp.get_magic():
print("*** Warning: file has wrong magic number ***")
stream.read(8) # Skip timestamp and additional 4 bytes for python 3.3
return marshal.load(stream)
通过运行此代码,我得到了以下错误:"在此处' str '对象没有属性' co_cellvars'":
class Code:
def __init__(self, code_obj, parent=None):
self.code_obj = code_obj
self.parent = parent
self.derefnames = [PyName(v)
for v in code_obj.co_cellvars + code_obj.co_freevars]
在初始化代码类时,如果出现字符串而不是代码对象code_obj,则会出现问题。我需要帮助弄清楚为什么会出现这种情况以及如何解决它。如果有人知道如何使用unpyc3并能提供帮助,请与我联系。我可以发送一个.pyc示例。