@@ -4,27 +4,34 @@ import com.blankj.util.JavassistUtils
44import com.blankj.util.ZipUtils
55import javassist.CtClass
66import javassist.CtMethod
7+ import javassist.NotFoundException
78import org.apache.commons.io.FileUtils
89
910class BusInject {
1011
1112 static void start (HashMap<String , String > bus , File busJar ) {
12- String jarPath = busJar. getAbsolutePath()
13- String decompressedJarPath = jarPath. substring(0 , jarPath. length() - 4 );
14- File decompressedJar = new File (decompressedJarPath)
15- ZipUtils . unzipFile(busJar, decompressedJar)
13+ String jarPath = busJar. getAbsolutePath()
14+ String decompressedJarPath = jarPath. substring(0 , jarPath. length() - 4 );
15+ File decompressedJar = new File (decompressedJarPath)
16+ ZipUtils . unzipFile(busJar, decompressedJar)
1617
17- CtClass busUtils = JavassistUtils . getPool(). get(Config . CLASS_BUS_UTILS )
18- CtMethod callMethod = busUtils. getDeclaredMethod(" post" );
19- callMethod. insertAfter(getInsertContent(bus));
20- busUtils. writeFile(decompressedJarPath)
21- busUtils. defrost();
22- FileUtils . forceDelete(busJar)
23- ZipUtils . zipFile(decompressedJar, busJar)
24- FileUtils . forceDelete(decompressedJar)
18+ CtClass busUtils = JavassistUtils . getPool(). get(Config . BUS_UTILS_CLASS )
19+ CtMethod callMethod;
20+ try {
21+ callMethod = busUtils. getDeclaredMethod(" injectShell" );
22+ callMethod. insertAfter(getInsertContent(bus, false ));
23+ } catch (NotFoundException ignore) {
24+ callMethod = busUtils. getDeclaredMethod(" post" );
25+ callMethod. insertAfter(getInsertContent(bus, true ));
26+ }
27+ busUtils. writeFile(decompressedJarPath)
28+ busUtils. defrost();
29+ FileUtils . forceDelete(busJar)
30+ ZipUtils . zipFile(decompressedJar, busJar)
31+ FileUtils . forceDelete(decompressedJar)
2532 }
2633
27- private static String getInsertContent (HashMap<String , String > bus ) {
34+ private static String getInsertContent (HashMap<String , String > bus , boolean isLow ) {
2835 StringBuilder sb = new StringBuilder ();
2936 bus. each { String key , String val ->
3037 String name = key
@@ -72,7 +79,9 @@ class BusInject {
7279 }
7380 sb. append(" }" )
7481 }
75- sb. append(' android.util.Log.e("BusUtils", "bus of <" + $1 + "> didn\' t exist.");' )
82+ if (isLow) {
83+ sb. append(' android.util.Log.e("BusUtils", "bus of <" + $1 + "> didn\' t exist.");' )
84+ }
7685 return sb. toString()
7786 }
7887}
0 commit comments