-
Notifications
You must be signed in to change notification settings - Fork 100
Home
zhouat edited this page Aug 9, 2016
·
9 revisions
XposedHelpers.findAndHookMethod("org.apache.http.impl.client.AbstractHttpClient", loadPackageParam.classLoader, "execute", HttpUriRequest.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!param.args[0].getClass().getCanonicalName().contains("HttpPost")) {
return;
}
HttpPost request = (HttpPost) param.args[0];
String url = request.getURI().toString();
}
}
final int apiLevel = Build.VERSION.SDK_INT;
/* 自 Android 4.4 后改用 okhttp 实现,在 6.0 后包名有改动 */
if (apiLevel >= 23) {
XposedHelpers.findAndHookMethod("com.android.okhttp.internal.huc.HttpURLConnectionImpl", loadPackageParam.classLoader, "getInputStream", URLGetInputStreamHook);
} else if (apiLevel >= 19) {
XposedHelpers.findAndHookMethod("com.android.okhttp.internal.http.HttpURLConnectionImpl", loadPackageParam.classLoader, "getInputStream", URLGetInputStreamHook);
} else {
XposedHelpers.findAndHookMethod("libcore.net.http.HttpURLConnectionImpl", loadPackageParam.classLoader, "getInputStream", URLGetInputStreamHook);
}
XposedHelpers.findAndHookConstructor("java.net.URL", loadPackageParam.classLoader, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String url = (String) param.args[0];
log("URL construct " + url);
/* 还可以通过修改参数或结果,改变应用逻辑 */
param.args[0] = "http://www.baidu.com/";
log("Change URL to " + param.args[0]);
}
});
## 所有网络 IO,本地 IO 等 IO 错误都会被捕获
XposedBridge.hookAllConstructors(IOException.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log((Throwable) param.thisObject);
}
});
Ref: https://github.com/rovo89/XposedBridge/wiki/Development-tutorial