From 25a0d981b3ff8456afd89d76a5f21871e9633346 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 23 Feb 2023 19:59:39 +0900 Subject: [PATCH] remove dead code --- .../CreateMixPlaylistFingerprint.kt | 27 --------- .../FourthCreateMixPlaylistFingerprint.kt | 23 -------- .../SecondCreateMixPlaylistFingerprint.kt | 27 --------- .../ThirdCreateMixPlaylistFingerprint.kt | 23 -------- .../mixplaylists/patch/MixPlaylistsPatch.kt | 59 +++---------------- .../resourceid/patch/SharedResourceIdPatch.kt | 4 -- 6 files changed, 8 insertions(+), 155 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/FourthCreateMixPlaylistFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/ThirdCreateMixPlaylistFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt deleted file mode 100644 index 0f88d2176..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt +++ /dev/null @@ -1,27 +0,0 @@ -package app.revanced.patches.youtube.layout.general.mixplaylists.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object CreateMixPlaylistFingerprint : MethodFingerprint( - returnType = "V", - access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - parameters = listOf("L", "L", "L", "L", "L", "L", "L"), - opcodes = listOf( - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_VIRTUAL - ) -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/FourthCreateMixPlaylistFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/FourthCreateMixPlaylistFingerprint.kt deleted file mode 100644 index c4cf9a5d3..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/FourthCreateMixPlaylistFingerprint.kt +++ /dev/null @@ -1,23 +0,0 @@ -package app.revanced.patches.youtube.layout.general.mixplaylists.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction - -object FourthCreateMixPlaylistFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.CONST, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.MOVE_OBJECT, - Opcode.CHECK_CAST - ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.abclistmenuitemLabelId - } == true - } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt deleted file mode 100644 index 5d34c5a90..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt +++ /dev/null @@ -1,27 +0,0 @@ -package app.revanced.patches.youtube.layout.general.mixplaylists.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object SecondCreateMixPlaylistFingerprint : MethodFingerprint( - returnType = "V", - access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - parameters = listOf("L", "L", "L", "L", "L", "L"), - opcodes = listOf( - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.RETURN_VOID - ) -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/ThirdCreateMixPlaylistFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/ThirdCreateMixPlaylistFingerprint.kt deleted file mode 100644 index 42a129880..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/fingerprints/ThirdCreateMixPlaylistFingerprint.kt +++ /dev/null @@ -1,23 +0,0 @@ -package app.revanced.patches.youtube.layout.general.mixplaylists.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction - -object ThirdCreateMixPlaylistFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IPUT_OBJECT - ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.bottompaneloverlaytextLabelId - } == true - } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt index f921f79f4..1470f321b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt @@ -1,56 +1,32 @@ package app.revanced.patches.youtube.layout.general.mixplaylists.patch -import app.revanced.extensions.injectHideCall -import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.instruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch 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.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.layout.general.mixplaylists.fingerprints.* +import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch -import org.jf.dexlib2.iface.instruction.Instruction -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction -import org.jf.dexlib2.iface.instruction.formats.Instruction21c @Patch @Name("hide-mix-playlists") @Description("Removes mix playlists from home feed and video player.") -@DependsOn([SettingsPatch::class]) +@DependsOn( + [ + LithoFilterPatch::class, + SettingsPatch::class + ] +) @YouTubeCompatibility @Version("0.0.1") -class MixPlaylistsPatch : BytecodePatch( - listOf( - CreateMixPlaylistFingerprint, - SecondCreateMixPlaylistFingerprint, - ThirdCreateMixPlaylistFingerprint, - FourthCreateMixPlaylistFingerprint - ) -) { +class MixPlaylistsPatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { - arrayOf( - CreateMixPlaylistFingerprint, - SecondCreateMixPlaylistFingerprint - ).forEach { - it.result?.addHook() ?: return it.toErrorResult() - } - - arrayOf( - ThirdCreateMixPlaylistFingerprint to true, - FourthCreateMixPlaylistFingerprint to false - ).map { (fingerprint, boolean) -> - fingerprint.result?.hookMixPlaylists(boolean) ?: return fingerprint.toErrorResult() - } - /* * Add settings */ @@ -65,23 +41,4 @@ class MixPlaylistsPatch : BytecodePatch( return PatchResultSuccess() } - - private fun MethodFingerprintResult.addHook() { - val insertIndex = scanResult.patternScanResult!!.endIndex - 3 - val register = (mutableMethod.instruction(insertIndex - 2) as OneRegisterInstruction).registerA - - mutableMethod.implementation!!.injectHideCall(insertIndex, register, "layout/GeneralLayoutPatch", "hideMixPlaylists") - } - - private fun MethodFingerprintResult.hookMixPlaylists(isThirdFingerprint: Boolean) { - fun getRegister(instruction: Instruction): Int { - if (isThirdFingerprint) return (instruction as TwoRegisterInstruction).registerA - return (instruction as Instruction21c).registerA - } - val endIndex = scanResult.patternScanResult!!.endIndex - val instruction = method.implementation!!.instructions.elementAt(endIndex) - val register = getRegister(instruction) - - mutableMethod.implementation!!.injectHideCall(endIndex, register, "layout/GeneralLayoutPatch", "hideMixPlaylists") - } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index a3f48ff64..447a50ac4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -16,12 +16,10 @@ import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch @Version("0.0.1") class SharedResourcdIdPatch : ResourcePatch { internal companion object { - var abclistmenuitemLabelId: Long = -1 var accessibilityProgressTimeLabelId: Long = -1 var accountSwitcherAccessibilityLabelId: Long = -1 var appearanceStringId: Long = -1 var backgroundCategoryLabelId: Long = -1 - var bottompaneloverlaytextLabelId: Long = -1 var bottomUiContainerResourceId: Long = -1 var controlsLayoutStubResourceId: Long = -1 var donationCompanionResourceId: Long = -1 @@ -47,12 +45,10 @@ class SharedResourcdIdPatch : ResourcePatch { .resourceMappings .single { it.type == type && it.name == name }.id - abclistmenuitemLabelId = findSharedResourceId("layout", "abc_list_menu_item_layout") accessibilityProgressTimeLabelId = findSharedResourceId("string", "accessibility_player_progress_time") accountSwitcherAccessibilityLabelId = findSharedResourceId("string", "account_switcher_accessibility_label") appearanceStringId = findSharedResourceId("string", "app_theme_appearance_dark") backgroundCategoryLabelId = findSharedResourceId("string", "pref_background_and_offline_category") - bottompaneloverlaytextLabelId = findSharedResourceId("id", "bottom_panel_overlay_text") bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub") controlsLayoutStubResourceId = findSharedResourceId("id", "controls_layout_stub") donationCompanionResourceId = findSharedResourceId("layout", "donation_companion")