Skip to content

Commit

Permalink
replace the hook of Application.attach with ContextWrapper.attachBase…
Browse files Browse the repository at this point in the history
…Context for CHA.
  • Loading branch information
weishu.tws committed Apr 16, 2018
1 parent 0fb1f6c commit 5258cda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exposed-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}

group = 'me.weishu.exposed'
version = '0.5.7'
version = '0.5.8'

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

Expand Down
17 changes: 17 additions & 0 deletions exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5258cda

Please sign in to comment.