简体   繁体   English

从APK恢复原始源

[英]Restore original source from apk

When I decompiled my .apk I saw some extra files such as MainActivity$1.java, MainActivity$1$1.java etc. In fact some of them are empty. 当我反编译.apk时,我看到了一些额外的文件,例如MainActivity $ 1.java,MainActivity $ 1 $ 1.java等。实际上,其中一些是空的。 Besides that there are some code snippets that are occuring many times such as 除此之外,还有一些代码片段会多次出现,例如

this$0 = MainActivity.this;
super();

or 要么

this$1 = _cls1.this;
super();

where can i read more about this? 我在哪里可以了解更多? and is there a way to restore my original source code? 有没有办法恢复我的原始源代码?

This code comes from the way inner classes are compiled in Java. 这段代码来自用Java编译内部类的方式。

There is no direct support for inner classes at the bytecode level. 在字节码级别上不直接支持内部类。 Instead, each inner class you create is compiled to a separate classfile, with compiler generated bridge code to allow the appropriate access. 而是将您创建的每个内部类编译为单独的类文件,并使用编译器生成的桥代码来允许适当的访问。

MainActivity$1 is just an anonymous class defined in MainActivity. MainActivity $ 1只是在MainActivity中定义的匿名类。 MainActivity$1$1 would be an anonymous inner class defined inside of that inner class. MainActivity $ 1 $ 1将是在该内部类内部定义的匿名内部类。

The second part is another implementation detail of inner classes. 第二部分是内部类的另一个实现细节。 The instance of an inner class needs a reference to the enclosing instance in order to be able to access it (since they're just ordinary classes at the bytecode level). 内部类的实例需要对封闭实例的引用才能访问它(因为它们只是字节码级别的普通类)。 To do this, the compiler generates a hidden field in the inner class, and inserts code to initialize it prior to calling the superclass constructor (which is allowed in bytecode but not in Java). 为此,编译器会在内部类中生成一个隐藏字段,并在调用超类构造函数之前插入代码对其进行初始化(这在字节码中允许,但在Java中不允许)。

Evidently, your decompiler tried to decompile these parts, but was unable to magically transform them back into Java style inner classes. 显然,您的反编译器试图对这些部分进行反编译,但是无法将它们神奇地转换回Java样式内部类。

Have you tried Procyon? 您尝试过Procyon吗? I'm not too familiar with its exact capabilities, but I bet it can reconstruct inner classes. 我不太了解它的确切功能,但我敢打赌它可以重构内部类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM