What does this perl line from a “bleached” file do?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 18:11:55

问题


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('#')

回答1:


  • $_ = << ''; 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.



回答2:


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



来源:https://stackoverflow.com/questions/7556782/what-does-this-perl-line-from-a-bleached-file-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!