Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to (ab)use sort

by Grimy (Monk)
on Apr 17, 2012 at 08:56 UTC ( #965457=obfuscated: print w/ replies, xml ) Need Help??

sort is, like, the single most abusable function in all of Perl. Seriously, side effects in the sorting code!
use strict; use warnings;()= sort{index+0x47,&$a($b)}sub{print&{;pop}}, sort{sub J{$!++&1}[0]}sub{exec''},map{@$_} sort{sub _{[(pop)x((1<<$!-->>47)|1)]}!{()= sort{my$_=$a;$a=_(sub{$_})if!/0/}$a,$b,0}} sort J('rke%ca hlrPe rhetoan tus;J')=~/./g
Obviously, this code depends on the internal, unspecified implementation of sort. I only tested it on Strawberry Perl 5.14.2 (64 bits); please let me know whether it works anywhere else. Edit: minor code improvements.

Comment on How to (ab)use sort
Download Code
Re: How to (ab)use sort
by moritz (Cardinal) on Apr 17, 2012 at 09:04 UTC
    $ perl -v|head -n2 This is perl 5, version 14, subversion 1 (v5.14.1) built for x86_64-li +nux $ perl obfu.pl Just another Perl hacker,Unknown warnings category 'CODE(0x1151998)' a +t obfu.pl line 6 BEGIN failed--compilation aborted at obfu.pl line 9.

    (with a pretty long pause after Just another Perl hacker,).

      Similar behaviour (plus a zero printed) in 5.10.1 for i486-linux-gnu-thread-multi.
        Thanks for the feedback :) Well, at least it prints what it's supposed to print before dying. s/use warnings/use warnings;@;=/ should fix this (both versions work with Strawberry, and the @;= version sounds less like an exploit).
Re: How to (ab)use sort
by biohisham (Priest) on Apr 22, 2012 at 16:33 UTC
    bioslayer@bioslayer:~/Desktop/Development/test$ perl - use strict; use warnings;()= sort{index+0x47,&$a($b)}sub{print&{;pop}}, sort{sub J{$!++&1}[0]}sub{exec''},map{@$_} sort{sub _{[(pop)x((1<<$!-->>47)|1)]}!{()= sort{my$_=$a;$a=_(sub{$_})if!/0/}$a,$b,0}} sort J('rke%ca hlrPe rhetoan tus;J')=~/./g __END__ Just another Perl hacker0bioslayer@bioslayer:~/Desktop/Development/tes +t$
    Works as advertised, printing an extra 0 at the trail.
    ##Platform## Perl 5, version 12, subversion 4 (v5.12.4) built for i686-linux-gnu-th +read-multi-64int

    David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...
Re: How to (ab)use sort
by kcott (Abbot) on Apr 23, 2012 at 00:15 UTC

    G'day Grimy,

    I'm getting a different result under Mac OS X:

    ken@ganymede: ~/tmp $ cat pm_sort_abuse.pl use strict; use warnings;()= sort{index+0x47,&$a($b)}sub{print&{;pop}}, sort{sub J{$!++&1}[0]}sub{exec''},map{@$_} sort{sub _{[(pop)x((1<<$!-->>47)|1)]}!{()= sort{my$_=$a;$a=_(sub{$_})if!/0/}$a,$b,0}} sort J('rke%ca hlrPe rhetoan tus;J')=~/./g ken@ganymede: ~/tmp $ perl pm_sort_abuse.pl Can't use string ("J") as an ARRAY ref while "strict refs" in use at p +m_sort_abuse.pl line 4. ken@ganymede: ~/tmp $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-th +read-multi-2level ...

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://965457]
Approved by moritz
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (18)
As of 2014-07-24 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (162 votes), past polls