I'm writing the chapter in Mastering Perl on cleaning up source code, so I figured I'd look at some code obfuscators. I'm sure other people will have stories to tell.
The most stupid obfuscators just get rid of whitespace. perltidy clears that right up.
The oddest one I found looked like it did a lot of stuff, but the last statement in the file was always
"eval($foo)"
. I changed the eval() to
print()
and there's the program. A slightly fancier one had several rounds of that. Still, I had the source in two minutes, and that's just doing it manually.
I'm thinking, just for the heck of it, creating some de-obfuscators just to put in the book.
de-obfuscators (Score:1)
perl -MO=Deparse obfuscated.pl
Re: (Score:2)
Re: (Score:1)
Override
CORE::GLOBAL::evalto print/save the code before running it?Re: (Score:1)
I just didn't get around to it.
B::Deobfuscate (Score:1)
I assume you've come across B::Deobfuscate [cpan.org]?
It was caused by a rather entertaining thread on perlmonks a few years back :-)
Re: (Score:2)
Re: (Score:1)
Re: (Score:2)
I could just delete the one that's already there, but something else keeps installing it.
Re: (Score:1)
Re: (Score:1)
Re: (Score:2)
Re: (Score:1)
-MO=Deobfuscate,-DFlowers
B::Deobfuscate->new( -DFlowers )
If you want to obfuscate... (Score:1)
The whole goal is information extraction, to remove anything that humans need for maintenance that the machine isn't going to need at run-time. But there's only so much of that you can do.
I can see some PPI-based functionality coming down the line eventually to munge the names of lexical scalars, but beyond that I honestly can't think of much you
Re:If you want to obfuscate… (Score:1)
You can do more. Besides removing information a human needs, you can also do the following:
In each scope, assign all variables from outer scopes that are used to new variables, so it becomes harder to track what is being modified where.
If you can analyse the source code sufficiently well, you could even introduce global variables used in multiple places as the new location for values.
Inline constants, except for a few instances. Fold most c
Re:If you want to obfuscate… (Score:1)
> would be hard to implement for Perl because the language is impossible
> to parse, whereas it would be easy to abuse the refactoring tools in
> Eclipse to automatically obfuscate Java.
Which is kind of what I meant by that being all we can do.
It's not that it's impossible in the general case, it's just that WE (Perl) can't do them. Or at least, we can't do many.