From 66f452173a0be3e5a55495112aeb0c831c90399f Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 23 Jan 2024 20:18:42 +0900 Subject: [PATCH] fix(YouTube Music/Hide taste builder): apply fingerprints compatible with the wider version --- .../misc/tastebuilder/TasteBuilderPatch.kt | 42 +++++++++++++++---- .../TasteBuilderConstructorFingerprint.kt | 32 ++------------ .../TasteBuilderSyntheticFingerprint.kt | 16 +++++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 + 4 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderSyntheticFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt index 51eab24d8..fea5092bc 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt @@ -1,18 +1,25 @@ package app.revanced.patches.music.misc.tastebuilder import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.music.misc.tastebuilder.fingerprints.TasteBuilderConstructorFingerprint +import app.revanced.patches.music.misc.tastebuilder.fingerprints.TasteBuilderSyntheticFingerprint +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicTastebuilderShelf import app.revanced.util.exception -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import app.revanced.util.getWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Hide taste builder", description = "Hides the \"Tell us which artists you like\" card from the homepage.", + dependencies = [SharedResourceIdPatch::class], compatiblePackages = [ CompatiblePackage( "com.google.android.apps.youtube.music", @@ -36,19 +43,38 @@ object TasteBuilderPatch : BytecodePatch( setOf(TasteBuilderConstructorFingerprint) ) { override fun execute(context: BytecodeContext) { - TasteBuilderConstructorFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - 8 - val register = getInstruction(insertIndex).registerA + TasteBuilderConstructorFingerprint.result?.let { parentResult -> + TasteBuilderSyntheticFingerprint.resolve(context, parentResult.classDef) + + parentResult.mutableMethod.apply { + val freeRegister = implementation!!.registerCount - parameters.size - 2 + val constIndex = getWideLiteralInstructionIndex(MusicTastebuilderShelf) + val targetIndex = implementation!!.instructions.let { + constIndex + it.subList(constIndex, it.size - 1).indexOfFirst { instruction -> + instruction.opcode == Opcode.MOVE_RESULT_OBJECT + } + } + val targetRegister = getInstruction(targetIndex).registerA addInstructions( - insertIndex, """ - const/16 v1, 0x8 - invoke-virtual {v$register, v1}, Landroid/view/View;->setVisibility(I)V + targetIndex + 1, """ + const/16 v$freeRegister, 0x8 + invoke-virtual {v$targetRegister, v$freeRegister}, Landroid/view/View;->setVisibility(I)V """ ) } } ?: throw TasteBuilderConstructorFingerprint.exception + TasteBuilderSyntheticFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.startIndex + val insertRegister = getInstruction(insertIndex).registerA + + addInstruction( + insertIndex, + "const/4 v$insertRegister, 0x0" + ) + } + } ?: throw TasteBuilderSyntheticFingerprint.exception } } diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderConstructorFingerprint.kt index f60551434..5d0af1799 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderConstructorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderConstructorFingerprint.kt @@ -1,36 +1,12 @@ package app.revanced.patches.music.misc.tastebuilder.fingerprints import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicTastebuilderShelf +import app.revanced.util.fingerprint.LiteralValueFingerprint import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode -@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. -object TasteBuilderConstructorFingerprint : MethodFingerprint( +object TasteBuilderConstructorFingerprint : LiteralValueFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - parameters = listOf("L", "L", "L"), - opcodes = listOf( - Opcode.INVOKE_DIRECT, - Opcode.INVOKE_VIRTUAL, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CONST, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.CONST, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CHECK_CAST, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.CONST - ) + literalSupplier = { MusicTastebuilderShelf } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderSyntheticFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderSyntheticFingerprint.kt new file mode 100644 index 000000000..362106f19 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/fingerprints/TasteBuilderSyntheticFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.music.misc.tastebuilder.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object TasteBuilderSyntheticFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC, + parameters = listOf("L", "Ljava/lang/Object;"), + opcodes = listOf( + Opcode.IF_NEZ, + Opcode.IGET_OBJECT + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt index 1727d40d1..5d89c5296 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt @@ -32,6 +32,7 @@ object SharedResourceIdPatch : ResourcePatch() { var MiniPlayerMdxPlaying: Long = -1 var MusicMenuLikeButtons: Long = -1 var MusicNotifierShelf: Long = -1 + var MusicTastebuilderShelf: Long = -1 var NamesInactiveAccountThumbnailSize: Long = -1 var OfflineSettingsMenuItem: Long = -1 var PlayerCastMediaRouteButton: Long = -1 @@ -67,6 +68,7 @@ object SharedResourceIdPatch : ResourcePatch() { MiniPlayerMdxPlaying = find(STRING, "mini_player_mdx_playing") MusicMenuLikeButtons = find(LAYOUT, "music_menu_like_buttons") MusicNotifierShelf = find(LAYOUT, "music_notifier_shelf") + MusicTastebuilderShelf = find(LAYOUT, "music_tastebuilder_shelf") NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size") OfflineSettingsMenuItem = find(ID, "offline_settings_menu_item") PlayerCastMediaRouteButton = find(LAYOUT, "player_cast_media_route_button")