Browse Source

打印旧版本的游戏盒网络请求

alex 1 year ago
parent
commit
b4ded95476
2 changed files with 43 additions and 15 deletions
  1. 41 13
      agent/HookGameCenter.js
  2. 2 2
      agent/index.ts

+ 41 - 13
agent/HookGameCenter.js

@@ -1,18 +1,46 @@
 export let HookGameCenter = {
-    startHook: function () {
-        Java.perform(()=>{
-            console.log("hook start")
-            //todo
-            //hook TextView的setText方法
-            let CharSequence = Java.use("java.lang.CharSequence");
-            //new CharSequence
+    printReqParam: function (HttpLoggingInterceptor) {
+        HttpLoggingInterceptor.a.overload('okhttp3.Interceptor$Chain').implementation = function (chain) {
+            var result = this.a(chain); // 先保存原方法执行的结果
+            // 获取THREAD_LOGS ThreadLocal对象
+            var threadLogs = HttpLoggingInterceptor.THREAD_LOGS.value;
 
-            let charSequence = Java.cast(Java.use("java.lang.String").$new("嘿嘿嘿"),CharSequence);
-            Java.use("android.widget.TextView").setText.overload("java.lang.CharSequence").implementation = function (x) {
-                console.log("hook setText",x)
-                return this.setText(charSequence)
+            // 通过get方法获取当前线程保存的JSONObject
+            var threadLogsValue = threadLogs.get();
+
+            // 检查并打印THREAD_LOGS的内容
+            if (threadLogsValue !== null) {
+                console.log('请求参数: ' + threadLogsValue.toString());
+            } else {
+                console.log('请求参数 is null or not set for the current thread');
             }
-            console.log("hook end")
-        })
+            return result; // 返回原方法执行的结果
+        }
+
+    }, startHook: function () {
+        // com.framework.net.okhttp3
+        var HttpLoggingInterceptor = Java.use('com.framework.net.okhttp3.HttpLoggingInterceptor');
+
+        HookGameCenter.printReqParam(HttpLoggingInterceptor);
+        HookGameCenter.printResponse(HttpLoggingInterceptor);
+
+    },
+    printResponse: function (HttpLoggingInterceptor) {
+        HttpLoggingInterceptor.intercept.overload('okhttp3.Interceptor$Chain').implementation = function (chain) {
+            var result = this.intercept(chain); // 先保存原方法执行的结果
+            // 预览响应体内容
+
+            // 预览响应体内容
+            try {
+                // 限制预览的最大字节数,避免大数据传输
+                var responseBody = result.peekBody(1024 * 1024); // 预览最大1MB的数据
+                var responseBodyString = responseBody.string(); // 将响应体转换为字符串
+                console.log("Response Body: " + responseBodyString);
+            } catch (e) {
+                console.log("Error reading response body: " + e);
+            }
+            return result; // 返回原方法执行的结果
+        }
     }
+
 }

+ 2 - 2
agent/index.ts

@@ -11,11 +11,11 @@ setImmediate(main)
 function main() {
 
 
-    setTimeout(() => {
+    // setTimeout(() => {
         Java.perform(() => {
             HookGameCenter.startHook()
         })
-    }, 3000);
+    // }, 5000);
     // init_array 通用模板的注入
     hooklinker.start();
     // dumper.start();