From 8b2663c3cb3c18a7f4cc958029e73475fa780e06 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Tue, 25 Jan 2022 04:06:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=A4=9A=E9=A1=B9=20Hook=20?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fankes/tsbattery/hook/HookMain.kt | 28 +++++++++++++++++++ .../com/fankes/tsbattery/hook/HookMedium.kt | 6 ++-- .../com/fankes/tsbattery/ui/MainActivity.kt | 24 ++++++++++++++-- app/src/main/res/layout/activity_main.xml | 2 +- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/fankes/tsbattery/hook/HookMain.kt b/app/src/main/java/com/fankes/tsbattery/hook/HookMain.kt index 0c5a778..c034aa0 100644 --- a/app/src/main/java/com/fankes/tsbattery/hook/HookMain.kt +++ b/app/src/main/java/com/fankes/tsbattery/hook/HookMain.kt @@ -23,6 +23,8 @@ package com.fankes.tsbattery.hook import android.app.Activity +import android.app.Service +import android.content.Intent import android.os.Build import android.os.Bundle import android.util.Log @@ -237,6 +239,30 @@ class HookMain : IXposedHookLoadPackage { } }) } + /** Hook CoreService 全部方法 */ + runWithoutError("CoreServiceAllMethods") { + if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) + lpparam.classLoader.loadClass("$QQ_PACKAGE_NAME.app.CoreService") + .methods.forEach { + if (it.name != "onCreate" && it.name != "onDestroy" && it.name != "onBind") + XposedBridge.hookMethod(it, replaceToNull) + } + } + /** Hook CoreService 启动方法 */ + runWithoutError("CoreService") { + if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) + XposedHelpers.findAndHookMethod( + "$QQ_PACKAGE_NAME.app.CoreService", + lpparam.classLoader, "onCreate", + object : XC_MethodHook() { + + override fun afterHookedMethod(param: MethodHookParam?) { + (param?.thisObject as? Service)?.apply { + stopService(Intent(applicationContext, javaClass)) + } + } + }) + } /** 关闭保守模式后不再仅仅作用于系统电源锁 */ if (!XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) { runWithoutError("BaseChatPie(first time)") { @@ -401,6 +427,8 @@ class HookMain : IXposedHookLoadPackage { } /** 微信 */ WECHAT_PACKAGE_NAME -> { + /** 判断是否关闭 Hook */ + if (XPrefUtils.getBoolean(HookMedium.DISABLE_WECHAT_HOOK)) return lpparam.hookSystemWakeLock() /** 判断是否开启提示模块运行信息 */ if (XPrefUtils.getBoolean(HookMedium.ENABLE_RUN_INFO)) diff --git a/app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt b/app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt index 6a90f1d..210c09e 100644 --- a/app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt +++ b/app/src/main/java/com/fankes/tsbattery/hook/HookMedium.kt @@ -34,9 +34,9 @@ object HookMedium { const val ENABLE_HIDE_ICON = "_hide_icon" const val ENABLE_RUN_INFO = "_tip_run_info" const val ENABLE_QQTIM_WHITE_MODE = "_qqtim_white_mode" - const val ENABLE_QQTIM_CORESERVICE = "_qqtim_core_service" - const val ENABLE_QQTIM_CORESERVICE_CHILD = "_qqtim_core_service_child" - const val ENABLE_WECHAT_HOOK = "_wechat_hook" + const val ENABLE_QQTIM_CORESERVICE_BAN = "_qqtim_core_service_ban" + const val ENABLE_QQTIM_CORESERVICE_CHILD_BAN = "_qqtim_core_service_child_ban" + const val DISABLE_WECHAT_HOOK = "_disable_wechat_hook" const val ENABLE_MODULE_VERSION = "_module_version" const val SELF_PACKAGE_NAME = "com.fankes.tsbattery" diff --git a/app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt b/app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt index 32cb152..730b0ee 100644 --- a/app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt +++ b/app/src/main/java/com/fankes/tsbattery/ui/MainActivity.kt @@ -139,17 +139,35 @@ class MainActivity : AppCompatActivity() { } } /** 初始化 View */ - val protectModeSwitch = findViewById(R.id.protect_mode_switch) + val qqTimProtectModeSwitch = findViewById(R.id.qqtim_protect_mode_switch) + val qqTimCoreServiceSwitch = findViewById(R.id.shut_core_sv_qqtim_switch) + val qqTimCoreServiceKnSwitch = findViewById(R.id.shut_core_sv_kn_qqtim_switch) + val wechatDisableHookSwitch = findViewById(R.id.disable_wechat_sv_switch) val hideIconInLauncherSwitch = findViewById(R.id.hide_icon_in_launcher_switch) val notifyModuleInfoSwitch = findViewById(R.id.notify_module_info_switch) /** 获取 Sp 存储的信息 */ - protectModeSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE) + qqTimProtectModeSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE) + qqTimCoreServiceSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN) + qqTimCoreServiceKnSwitch.isChecked = getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN) + wechatDisableHookSwitch.isChecked = getBoolean(HookMedium.DISABLE_WECHAT_HOOK) hideIconInLauncherSwitch.isChecked = getBoolean(HookMedium.ENABLE_HIDE_ICON) notifyModuleInfoSwitch.isChecked = getBoolean(HookMedium.ENABLE_RUN_INFO) - protectModeSwitch.setOnCheckedChangeListener { btn, b -> + qqTimProtectModeSwitch.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE, b) } + qqTimCoreServiceSwitch.setOnCheckedChangeListener { btn, b -> + if (!btn.isPressed) return@setOnCheckedChangeListener + putBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN, b) + } + qqTimCoreServiceKnSwitch.setOnCheckedChangeListener { btn, b -> + if (!btn.isPressed) return@setOnCheckedChangeListener + putBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN, b) + } + wechatDisableHookSwitch.setOnCheckedChangeListener { btn, b -> + if (!btn.isPressed) return@setOnCheckedChangeListener + putBoolean(HookMedium.DISABLE_WECHAT_HOOK, b) + } hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b -> if (!btn.isPressed) return@setOnCheckedChangeListener putBoolean(HookMedium.ENABLE_HIDE_ICON, b) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 254f3f4..1300ded 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -313,7 +313,7 @@