-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. fix the Application.attach may be hooked multi-times.
2. reduce the log of Xposed.
- Loading branch information
tiann
committed
Jun 19, 2018
1 parent
510f056
commit dfcf21c
Showing
4 changed files
with
101 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
exposed-core/src/main/java/me/weishu/exposed/CHAHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package me.weishu.exposed; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.ContextWrapper; | ||
import android.util.Log; | ||
|
||
import java.lang.reflect.Member; | ||
import java.lang.reflect.Method; | ||
|
||
import de.robv.android.xposed.DexposedBridge; | ||
import de.robv.android.xposed.ExposedHelper; | ||
import de.robv.android.xposed.XC_MethodHook; | ||
import de.robv.android.xposed.XposedBridge; | ||
import de.robv.android.xposed.XposedHelpers; | ||
|
||
/** | ||
* @author weishu | ||
* @date 2018/6/19. | ||
*/ | ||
public final class CHAHelper { | ||
private static final String TAG = "CHAHelper"; | ||
|
||
static class ApplicationHookProxy extends XC_MethodHook { | ||
|
||
XC_MethodHook original; | ||
|
||
ApplicationHookProxy(XC_MethodHook original) { | ||
this.original = original; | ||
} | ||
|
||
@Override | ||
protected void beforeHookedMethod(MethodHookParam param) throws Throwable { | ||
super.beforeHookedMethod(param); | ||
if (param.thisObject == null) { | ||
throw new IllegalArgumentException("can not use static method!!"); | ||
} | ||
|
||
if (param.thisObject instanceof Application) { | ||
ExposedHelper.beforeHookedMethod(this.original, param); | ||
} else { | ||
Log.d(TAG, "ignore non-application of ContextWrapper: " + param.thisObject); | ||
} | ||
} | ||
|
||
@Override | ||
protected void afterHookedMethod(MethodHookParam param) throws Throwable { | ||
super.afterHookedMethod(param); | ||
if (param.thisObject == null) { | ||
throw new IllegalArgumentException("can not use static method!!"); | ||
} | ||
|
||
if (param.thisObject instanceof Application) { | ||
ExposedHelper.afterHookedMethod(this.original, param); | ||
} else { | ||
Log.d(TAG, "ignore non-application of ContextWrapper: " + param.thisObject); | ||
} | ||
} | ||
} | ||
|
||
static XC_MethodHook.Unhook replaceForCHA(Member member, final XC_MethodHook callback) { | ||
|
||
if (member.getDeclaringClass() == Application.class && member.getName().equals("attach")) { | ||
XposedBridge.log("replace Application.attach with ContextWrapper.attachBaseContext for CHA"); | ||
Method m = XposedHelpers.findMethodExact(ContextWrapper.class, "attachBaseContext", Context.class); | ||
return DexposedBridge.hookMethod(m, new ApplicationHookProxy(callback)); | ||
} | ||
|
||
if (member.getDeclaringClass() == Application.class && member.getName().equals("onCreate")) { | ||
XposedBridge.log("replace Application.onCreate with ContextWrapper.attachBaseContext for CHA"); | ||
Method m = XposedHelpers.findMethodExact(ContextWrapper.class, "attachBaseContext", Context.class); | ||
return DexposedBridge.hookMethod(m, new ApplicationHookProxy(callback)); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
为什么onCreate要改为attchBaseContext,本想hook onCreate方法,结果发现onCreate并没有执行完毕,在这里被attchBaseContext替代了,是作者写错了还是有其他原因?