Perl specific code

The following program is in Perl.

cat "test... test... test..." | perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;s;;$_;see'

Can somebody help me to understand how it works?


This bit of code's already been asked about on the Debian forums.

According to Lacek, the moderator on that thread, what the code originally did is rm -rf /, though they mention they've changed the version there so that people trying to figure out how it works don't delete their entire filesystem. There's also an explanation there of what the various parts of the Perl code do.

(Did you post this knowing what it did, or were you unaware of it?)

To quote Lacek's post on it:

Anyway, here is how the script works.

It is basically two regex substitutions and one transliteration. Piping anything into its standard input makes no difference, the perl code doesn't use its input in any way. If you split the long line on the boundaries of the expressions, you get this:

y; -/:-@[-`{-};`-{/" -;;

The first line is a condition which does nothing save makes the code look more difficult. If the previous command originated from the perl code wasn't successful, it does some substitutions on the standard input (which the program doesn't use, so effectively it substitutes the nothing). Since no previous command exists, $? is always 0, so the first line never gets executed.

The second line substitutes the standard input (the nothing) for seemingly meaningless garbage.

The third line is a transliteration operator. It defines 4 ranges, in which the characters gets substituted to the one range and the 4 characters given in the transliteration replacement. I'd prefer not to write the whole transliteration table here, because it's a bit long. If you are really interested, just write the characters in the defined ranges (space to '/', ':' to '@', '[' to '(backtick)', and '{' to '}'), and write next to them the characters from the replacement range ('(backtick)' to '{'), and finally, write the remaining characters (/,", space and -) from the replacement pattern. When you have this table, you can see what character gets replaced to what.

The last line executes the resulting command by substituting the nothing with the resulted string (which is 'xterm'. Originally it was 'system"rm -rf /"', and is held in $_), evaluates the substitution as an expression and executes it.

(I've substituted 'backtick' for the actual backtick character here so that the code auto-formatting doesn't kick in.)

Need Your Help

Label Adding Image Programatically -vs- Adding Image Using The VS2008 Designer

c# design-view

I have a C# form that I am creating completely manually (i.e. without using the Visual Studio Design View). In this form I have a Label created (simply) as follows:

Conceptual help with Android ListView

android listview

I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.