如何反编译混淆的java程序,避免类/包名冲突 [英] How to decompile obfuscated java programs avoiding class/package name collisions

查看:1448
本文介绍了如何反编译混淆的java程序,避免类/包名冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想反编译一个java程序并重新编译派生(混淆)的源代码。我解压缩.jar存档并获得了类似的目录结构:

I want to decompile a java program and recompile the derived (obfuscated) source. I unpacked the .jar archive and got a directory structure like that:

com/
com/foo/A/
com/foo/A/A.class
com/foo/A/B.Class
com/foo/B/A.class
...
com/foo/A.class
com/foo/B.class
org/foo/Bar.class
...

问题是包和类之间存在名称冲突,这使得无法重新编译反编译的类文件。
反编译类看起来像这样:

The problem is that there are name collisions between packages and classes, which makes it impossible to recompile the decompiled class files. A decompiled class will look like this:

package org.foo;
import com.foo.A; // <-- name collision error

class Bar {
    ...
}

有没有办法解决这些命名问题,而无需重命名类文件?

Is there any way to resolve those naming issues, without renaming the class files?

编辑:
这是不是一个反编译器问题,而是如何使用违反命名约定的类来生成.jar文件的问题。

This is not a decompiler problem, but the question how it is possible to have a working .jar file with classes that violate naming conventions.

EDIT2:
好​​的,我猜测字节码级别这样命名是可能的,因此使用更智能的反编译器(自动重命名类并修复其引用)可以解决这个问题。

Okay, i guess on bytecode level such naming is possible, so with a smarter decompiler (who automatically renames the classes and fixes their references) this problem could be solved.

推荐答案

Java的导入机制提供了命名事项的简写,但是当发生冲突时你显然无法使用它。您始终可以在代码中使用完全限定名称,例如

Java's import mechanism provides a shorthand for naming things, but you obviously cannot use it when there are collisions. You can always use the fully qualified name in your code, e.g.

package org.foo;  

class Bar { 
    private com.foo.Bar aDifferentBar;
    ...
}

编辑:

我想可能有类文件符合JVM规范但是不能由符合JLS规范的Java程序生成。如果是这样,那么你肯定需要一个更聪明的反编译器。

I suppose there could be class files that comply with the JVM spec but which cannot be produced by a Java program that complies with the JLS spec. If so then you'll definitely need a smarter decompiler.

这篇关于如何反编译混淆的java程序,避免类/包名冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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