Decompile python2.5-pyc

skip at pobox.com skip at pobox.com
Mon Sep 15 20:49:06 EDT 2008


>>>>> "Manuel" == Manuel Ebert <maebert at uos.de> writes:

    Manuel> Does anybody know something I don't, some home-brewn decompiler,
    Manuel> anything? I *am* quite desperate...

Well...  If you have some time and are desperate, you might try importing
the module(s) then disassembling them with the dis module.  The output will
still be Python's virtual machine assembly, but at least it will be sort of
readable.  You might be able to manually translate it back to the equivalent
Python source code.  For example:

    >>> def f(a):
    ...   a.append(7)
    ...   if len(a) > 5:
    ...     del a[0]
    ... 
    >>> import dis
    >>> dis.dis(f)
      2           0 LOAD_FAST                0 (a)
                  3 LOAD_ATTR                0 (append)
                  6 LOAD_CONST               1 (7)
                  9 CALL_FUNCTION            1
                 12 POP_TOP             

      3          13 LOAD_GLOBAL              1 (len)
                 16 LOAD_FAST                0 (a)
                 19 CALL_FUNCTION            1
                 22 LOAD_CONST               2 (5)
                 25 COMPARE_OP               4 (>)
                 28 JUMP_IF_FALSE           11 (to 42)
                 31 POP_TOP             

      4          32 LOAD_FAST                0 (a)
                 35 LOAD_CONST               3 (0)
                 38 DELETE_SUBSCR       
                 39 JUMP_FORWARD             1 (to 43)
            >>   42 POP_TOP             
            >>   43 LOAD_CONST               0 (None)
                 46 RETURN_VALUE        

Skip



More information about the Python-list mailing list