Skip to content

Commit

Permalink
应用包管理组件hook
Browse files Browse the repository at this point in the history
  • Loading branch information
hosizoraru committed May 18, 2023
1 parent ec2b76d commit 84ed571
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ class AppManagerPage : BasePage() {
},
)
Line()
TitleText(textId = R.string.scope_pkg_installer)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.package_installer_remove_check),
SwitchV("package_installer_remove_check")
)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.package_installer_remove_ads),
SwitchV("package_installer_remove_ads")
)
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.Disable_Safe_Model_Tip),
SwitchV("Disable_Safe_Model_Tip")
)
// TextSummaryWithSwitch(
// TextSummaryV(textId = R.string.package_installer_allow_update_system_app),
// SwitchV("package_installer_allow_update_system_app")
// )
TextSummaryWithSwitch(
TextSummaryV(textId = R.string.package_installer_show_more_apk_info),
SwitchV("package_installer_show_more_apk_info")
)
Line()
TitleText(textId = R.string.scope_settings)
TextSummaryWithSwitch(
TextSummaryV(
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/star/sky/voyager/hook/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import star.sky.voyager.hook.apps.Market
import star.sky.voyager.hook.apps.MediaEditor
import star.sky.voyager.hook.apps.MiSettings
import star.sky.voyager.hook.apps.MiShare
import star.sky.voyager.hook.apps.PackageInstaller
import star.sky.voyager.hook.apps.PowerKeeper
import star.sky.voyager.hook.apps.RearDisplay
import star.sky.voyager.hook.apps.Scanner
Expand Down Expand Up @@ -45,6 +46,7 @@ val PACKAGE_NAME_HOOKED = listOf(
"com.miui.mediaeditor",
"com.xiaomi.misettings",
"com.miui.mishare.connectivity",
"com.miui.packageinstaller",
"com.miui.powerkeeper",
"com.xiaomi.misubscreenui",
"com.xiaomi.scanner",
Expand Down Expand Up @@ -75,6 +77,7 @@ class MainHook : EasyXposedInit() {
MediaEditor, // 小米相册-编辑
MiSettings, // 小米设置
MiShare, // 小米互传
PackageInstaller, // 应用包管理组件
PowerKeeper, // 电量与性能
RearDisplay, // 背屏
Scanner, // 小爱视觉
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/kotlin/star/sky/voyager/hook/apps/PackageInstaller.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package star.sky.voyager.hook.apps

import de.robv.android.xposed.callbacks.XC_LoadPackage
import star.sky.voyager.hook.hooks.packageinstaller.DisableCountCheck
import star.sky.voyager.hook.hooks.packageinstaller.DisableSafeModelTip
import star.sky.voyager.hook.hooks.packageinstaller.RemovePackageInstallerAds
import star.sky.voyager.hook.hooks.packageinstaller.ShowMoreApkInfo
import star.sky.voyager.utils.init.AppRegister

object PackageInstaller : AppRegister() {
override val packageName: String = "com.miui.packageinstaller"

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
autoInitHooks(
lpparam,
DisableCountCheck, // 禁用频繁安装应用检查
RemovePackageInstallerAds, // 去广告
DisableSafeModelTip, // // 禁用安全守护提示
// AllowUpdateSystemApp, // 允许更新系统应用
ShowMoreApkInfo, // 显示更多应用信息
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package star.sky.voyager.hook.hooks.packageinstaller

import android.content.pm.ApplicationInfo
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.EzXHelper
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.Log
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.api.hookBeforeMethod
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable


object AllowUpdateSystemApp : HookRegister() {
override fun init() = hasEnable("package_installer_allow_update_system_app") {
try {
"android.os.SystemProperties".hookBeforeMethod(
EzXHelper.classLoader,
"getBoolean", String::class.java, Boolean::class.java
) {
if (it.args[0] == "persist.sys.allow_sys_app_update") it.result = true
}
} catch (e: Throwable) {
Log.ex(e)
}

var letter = 'a'
for (i in 0..25) {
val classIfExists = loadClassOrNull("j2.${letter}")
classIfExists?.let {
if (it.declaredMethods.size in 15..25) {
it.methodFinder().first {
parameterTypes[0] == ApplicationInfo::class.java
}.createHook {
before { hookParam ->
hookParam.result = false
}
}
}
}
Log.i(letter.toString() + classIfExists.toString())
letter++
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package star.sky.voyager.hook.hooks.packageinstaller

import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.Log
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable

object DisableCountCheck : HookRegister() {
override fun init() = hasEnable("package_installer_remove_check") {
loadClass("com.miui.packageInstaller.model.RiskControlRules").methodFinder().first {
name == "getCurrentLevel"
}.createHook {
before { param ->
Log.i("Hooked getCurrentLevel, param result = ${param.result}")
param.result = 0
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package star.sky.voyager.hook.hooks.packageinstaller

import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.finders.FieldFinder.`-Static`.fieldFinder
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable

object DisableSafeModelTip : HookRegister() {
override fun init() = hasEnable("Disable_Safe_Model_Tip") {
loadClass("com.miui.packageInstaller.model.ApkInfo").methodFinder().first {
name == "getSystemApp"
}.createHook {
returnConstant(true)
}
loadClass("com.miui.packageInstaller.InstallProgressActivity").methodFinder().first {
name == "g0"
}.createHook {
returnConstant(false)
}
loadClass("com.miui.packageInstaller.InstallProgressActivity").methodFinder().first {
name == "Q1"
}.createHook {
before {
it.result = null
}
}
loadClass("com.miui.packageInstaller.InstallProgressActivity").methodFinder().first {
true
}.createHook {
after { param ->
param.thisObject.javaClass.fieldFinder().first {
type == Boolean::class.java
}.setBoolean(param.thisObject, false)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package star.sky.voyager.hook.hooks.packageinstaller

import android.content.Context
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.EzXHelper
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.MemberExtensions.paramCount
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.api.findClassOrNull
import star.sky.voyager.utils.api.setBooleanField
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable

object RemovePackageInstallerAds : HookRegister() {
override fun init() = hasEnable("package_installer_remove_ads") {
loadClass("com.android.packageinstaller.compat.MiuiSettingsCompat").methodFinder().first {
name == "isPersonalizedAdEnabled" && returnType == Boolean::class.java
}.createHook {
after {
it.result = false
}
}
loadClass("com.android.packageinstaller.compat.MiuiSettingsCompat").methodFinder().first {
name == "isInstallRiskEnabled" &&
paramCount == 1 &&
parameterTypes[0] == Context::class.java
}.createHook {
after {
it.result = false
}
}
val qaq = listOf("s", "q", "f", "t", "r")
loadClass("m2.b").methodFinder().apply {
qaq.forEach { qaq ->
first {
name == qaq
}.createHook {
returnConstant(false)
}
}
}
var letter = 'a'
for (i in 0..25) {
try {
val classIfExists =
"com.miui.packageInstaller.ui.listcomponets.${letter}0".findClassOrNull(
EzXHelper.classLoader
)
classIfExists?.let {
it.methodFinder().first {
name == "a"
}.createHook {
after { hookParam ->
hookParam.thisObject.setBooleanField("l", false)
}
}
}
} catch (t: Throwable) {
letter++
}
}
}
}
Loading

0 comments on commit 84ed571

Please sign in to comment.