Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this perl line from a "bleached" file do?

I have some perl files which have been "bleached" (don't know if it was from ACME::Bleach, or something similar). Not being very fluent in perl, I'd like to understand what the one-liner that starts the file does to decode the whitespace that follows:

$_=<<'';y;\r\n;;d;$_=pack'b*',$_;$_=eval;$@&&die$@;$_

The rest of the file is whitespace characters, and the file is executable by itself (it's placed in a /bin directory).

[Solution], thanks to @JB.

The pack portion of this seems the most complex, and it took me a while to notice what was going on. Pack is taking the LSB only of every 8 characters, and unpacking that as a big-endian character in binary. Tabs hence become '0's, and spaces become '1's.

    '\t\t   \t  ' => '#'
in binary:
    00001001 00001001 00100000 00100000 00100000 00001001 00100000 0100000
every LSB:
    1 1 0 0 0 1 0 0
convert from from big-endian format:
    0b00100011 == 35 == ord('#')
like image 381
JimB Avatar asked Sep 26 '11 14:09

JimB


2 Answers

  • $_ = << ''; reads the rest of the file into the accumulator.
  • y;\r\n;;d; strips carriage returns and line feeds.
  • $_ = pack 'b*', $_; converts characters to bits in $_, LSB first.
  • $_ = eval; executes $_ as Perl code.
  • $@ && die $@; $_ handles exceptions and the return code gracefully.
like image 156
JB. Avatar answered Sep 22 '22 17:09

JB.


You can use unbleach.pl to remove bleaching, if that's what you're really trying to do.

like image 39
ikegami Avatar answered Sep 18 '22 17:09

ikegami