Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
feat: redirect internal log
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Aug 6, 2024
1 parent b72a758 commit 1a6443b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
21 changes: 16 additions & 5 deletions app/src/main/java/gm/tieba/tabswitch/XposedInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.app.Instrumentation
import android.content.Intent
import android.content.res.XModuleResources
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import de.robv.android.xposed.IXposedHookLoadPackage
Expand All @@ -23,6 +24,7 @@ import gm.tieba.tabswitch.dao.Adp.initializeAdp
import gm.tieba.tabswitch.dao.Preferences
import gm.tieba.tabswitch.dao.Preferences.getAll
import gm.tieba.tabswitch.dao.Preferences.getBoolean
import gm.tieba.tabswitch.dao.Preferences.putBoolean
import gm.tieba.tabswitch.dao.Preferences.putSignature
import gm.tieba.tabswitch.hooker.IHooker
import gm.tieba.tabswitch.hooker.Obfuscated
Expand Down Expand Up @@ -62,6 +64,7 @@ import gm.tieba.tabswitch.hooker.eliminate.UserFilter
import gm.tieba.tabswitch.hooker.extra.AutoRefresh
import gm.tieba.tabswitch.hooker.extra.ForbidGesture
import gm.tieba.tabswitch.hooker.extra.Hide
import gm.tieba.tabswitch.hooker.extra.LogRedirect
import gm.tieba.tabswitch.hooker.extra.StackTrace
import gm.tieba.tabswitch.util.fixAlertDialogWidth
import gm.tieba.tabswitch.util.getDialogTheme
Expand Down Expand Up @@ -169,7 +172,8 @@ class XposedInit : XposedContext(), IXposedHookZygoteInit, IXposedHookLoadPackag
SelectClipboard(),
UserFilter(),
TransitionAnimation(),
AutoRefresh()
AutoRefresh(),
LogRedirect()
)
val matchers = ArrayList<Obfuscated>(hookers.size + 1)
matchers.add(TbToast())
Expand All @@ -179,9 +183,6 @@ class XposedInit : XposedContext(), IXposedHookZygoteInit, IXposedHookLoadPackag
}
}

val enabledKeys = getAll().filter { (_, value) -> value is Boolean && value == true }.keys
XposedBridge.log("Enabled hooks: ${enabledKeys.joinToString(", ")}")

val matchersList = matchers.flatMap { it.matchers() }.toMutableList()

// Remove matchers that does not satisfy version requirement
Expand Down Expand Up @@ -216,7 +217,7 @@ class XposedInit : XposedContext(), IXposedHookZygoteInit, IXposedHookLoadPackag
).apply { addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) })
}
}
XposedBridge.log("Tb version changed. Performing deobfuscation")
XposedBridge.log("Tb version changed, performing deobfuscation")

DeobfuscationHooker(matchersList).hook()
return@hookAfterMethod
Expand Down Expand Up @@ -282,6 +283,15 @@ class XposedInit : XposedContext(), IXposedHookZygoteInit, IXposedHookLoadPackag
}
}

val shouldEnableTransitionAnimationFix = Build.VERSION.SDK_INT >= 34 && isTbSatisfyVersionRequirement("12.58.2.1")
if (!shouldEnableTransitionAnimationFix && getBoolean("transition_animation")) {
putBoolean("transition_animation", false)
}

if (!isModuleBetaVersion && getBoolean("log_redirect")) {
putBoolean("log_redirect", false)
}

val activeHookerKeys = getAll().entries
.filter { it.value != false }
.map { it.key }
Expand All @@ -290,6 +300,7 @@ class XposedInit : XposedContext(), IXposedHookZygoteInit, IXposedHookLoadPackag
add("ts_pref")
add("fragment_tab")
}
XposedBridge.log("Enabled hooks: ${activeHookerKeys.joinToString(", ")}")

hookers.forEach { hooker ->
try {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/gm/tieba/tabswitch/dao/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ object Preferences {

fun getIsAutoSignEnabled(): Boolean = sTsConfig.getBoolean("auto_sign", false)

fun getTransitionAnimationEnabled(): Boolean =
sTsPreferences.getBoolean("transition_animation", false)

@SuppressLint("ApplySharedPref")
fun putPurgeEnabled() {
sTsConfig.edit().putBoolean("ze", true).commit()
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import gm.tieba.tabswitch.dao.Preferences.getBoolean
import gm.tieba.tabswitch.dao.Preferences.getIsAutoSignEnabled
import gm.tieba.tabswitch.dao.Preferences.getIsEULAAccepted
import gm.tieba.tabswitch.dao.Preferences.getIsPurgeEnabled
import gm.tieba.tabswitch.dao.Preferences.getTransitionAnimationEnabled
import gm.tieba.tabswitch.dao.Preferences.putAutoSignEnabled
import gm.tieba.tabswitch.dao.Preferences.putEULAAccepted
import gm.tieba.tabswitch.dao.Preferences.putPurgeEnabled
Expand Down Expand Up @@ -268,6 +267,10 @@ class TSPreference : XposedContext(), IHooker, Obfuscated {
preferenceLayout.addView(SwitchButtonHolder(activity, "禁止检测通知开启状态", "notification_detect", SwitchButtonHolder.TYPE_SWITCH))
preferenceLayout.addView(SwitchButtonHolder(activity, "禁止首页自动刷新", "auto_refresh", SwitchButtonHolder.TYPE_SWITCH))

if (isModuleBetaVersion) {
preferenceLayout.addView(SwitchButtonHolder(activity, "重定向内部日志", "log_redirect", SwitchButtonHolder.TYPE_SWITCH))
}

preferenceLayout.addView(createButton(TRACE, "希望有一天不再需要贴吧TS", true) { _ ->
activity.startActivity(Intent().apply {
setClassName(activity, PROXY_ACTIVITY)
Expand Down Expand Up @@ -327,10 +330,6 @@ class TSPreference : XposedContext(), IHooker, Obfuscated {
val transitionAnimation = SwitchButtonHolder(activity, "修复过渡动画", "transition_animation", SwitchButtonHolder.TYPE_SWITCH)

val shouldEnableTransitionAnimationFix = Build.VERSION.SDK_INT >= 34 && isTbSatisfyVersionRequirement("12.58.2.1")
if (!shouldEnableTransitionAnimationFix && getTransitionAnimationEnabled()) {
transitionAnimation.bdSwitch.turnOff()
}

transitionAnimation.setOnButtonClickListener { _ ->
if (!shouldEnableTransitionAnimationFix) {
showTbToast("当前贴吧版本不支持此功能", TbToast.LENGTH_SHORT)
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/hooker/extra/LogRedirect.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package gm.tieba.tabswitch.hooker.extra

import android.util.Log
import de.robv.android.xposed.XposedBridge
import gm.tieba.tabswitch.XposedContext
import gm.tieba.tabswitch.hooker.IHooker

class LogRedirect : XposedContext(), IHooker {

override fun key(): String {
return "log_redirect"
}

override fun hook() {
XposedBridge.log("TbLog redirect enabled")
hookAfterMethod("com.baidu.tieba.log.TbLog",
"d", String::class.java, String::class.java
) { param ->
(param.args[0] as? String)?.let { tag ->
(param.args[1] as? String)?.let { msg ->
Log.d("TbLog-$tag", msg)
}
}
}
hookAfterMethod("com.baidu.tieba.log.TbLog",
"e", String::class.java, String::class.java
) { param ->
(param.args[0] as? String)?.let { tag ->
(param.args[1] as? String)?.let { msg ->
Log.e("TbLog-$tag", msg)
}
}
}
hookAfterMethod("com.baidu.tieba.log.TbLog",
"i", String::class.java, String::class.java
) { param ->
(param.args[0] as? String)?.let { tag ->
(param.args[1] as? String)?.let { msg ->
Log.i("TbLog-$tag", msg)
}
}
}
hookAfterMethod("com.baidu.tieba.log.TbLog",
"v", String::class.java, String::class.java
) { param ->
(param.args[0] as? String)?.let { tag ->
(param.args[1] as? String)?.let { msg ->
Log.v("TbLog-$tag", msg)
}
}
}
hookAfterMethod("com.baidu.tieba.log.TbLog",
"w", String::class.java, String::class.java
) { param ->
(param.args[0] as? String)?.let { tag ->
(param.args[1] as? String)?.let { msg ->
Log.w("TbLog-$tag", msg)
}
}
}
}
}

0 comments on commit 1a6443b

Please sign in to comment.