Permalink
Browse files

* decompyle: add the version that sorta supports python 2.5 bytecode.

  • Loading branch information...
1 parent a4a14d9 commit 66aad35513f42db8e91f7a77ca1b5401e9a17431 _why committed May 5, 2008
Showing with 77,691 additions and 0 deletions.
  1. +94 −0 decompyle/CHANGES
  2. +125 −0 decompyle/README
  3. +17 −0 decompyle/TODO
  4. +582 −0 decompyle/decompyle/Parser.py
  5. +207 −0 decompyle/decompyle/Scanner.py
  6. +841 −0 decompyle/decompyle/Walker.py
  7. +225 −0 decompyle/decompyle/__init__.py
  8. +253 −0 decompyle/decompyle/dis_15.py
  9. +284 −0 decompyle/decompyle/dis_16.py
  10. +303 −0 decompyle/decompyle/dis_20.py
  11. +320 −0 decompyle/decompyle/dis_21.py
  12. +327 −0 decompyle/decompyle/dis_22.py
  13. +227 −0 decompyle/decompyle/dis_23.py
  14. +223 −0 decompyle/decompyle/dis_25.py
  15. +44 −0 decompyle/decompyle/dis_files.py
  16. +46 −0 decompyle/decompyle/magics.py
  17. +868 −0 decompyle/decompyle/marshal_20.c
  18. +868 −0 decompyle/decompyle/marshal_22.c
  19. +882 −0 decompyle/decompyle/marshal_23.c
  20. +1,161 −0 decompyle/decompyle/marshal_25.c
  21. +30 −0 decompyle/decompyle/marshal_files.py
  22. +529 −0 decompyle/decompyle/new-Parser.py
  23. +188 −0 decompyle/decompyle/opcode_23.py
  24. +185 −0 decompyle/decompyle/opcode_25.py
  25. +370 −0 decompyle/decompyle/optimizer.py
  26. +630 −0 decompyle/decompyle/peephole.c
  27. +569 −0 decompyle/decompyle/spark.py
  28. +222 −0 decompyle/decompyle/verify.py
  29. +97 −0 decompyle/scripts/decompyle
  30. +21 −0 decompyle/setup.py
  31. +76 −0 decompyle/test/compile_tests
  32. +30 −0 decompyle/test/test_applyEquiv.py
  33. +55 −0 decompyle/test/test_augmentedAssign.py
  34. +43 −0 decompyle/test/test_class.py
  35. +35 −0 decompyle/test/test_del.py
  36. +6 −0 decompyle/test/test_divide_future.py
  37. +6 −0 decompyle/test/test_divide_no_future.py
  38. +41 −0 decompyle/test/test_docstring.py
  39. +1 −0 decompyle/test/test_empty.py
  40. +107 −0 decompyle/test/test_exceptions.py
  41. +13 −0 decompyle/test/test_exec.py
  42. +13 −0 decompyle/test/test_expressions.py
  43. +18 −0 decompyle/test/test_extendedImport.py
  44. +14 −0 decompyle/test/test_extendedPrint.py
  45. +65,547 −0 decompyle/test/test_extendedarg.py
  46. +58 −0 decompyle/test/test_functions.py
  47. +26 −0 decompyle/test/test_global.py
  48. +18 −0 decompyle/test/test_globals.py
  49. +21 −0 decompyle/test/test_import.py
  50. +23 −0 decompyle/test/test_import_as.py
  51. +33 −0 decompyle/test/test_integers.py
  52. +11 −0 decompyle/test/test_iterators.py
  53. +16 −0 decompyle/test/test_lambda.py
  54. +36 −0 decompyle/test/test_listComprehensions.py
  55. +48 −0 decompyle/test/test_loops.py
  56. +20 −0 decompyle/test/test_loops2.py
  57. +32 −0 decompyle/test/test_misc.py
  58. +89 −0 decompyle/test/test_nested_elif.py
  59. +95 −0 decompyle/test/test_nested_scopes.py
  60. +139 −0 decompyle/test/test_prettyprint.py
  61. +16 −0 decompyle/test/test_print.py
  62. +21 −0 decompyle/test/test_print_to.py
  63. +1 −0 decompyle/test/test_single_stmt.py
  64. +43 −0 decompyle/test/test_slices.py
  65. +24 −0 decompyle/test/test_tuple_params.py
  66. +25 −0 decompyle/test/test_tuples.py
  67. +22 −0 decompyle/test/test_yield.py
  68. +16 −0 decompyle/test_one
  69. +115 −0 decompyle/test_pythonlib
