From 5dab82ffff6ee8be972c20945ffa5c5a47dfa8a2 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 18 Sep 2023 18:59:23 +0900 Subject: [PATCH] feat(music): add `hide-handle` patch --- ...ntSwitcherAccessibilityLabelFingerprint.kt | 11 +++ ...InactiveAccountThumbnailSizeFingerprint.kt | 29 ++++++ .../account/handle/patch/HideHandlePatch.kt | 95 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 4 + .../app/revanced/util/enum/CategoryType.kt | 1 + .../revanced/util/integrations/Constants.kt | 1 + .../music/settings/host/values/strings.xml | 3 + 7 files changed, 144 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/NamesInactiveAccountThumbnailSizeFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/account/handle/patch/HideHandlePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt new file mode 100644 index 000000000..825635411 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.account.handle.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.AccountSwitcherAccessibility +import app.revanced.util.bytecode.isWideLiteralExists + +object AccountSwitcherAccessibilityLabelFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("L", "Ljava/lang/Object;"), + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(AccountSwitcherAccessibility) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/NamesInactiveAccountThumbnailSizeFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/NamesInactiveAccountThumbnailSizeFingerprint.kt new file mode 100644 index 000000000..f044c45bb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/fingerprints/NamesInactiveAccountThumbnailSizeFingerprint.kt @@ -0,0 +1,29 @@ +package app.revanced.patches.music.account.handle.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.NamesInactiveAccountThumbnailSize +import app.revanced.util.bytecode.isWideLiteralExists +import com.android.tools.smali.dexlib2.Opcode + +object NamesInactiveAccountThumbnailSizeFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("L", "Ljava/lang/Object;"), + opcodes = listOf( + Opcode.IF_NEZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.GOTO, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IF_EQZ + ), + customFingerprint = { methodDef, _ -> + methodDef.isWideLiteralExists( + NamesInactiveAccountThumbnailSize + ) + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/patch/HideHandlePatch.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/patch/HideHandlePatch.kt new file mode 100644 index 000000000..05093960a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/patch/HideHandlePatch.kt @@ -0,0 +1,95 @@ +package app.revanced.patches.music.account.handle.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.music.account.handle.fingerprints.AccountSwitcherAccessibilityLabelFingerprint +import app.revanced.patches.music.account.handle.fingerprints.NamesInactiveAccountThumbnailSizeFingerprint +import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.enum.CategoryType +import app.revanced.util.integrations.Constants.MUSIC_ACCOUNT +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +@Patch +@Name("Hide handle") +@Description("Hides the handle in the account switcher.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@MusicCompatibility +class HideHandlePatch : BytecodePatch( + listOf( + AccountSwitcherAccessibilityLabelFingerprint, + NamesInactiveAccountThumbnailSizeFingerprint + ) +) { + override fun execute(context: BytecodeContext) { + + /** + * Hide handle in account menu + */ + AccountSwitcherAccessibilityLabelFingerprint.result?.let { + it.mutableMethod.apply { + val textColorIndex = implementation!!.instructions.indexOfFirst { instruction -> + ((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "setTextColor" + } + + for (index in textColorIndex until textColorIndex + 5) { + if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) continue + + if ((getInstruction(index).reference as MethodReference).name == "setVisibility") { + + val textViewInstruction = getInstruction(index) + + replaceInstruction( + index, + "invoke-static {v${textViewInstruction.registerC}, v${textViewInstruction.registerD}}, $MUSIC_ACCOUNT->hideHandle(Landroid/widget/TextView;I)V" + ) + + break + } + } + } + } ?: throw AccountSwitcherAccessibilityLabelFingerprint.exception + + /** + * Hide handle in account switcher + */ + NamesInactiveAccountThumbnailSizeFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.startIndex + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex, """ + invoke-static {v$targetRegister}, $MUSIC_ACCOUNT->hideHandle(Z)Z + move-result v$targetRegister + """ + ) + } + } ?: throw NamesInactiveAccountThumbnailSizeFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.ACCOUNT, + "revanced_hide_handle", + "true" + ) + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt index c02249695..aaa4a91a9 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -16,6 +16,7 @@ import app.revanced.util.enum.ResourceType.STYLE @DependsOn([ResourceMappingPatch::class]) class SharedResourceIdPatch : ResourcePatch { internal companion object { + var AccountSwitcherAccessibility: Long = -1 var ActionsContainer: Long = -1 var ButtonIconPaddingMedium: Long = -1 var ChipCloud: Long = -1 @@ -25,6 +26,7 @@ class SharedResourceIdPatch : ResourcePatch { var InlineTimeBarAdBreakMarkerColor: Long = -1 var IsTablet: Long = -1 var MusicMenuLikeButtons: Long = -1 + var NamesInactiveAccountThumbnailSize: Long = -1 var PrivacyTosFooter: Long = -1 var QualityTitle: Long = -1 var Text1: Long = -1 @@ -38,6 +40,7 @@ class SharedResourceIdPatch : ResourcePatch { .find { it.type == resourceType.value && it.name == resourceName }?.id ?: -1 + AccountSwitcherAccessibility = find(STRING, "account_switcher_accessibility_label") ActionsContainer = find(ID, "actions_container") ButtonIconPaddingMedium = find(DIMEN, "button_icon_padding_medium") ChipCloud = find(LAYOUT, "chip_cloud") @@ -47,6 +50,7 @@ class SharedResourceIdPatch : ResourcePatch { InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color") IsTablet = find(BOOL, "is_tablet") MusicMenuLikeButtons = find(LAYOUT, "music_menu_like_buttons") + NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size") PrivacyTosFooter = find(ID, "privacy_tos_footer") QualityTitle = find(STRING, "quality_title") Text1 = find(ID, "text1") diff --git a/src/main/kotlin/app/revanced/util/enum/CategoryType.kt b/src/main/kotlin/app/revanced/util/enum/CategoryType.kt index 704fec86e..555c2aa86 100644 --- a/src/main/kotlin/app/revanced/util/enum/CategoryType.kt +++ b/src/main/kotlin/app/revanced/util/enum/CategoryType.kt @@ -1,6 +1,7 @@ package app.revanced.util.enum internal enum class CategoryType(val value: String, var added: Boolean) { + ACCOUNT("account", false), ACTION_BAR("action_bar", false), ADS("ads", false), FLYOUT("flyout", false), diff --git a/src/main/kotlin/app/revanced/util/integrations/Constants.kt b/src/main/kotlin/app/revanced/util/integrations/Constants.kt index efe572d8a..d6bbd9f63 100644 --- a/src/main/kotlin/app/revanced/util/integrations/Constants.kt +++ b/src/main/kotlin/app/revanced/util/integrations/Constants.kt @@ -21,6 +21,7 @@ internal object Constants { const val MUSIC_INTEGRATIONS_PATH = "Lapp/revanced/music" private const val MUSIC_PATCHES_PATH = "$MUSIC_INTEGRATIONS_PATH/patches" + const val MUSIC_ACCOUNT = "$MUSIC_PATCHES_PATH/account/AccountPatch;" const val MUSIC_ACTIONBAR = "$MUSIC_PATCHES_PATH/actionbar/ActionBarPatch;" const val MUSIC_ADS_PATH = "$MUSIC_PATCHES_PATH/ads" const val MUSIC_FLYOUT = "$MUSIC_PATCHES_PATH/flyout/FlyoutPatch;" diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index bb9841934..8f74910f0 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -1,5 +1,6 @@ + Account Action Bar Ads Flyout @@ -94,6 +95,8 @@ Hide share menu Hide start radio menu Hide view song credit menu + Hides the handle in the account switcher. + Hide handle Hides the home button. Hide home button Hides the library button.