From 346b9bdaae6da72adc5b0f2330ef4fd0a10e9551 Mon Sep 17 00:00:00 2001 From: OxrxL <108184954+OxrxL@users.noreply.github.com> Date: Wed, 28 Sep 2022 13:28:07 +0200 Subject: [PATCH] feat: `hide-email-address` patch (#578) --- .../HideEmailAddressCompatibility.kt | 13 ++++ ...ntSwitcherAccessibilityLabelFingerprint.kt | 46 +++++++++++ .../patch/HideEmailAddressPatch.kt | 76 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/annotations/HideEmailAddressCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/patch/HideEmailAddressPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/annotations/HideEmailAddressCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/annotations/HideEmailAddressCompatibility.kt new file mode 100644 index 000000000..dec9f04b5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/annotations/HideEmailAddressCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.personalinformation.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.25.34", "17.26.35", "17.27.39", "17.28.34", "17.29.34", "17.32.35", "17.33.42", "17.34.35", "17.34.36", "17.36.37") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class HideEmailAddressCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt new file mode 100644 index 000000000..ec6e5e2ae --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt @@ -0,0 +1,46 @@ +package app.revanced.patches.youtube.layout.personalinformation.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.personalinformation.annotations.HideEmailAddressCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("account-switcher-accessibility-label-fingerprint") +@MatchingMethod("Lqvs;", "mH") +@FuzzyPatternScanMethod(3) +@HideEmailAddressCompatibility +@Version("0.0.1") +object AccountSwitcherAccessibilityLabelFingerprint : MethodFingerprint( + "V", + AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.BRIDGE or AccessFlags.SYNTHETIC, + listOf("L", "L"), + listOf( + Opcode.CHECK_CAST, + Opcode.IGET_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.IGET_OBJECT, + Opcode.INVOKE_DIRECT, + Opcode.CONST_4, + Opcode.INVOKE_INTERFACE, + Opcode.IGET, + Opcode.CONST_4, + Opcode.ADD_INT_2ADDR, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.IF_NEZ, + Opcode.SGET_OBJECT, + Opcode.GOTO, + Opcode.MOVE_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/patch/HideEmailAddressPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/patch/HideEmailAddressPatch.kt new file mode 100644 index 000000000..9748459fa --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/personalinformation/patch/HideEmailAddressPatch.kt @@ -0,0 +1,76 @@ +package app.revanced.patches.youtube.layout.personalinformation.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patches.youtube.layout.personalinformation.annotations.HideEmailAddressCompatibility +import app.revanced.patches.youtube.layout.personalinformation.fingerprints.AccountSwitcherAccessibilityLabelFingerprint +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource +import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.iface.reference.MethodReference + +@Patch +@DependsOn([IntegrationsPatch::class, SettingsPatch::class, ResourceMappingResourcePatch::class]) +@Name("hide-email-address") +@Description("Hides the email address in the account switcher.") +@HideEmailAddressCompatibility +@Version("0.0.1") +class HideEmailAddressPatch : BytecodePatch( + listOf( + AccountSwitcherAccessibilityLabelFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_email_address", + StringResource("revanced_hide_email_address_title", "Hide the email address"), + false, + StringResource("revanced_hide_email_address_summary_on", "Email address is hidden"), + StringResource("revanced_hide_email_address_summary_off", "Email address is visible") + ) + ) + + val accountSwitcherAccessibilityLabelId = + ResourceMappingResourcePatch.resourceMappings.single { + it.type == "string" && it.name == "account_switcher_accessibility_label" + }.id + + val accountSwitcherAccessibilityLabelMethod = AccountSwitcherAccessibilityLabelFingerprint.result!!.mutableMethod + val accountSwitcherAccessibilityLabelInstruction = accountSwitcherAccessibilityLabelMethod.implementation!!.instructions + + val setVisibilityConstIndex = accountSwitcherAccessibilityLabelInstruction.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == accountSwitcherAccessibilityLabelId + } - 2 + + val setVisibilityConstRegister = (accountSwitcherAccessibilityLabelInstruction[setVisibilityConstIndex] as OneRegisterInstruction).registerA + val toggleRegister = (setVisibilityConstRegister - 3) + + accountSwitcherAccessibilityLabelMethod.addInstructions( + setVisibilityConstIndex + 1, """ + invoke-static {}, Lapp/revanced/integrations/patches/HideEmailAddressPatch;->hideEmailAddress()Z + move-result v$toggleRegister + if-eqz v$toggleRegister, :hide + const/16 v$setVisibilityConstRegister, 0x8 + :hide + nop + """ + ) + + return PatchResultSuccess() + } +}