Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:ANN': 0.02; 'anyway': 0.03; '3.2': 0.05; 'sys': 0.05; 'attribute': 0.07; 'prints': 0.07; 'python': 0.08; '>>>>': 0.09; 'lines:': 0.09; 'subject:python': 0.11; 'def': 0.15; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '...]': 0.16; '.py': 0.16; '110,': 0.16; '3.2,': 0.16; '3.2.1': 0.16; '[gcc': 0.16; '__all__': 0.16; '__init__': 0.16; '__pycache__': 0.16; 'imp': 0.16; 'linux2': 0.16; 'name):': 0.16; 'opcode': 0.16; 'subject:Python3': 0.16; 'syntaxerror:': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'seems': 0.20; '(most': 0.21; 'badly': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'compiled': 0.23; 'incorrect': 0.23; 'received:209.85.213.46': 0.23; 'received:mail- yw0-f46.google.com': 0.23; 'though.': 0.23; 'changed': 0.24; 'byte': 0.24; 'traceback': 0.24; 'code': 0.25; 'guess': 0.26; 'function': 0.27; 'skip:[ 10': 0.27; 'skip:_ 20': 0.28; 'import': 0.28; "skip:' 30": 0.29; 'message-id:@mail.gmail.com': 0.29; 'print': 0.29; 'skip:( 20': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'lines': 0.30; 'module': 0.30; 'loads': 0.30; '\xc2\xa0\xc2\xa0\xc2\xa0': 0.30; "skip:' 10": 0.30; 'version': 0.32; 'ps:': 0.32; 'break': 0.32; 'probably': 0.33; "i've": 0.34; 'follows:': 0.34; 'directory.': 0.34; 'last):': 0.34; 'try:': 0.34; 'thank': 0.35; 'object': 0.35; 'file': 0.36; 'none': 0.37; 'skip:i 30': 0.37; 'but': 0.37; 'two': 0.37; 'could': 0.38; 'think': 0.38; 'easiest': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'more': 0.60; 'your': 0.61; 'hope': 0.61; 'skip:o 30': 0.63; 'show': 0.67; 'skip:. 40': 0.67; "'nonetype'": 0.84; 'warning.': 0.84; 'jul': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xvC7KwXeFAJGIxTU5SvukhAmGQRrRljLa2lTwc2dHc8=; b=wrldgZ8UeW4FpbWP4LA4oa4zfcunz2g0FT3+/c+rvA8p6lVBAzc8GCQThfd+P6nmHc xWz4Jp6cZEuRZiNLmUMWNGXiPR3pNgpB0ZS/R7QjqWi0cjzVX4jH/8xdQtUumvjyHgek jA+d6kWP1yFm02xQ77jS4VwVFe3H/lUR403kI= MIME-Version: 1.0 In-Reply-To: <4E707C05.70103@swing.be> References: <4E70416E.5090208@swing.be> <4E70621B.2000408@swing.be> <4E706952.8000201@swing.be> <4E707C05.70103@swing.be> Date: Wed, 14 Sep 2011 20:51:37 +0100 Subject: Re: ANN: unpyc3 - a python bytecode decompiler for Python3 From: Arnaud Delobelle To: Vincent Vande Vyvre Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 95 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1316029901 news.xs4all.nl 2415 [2001:888:2000:d::a6]:57059 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13283 On 14 September 2011 11:03, Vincent Vande Vyvre wrote: > Le 14/09/11 11:31, Arnaud Delobelle a =C3=A9crit=C2=A0: [...] > Could you show me what you do to get this error? Thank you, > [vincent@myhost unpyc3]$ python > Python 3.2.1 (default, Jul 11 2011, 12:37:47) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from unpyc3 import decompile >>>> print (decompile("shredder.pyc")) > Traceback (most recent call last): > =C2=A0 File "", line 1, in > =C2=A0 File "unpyc3.py", line 110, in decompile > =C2=A0=C2=A0=C2=A0 return dec_module(obj) > =C2=A0 File "unpyc3.py", line 99, in dec_module > =C2=A0=C2=A0=C2=A0 code =3D Code(code_obj) > =C2=A0 File "unpyc3.py", line 211, in __init__ > =C2=A0=C2=A0=C2=A0 for v in code_obj.co_cellvars + code_obj.co_freevars] > AttributeError: 'NoneType' object has no attribute 'co_cellvars' >>>> print (decompile("unpyc3.pyc")) > Traceback (most recent call last): > =C2=A0 File "", line 1, in > =C2=A0 File "unpyc3.py", line 110, in decompile > =C2=A0=C2=A0=C2=A0 return dec_module(obj) > =C2=A0 File "unpyc3.py", line 99, in dec_module > =C2=A0=C2=A0=C2=A0 code =3D Code(code_obj) > =C2=A0 File "unpyc3.py", line 211, in __init__ > =C2=A0=C2=A0=C2=A0 for v in code_obj.co_cellvars + code_obj.co_freevars] > AttributeError: 'NoneType' object has no attribute 'co_cellvars' >>>> import os >>>> os.path.isfile("shredder.pyc") > True >>>> os.path.isfile("unpyc3.pyc") > True >>>> > > it seems the return of marshal.load(stream) is None I think the reason may be that your unpyc3.pyc and shredder.pyc files were compiled with a different version of python and the read_code function returns None because the magic number in the .pyc file is incorrect because of these two lines: if magic !=3D imp.get_magic(): return None I have now changed this so that it loads the file anyway but prints a warning. I guess this may break badly though. In Python 3.2, .pyc files are "hidden" in a __pycache__ directory. So the Python 3.2 specific unpyc3.pyc file for example is probably located at .../unpyc3/__pycache__/unpyc3-cpython-32.pyc The easiest way to find the path of the .pyc file if you know the path of the .py file is probably as follows: >>> import imp >>> imp.cache_from_source("unpyc3.py") '__pycache__/unpyc3.cpython-32.pyc' Here's an example decompiling the dis module from the standard library: >>> import dis >>> dis.__file__ '/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/dis.py' >>> imp.cache_from_source(dis.__file__) '/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/__pycache_= _/dis.cpython-32.pyc' >>> print(decompile(_)) __doc__ =3D 'Disassembler of Python byte code into mnemonics.' import sys import types from opcode import * from opcode import __all__ as _opcodes_all __all__ =3D ['code_info', 'dis', 'disassemble', 'distb', 'disco', 'findlinestarts', 'findlabels', 'show_code'] + _opcodes_all del _opcodes_all _have_code =3D types.MethodType, types.FunctionType, types.CodeType, type def _try_compile(source, name): try: c =3D compile(source, name, 'eval') except SyntaxError: c =3D compile(source, name, 'exec') return c [... many more lines ...] I hope this will work for you, --=20 Arnaud PS: I've also added support for the IMPORT_STAR opcode which I had overlook= ed.