View
@@ -0,0 +1,94 @@
+release 2.3.2
+ - tidied up copyright and changelog information for releases 2.3 and later
+
+release 2.3.1 (Dan Pascu)
+ - implemented a structure detection technique that fixes problems with
+ optimised jumps in Python >= 2.3. In the previous release (decompyle 2.3),
+ these problems meant that some files were incorrectly decompiled and others
+ could not be decompiled at all. With this new structure detection
+ technique, thorough testing over the standard python libraries suggests
+ that decompyle 2.3.1 can handle everything that decompyle 2.2beta1 could,
+ plus new Python 2.3 bytecodes and constructs.
+
+release 2.3 (Dan Pascu)
+ - support for Python 2.3 added
+ - use the marshal and disassembly code from their respective python
+ versions, so that decompyle can manipulate bytecode independently
+ of the interpreter that runs decompyle itself (for example it can
+ decompile python2.3 bytecode even when running under python2.2)
+
+release 2.2beta1 (hartmut Goebel)
+ - support for Python 1.5 up to Python 2.2
+ - no longer requires to be run with the Python interpreter version
+ which generated the byte-code.
+ - requires Python 2.2
+ - pretty-prints docstrings, hashes, lists and tuples
+ - decompyle is now a script and a package
+ - added emacs mode-hint and tab-width for each file output
+ - enhanced test suite: more test patterns, .pyc/.pyo included
+ - avoids unnecessary 'global' statements
+ - still untested: EXTENDED_ARG
+
+ internal changes:
+ - major code overhoul: splitted into several modules, clean-ups
+ - use a list of valid magics instead of the single one from imp.py
+ - uses copies of 'dis.py' for every supported version. This ensures
+ correct disassemling of the byte-code.
+ - use a single Walker and a single Parser, thus saving time and memory
+ - use augmented assign and 'print >>' internally
+ - optimized 'Walker.engine', the main part of code generation
+
+release 0.6.0: (hartmut Goebel)
+ - extended print (Python 2.0)
+ - extended import (Python 2.0) (may not cover all cases)
+ - augmented assign (Python 2.0) (may not cover all cases)
+ - list comprehensions (Python 2.0)
+ - equivalent for 'apply' (Python 1.6)
+ - if .. elif .. else are now nested as expected
+ - assert test, data
+ - unpack list corrected (was the same as unpack tuple)
+ - fixed unpack tuple (trailing semicolon was missing)
+ - major speed up :-)
+ - reduced memory usage (pre-alpha-0.5 has increased it a lot)
+ - still missing: EXTENDED_ARG
+
+pre-alpha-0.5: (hartmut Goebel)
+ - *args, **kwargs
+ - global
+ - formal tuple parameters (eg. def a(self, (x,y,z)) )
+ - actual lambda parameters (eg. X(lambda z: z**2) )
+ - remove last 'return None' in procedures
+ - remove last 'return locals()' in class definitions
+ - docstrings
+
+pre-alpha-0.4: (hartmut Goebel)
+ - assert
+ - try/except/finally
+ - parentheses in expressions
+ - nested expressions
+ - extracted dissassemble() from module dis and
+ removed ugly redirect of stdout, thus saved a lot of
+ ugly code and a lot of memory
+
+pre-alpha-0.3: (hartmut Goebel)
+ - keyword arguments
+ - some boolean expressions
+ - and/or
+ - complex conditions in if/while
+ - read byte-code from .pyc without importing
+ - access to the body of classes and modules
+ - class and function definitions
+ - a = b = c = xxx
+
+pre-alpha-0.1 -> pre-alpha-0.2:
+ - SET_LINENO filtered out in lexer now
+ - added support for subscripts (just for Christian Tismer :-)
+ - fixed bug with handling of BUILD_{LIST,TUPLE} & CALL_FUNCTION
+ - dict-building support
+ - comparison support
+ - exec support
+ - del support
+ - pass support
+ - slice support
+ - no more extraneous (albeit legal) commas
+ - finally, it excepts try [sic] but not all 42 variations of it
View
@@ -0,0 +1,125 @@
+
+ decompyle -- A Python byte-code decompiler
+ 2.3
+ 2004-12-12
+
+Introduction
+------------
+
+'decompyle' converts Python byte-code back into equivalent Python
+source. It accepts byte-code from any Python version starting with 1.5
+up to 2.3.
+
+The generated source is very readable: docstrings, lists, tuples and
+hashes get pretty-printed.
+
+'decompyle' may also verify the equivalence of the generated source by
+by compiling it and comparing both byte-codes.
+
+'decompyle' is based on John Aycock's generic small languages compiler
+'spark' (http://www.csr.uvic.ca/~aycock/python/) and his prior work on
+'decompyle'.
+
+Additional note (3 July 2004, Ben Burton):
+
+ The original website from which this software was obtained is no longer
+ available. It has now become a commercial decompilation service, with
+ no software available for download.
+
+ Any developers seeking to make alterations or enhancements to this code
+ should therefore consider these debian packages an appropriate starting
+ point.
+
+Features
+--------
+
+ * decompyles Python byte-code into equivalent Python source
+
+ * decompyles byte-code from Python versions 1.5 up to 2.3
+
+ * pretty-prints docstrings, hashes, lists and tuples
+
+ * supports an option for verifing the generated Python source is
+ equivalent to the byte-code. This is done by compiling the
+ generated source and comparing both byte-codes.
+
+ * decompyles and successfully verifies 100% of the Python 1.5, 2.0,
+ 2.1 and 2.2 library
+
+ * decompyles and successfully verifies 100% of the Python 1.5
+ library, including lib-stdwin, lib-tk, gnome and gtk.
+
+ * reads directly from .pyc/.pyo files, bulk-decompyle whole
+ directories
+
+ * output may be written to file, a directory or to stdout
+
+ * option for including byte-code disassembly into generated source
+
+ * If translation fails, the part causing the problem is output. This
+ helps improofing 'decompyle'. If this happens to you, please
+ contact the author.
+
+ For a list of changes please refer to the 'CHANGES' file.
+
+
+Requirements
+------------
+
+'decompyle' requires Python 2.2 or later.
+
+
+Installation
+------------
+
+You may either create a RPM and install this, or install directly from
+the source distribution.
+
+Creating RPMS:
+
+ python setup.py bdist_rpm
+
+ If you need to force the python interpreter to eg. pyton2:
+ python2 setup.py bdist_rpm --python=python2
+
+
+Installation from the source distribution:
+
+ python setup.py install
+
+ To install to a user's home-dir:
+ python setup.py install --home=<dir>
+
+ To install to another prefix (eg. /usr/local)
+ python setup.py install --prefix=/usr/local
+
+ If you need to force the python interpreter to eg. pyton2:
+ python2 setup.py install
+
+ For more information on 'Installing Python Modules' please refer to
+ http://www.python.org/doc/current/inst/inst.html
+
+
+Usage
+-----
+
+decompyle -h prints short usage
+decompyle --help prints long usage
+
+
+Known Bugs/Restrictions
+-----------------------
+
+* EXTENDED_ARG token is untested (this is a new token for Python 2.0
+ which is used only if many items exist within a code object).
+
+* Verifying decompyled source with optizimzed byte code (.pyo) when
+ running without optimizations (option '-O' not given) fails in most
+ cases. Same is true for vis-a-versa. This is due to the fact that
+ Python generated different bytecode depending on option '-O'.
+
+
+* Python 2.2 generated different byte-code than prior version for the
+ same source. This is due the intruduction of iterators. Currently
+ 'decompyle' fails verifying this source if the byte-code was
+ generated by an older version of Python.
View
@@ -0,0 +1,17 @@
+TODO-list decompyle
+
+For Release 2.2:
+easy:
+- add options for tabwidth, TAB, etc.
+- Check whether decompyle can read 1.6 and 2.0 bytecode
+medium:
+- find out how to verify optimized bytecode (.pyo)
+- extend test_nested_scopes with parts form cgitb.html()
+- test EXTENDED_ARG -> how?
+hard:
+- try to find a way to verify 'for ...' if byte-code is generated by
+ older versions of Python.
+
+Planned for future releases:
+- use weak references in Parser to save memory (maybe)
+- avoid unnecessary parentesis in expressions
Oops, something went wrong.

0 comments on commit 66aad35

Please sign in to comment.