Below is a quick obfuscation script I wrote. That is, a script which obfuscates other scripts. The obfuscation isn't terribly good, but it's been successful in terms of keeping other peoples hands off of my code, which was the object in this case. Quite handy for those 700 line scripts that you don't want to obfuscate by hand. (Multi file scripts will need to be catted together before being run through the obfuscater.) Also, I have a question. I wonder if one of you obfuscation fans could give me a nice little obfuscation of this one line, such that I might add it to my automatically obfuscated script:
unless ($ENV{HTTP_HOST} ~= m/licensed_site.com/) {die "Code thief!"}
Of course, I need te be able to replace the domain name fairly easily. Perhaps a Perl one liner that obfuscates the string? Anyway, here's auto_obfuscate.pl:
#!/usr/bin/perl $debug = 0; my %varname; my $varnum = 0; my %subname; my $subnum; my $sub = 0; $infile = $ARGV[0]; open(IN, "<$infile"); @prog = <IN>; close IN; open(TIDY, "|perltidy --mangle -st"); foreach $line (@prog) { @token = split (/[^A-Za-z0-9_\$\@\%\\]+|\\./, "$line"); foreach $tok (@token) { if ("$tok" eq "sub") { $sub = 1; } elsif ($sub) { $subnum++; $sub = 0; if ($subname{$tok} eq "") { $subname{$tok} =~ s/[a-z0-9]*/s_$subnum/; } } } } foreach $line (@prog) { if ($debug) { print "$line"; } # "$first$last" comes out as one token, so split them $line =~ s/(\".*)(\$[A-Za-z0-9_\-]*)(\$[A-Za-z0-9_\-]*)(.*\")/\1\2\".\"\3\ +4/g; @token = split (/[^A-Za-z0-9_\$\@\%\\\#]+|\\./, "$line"); foreach $tok (@token) { if ($debug) { print "$tok:"; } if ($tok =~ m/[\$\@\%\#][a-z][a-z0-9]*/) { $oldname = "$tok"; $oldname =~ s/[\$\@\%\#]*//; if ($varname{$oldname} eq "") { $varname{$oldname} =~ s/[a-z0-9]*/v_$varnum/; $varnum++; } $line =~ s/([\$\%\@]#?)$oldname([^a-z0-9A-Z])/\1$varname{$old +name}\2/g; } } while (($oldname, $newname) = each %subname) { $line =~ s/$oldname([ \(\;])/$newname\1/g; $line =~ s/sub *$oldname([^a-zA-Z])/sub $newname\1/g; } $line =~ s/^\s*//g; unless (($line =~ m/^$/) || ($line =~ m/^#[^\!\-]/)) { $outline++; if ($debug) { print "\n$line\n\n"; } else { print TIDY "$line"; } } if ($line =~ m/[\$\@\%]\{[^v]/) { print STDERR "Warning: bracketed variable not changed line $outline:\n$line +"; } } print "\n\n"; close TIDY;

In reply to An obfuscation script, and a question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.