HookGameCenter.js 2.0 KB

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