generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
hide-email-address
patch (#578)
- Loading branch information
OxrxL
committed
Sep 28, 2022
1 parent
33df7e2
commit 346b9bd
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...d/patches/youtube/layout/personalinformation/annotations/HideEmailAddressCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
46 changes: 46 additions & 0 deletions
46
...e/layout/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) | ||
) |
76 changes: 76 additions & 0 deletions
76
...in/app/revanced/patches/youtube/layout/personalinformation/patch/HideEmailAddressPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |