liftoff / pyminifier

Pyminifier is a Python code minifier, obfuscator, and compressor.
GNU General Public License v3.0
1.45k stars 223 forks source link

Variables in Lambdas are not minified #63

Open Levanth opened 8 years ago

Levanth commented 8 years ago

I tried pyminifier with a file which has some lambdas and it won't minify them:

test=lambda first,second,third: first + second + third
print(test(2,6,8))

After I use pyminifier -O -o myfile_min.py myfile.py I get

A=lambda first,second,third:first+second+third
q=print
q(A(2,6,8))
sejans commented 8 years ago

My guess is that this kind of one liners was not mandatory to obfuscate, because anyway the keyword lambda is builtin and can be found, and all the following params are local to this lambda, so its easy to decode.

However if you think that its important even for these situations I made a fix for this, so now your code will be obfuscated for example to this one:

F=lambda Y,M,t:Y+M+t
print(F(2,6,8))

or in non-latin

䪟ﲬề=lambda 䪟ﲬ蚟,䪟ﲬ铃,䪟ﲬۉ:䪟ﲬ蚟+䪟ﲬ铃+䪟ﲬۉ
print(䪟ﲬề(2,6,8))

Also the provided fix solves the problem to the following code (which without it wasnt obfuscated, because there are no operations and its like one liner function:

def the_function(the_first, the_second, the_third=None, the_fourth=5):
    return the_first + the_second + the_third

Its now

䪟ﲬ輔=None
def 䪟ﲬ굵(䪟ﲬޕ,䪟ﲬ䛠,the_third=䪟ﲬ輔,the_fourth=5):
 return 䪟ﲬޕ+䪟ﲬ䛠+the_third

Prior to fix it was (you can see params in obfucated version)

def the_function(the_first, the_second, the_third):
    return the_first + the_second + the_third

obfuscated to
def 奧ﯳﭴ(奧ﯳ鏝,the_second,the_third):
 return 奧ﯳ鏝+the_second+the_third