HookGameCenter.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {LogColor, logColor} from "./logger";
  2. export let HookGameCenter = {
  3. printReqParam: function (HttpLoggingInterceptor) {
  4. HttpLoggingInterceptor.a.overload('okhttp3.Interceptor$Chain').implementation = function (chain) {
  5. var result = this.a(chain); // 先保存原方法执行的结果
  6. // 获取THREAD_LOGS ThreadLocal对象
  7. var threadLogs = HttpLoggingInterceptor.THREAD_LOGS.value;
  8. // 通过get方法获取当前线程保存的JSONObject
  9. var threadLogsValue = threadLogs.get();
  10. // 检查并打印THREAD_LOGS的内容
  11. if (threadLogsValue !== null) {
  12. logColor('请求参数: ' + threadLogsValue.toString(), LogColor.GREEN_TEXT);
  13. } else {
  14. console.log('请求参数 is null or not set for the current thread');
  15. }
  16. return result; // 返回原方法执行的结果
  17. }
  18. }, startHook: function () {
  19. // com.framework.net.okhttp3
  20. var HttpLoggingInterceptor = Java.use('com.framework.net.okhttp3.HttpLoggingInterceptor');
  21. HookGameCenter.printReqParam(HttpLoggingInterceptor);
  22. HookGameCenter.printResponse(HttpLoggingInterceptor);
  23. },
  24. printResponse: function (HttpLoggingInterceptor) {
  25. HttpLoggingInterceptor.intercept.overload('okhttp3.Interceptor$Chain').implementation = function (chain) {
  26. var result = this.intercept(chain); // 先保存原方法执行的结果
  27. // 预览响应体内容
  28. // 预览响应体内容
  29. try {
  30. // 限制预览的最大字节数,避免大数据传输
  31. var responseBody = result.peekBody(1024 * 1024); // 预览最大1MB的数据
  32. var responseBodyString = responseBody.string(); // 将响应体转换为字符串
  33. logColor("Response Body: " + responseBodyString, LogColor.BLUE_TEXT);
  34. } catch (e) {
  35. console.log("Error reading response body: " + e);
  36. }
  37. return result; // 返回原方法执行的结果
  38. }
  39. }
  40. }