Skip to content

Commit

Permalink
Support Mi browser (Chinese version)
Browse files Browse the repository at this point in the history
  • Loading branch information
JingMatrix committed Sep 29, 2024
1 parent 61465ed commit 0934f69
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions app/src/main/java/org/matrix/chromext/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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"

Expand All @@ -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
}
Expand Down

0 comments on commit 0934f69

Please sign in to comment.