Skip to content

Commit 5258cda

Browse files
author
weishu.tws
committed
replace the hook of Application.attach with ContextWrapper.attachBaseContext for CHA.
1 parent 0fb1f6c commit 5258cda

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

exposed-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
}
3232

3333
group = 'me.weishu.exposed'
34-
version = '0.5.7'
34+
version = '0.5.8'
3535

3636
apply plugin: 'com.novoda.bintray-release'
3737

exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package me.weishu.exposed;
22

33
import android.annotation.SuppressLint;
4+
import android.app.Application;
45
import android.content.ComponentName;
56
import android.content.Context;
7+
import android.content.ContextWrapper;
68
import android.content.Intent;
79
import android.content.ServiceConnection;
810
import android.content.SharedPreferences;
@@ -33,6 +35,7 @@
3335
import java.lang.reflect.Constructor;
3436
import java.lang.reflect.Field;
3537
import java.lang.reflect.Member;
38+
import java.lang.reflect.Method;
3639
import java.util.Arrays;
3740
import java.util.HashMap;
3841
import java.util.HashSet;
@@ -268,10 +271,24 @@ public static XC_MethodHook.Unhook hookMethod(Member method, XC_MethodHook callb
268271
if (ignoreHooks(method)) {
269272
return null;
270273
}
274+
275+
method = replaceForCHA(method);
276+
271277
final XC_MethodHook.Unhook unhook = DexposedBridge.hookMethod(method, callback);
272278
return ExposedHelper.newUnHook(callback, unhook.getHookedMethod());
273279
}
274280

281+
private static Member replaceForCHA(Member member) {
282+
283+
if (member.getDeclaringClass() == Application.class && member.getName().equals("attach")) {
284+
285+
Method m = XposedHelpers.findMethodExact(ContextWrapper.class, "attachBaseContext", Context.class);
286+
XposedBridge.log("replace ContextWrapper.attachBaseContext with Application.attach for CHA");
287+
return m;
288+
}
289+
return member;
290+
}
291+
275292
private static void initForXposedModule(Context context, ApplicationInfo applicationInfo, ClassLoader appClassLoader) {
276293
InputStream inputStream = null;
277294

0 commit comments

Comments
 (0)