From 4c3f0ff30c819c42598346a05c1eff1125bdff1d Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 13 Jun 2024 23:44:08 +0900 Subject: [PATCH] fix(YouTube Music/Custom header for YouTube Music): patch not applied to some users (due to A/B testing) --- .../music/layout/header/ChangeHeaderPatch.kt | 2 + .../utils/fix/header/RestoreOldHeaderPatch.kt | 47 +++++++++++++++++++ .../HeaderSwitchConfigFingerprint.kt | 14 ++++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/fix/header/RestoreOldHeaderPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/fix/header/fingerprints/HeaderSwitchConfigFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/header/ChangeHeaderPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/header/ChangeHeaderPatch.kt index bc519e7d7..c18a1d273 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/header/ChangeHeaderPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/header/ChangeHeaderPatch.kt @@ -3,6 +3,7 @@ package app.revanced.patches.music.layout.header import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption import app.revanced.patches.music.utils.compatibility.Constants +import app.revanced.patches.music.utils.fix.header.RestoreOldHeaderPatch import app.revanced.patches.music.utils.settings.ResourceUtils import app.revanced.util.ResourceGroup import app.revanced.util.Utils.trimIndentMultiline @@ -15,6 +16,7 @@ import app.revanced.util.underBarOrThrow object ChangeHeaderPatch : BaseResourcePatch( name = "Custom header for YouTube Music", description = "Applies a custom header in the top left corner within the app.", + dependencies = setOf(RestoreOldHeaderPatch::class), compatiblePackages = Constants.COMPATIBLE_PACKAGE, use = false, ) { diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/header/RestoreOldHeaderPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/header/RestoreOldHeaderPatch.kt new file mode 100644 index 000000000..c245f8bcf --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/header/RestoreOldHeaderPatch.kt @@ -0,0 +1,47 @@ +package app.revanced.patches.music.utils.fix.header + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.music.layout.header.ChangeHeaderPatch +import app.revanced.patches.music.utils.fix.header.fingerprints.HeaderSwitchConfigFingerprint +import app.revanced.util.getTargetIndex +import app.revanced.util.getWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + description = "Fix the issues where new headers are used." +) +object RestoreOldHeaderPatch : BytecodePatch( + setOf(HeaderSwitchConfigFingerprint) +) { + override fun execute(context: BytecodeContext) { + + /** + * New Header has been added from YouTube Music v7.04.51. + * + * The new header's file names are 'action_bar_logo_ringo2.png' and 'ytm_logo_ringo2.png'. + * The only difference between the existing header and the new header is the dimensions of the image. + * + * The affected patch is [ChangeHeaderPatch]. + * + * TODO: Add a new header image file to [ChangeHeaderPatch] later. + */ + HeaderSwitchConfigFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = + getTargetIndex(getWideLiteralInstructionIndex(45617851), Opcode.MOVE_RESULT) + val targetRegister = getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "const/4 v$targetRegister, 0x0" + ) + } + } + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/header/fingerprints/HeaderSwitchConfigFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/header/fingerprints/HeaderSwitchConfigFingerprint.kt new file mode 100644 index 000000000..4b0d14f5e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/header/fingerprints/HeaderSwitchConfigFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.music.utils.fix.header.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +/** + * This fingerprint is compatible with YouTube Music v7.04.51+ + */ +internal object HeaderSwitchConfigFingerprint : LiteralValueFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + literalSupplier = { 45617851 } +) \ No newline at end of file