From 5258cda1d3298b91de91d2f31cbd2cdf222771db Mon Sep 17 00:00:00 2001 From: "weishu.tws" Date: Mon, 16 Apr 2018 12:04:35 +0800 Subject: [PATCH] replace the hook of Application.attach with ContextWrapper.attachBaseContext for CHA. --- exposed-core/build.gradle | 2 +- .../java/me/weishu/exposed/ExposedBridge.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/exposed-core/build.gradle b/exposed-core/build.gradle index 6de42a1..49bc804 100644 --- a/exposed-core/build.gradle +++ b/exposed-core/build.gradle @@ -31,7 +31,7 @@ dependencies { } group = 'me.weishu.exposed' -version = '0.5.7' +version = '0.5.8' apply plugin: 'com.novoda.bintray-release' diff --git a/exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java b/exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java index ba75cbf..b94aa2e 100644 --- a/exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java +++ b/exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java @@ -1,8 +1,10 @@ package me.weishu.exposed; import android.annotation.SuppressLint; +import android.app.Application; import android.content.ComponentName; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; @@ -33,6 +35,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -268,10 +271,24 @@ public static XC_MethodHook.Unhook hookMethod(Member method, XC_MethodHook callb if (ignoreHooks(method)) { return null; } + + method = replaceForCHA(method); + final XC_MethodHook.Unhook unhook = DexposedBridge.hookMethod(method, callback); return ExposedHelper.newUnHook(callback, unhook.getHookedMethod()); } + private static Member replaceForCHA(Member member) { + + if (member.getDeclaringClass() == Application.class && member.getName().equals("attach")) { + + Method m = XposedHelpers.findMethodExact(ContextWrapper.class, "attachBaseContext", Context.class); + XposedBridge.log("replace ContextWrapper.attachBaseContext with Application.attach for CHA"); + return m; + } + return member; + } + private static void initForXposedModule(Context context, ApplicationInfo applicationInfo, ClassLoader appClassLoader) { InputStream inputStream = null;