如何来缩小/混淆bash脚本 [英] How to minify/obfuscate a bash script

查看:339
本文介绍了如何来缩小/混淆bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当然是bash文件不能真正混淆而且将永远是可读的。我不想将它们包装在一些二进制包。
和重命名局部变量就不值得麻烦。

Of course a bash file cannot be truly obfuscated and will always be readable. And I don't want to wrap them in some binary package. And renaming local variables wouldn't be worth the trouble.

但有一个可靠的简单的bash混淆或minifier其中至少删除所有的压痕,所有的空行和不破坏任何东西都空白?尤其是评论和注释可能包含敏感文件或资料的脚本的部分?

But is there a reliable simple bash obfuscator or minifier which at least removes all the indentation, all the empty lines and all whitespace without breaking anything? And especially the comments and commented out portions of the script which might contain sensitive documents or information?

我会害怕的简单的grep / sed的线要做到这一点,因为 here文档一定不能修改当然,如此真实解析一点点是必要的。

I would be afraid of simple grep/sed-lines to do this because "HEREDOCs" must not be modified of course, so a little bit of real parsing is necessary.

也许有这样做的一个工具,这将是伟大的!

Maybe there's a tool to do this, that would be great!

推荐答案

尽管这是一个老问题,这似乎是流行的谷歌。我也想找一个bash minifer /混淆,并没有喜欢的人的答案。

Even though this is an old question, it seems to be popular on Google. I was also looking for a bash minifer/obfuscator, and didn't like the one in the answer.

我不想加入任何胡言乱语,或者编译脚本。所以我写了一个做了我在Perl想,并把它放在GitHub上的<一个href=\"https://github.com/Aralhach/bashobfus/tree/master\">https://github.com/Aralhach/bashobfus/tree/master

它可以:

I didn't want to add gibberish either, or compile the script. So I wrote one that did what I wanted in Perl, and put it on GitHub at https://github.com/Aralhach/bashobfus/tree/master
It can:


  • 平展缩进
  • 删除全行注释(除初始hashbang(#!))和空行
  • 重命名所有的小写变量基本声明(以避免重命名像PATH变量),for循环,数组访问,和读的语句。
  • Flatten indentation
  • Remove full-line comments (except the initial hashbang (#!)) and blank lines
  • Renames all lowercase variables in basic declarations (to avoid renaming variables like PATH), for loops, array access, and 'read' statements.

有可能是它失败的情况下一些,但我有一个相当大的bash脚本测试它,和可变的上市情况更换弹出。它还叶单引号(')单独 - 此打印awk脚本的时候突然出现了 - 但单引号之间的替代变量(')时,声明已经是双引号()里面 - 本上打印的MySQL语句时,弹出

There might be some case where it fails, but I tested it with a fairly big bash script, and the listed cases of variable replacing popped up. It also leaves variables within single quotes (') alone --this popped up when printing an AWK script-- but replaces between single quotes (') when the statement is already inside double quotes (") --this popped up when printing an MySQL statement.

这让我觉得我已经涵盖了所有大的用例,但我已经错了。如果您发现任何错误,可随时举报他们(或修复它们!:D)。我也在想增加一个功能,加入短线成一个以;但案件太多,同时使我的最后期限分析。

This makes me think I've covered all the big use cases, but I've been wrong before. If you find any bugs, feel free to report them (or fix them! :D). I was also thinking of adding a feature to join short lines into one with ";" but the cases were too many to analyze while making my deadline.

我希望人们会发现它有用!

I hope people find it useful!

这篇关于如何来缩小/混淆bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