soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.89k stars 709 forks source link

Failed to launch the instrumented android apk #863

Closed Xiangxingqian closed 6 years ago

Xiangxingqian commented 6 years ago

Hi all,

Problem

I use soot to instrument mutilple dex android apk. I insert some methods and a few classes into apk, the apk is instrumented successfully, but fail to launch it. The error message is shown below:

D/DocRabPro(18355): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.rong.imkit.RongIM$2" on path: DexPathList[[zip file "/data/app/com.docrab.pro-1/base.apk"],nativeLibraryDirectories=[/data/app/com.docrab.pro-1/lib/arm, /vendor/lib, /system/lib]]
D/DocRabPro(18355):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
D/DocRabPro(18355):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
D/DocRabPro(18355):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
D/DocRabPro(18355):     ... 15 more
D/DocRabPro(18355):     Suppressed: java.lang.ClassNotFoundException: io.rong.imkit.RongIM$2
D/DocRabPro(18355):         at java.lang.Class.classForName(Native Method)
D/DocRabPro(18355):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
D/DocRabPro(18355):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
D/DocRabPro(18355):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
D/DocRabPro(18355):         ... 16 more
D/DocRabPro(18355):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
D/DocRabPro(18355): ]

Then I do some expriments:

Scene 1:

a new version of apk & same inserted methods

Still the error java.lang.ClassNotFoundException, but the not found class is different.

Scene 2:

apk & insert some statements, no any methods

Success

Thinking

What if dex1 has been over 65535 methods after instrumenting some methods?

Thank you for your reply.

mbenz89 commented 6 years ago

Which Android version are you using? If you are using a version with art runtime, your suggested error cannot happen with our current implementation. Soot will write out dex files so that they are below the 65535 method threshold. It will take no effort to place methods in dex files corresponding to the original ones (i.e., dex content ist arbitrarily distributed among dex files) since art will unpack and compile the dex files all together anyway.

Is this error happening when you are trying to call the stated method? Maybe it is not correctly added to the corresponding class.

Xiangxingqian commented 6 years ago

Hi @mbenz89 Thank you for your reply, I have solved the problem. It seems that this problem is caused by setting android classes as application classes, like Scene.v().getSootClass("android.view.Menu").setApplicationClass(). I exclude the android classes, the instrumented apk runs well.