diff --git a/uncompyle6/load.py b/uncompyle6/load.py index f11beaf2..24fd5bc9 100644 --- a/uncompyle6/load.py +++ b/uncompyle6/load.py @@ -88,15 +88,16 @@ def load_module(filename, code_objects={}): magic_int = magics.magic2int(magic) my_magic_int = magics.magic2int(imp.get_magic()) + # Note: a higher magic number doesn't necessarily mean a later + # release. At Python 3.0 the magic number decreased + # significantly. Hence the range below. Also note inclusion of + # the size info, occurred within a Python major/minor + # release. Hence the test on the magic value rather than + # PYTHON_VERSION, although PYTHON_VERSION would probably work. + if 3200 <= magic_int < 20121: + fp.read(4) # size mod 2**32 + if my_magic_int == magic_int: - # Note: a higher magic number necessarily mean a later - # release. At Python 3.0 the magic number decreased - # significantly. Hence the range below. Also note - # inclusion of the size info, occurred within a - # Python magor/minor release. Hence the test on the - # magic value rather than PYTHON_VERSION - if 3200 <= magic_int < 20121: - fp.read(4) # size mod 2**32 bytecode = fp.read() co = marshal.loads(bytecode) else: diff --git a/uncompyle6/marsh.py b/uncompyle6/marsh.py index 92256ffa..387a659d 100644 --- a/uncompyle6/marsh.py +++ b/uncompyle6/marsh.py @@ -43,7 +43,13 @@ def load_code(fp, magic_int, code_objects={}): internStrings = [] seek_pos = fp.tell() # Do a sanity check. Is this a code type? - if fp.read(1).decode('utf-8') != 'c': + b = ord(fp.read(1)) + + if (b & 0x80): + b = b & 0x7f + + c = chr(b) + if c != 'c': raise TypeError("File %s doesn't smell like Python bytecode" % fp.name) fp.seek(seek_pos) @@ -52,8 +58,11 @@ def load_code(fp, magic_int, code_objects={}): def load_code_internal(fp, magic_int, bytes_for_s=False, code_objects={}): global internStrings - b1 = fp.read(1) - marshalType = b1.decode('utf-8') + b1 = ord(fp.read(1)) + if b1 & 0x80: + TypeError("Can't handle object references yet") + + marshalType = chr(b1) if marshalType == 'c': Code = types.CodeType @@ -114,6 +123,8 @@ def load_code_internal(fp, magic_int, bytes_for_s=False, code_objects={}): code_objects[str(code)] = code return code + elif marshalType == 'C': + raise KeyError("New-style code not finished yet") # const type elif marshalType == '.': return Ellipsis