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 '', (<SCRIPT>);
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 ;-)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.