且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ruby 混淆器

更新时间:2023-12-03 21:56:58

有几个选项,例如 RubyScript2ExeAllInOneRuby.然而,所有解释型语言的混淆器都有一个严重的缺陷:他们通常不了解更复杂的元编程技术.

There are a few options, like RubyScript2Exe or AllInOneRuby. However, all obfuscators of interpreted languages tend to have a serious flaw: they usually don't understand more sophisticated metaprogramming techniques.

也就是说,他们不一定能分辨出像 foo.send(:bar, ...) 这样的东西是对 bar 方法的完全调用不同的库,或者 eval("require %w{abc def ghi}") 意味着需要三个不同的库.这些都是微不足道的例子——当你把 method_missing 和它的同类混在一起时,事情会变得更加复杂.

That is, they can't necessarily tell that something like foo.send(:bar, ...) is an invocation on the bar method in a completely different library, or that eval("require %w{abc def ghi}") means to require three different libraries. These are trivial examples -- things get much more complex when you throw method_missing and its ilk into the mix.

当混淆器遇到此类代码时,它会尽职尽责地编译适当的指令,但它可能不知道还包含某些库或其他地方的其他代码.这可能会导致严重的问题,因为动态 included 或 required 在静态链接的可执行文件中在运行时将不可用.

When an obfuscator encounters this sort of code, it will dutifully compile the appropriate instructions, but it may not know to also include certain libraries or other code from elsewhere. That can cause serious issues, since the dynamically included or required will not be available at runtime in a statically linked executable.

不幸的是,许多 gem 和库使用复杂的元编程技术.如果您尝试使用混淆并期望您的程序具有相同的行为,那么您可能会在这里遇到麻烦.更糟糕的是,因为有很多层次的间接性,如果混淆版本中出现错误,您可能永远不知道到底发生了什么或如何重现它.

Unfortunately, many gems and libraries use sophisticated metaprogramming techniques. You'll likely get into trouble here if you try to use obfuscation and expect your program to have the same behavior. Worse still, because there are so many levels of indirection, if a bug occurs in the obfuscated version, you may never know what exactly happened or how to reproduce it.