Not sure if this fits the bill, but it might be of interest nonetheless
package Filter::ObfuMethods; use Exporter::Tidy default => [ 'filter' ]; use Crypt::Rot13; use vars '%methods'; sub filter { my $code = pop; my(@calls) = $code =~ m{ \$? \w+ \s* -> \s* (\w+) }gx; @methods{map crypt_method($_), @calls} = @calls; $code =~ s{ ( \$? \w+ \s* -> \s* ) $methods{$_} } ($1\${\\\$Filter::ObfuMethods::methods{"$_"}})gx for keys %methods; return $code; } sub crypt_method { my $c = Crypt::Rot13->new; $c->charge(shift); return $c->rot13(6); } q[the end];
And some code
use Filter::ObfuMethods; my $code = <<'CODE'; sub foo { print "in foo\n" } sub bar { print "in bar\n" } main->foo; main -> bar(); my $o = bless []; $o->foo(); $o -> bar; CODE print filter($code); eval filter($code); warn "ack - $@" if $@; __output__ sub foo { print "in foo\n" } sub bar { print "in bar\n" } main->${\$Filter::ObfuMethods::methods{"luu"}}; main -> ${\$Filter::ObfuMethods::methods{"hgx"}}(); my $o = bless []; $o->${\$Filter::ObfuMethods::methods{"luu"}}(); $o -> ${\$Filter::ObfuMethods::methods{"hgx"}}; in foo in bar in foo in bar
Ok, it's not terrifically obfuscated (rot13 not being the most secure of obfuscation methods) but it's something ;) It also needs to have more rigorous regex matching if it's going to be used on any old code and probably not delivered in it's current form and many other tweaks besides.
HTH

_________
broquaint


In reply to Re: Obfuscating method calls by broquaint
in thread Obfuscating method calls by diotalevi

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.