From 582af167edc3304f1830b06df304382f11cc774d Mon Sep 17 00:00:00 2001 From: LittleTurtle2333 Date: Fri, 24 Feb 2023 01:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0AndoridHooker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simplicitytools/activity/MainActivity.kt | 11 ++ .../hooks/apps/AndroidHooker.kt | 7 +- .../hooks/apps/MiuiHomeHooker.kt | 3 + .../android/AllowUntrustedTouchesForAll.kt | 19 +++ .../android/DeleteOnPostNotificationForAll.kt | 19 +++ .../miuihome/ShortcutAddSmallWindowForAll.kt | 137 ++++++++++++++++++ 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/AllowUntrustedTouchesForAll.kt create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/DeleteOnPostNotificationForAll.kt create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/MainActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/MainActivity.kt index b98d6037..d331cb22 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/MainActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/MainActivity.kt @@ -11,6 +11,9 @@ import com.lt2333.simplicitytools.activity.pages.all.AboutPage import com.lt2333.simplicitytools.activity.pages.all.MenuPage import com.lt2333.simplicitytools.activity.pages.s.* import com.lt2333.simplicitytools.activity.pages.t.* +import com.microsoft.appcenter.AppCenter +import com.microsoft.appcenter.analytics.Analytics +import com.microsoft.appcenter.crashes.Crashes import java.util.* import kotlin.system.exitProcess @@ -19,6 +22,14 @@ class MainActivity : MIUIActivity() { override fun onCreate(savedInstanceState: Bundle?) { if (!checkLSPosed()) isLoad = false super.onCreate(savedInstanceState) + if (isLoad && !BuildConfig.DEBUG) { + AppCenter.start( + application, + "ae2037d3-9914-4e0c-b02b-f9b2bb2574e5", + Analytics::class.java, + Crashes::class.java + ) + } } //检测LSPosed是否激活 diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/AndroidHooker.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/AndroidHooker.kt index 67d34f1d..775711f6 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/AndroidHooker.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/AndroidHooker.kt @@ -2,18 +2,23 @@ package com.lt2333.simplicitytools.hooks.apps import android.os.Build import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.lt2333.simplicitytools.hooks.rules.all.android.AllowUntrustedTouchesForAll +import com.lt2333.simplicitytools.hooks.rules.all.android.DeleteOnPostNotificationForAll import com.lt2333.simplicitytools.hooks.rules.all.android.DisableFlagSecureForAll -import com.lt2333.simplicitytools.hooks.rules.all.corepatch.CorePatchMainHook object AndroidHooker: YukiBaseHooker() { override fun onHook() { when (Build.VERSION.SDK_INT) { Build.VERSION_CODES.TIRAMISU -> { loadHooker(DisableFlagSecureForAll) //允许截图 + loadHooker(AllowUntrustedTouchesForAll) //允许不受信任触摸 + loadHooker(DeleteOnPostNotificationForAll) //上层显示 } Build.VERSION_CODES.S -> { loadHooker(DisableFlagSecureForAll) //允许截图 + loadHooker(AllowUntrustedTouchesForAll) //允许不受信任触摸 + loadHooker(DeleteOnPostNotificationForAll) //上层显示 } } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/MiuiHomeHooker.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/MiuiHomeHooker.kt index 3e98f5ee..3fa9abcf 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/MiuiHomeHooker.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/apps/MiuiHomeHooker.kt @@ -2,14 +2,17 @@ package com.lt2333.simplicitytools.hooks.apps import android.os.Build import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.lt2333.simplicitytools.hooks.rules.all.miuihome.ShortcutAddSmallWindowForAll object MiuiHomeHooker: YukiBaseHooker() { override fun onHook() { when (Build.VERSION.SDK_INT) { Build.VERSION_CODES.TIRAMISU -> { + loadHooker(ShortcutAddSmallWindowForAll) //快捷方式添加小窗 } Build.VERSION_CODES.S -> { + loadHooker(ShortcutAddSmallWindowForAll) //快捷方式添加小窗 } } } diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/AllowUntrustedTouchesForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/AllowUntrustedTouchesForAll.kt new file mode 100644 index 00000000..20270b2c --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/AllowUntrustedTouchesForAll.kt @@ -0,0 +1,19 @@ +package com.lt2333.simplicitytools.hooks.rules.all.android + +import android.content.Context +import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.lt2333.simplicitytools.utils.hasEnable + +object AllowUntrustedTouchesForAll : YukiBaseHooker() { + override fun onHook() = hasEnable("allow_untrusted_touches") { + "android.hardware.input.InputManager".hook { + injectMember { + method { + name = "getBlockUntrustedTouchesMode" + param(Context::class.java) + } + replaceTo(0) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/DeleteOnPostNotificationForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/DeleteOnPostNotificationForAll.kt new file mode 100644 index 00000000..29fc5806 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/android/DeleteOnPostNotificationForAll.kt @@ -0,0 +1,19 @@ +package com.lt2333.simplicitytools.hooks.rules.all.android + +import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.lt2333.simplicitytools.utils.hasEnable + +object DeleteOnPostNotificationForAll: YukiBaseHooker() { + override fun onHook() { + "com.android.server.wm.AlertWindowNotification".hook { + injectMember { + method { name = "onPostNotification" } + beforeHook { + hasEnable("delete_on_post_notification") { + this.result = null + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt new file mode 100644 index 00000000..70fa48b5 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hooks/rules/all/miuihome/ShortcutAddSmallWindowForAll.kt @@ -0,0 +1,137 @@ +package com.lt2333.simplicitytools.hooks.rules.all.miuihome + +import android.app.AndroidAppHelper +import android.content.ComponentName +import android.content.Intent +import android.content.res.Configuration +import android.os.Bundle +import android.view.View +import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.highcapable.yukihookapi.hook.factory.current +import com.highcapable.yukihookapi.hook.factory.field +import com.highcapable.yukihookapi.hook.factory.toClass +import com.lt2333.simplicitytools.R +import com.lt2333.simplicitytools.utils.hasEnable +import de.robv.android.xposed.XposedHelpers + +object ShortcutAddSmallWindowForAll : YukiBaseHooker() { + override fun onHook() = hasEnable("miuihome_shortcut_add_small_window") { + val mViewDarkModeHelper = "com.miui.home.launcher.util.ViewDarkModeHelper".toClass() + val mSystemShortcutMenu = "com.miui.home.launcher.shortcuts.SystemShortcutMenu".toClass() + val mSystemShortcutMenuItem = "com.miui.home.launcher.shortcuts.SystemShortcutMenuItem".toClass() + val mAppShortcutMenu = "com.miui.home.launcher.shortcuts.AppShortcutMenu".toClass() + val mShortcutMenuItem = "com.miui.home.launcher.shortcuts.ShortcutMenuItem".toClass() + val mAppDetailsShortcutMenuItem = "com.miui.home.launcher.shortcuts.SystemShortcutMenuItem\$AppDetailsShortcutMenuItem".toClass() + val mActivityUtilsCompat = "com.miui.launcher.utils.ActivityUtilsCompat".toClass() + + mViewDarkModeHelper.hook { + injectMember { + method { name = "onConfigurationChanged" }.all() + afterHook { + mSystemShortcutMenuItem.current { + method { name = "createAllSystemShortcutMenuItems" }.call() + } + } + } + } + mShortcutMenuItem.hook { + injectMember { + method { name = "getShortTitle" } + afterHook { + if (this.result == "应用信息") { + this.result = "信息" + } + } + } + } + mAppDetailsShortcutMenuItem.hook { + injectMember { + method { + name = "lambda\$getOnClickListener$0" + paramCount = 2 + } + beforeHook { + val obj = this.args[0] + val view: View = this.args[1] as View + val mShortTitle = obj?.current { + method { name = "getShortTitle" }.invoke() + } + + if (mShortTitle == moduleAppResources.getString(R.string.miuihome_shortcut_add_small_window_title)) { + this.result = null + val intent = Intent() + val mComponentName = obj.current { + method { name = "getComponentName" }.call() + } as ComponentName + intent.action = "android.intent.action.MAIN" + intent.addCategory("android.intent.category.LAUNCHER") + intent.component = mComponentName + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + val callStaticMethod = mActivityUtilsCompat.current { + method { + name = "makeFreeformActivityOptions" + paramCount = 2 + }.call( + view.context, mComponentName.packageName + ) + } + if (callStaticMethod != null) { + view.context.startActivity(intent, callStaticMethod.current { + method { name = "toBundle" }.call() + } as Bundle) + } + } + } + } + } + mSystemShortcutMenu.hook { + injectMember { + method { + name = "getMaxShortcutItemCount" + }.all() + afterHook { + this.result = 5 + } + } + } + mAppShortcutMenu.hook { + injectMember { + method { + name = "getMaxShortcutItemCount" + }.all() + afterHook { + this.result = 5 + } + } + } + mSystemShortcutMenuItem.hook { + injectMember { + method { name = "createAllSystemShortcutMenuItems" }.all() + afterHook { + val isDarkMode = + AndroidAppHelper.currentApplication().applicationContext.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES + val mAllSystemShortcutMenuItems = mSystemShortcutMenuItem.field { + name = "sAllSystemShortcutMenuItems" + }.get().cast>() + val mSmallWindowInstance = mAppDetailsShortcutMenuItem.newInstance() + mSmallWindowInstance.current { + method { + name = "setShortTitle" + }.call(moduleAppResources.getString(R.string.miuihome_shortcut_add_small_window_title)) + } + mSmallWindowInstance.current { + method { + name = "setIconDrawable" + }.call(if (isDarkMode) moduleAppResources.getDrawable(R.drawable.ic_small_window_dark) else moduleAppResources.getDrawable(R.drawable.ic_small_window_light)) + } + val sAllSystemShortcutMenuItems = ArrayList() + sAllSystemShortcutMenuItems.add(mSmallWindowInstance) + mAllSystemShortcutMenuItems?.let { sAllSystemShortcutMenuItems.addAll(it) } + mSystemShortcutMenuItem.field { name = "sAllSystemShortcutMenuItems" }.get().set(sAllSystemShortcutMenuItems) + } + } + } + + + } +} \ No newline at end of file