Skip to content

Tips for creating bytecode to foil uncompyle6

R. Bernstein edited this page Sep 22, 2017 · 5 revisions

I suspect a large use case for uncompyle6 is to reverse engineer Python bytecode where source isn't given.

So here are some tips for people who want to foil uncompyle6.

Use a non-final release bytecode.

uncompyle6 works off of final release bytecode within a release. So there are intermediary bytecodes that uncompyle doesn't support. Python 3.6 is a good case in point. For Python 3.6.0a1 3 different magic numbers were used and that reflected slight differences in Python bytecode. So a number of Python 3.6.0a1 release won't work with uncompyle6.

Use a python bytecode obfuscator

As mentioned in README.md the PJOrion obfuscated code won't work as is.

If you have a file with say 32,000 assignment statements that will slow down uncompyle6. I have a possible patch for that but I'm not sure it works well. (Note though that pycdc doesn't suffer from this problem.)

Use complex control flow

Right now detecting control flow is difficult and too often wrong with complex nested if's and and's with exception handling.

Python has these weird "else" form on try, for, and while statements. pyuncdc might not support them and uncompyle6 often gets horribly confused by these.

Write custom Python bytecode

uncompyle6 goes off of patterns in compiler-generated bytecode. I suspect that if you wrote python bytecode from scratch or changed even a little portion of it, that would fool the decompiler when those patterns are different.

Tip to foil those who would foil uncompyle6

Beef up the code to address all of its weaknesses.