硕士生
 
- 金币
- 2061
- 好评
- 22
- 信誉
- 105
|
发表于
2025-9-14 03:42:47
来自手机
|
显示全部楼层
来自 四川
这是很久以前写的一个okhttp替换目标url请求返回
数据的一个方法,应该可以给你参考参考。
- public static void replaceOkhttpResult(String methodName, String packageName , final String aimUrl, final String result, final ClassLoader classLoader)
- {
- final Log log = Log.newInstance("okhttp:");
- Object[] es={new XC_MethodHook(){
- protected void afterHookedMethod(XC_MethodHook.MethodHookParam methodHookParam) throws Throwable
- {
- Object res = methodHookParam.thisObject;
- Object req = res.getClass().getMethod("request").invoke(res);
- Object u1 = req.getClass().getMethod("url").invoke(req);
- String url = u1.toString();
- if(url.indexOf(aimUrl) != -1)
- {
- log.printLog("|url:replace|result:;" + url);
- Class cls = res.getClass();
- Field code = cls.getDeclaredField("code");
- code.setAccessible(true);
- code.set(res, 200);
- Field body = cls.getDeclaredField("body");
- body.setAccessible(true);
- Class clsBody = XposedHelpers.findClass("okhttp3.ResponseBody", classLoader);
- Class clsMediaType = XposedHelpers.findClass("okhttp3.MediaType", classLoader);
- Method met = clsBody.getMethod("create", clsMediaType, String.class);
- Object b1 = met.invoke(body, null, result);
- body.set(res, b1);
- methodHookParam.setResult(true);
- }
- }
- }
- };
- XposedHelpers.findAndHookMethod("okhttp3.Response", classLoader, methodName, es);
- }
复制代码 |
-
查看全部评分
总评分:金币 +1
|