2014-02-28 71 views
6

Accedentely我遺失了我所有的項目源代碼。但我仍然有我的.pyc文件。我需要幫助反編譯它們。我下載了可以反編譯python 3.2文件的unpyc3腳本。並做了更改,以允許其3.3 PYC文件讀取正確的Python:使用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)   

通過運行該代碼,我有以下錯誤:「‘海峽’對象有沒有屬性‘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例子。

回答

5

經過一番認真的調試,我發現從MAKE_FUNCTION修改代碼應該做的伎倆:

def MAKE_FUNCTION(self, addr, argc, is_closure=False): 
    testType = self.stack.pop().val 
    if isinstance(testType, str) : 
     code = Code(self.stack.pop().val, self.code) 
    else : 
     code = Code(testType, self.code) 

希望這有助於!