简体   繁体   中英

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. 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.

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$1 would be an anonymous inner class defined inside of that inner class.

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).

Evidently, your decompiler tried to decompile these parts, but was unable to magically transform them back into Java style inner classes.

Have you tried Procyon? I'm not too familiar with its exact capabilities, but I bet it can reconstruct inner classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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