in reply to Obfuscating method calls

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