From 0934f69a20c8b330a9286296b6b64ed2c932662c Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 29 Sep 2024 02:00:11 +0200 Subject: [PATCH] Support Mi browser (Chinese version) --- .../main/java/org/matrix/chromext/MainHook.kt | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/matrix/chromext/MainHook.kt b/app/src/main/java/org/matrix/chromext/MainHook.kt index 16d4462..9462505 100644 --- a/app/src/main/java/org/matrix/chromext/MainHook.kt +++ b/app/src/main/java/org/matrix/chromext/MainHook.kt @@ -16,6 +16,7 @@ import org.matrix.chromext.hook.PreferenceHook import org.matrix.chromext.hook.UserScriptHook import org.matrix.chromext.hook.WebViewHook import org.matrix.chromext.utils.Log +import org.matrix.chromext.utils.findMethodOrNull import org.matrix.chromext.utils.hookAfter val supportedPackages = @@ -73,7 +74,8 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { val ctx = AndroidAppHelper.currentApplication() Chrome.isMi = - lpparam.packageName == "com.mi.globalbrowser" || + Chrome.isMi || + lpparam.packageName == "com.mi.globalbrowser" || lpparam.packageName == "com.android.browser" Chrome.isQihoo = lpparam.packageName == "com.qihoo.contents" @@ -84,8 +86,37 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { if (Chrome.isMi) { WebViewHook.WebView = Chrome.load("com.miui.webkit.WebView") - WebViewHook.ViewClient = Chrome.load("com.android.browser.tab.TabWebViewClient") - WebViewHook.ChromeClient = Chrome.load("com.android.browser.tab.TabWebChromeClient") + runCatching { + WebViewHook.ViewClient = Chrome.load("com.android.browser.tab.TabWebViewClient") + WebViewHook.ChromeClient = Chrome.load("com.android.browser.tab.TabWebChromeClient") + } + .onFailure { + val miuiAutologinBar = Chrome.load("com.android.browser.MiuiAutologinBar") + // Use MiuiAutologinBar to find `com.android.browser.tab.Tab`, which can located by + // searching the string "X-MiOrigin" + val fields = miuiAutologinBar.declaredFields.map { it.type } + val tab = + miuiAutologinBar.declaredMethods + .find { + it.parameterCount == 2 && + it.parameterTypes[1] == Boolean::class.java && + !fields.contains(it.parameterTypes[0]) + }!! + .run { parameterTypes[0] } + tab.declaredFields.forEach { + if (findMethodOrNull(it.type) { + // Found by searching the string "Console: " + it.name == "onGeolocationPermissionsHidePrompt" + } != null) + WebViewHook.ChromeClient = it.type + if (findMethodOrNull(it.type) { + // Found by searching the string "Tab.MainWebViewClient" + it.name == "onReceivedHttpAuthRequest" + } != null) + WebViewHook.ViewClient = it.type + } + } + hookWebView() return }