Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Careful Evaluation

by iamcal (Friar)
on Jun 14, 2001 at 18:47 UTC ( #88437=obfuscated: print w/replies, xml ) Need Help??

A bit of a silly one. I dare somebody to deconstruct it :)
$$=q{$_=unpack'u',q|L)%\]<2$D7STG<')I;G0@(DIU<W0@86YO=&AE<B! 097)L(&AA8VME<B(G(3L`|;};$}=q{$_=unpack'u',q|<)%\])R1?/7$A*" 1?*3TH)"0]?B\N*B]G*2$G.P``|;};$$=~s;\n;;g;$;=q;$_=$};;$_='$_ =$;;';$}=~s;\n;;g; eval;eval;eval;eval;eval;eval;eval;eval;eval;eval;

Replies are listed 'Best First'.
Re: Careful Evaluation
by VSarkiss (Monsignor) on Jun 15, 2001 at 00:49 UTC
    All right, nobody else has, so I'll take the bait. ;-)

    For those who may not have seen them before (*cough* young whipper-snappers), uuencode and uudecode are encoding and decoding mechanisms that were originally developed to allow transmitting binary files via uucp over lines that were not always eight-bit-clean. Just like MIME.

    Now, on to the real decode. I've separated the lines to make them a little easier to read.

    # # Set $$ -- usually the PID of the running Perl, but not a read-only # variable -- to a strange string: first part looks like code, # but latter half looks like junk. If you uudecode the junk (minus # the embedded newline) you get: # # $_=q!$_='print "Just another Perl hacker"'!; # $$ = q{$_=unpack'u',q|L)%\]<2$D7STG<')I;G0@(DIU<W0@86YO=&AE<B! 097)L(&AA8VME<B(G(3L`|;}; # # Set $} -- another strange variable -- to another strange string. # This time the uuencoded part (again minus \n) is # # $_='$_=q!($_)=($$=~/.*/g)!'; # $} = q{$_=unpack'u',q|<)%\])R1?/7$A*" 1?*3TH)"0]?B\N*B]G*2$G.P``|;}; # # The next few lines remove embedded newlines in $$ and $} (first # and fourth lines), and set these variables to these values: # $; $_=$}; (second line) # $_ $_\n=$;; (third line, including embedded newline) # $$=~s;\n;;g; $;=q;$_=$};; $_='$_ =$;;'; $}=~s;\n;;g; # # Each of these evals executes the code in $_. Before the first, # $_ contains "$_\n=$;;" as shown above. Here are the values of $_ # after each eval completes. # eval; # $_=$}; eval; # $_=unpack'u',q|<)%\\])R1?/7$A*"1?*3TH)"0]?B\\N*B]G*2$G.P``|; eval; # $_='$_=q!($_)=($$=~/.*/g)!'; eval; # ($_)=($$=~/.*/g) # BTW, the parens and "=~ /.*/g" do nothing. # Executing this is the same as "$_ = $$". eval; # $_=unpack'u',q|L)%\\]<2$D7STG<\')I;G0@(DIU<W0@86YO=&AE<B!097)L(& +AA8VME<B(G(3L`|; eval; # $_=q!$_='print "Just another Perl hacker"'!; eval; # $_='print "Just another Perl hacker"' eval; # print "Just another Perl hacker" eval; # The final eval just executes the contents of $_ seen above. eval;
    BTW, if you try to execute this in the debugger, beware: setting $$ causes it to fork. Fiendishly clever!
Re: Careful Evaluation
by Brovnik (Hermit) on Jun 15, 2001 at 01:07 UTC
    I dare somebody to deconstruct it :)

    OK. First, tidy up syntax and delimiters and rename some variables.

    $$ = q{$_=unpack'u',q|L)%\]<2$D7STG<')I;G0@(DIU<W0@86YO=&AE<B!097)L(&A +A8VME<B(G(3L`|;}; $b = q{$_=unpack'u',q|<)%\])R1?/7$A*"1?*3TH)"0]?B\N*B]G*2$G.P``|;}; #$$ =~ s/\n//g; $a = '$_=$b'; $_ = '$_=$a'; #$} =~ s/\n//g; eval; eval; eval; eval; eval; eval; eval; eval; eval; eval;
    The commented lines aren't needed if the q|| are on one line.

    So, (this is easier to read starting from the bottom of the tidied code) the first 3 evals set $_ to $a and then $b then eval the unpack inside $b.

    The unpack produces $_='$_=q!($_)=($$=~/.*/g)!';, which, after 3 more iterations sets $_ to $$ (the unpack on the first line).
    This unpack sets $_=q!$_='print "Just another Perl hacker"'!;, which, after another 2 iterations gives us the familiar
    print "Just another Perl hacker" which duly evals.

    Hope that is sufficient explanation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://88437]
Approved by root
[Corion]: Maybe Merck Pharma has? ;-)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (17)
As of 2017-05-25 14:03 GMT
Find Nodes?
    Voting Booth?