Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Writing highly obfuscated code in Perl

by cLive ;-) (Parson)
on Mar 14, 2001 at 20:19 UTC ( #64414=note: print w/ replies, xml ) Need Help??


in reply to Writing highly obfuscated code in Perl

This is the shell of what I use. I actually build %replace_key manually. This version only works if you ensure that all subs and vars are unlikely to appear as words (or part of word) you print. Eg, don't use a var called $time if your script outputs something like:

print "The time is $time\n";
OK, here's the meat (unobfuscated, and well commented :)...
#!/usr/bin/perl use strict; print "Enter path to script: "; my $script_path = (<STDIN>); # read in script open (SCRIPT, $script_path) || die("Can't find script $script_path - $ +!"); my $script_text = join '', (&lt;SCRIPT&gt;); close(SCRIPT); my %replace_key; # read in vars of at least 2 chars - well, I always use $i anyway :) while ($script_text =~ /\$(\w\w+)/gs) { $replace_key{$1} = 1; } # read in subs while ($script_text =~ /sub (\w+)/gs) { $replace_key{$1} = 1; } my $i=1; for (keys %replace_key) { my $replace = unpack ("B32", pack("N", $i)); # get binary of $i $replace =~ s/^0+(?=\d)//; # remove trailing zer +oes $replace =~ s/0/I/g; # change 0 -> I $replace =~ s/1/l/g; # change 1 -> l (lowe +rcase L) $i++; $script_text =~ s/$_/$replace/gs; # obfuscate } # remove extraneous CRs $script_text =~ s/;\s*\n\s*/;\n/gis; # now screw up tab spacing $script_text =~ s/\t+/"\t" x (int(rand 6))/ges; # take a look at your handywork print $script_text; exit(0);
Depending on the consistancy of your coding style, you can add other obfuscations. EG, I always mark comments as:
# ## comment
so I can rip them all out with
s/# ##[^\n]+\n\s*/\n/g;
I also use the following:
s/\{/n/ /g; s/\}\s+elsif/} elsif/g; s/;\s+my/; my/g;
That leaves your code totally readable, but when you run it through the obfuscater and let it loose... ;-)

Any othet s/obfuscation/pattern/ suggestions welcomed :)

later

cLive ;-)


Comment on Re: Writing highly obfuscated code in Perl
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://64414]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-08-20 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls