Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

J.A.P.H. with intentional eval failure

by ktross (Deacon)
on Feb 26, 2005 at 17:23 UTC ( [id://434794]=obfuscated: print w/replies, xml ) Need Help??

updated code:
$_='@26^37#30%5e.37%32%25^36@39@21.36%65%40#37!34^40@32!30!40#32.32@40 +%34#61#26@32%65^21#34#31%40@32%65@21#35@30@5e.32.65@25.34.38^25^32%65 +!21@32.30#23&35@63!2e!36^65.25@32^32^40!33&62';l:$a = undef;@_ = spli +t(/[\. # ! % & ^ @]/,$_);foreach $_(@_){$_=~ s/([a-fA-F0-9]{2})/chr(h +ex $1)/eg;$a = $a.$_;}$_ = $a;system(($^O eq 'MSWin32') ?'cls':'clear +');eval or goto l;
Here is my first attempt to obfuscate code. I basically took the code for printing J.A.P.H, converted its ascii to hex, and then took that ascii and converted it to hex. I wanted this program to work without knowing how many times the data had been converted. The only problem is that when the eval fails it prints text to the screen. It is removed with a cls/clear operation. Any ideas how to silence the eval warning? I tried 'no warnings' and it didn't work.
$_='%70^72#69.6e@74&20@22!4a&2e%20@41.2e.20.50!20!48&2e.5c@6e^22&3b@25 +!37!30^5e!37^32!23&36^39!2e^36%65%40@37#34!26%32!30^40^32^32!21#34.61 +#26#32!65^25!32^30@40!34&31@2e.32@65^2e#32&30^2e.35!30&21%32@30!21!34 +@38.26%32^65#2e@35&63!40&36#65!5e&32#32&26%33%62';l:$a = undef;@_ = s +plit(/[\. # ! % & ^ @]/,$_);foreach $_(@_){$_=~ s/([a-fA-F0-9]{2})/ch +r(hex $1)/eg;$a = $a.$_;}$_ = $a;system(($^O eq 'MSWin32')?'cls':'cle +ar');eval or goto l;

Replies are listed 'Best First'.
Re: J.A.P.H. with intentional eval failure
by K_M_McMahon (Hermit) on Feb 26, 2005 at 18:47 UTC
    Nice Job making the clear system independent! ++


    -Kevin
    my $a='62696c6c77667269656e6440676d61696c2e636f6d'; while ($a=~m/(^.{2})/s) {print unpack('A',pack('H*',"$1"));$a=~s/^.{2}//s;}
Re: J.A.P.H. with intentional eval failure
by jdalbec (Deacon) on Feb 27, 2005 at 01:24 UTC
    One option would be to close STDERR; at the top of your program. On my systems the initial eval does not fail because perl (v5.8.1-RC3 built for darwin-thread-multi-2level and v5.6.1 built for i386-linux) interprets %70^72#... as the hash named "70", xored with 72, followed by a comment. Or was the comment about eval failing misdirection on your part?

      If by 'misdirection' you mean "Gee it sure looks like you posted the wrong code..." then you are right on the money. I've updated it with one that does fail, as advertized, the first time through. It should be noted that this program does not actually eval the string on the first line without modifying it heavily. In the case of the old code something like 'print "J.A.P.H \n";%70^72#...' was being eval-ed. As you mention, that line is runnable.

      Anyways, I've been trying to figure out how to block error messages and STDOUT generated in functions used in my programs that were written by other people. 'close' seems to work great! Thanks! Do you know how to re-open STDERR and STOUT properly?

        perldoc -f open has examples. Basically you duplicate STDOUT and STDERR to other filehandles before closing them. Then you duplicate the saved filehandles back to STDOUT and STDERR.
        print "STDOUT #1\n";warn "STDERR #1\n"; open my $savestdout, '>&', \*STDOUT; print "STDOUT #2\n";warn "STDERR #2\n"; open my $savestderr, '>&', \*STDERR; print "STDOUT #3\n";warn "STDERR #3\n"; close STDOUT; print "STDOUT #4\n";warn "STDERR #4\n"; close STDERR; print "STDOUT #5\n";warn "STDERR #5\n"; open STDOUT, '>&', $savestdout; print "STDOUT #6\n";warn "STDERR #6\n"; open STDERR, '>&', $savestderr; print "STDOUT #7\n";warn "STDERR #7\n"; close $savestdout; print "STDOUT #8\n";warn "STDERR #8\n"; close $savestderr; print "STDOUT #9\n";warn "STDERR #9\n";
        OK, this is bizarre. When I re-open STDOUT, I get output from warn even though STDERR is still closed. perldoc -f warn doesn't describe this behavior.
Re: J.A.P.H. with intentional eval failure
by Anonymous Monk on Feb 28, 2005 at 16:29 UTC
    I took the liberty of shortening your Japh, while getting rid of the need to clear the screen. It does keep the logic though:
    $_='@26^37#30%5e.37%32%25^36@39@21.36%65%40#37!34^40@32!30!40#32.32@40 +%34#61#26@32%65^21#34#31%40@32%65@21#35@30@5e.32.65@25.34.38^25^32%65 +!21@32.30#23&35@63!2e!36^65.25@32^32^40!33&62';$"=$';close STDERR;l:s +plit/\W/;s/[a-f0-9]{2}/chr(hex$&)/eg for@_;$_="@_";eval||goto l

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://434794]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-25 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found