From a6aeca31bd80b8c4a8acd071e22faca6e136bdb0 Mon Sep 17 00:00:00 2001 From: epicsampler <102923070+epicsampler@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:47:08 +0000 Subject: [PATCH] feat: `tastebuilder-remover` for music --- src/main/kotlin/app/revanced/patches/Index.kt | 2 + .../music/layout/RemoveTastebuilderPatch.kt | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/Index.kt b/src/main/kotlin/app/revanced/patches/Index.kt index 55ce0e28..6aacc9a7 100644 --- a/src/main/kotlin/app/revanced/patches/Index.kt +++ b/src/main/kotlin/app/revanced/patches/Index.kt @@ -3,6 +3,7 @@ package app.revanced.patches import app.revanced.patcher.patch.Patch import app.revanced.patches.music.audio.EnableAudioOnlyPatch import app.revanced.patches.music.layout.RemoveUpgradeTabPatch +import app.revanced.patches.music.layout.RemoveTastebuilderPatch import app.revanced.patches.music.premium.BackgroundPlayPatch import app.revanced.patches.youtube.ad.HomeAdsPatch import app.revanced.patches.youtube.ad.HomePromoPatch @@ -33,6 +34,7 @@ object Index { ::EnableSeekbarTappingPatch, ::EnableAudioOnlyPatch, ::RemoveUpgradeTabPatch, + ::RemoveTastebuilderPatch, ::BackgroundPlayPatch, ::CodecsUnlockPatch ) diff --git a/src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt new file mode 100644 index 00000000..723ba6a0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt @@ -0,0 +1,80 @@ +package app.revanced.patches.music.layout + +import app.revanced.patcher.PatcherData +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.or +import app.revanced.patcher.patch.* +import app.revanced.patcher.signature.MethodMetadata +import app.revanced.patcher.signature.MethodSignature +import app.revanced.patcher.signature.MethodSignatureMetadata +import app.revanced.patcher.signature.PatternScanMethod +import app.revanced.patcher.smali.toInstructions +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.formats.Instruction22c + +private val compatiblePackages = listOf( + PackageMetadata( + "com.google.android.apps.youtube.music", + listOf("5.03.50") + ) +) + +class RemoveTastebuilderPatch : Patch( + PatchMetadata( + "tastebuilder-remover", + "Remove Tastebuilder Patch", + "Remove the tastebuilder from the Home screen.", + compatiblePackages, + "0.0.1" + ), + listOf( + MethodSignature( + MethodSignatureMetadata( + "tastebuilder-constructor", + MethodMetadata("Lkyu;", ""), + PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value. + compatiblePackages, + "Required signature for this patch.", + "0.0.1" + ), + "V", + AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + listOf("L", "L", "L", "L"), + 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 + ) + ) + ) +) { + override fun execute(patcherData: PatcherData): PatchResult { + val result = signatures.first().result!! + val implementation = result.method.implementation!! + + val register = (implementation.instructions[result.scanData.endIndex] as Instruction22c).registerA + + val instructionList = + """ + const/16 v1, 0x8 + invoke-virtual {v${register}, v1}, Landroid/view/View;->setVisibility(I)V + """.trimIndent().toInstructions().toMutableList() + + implementation.addInstructions( + result.scanData.endIndex, + instructionList + ) + + return PatchResultSuccess() + } +}