Xposed
Xposed能够勾住(Hook) Android应用程序对象的方法,实现AOP,一个简单的例子:
public class WebViewHook implements IXposedHookLoadPackage {
// handleLoadPackage 会在android加载每一个apk后执行
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
// 可以从lpparam中获取当前apk的名字
if (! lpparam.packageName.equals("com.tencent.mobileqq")) {
return;
}
XposedBridge.log("WebViewHook handleLoadPackage: " + lpparam.packageName);
// 勾住 WebView 所有的构造器
XposedBridge.hookAllConstructors(WebView.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// 打开webContentsDebuggingEnabled
XposedHelpers.callStaticMethod(WebView.class, "setWebContentsDebuggingEnabled", true);
XposedBridge.log("WebViewHook new WebView(): " + packageName);
}
});
}
}
上面的代码可以为QQ打开WebView的webContentsDebuggingEnabled
参考文档:
Xposed工作原理可以
https://github.com/rovo89/XposedBridge/wiki/Development-tutorial
没有详细的API页面, 因为API也就几个,可以查看源代码: https://github.com/rovo89/XposedBridge/tree/master/src/de/robv/android/xposed