有没有难以反编译的代码示例?

发布于 2024-07-27 12:05:46 字数 227 浏览 2 评论 0原文

有时,在反编译 Java 代码时,反编译器无法正确反编译它,最终会在输出中得到少量字节码。

反编译器的缺点是什么? 有没有Java源代码编译成难以反编译的字节码的例子?

更新:

请注意,我知道利用此信息并不是在代码中隐藏秘密的安全方法,并且反编译器将来可以得到改进。

尽管如此,我仍然有兴趣找出当今反编译器中的哪些类型的代码。

Sometimes when decompiling Java code, the decompiler doesn't manage to decompile it properly and you end up with little bits of bytecode in the output.

What are the weaknesses of decompilers? Are there any examples of Java source code that compiles into difficult-to-decompile bytecode?

Update:

Note that I'm aware that exploiting this information is not a safe way to hide secrets in code, and that decompilers can be improved in the future.

Nonetheless I am still interested in finding out what kinds of code foxes todays crop of decompilers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

余罪 2024-08-03 12:05:46

任何经过混淆器处理的 Java 字节码都会从反编译器中得到“荒谬的”输出。 此外,当您使用 Scala 等其他语言编译为 JVM 字节码时,没有规定字节码可以很容易地用 Java 表示,而且很可能并非如此。

随着时间的推移,反编译器必须跟上新的语言功能及其生成的字节码,因此新的语言功能可能不会轻易被您使用的工具逆转。

编辑:作为 .NET 中的示例,以下代码:

lock (this)
{
    DoSomething();
}

编译为:

Monitor.Enter(this);
try
{
    DoSomething();
}
catch
{
    Monitor.Exit(this);
}

反编译器必须知道 C#(与任何其他 .NET 语言相反)具有专用于这两个调用的特殊语法。 否则你会得到意想不到的(冗长的)结果。

Any Java byte code that's been through an obfuscator will have "ridiculous" output from the decompiler. Also, when you have other languages like Scala that compile to JVM byte code, there's no rule that the byte code be easily represented back in Java, and likely isn't.

Over time, decompilers have to keep up with the new language features and the byte code they produce, so it's plausible that new language features are not easily reversed by the tools you're using.

Edit: As an example in .NET, the following code:

lock (this)
{
    DoSomething();
}

compiles to this:

Monitor.Enter(this);
try
{
    DoSomething();
}
catch
{
    Monitor.Exit(this);
}

The decompiler has to know that C# (as opposed to any other .NET language) has a special syntax dedicated to exactly those two calls. Otherwise you get unexpected (verbose) results.

黯然#的苍凉 2024-08-03 12:05:46

DB2 Connect 的 JDBC type-4 驱动程序非常经典。 所有被称为一两个字母名称的东西、最终没有效果的不相关代码等等。 我曾经尝试看看调试一个特别烦人的问题,基本上放弃了。 我希望(但绝不自信)这是通过混淆器传递的,而不是实际看起来像那样的代码。

另一个最喜欢的技巧(虽然我不记得产品了)是重命名要从集合 {'0','O','l','1'} 构造的所有对象,其中使阅读变得非常困难。

The JDBC type-4 drivers for DB2 Connect are classics. Everything called one or two-letter names, irrelevant code that ends up having no effect, and more. I once tried to take a look to debug a particularly annoying problem and basically gave up. I'm hoping (but by no means confident) that this was passed through an obfuscator rather than the code actually looking like that.

Another favorite trick (although I can't remember the product) was to rename all objects to be constructed from the set {'0','O','l','1'}, which made reading it very difficult.

云之铃。 2024-08-03 12:05:46

假设您可以反编译回合理风格的源代码(您不能总是这样做),那么难以“逆向工程”的是在不熟悉的问题域中运行的算法。 如果您不理解快速傅立叶变换,那么您是否能获得实现 FFT 蝴蝶的代码也没有多大关系。
(如果你不熟悉这个短语,那么如果我编码一个,我就已经赢了。如果你熟悉它,那么你是一位非常优秀的工程师,并且可能对逆向工程没有任何兴趣代码)。 [你与朝鲜人相处的里程可能会有所不同。]

Assuming you can decompile back to a reasonable style of source code (you can't always do that), what is hard to "reverse engineer" are algorithms that operate in unfamiliar problem domains. If you don't understand Fast Fourier transforms, it doesn't matter much if you can get back the code that implements an FFT Butterfly.
(If this phrase is unfamiliar to you, I've already won if I encode one. If it is familiar to you, you are a pretty good engineer and probably don't have any interest in reverse engineering code). [Your mileage with North Koreans may vary.]

×眷恋的温暖 2024-08-03 12:05:46

Java 在字节码中保存了大量信息(例如许多名称)。 所以反编译还是比较容易的。 难以反编译的字节码主要是由难以读取的源代码生成的(所以这不是真正的选择)。 如果您确实想混淆代码,请使用混淆器,它将所有方法和变量重命名为无法识别的内容。

Java keeps a lot of information in the bytecode (for instance many names). So it is relatively easy to decompile. Hard to decompile bytecode mostly is generated by hard to read sourcecode (so that's not really an option). If you really want to obfuscate your code, use a obfuscator, that renames all methods and variables to unrecognizable stuff.

无声无音无过去 2024-08-03 12:05:46

异常通常很难反编译。
然而,任何被混淆或用另一种语言编写的代码都很难反编译。

顺便说一句:你为​​什么想知道这个?

Exceptions are often difficult to decompile.
However, any code which has been obfuscated or has been written in another language is difficult to decompile.

BTW: Why would you want to know this?

谎言 2024-08-03 12:05:46

Java字节码并不直接对应于Java构造,因此反编译意味着您知道某个Java字节码序列对应于Java代码构造。

用于反编译 Java 字节码的 Soot 框架有很多这方面的信息,但我现在无法访问他们的网页。

http://www.sable.mcgill.ca/soot/

Java Bytecode does not correspond directly to Java constructions, so decompiling implies that you know that a certain java byte code sequence corresponds to a Java code construction.

The Soot framework for decompiling java byte code has a lot of information on this, but their webpage is down for me right now.

http://www.sable.mcgill.ca/soot/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文