Browse Source

douyin 直播房间消息监听

Alex 1 year ago
parent
commit
91e8dbaba9
2 changed files with 224 additions and 64 deletions
  1. 178 29
      agent/HookDY.js
  2. 46 35
      agent/logger.ts

+ 178 - 29
agent/HookDY.js

@@ -1,6 +1,12 @@
+import {logColor, LogColor} from "./logger";
+
 export let HOOK_DY = {
-    hookTextViewClick: function () {
-        Java.perform(function () {
+    printStackTrace: function () {
+        Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()).split("\n").forEach(function (line) {
+            console.log(line);
+        });
+    }, hookTextViewClick: function () {
+        function hookTextView() {
             var View = Java.use("android.view.View"); // setOnClickListener 定义在 View 类中
             var TextView = Java.use("android.widget.TextView"); // 为了访问 getText 方法
 
@@ -13,24 +19,24 @@ export let HOOK_DY = {
                         var textView = Java.cast(this, TextView);
                         let text = textView.getText();
                         console.log("id: " + textView.getId(), "\t\t >>> \t\t" + text)
-                        if (text.toString().includes("***")) {
-                            // var stack = Java.use("java.lang.Thread").currentThread().getStackTrace();
-                            // for (var i = 0; i < stack.length; i++) {
-                            //     console.log(stack[i].toString());
-                            // }
-                            //打印堆栈信息
-                            console.log("1111")
-                            var jThrowable = Java.use("java.lang.Throwable");
-                            console.log("2222")
-                            var jStackTrace = jThrowable.$new().getStackTrace();
-                            console.log("Stack trace:");
-                            jStackTrace.forEach(function (stackTraceElement) {
-                                console.log("\t" + stackTraceElement.toString());
-                            });
-                            console.log("33333")
-                        }
+                        // if (text.toString().includes("***")) {
+                        //     var stack = Java.use("java.lang.Thread").currentThread().getStackTrace();
+                        //     for (var i = 0; i < stack.length; i++) {
+                        //         console.log(stack[i].toString());
+                        //     }
+                        //     //打印堆栈信息
+                        //     console.log("1111")
+                        //     var jThrowable = Java.use("java.lang.Throwable");
+                        //     console.log("2222")
+                        //     var jStackTrace = jThrowable.$new().getStackTrace();
+                        //     console.log("Stack trace:");
+                        //     jStackTrace.forEach(function (stackTraceElement) {
+                        //         console.log("\t" + stackTraceElement.toString());
+                        //     });
+                        //     console.log("33333")
+                        // }
                     } catch (e) {
-                        console.log("报错:",e);
+                        console.log("报错:", e);
                     }
                 } else {
                     // console.log("Not a TextView");
@@ -39,20 +45,163 @@ export let HOOK_DY = {
                 // 调用原始的 setOnClickListener 方法
                 this.setOnClickListener(listener);
             };
+        }
 
-            //hook X.0mSO
-            setTimeout(function (){
-                let use = Java.use("X.0mSO");
-                if (use!==null){
-                    console.log("hook java")
-                    use.LIZJ.overload().implementation=function () {
-                        let lizj = this.LIZJ();
-                        console.log("call lizj:",lizj);
-                        return lizj;
+        function hookSocket() {
+            Java.perform(function () {
+                // Hook Socket's OutputStream
+                var SocketOutputStream = Java.use("java.net.SocketOutputStream");
+                SocketOutputStream.write.overload('[B').implementation = function (b) {
+                    console.log("SocketOutputStream.write:", Java.array('byte', b));
+                    return this.write(b);
+                };
+                SocketOutputStream.write.overload('[B', 'int', 'int').implementation = function (b, off, len) {
+                    console.log("SocketOutputStream.write with offset and length:", Java.array('byte', b).slice(off, off + len));
+                    return this.write(b, off, len);
+                };
+
+                // Hook Socket's InputStream
+                var SocketInputStream = Java.use("java.net.SocketInputStream");
+                SocketInputStream.read.overload('[B').implementation = function (b) {
+                    var result = this.read(b);
+                    console.log("SocketInputStream.read:", Java.array('byte', b));
+                    return result;
+                };
+                SocketInputStream.read.overload('[B', 'int', 'int').implementation = function (b, off, len) {
+                    var result = this.read(b, off, len);
+                    console.log("SocketInputStream.read with offset and length:", Java.array('byte', b).slice(off, off + len));
+                    return result;
+                };
+            });
+
+
+            let IMessageReceiveListener = Java.use("com.bytedance.frameworks.baselib.network.http.cronet.websocket.IMessageReceiveListener");
+            IMessageReceiveListener["onConnection"].implementation = function (i, str, jSONObject) {
+                console.log(`IMessageReceiveListener.onConnection is called: i=${i}, str=${str}, jSONObject=${jSONObject}`);
+                this["onConnection"](i, str, jSONObject);
+            };
+            IMessageReceiveListener["onFeedBackLog"].implementation = function (str) {
+                console.log(`IMessageReceiveListener.onFeedBackLog is called: str=${str}`);
+                this["onFeedBackLog"](str);
+            };
+            IMessageReceiveListener["onMessage"].implementation = function (bArr, i) {
+                console.log(`IMessageReceiveListener.onMessage is called: bArr=${bArr}, i=${i}`);
+                this["onMessage"](bArr, i);
+            };
+
+            let IWsClient = Java.use("com.bytedance.frameworks.baselib.network.http.cronet.websocket.IWsClient");
+            IWsClient["sendMessage"].implementation = function (bArr, i) {
+                console.log(`IWsClient.sendMessage is called: bArr=${bArr}, i=${i}`);
+                let result = this["sendMessage"](bArr, i);
+                console.log(`IWsClient.sendMessage result=${result}`);
+                return result;
+            };
+        }
+
+        function hookDebugMode() {
+            let DebugUtil = Java.use("com.bytedance.bdp.appbase.debug.DebugUtil");
+            DebugUtil["debug"].implementation = function () {
+                console.log(`DebugUtil.debug is called`);
+                let result = this["debug"]();
+                console.log(`DebugUtil.debug result=${result}`);
+                return true;
+            };
+            DebugUtil["checkDebugSign"].implementation = function (str) {
+                console.log(`DebugUtil.checkDebugSign is called: str=${str}`);
+                let result = this["checkDebugSign"](str);
+                console.log(`DebugUtil.checkDebugSign result=${result}`);
+                return true;
+            };
+
+            let ChannelUtil = Java.use("com.tt.miniapp.util.ChannelUtil");
+            ChannelUtil["isLocalTest"].implementation = function () {
+                console.log(`ChannelUtil.isLocalTest is called`);
+                let result = this["isLocalTest"]();
+                console.log(`ChannelUtil.isLocalTest result=${result}`);
+                return true;
+            };
+
+            DebugUtil.DEBUG = true;
+        }
+
+        Java.perform(function () {
+            logColor("HookDY.js is loaded", LogColor.GREEN_TEXT);
+            // hookDebugMode();
+            // hookTextView();
+            // hookSocket();
+
+            let OnMessageListener = Java.use("com.ss.ugc.live.sdk.message.interfaces.OnMessageListener");
+            OnMessageListener["onMessage"].implementation = function (iMessage) {
+                console.log(`OnMessageListener.onMessage is called: iMessage=${iMessage}`);
+                logColor("OnMessageListener.onMessage is called: iMessage=" + iMessage, LogColor.RED_TEXT);
+                this["onMessage"](iMessage);
+            };
+
+            // let C2120008In = Java.use("X.08In");
+            // C2120008In["onMessage"].implementation = function (iMessage) {
+            //     console.log(`C2120008In.onMessage is called: iMessage=${iMessage}`);
+            //     console.log("performClick triggered, printing stack trace:");
+            //     Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()).split("\n").forEach(function (line) {
+            //         console.log(line);
+            //     });
+            //     this["onMessage"](iMessage);
+            // };
+            //
+            // let C1420440n0C = Java.use("X.0n0C");
+            // C1420440n0C["onMessage"].implementation = function (iMessage) {
+            //     console.log(`C1420440n0C.onMessage is called: iMessage=${iMessage}`);
+            //     this.printStackTrace();
+            //     this["onMessage"](iMessage);
+            // };
+            let GsonUtil = Java.use("com.bytedance.android.ec.core.utils.GsonUtil");
+
+            let HandlerC8064033h = Java.use("X.033h");
+            HandlerC8064033h["handleMessage"].implementation = function (msg) {
+                //解析 android.os.Message
+                let what = msg.what.value;
+                // console.log(`msg.what:${what}`);
+                let objArr = msg.obj.value;
+                if (what !== 202 && objArr != null) {
+                    let ArrayList = Java.use("java.util.ArrayList");
+                    let objList = Java.cast(objArr, ArrayList);
+                    for (let index = 0; index < objList.size(); index++) {
+                        logColor(`---------------------------------------------------------------------------------------------------------------------------------`, LogColor.RED_TEXT);
+                        let obj = objList.get(index);
+                        let toString = obj.toString();
+                        if (toString.includes("Gift")/*||toString.includes("gift")*/) {
+                            logColor(`what:${what}\t\t obj${index}\t\tclass:${obj.getClass().getName()} =>\n` + GsonUtil.toJson(obj), LogColor.YELLOW_TEXT);
+                        } else {
+                            logColor(`what:${what}\t\t obj${index}\t\tclass:${obj.getClass().getName()} =>\n` + obj, LogColor.GREEN_TEXT);
+                        }
+                        logColor(`---------------------------------------------------------------------------------------------------------------------------------`, LogColor.RED_TEXT);
                     }
                 }
 
-            },5000);
+                this["handleMessage"](msg);
+            };
+
+            //hook X.0mSO
+            // setTimeout(function (){
+            //     let use = Java.use("X.0mSO");
+            //     if (use!==null){
+            //         console.log("hook java")
+            //         use.LIZJ.overload().implementation=function () {
+            //             let lizj = this.LIZJ();
+            //             console.log("call lizj:",lizj);
+            //             return lizj;
+            //         }
+            //     }
+            //
+            // },5000);
+            // setTimeout(function () {
+            //     //hook webview的load url的所有方法
+            //     Java.perform(function () {
+            //         Java.use("android.webkit.WebView").loadUrl.overload("java.lang.String").implementation = function (url) {
+            //             console.log("load url:", url);
+            //             return this.loadUrl(url);
+            //         }
+            //     });
+            // }, 5000);
         });
     }
 }

+ 46 - 35
agent/logger.ts

@@ -1,6 +1,6 @@
 
 const DEBUG: boolean = false;
-const INTOOLS: boolean=true;
+const INTOOLS: boolean = false;
 export function log(msg: string): void {
     if (DEBUG) {
         log4Android(msg);
@@ -73,13 +73,16 @@ export function logColor(message: string, type: number): void {
         return;
     }
     switch (type) {
-        case LogColor.WHITE:
+        case LogColor.WHITE_TEXT:
+        case LogColor.WHITE_BG:
             log(message);
             break;
-        case LogColor.RED:
+        case LogColor.RED_TEXT:
+        case LogColor.RED_BG:
             console.error(message);
             break;
-        case LogColor.YELLOW:
+        case LogColor.YELLOW_TEXT:
+        case LogColor.YELLOW_BG:
             console.warn(message);
             break;
         default:
@@ -91,37 +94,45 @@ export function logColor(message: string, type: number): void {
 }
 
 export var LogColor = {
-    WHITE: 0,
-    RED: 1,
-    YELLOW: 3,
-    C31: 31,
-    C32: 32,
-    C33: 33,
-    C34: 34,
-    C35: 35,
-    C36: 36,
-    C41: 41,
-    C42: 42,
-    C43: 43,
-    C44: 44,
-    C45: 45,
-    C46: 46,
-    C90: 90,
-    C91: 91,
-    C92: 92,
-    C93: 93,
-    C94: 94,
-    C95: 95,
-    C96: 96,
-    C97: 97,
-    C100: 100,
-    C101: 101,
-    C102: 102,
-    C103: 103,
-    C104: 104,
-    C105: 105,
-    C106: 106,
-    C107: 107
+    // STANDARD TEXT COLORS
+    BLACK_TEXT: 30,
+    RED_TEXT: 31,
+    GREEN_TEXT: 32,
+    YELLOW_TEXT: 33,
+    BLUE_TEXT: 34,
+    MAGENTA_TEXT: 35,
+    CYAN_TEXT: 36,
+    WHITE_TEXT: 37,
+
+    // EXTENDED TEXT COLORS (BRIGHT VERSIONS)
+    BRIGHT_BLACK_TEXT: 90,
+    BRIGHT_RED_TEXT: 91,
+    BRIGHT_GREEN_TEXT: 92,
+    BRIGHT_YELLOW_TEXT: 93,
+    BRIGHT_BLUE_TEXT: 94,
+    BRIGHT_MAGENTA_TEXT: 95,
+    BRIGHT_CYAN_TEXT: 96,
+    BRIGHT_WHITE_TEXT: 97,
+
+    // STANDARD BACKGROUND COLORS
+    BLACK_BG: 40,
+    RED_BG: 41,
+    GREEN_BG: 42,
+    YELLOW_BG: 43,
+    BLUE_BG: 44,
+    MAGENTA_BG: 45,
+    CYAN_BG: 46,
+    WHITE_BG: 47,
+
+    // EXTENDED BACKGROUND COLORS (BRIGHT VERSIONS)
+    BRIGHT_BLACK_BG: 100,
+    BRIGHT_RED_BG: 101,
+    BRIGHT_GREEN_BG: 102,
+    BRIGHT_YELLOW_BG: 103,
+    BRIGHT_BLUE_BG: 104,
+    BRIGHT_MAGENTA_BG: 105,
+    BRIGHT_CYAN_BG: 106,
+    BRIGHT_WHITE_BG: 107
 }