这条来自“漂白”的 Perl 行是什么意思?文件做什么?
我有一些已被“漂白”的 perl 文件(不知道它是否来自 ACME::Bleach,或类似的东西)。我对 perl 不是很流利,我想了解启动文件的单行代码如何解码后面的空格:
$_=<<'';y;\r\n;;d;$_=pack'b*',$_;$_=eval;$@&&die$@;$_
文件的其余部分是空格字符,并且文件本身是可执行的(它位于/bin 目录)。
[解决方案],感谢@JB。
其中的 pack
部分似乎是最复杂的,我花了一段时间才注意到发生了什么。 Pack 只获取每 8 个字符的 LSB,并将其解包为二进制的大端字符。因此,制表符变为“0”,空格变为“1”。
'\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('#')
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('#')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
y;\r\n;;d;
去除回车符和换行符。$_ = pack 'b*', $_;
将字符转换为$_
中的位,LSB 在前。$_ = eval;
将$_
作为 Perl 代码执行。$@ &&死$@; $_
优雅地处理异常和返回码。$_ = << '';
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.您可以使用
unbleach.pl
去除漂白,如果这就是你真正想做的事情。You can use
unbleach.pl
to remove bleaching, if that's what you're really trying to do.