From 09b2adbbbde46ce30d3f1a36c83293572f8b56f0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 18 Jul 2013 10:09:02 +0200 Subject: [PATCH] Fix marshal UTF8 bug --- uncompyle2/__init__.py | 6 +----- uncompyle2/disas.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/uncompyle2/__init__.py b/uncompyle2/__init__.py index af86852d..710e10db 100755 --- a/uncompyle2/__init__.py +++ b/uncompyle2/__init__.py @@ -38,13 +38,10 @@ __all__ = ['uncompyle_file', 'main'] def _load_file(filename): ''' load a Python source file and compile it to byte-code - _load_module(filename: string): code_object - filename: name of file containing Python source code (normally a .py) code_object: code_object compiled from this source code - This function does NOT write any file! ''' fp = open(filename, 'rb') @@ -61,7 +58,6 @@ def _load_module(filename): ''' load a module without importing it _load_module(filename: string): code_object - filename: name of file containing Python byte-code object (normally a .pyc) code_object: code_object from this file @@ -77,7 +73,7 @@ def _load_module(filename): raise ImportError, "This is a Python %s file! Only Python 2.5 to 2.7 files are supported." % version #print version fp.read(4) # timestamp - co = marshal.load(fp) #dis.marshalLoad(fp) + co = dis.marshalLoad(fp) fp.close() return version, co diff --git a/uncompyle2/disas.py b/uncompyle2/disas.py index fc0a272d..94f662eb 100755 --- a/uncompyle2/disas.py +++ b/uncompyle2/disas.py @@ -254,7 +254,6 @@ def load(fp): n = unpack('l', fp.read(4))[0] if n == 0: return long(0) - ratio = 2 #2 for 64bit 1 for 32bit size = abs(n); d = long(0) for j in range(0, size): @@ -277,7 +276,8 @@ def load(fp): return interned elif marshalType == 'u': strsize = unpack('l', fp.read(4))[0] - return unicode(fp.read(strsize)) + unicodestring = fp.read(strsize) + return unicodestring.decode('utf-8') # collection type elif marshalType == '(': tuplesize = unpack('l', fp.read(4))[0]