[Announce] pyobfuscate

steve smtwfs0 at yahoo.com.au
Wed Feb 18 22:01:53 EST 2004


Peter Astrand <peter at cendio.se> wrote in message news:<mailman.64.1077030517.31398.python-list at python.org>...
> I've written a Python source code obfuscator. The project home page is
> http://www.lysator.liu.se/~astrand/projects/pyobfuscate/. I'm including a
> copy of the README file below.
<snip>

I love pyobfuscate!!!!  Well done.

I have an idea to make it even more evil:
Replace all constants with variables.
This means that you need to define the
variables with the constants above.
This should be as complicated as possible
and hidden within all of the 'if 1 - 1:' lines.

eg
def double_x(x):
    return x * 2

becomes:

# start with a few lines of confusing many digit
# integers to set up some starting variables
if 100111001 - 10011001: i1II11 = 36
    # true -> really set
if 1011001 - 1011001: o00O0o = "bu"
    # false -> not set
if 10111101 - 1011101: i1II11 = 108
    # false -> not reset - still 36
if 100111001 - 10011001: i1II11 = 18
    # true -> really reset
    # => this prevents anyone from doing
    # a global replace of i1II11 with 36

# after you have a few variables to play
# with use them instead of integers
if i1II11 - oOO0ooOO: oo00 = i1II11 / ooOO00

# (assuming ooOOoOo == iiiIii11 and OOOooo00 == 2)
# eventually you get to:
def oooOOooOO (iiI11I1i):
    if ooOOoOo - iiiIii11: return iiI11I1i * oo00
    else: return iiIII11I1i * OOOooo00
    # okay maybe the bogus return is overdoing it ;)

Of course this is all interspersed with the classes
and functions above the one you are interested in.
This also has a major benefit of preventing anyone
from just deleting all of the 'if 27 - 27:' lines.

To make it even more evil include a few lists,
this enables you to change numbers using other
references.
eg (assuming ii == 1 and oo = 0)

if ii - oo: II = [o0, i1]
...
if oo - ii: OO = II
...
if ii - oo: OO[oo] = iI
...
if oo - ii: iii = II[oo]    # now iii == iI

Also I don't understand why you don't obfuscate
the parameters of methods.  Shouldn't they be
the same as the parameters of global functions?
(Sorry I am a bit of a newbie,
 so I may be missing something.)

A potential way to obfuscate method names while
keeping the original name would be to define the
method with an obfuscated name and then to set
the proper name to the obfuscated name.
eg

class a:
    def __init__():
        pass

becomes

class iIiIiI:
    def oOoOoO(ii111II):
        pass
    __init__ = oOoOoO

And if you use some list references set up before the
class definition like above then it would be murder
to find which definition went with which name.

class iIiIiI:
    def oOoOoO(ii111II):
        pass
    OO[ii] = oOoOoO
    __init__ = II[ii]

Ah, this has got so much potential...

Steve



More information about the Python-list mailing list