11package me .weishu .exposed ;
22
33import android .annotation .SuppressLint ;
4- import android .app .Application ;
54import android .content .ComponentName ;
65import android .content .Context ;
7- import android .content .ContextWrapper ;
86import android .content .Intent ;
97import android .content .ServiceConnection ;
108import android .content .SharedPreferences ;
3634import java .lang .reflect .Field ;
3735import java .lang .reflect .InvocationTargetException ;
3836import java .lang .reflect .Member ;
39- import java .lang .reflect .Method ;
4037import java .util .Arrays ;
4138import java .util .HashMap ;
4239import java .util .HashSet ;
@@ -205,11 +202,11 @@ public static ModuleLoadResult loadModule(final String moduleApkPath, String mod
205202 loadModuleConfig (rootDir , currentApplicationInfo .processName );
206203
207204 if (lastModuleList .second == null || !lastModuleList .second .contains (moduleApkPath )) {
208- log ( "module:" + moduleApkPath + " is disabled, ignore" );
205+ Log . i ( TAG , "module:" + moduleApkPath + " is disabled, ignore" );
209206 return ModuleLoadResult .DISABLED ;
210207 }
211208
212- log ( "Loading modules from " + moduleApkPath + " for process: " + currentApplicationInfo .processName + " i s c: " + SYSTEM_CLASSLOADER_INJECT );
209+ Log . i ( TAG , "Loading modules from " + moduleApkPath + " for process: " + currentApplicationInfo .processName + " i s c: " + SYSTEM_CLASSLOADER_INJECT );
213210
214211 if (!new File (moduleApkPath ).exists ()) {
215212 log (moduleApkPath + " does not exist" );
@@ -249,7 +246,7 @@ public static ModuleLoadResult loadModule(final String moduleApkPath, String mod
249246 continue ;
250247 }
251248 try {
252- log ( " Loading class " + moduleClassName );
249+ Log . i ( TAG , " Loading class " + moduleClassName );
253250 Class <?> moduleClass = mcl .loadClass (moduleClassName );
254251
255252 sModuleLoadListener .onLoadingModule (moduleClassName , currentApplicationInfo , mcl );
@@ -334,7 +331,10 @@ public static XC_MethodHook.Unhook hookMethod(Member method, XC_MethodHook callb
334331 return null ;
335332 }
336333
337- method = replaceForCHA (method );
334+ XC_MethodHook .Unhook replaceUnhook = CHAHelper .replaceForCHA (method , callback );
335+ if (replaceUnhook != null ) {
336+ return ExposedHelper .newUnHook (callback , replaceUnhook .getHookedMethod ());
337+ }
338338
339339 final XC_MethodHook .Unhook unhook = DexposedBridge .hookMethod (method , callback );
340340 return ExposedHelper .newUnHook (callback , unhook .getHookedMethod ());
@@ -346,22 +346,7 @@ public static Object invokeOriginalMethod(Member method, Object thisObject, Obje
346346 return DexposedBridge .invokeOriginalMethod (method , thisObject , args );
347347 }
348348
349- private static Member replaceForCHA (Member member ) {
350-
351- if (member .getDeclaringClass () == Application .class && member .getName ().equals ("attach" )) {
352- Method m = XposedHelpers .findMethodExact (ContextWrapper .class , "attachBaseContext" , Context .class );
353- XposedBridge .log ("replace Application.attach with ContextWrapper.attachBaseContext for CHA" );
354- return m ;
355- }
356-
357- if (member .getDeclaringClass () == Application .class && member .getName ().equals ("onCreate" )) {
358- Method m = XposedHelpers .findMethodExact (ContextWrapper .class , "attachBaseContext" , Context .class );
359- XposedBridge .log ("replace Application.onCreate with ContextWrapper.attachBaseContext for CHA" );
360- return m ;
361- }
362349
363- return member ;
364- }
365350
366351 private static void initForXposedModule (Context context , ApplicationInfo applicationInfo , ClassLoader appClassLoader ) {
367352 InputStream inputStream = null ;
@@ -370,7 +355,7 @@ private static void initForXposedModule(Context context, ApplicationInfo applica
370355 inputStream = context .getAssets ().open ("xposed_init" );
371356 System .setProperty ("epic.force" , "true" );
372357 } catch (IOException e ) {
373- log ( applicationInfo .packageName + " is not a Xposed module" );
358+ Log . i ( TAG , applicationInfo .packageName + " is not a Xposed module, do not init epic.force " );
374359 } finally {
375360 closeSliently (inputStream );
376361 }
@@ -440,7 +425,7 @@ private static void initForXposedInstaller(Context context, ApplicationInfo appl
440425 if (!fakeVersionString .equals (oldVersion )) {
441426 writeXposedProperty (xposedProp , fakeVersionString , true );
442427 } else {
443- log ( "xposed version keep same, continue." );
428+ Log . i ( TAG , "xposed version keep same, continue." );
444429 }
445430 }
446431
0 commit comments