diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsFingerprint.kt deleted file mode 100644 index 44a54490..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsFingerprint.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patches.youtube.ad.infocardsuggestions.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.impl.MethodFingerprint -import app.revanced.patches.youtube.ad.infocardsuggestions.annotations.HideInfocardSuggestionsCompatibility -import org.jf.dexlib2.AccessFlags - -@Name("hide-infocard-suggestions-fingerprint") -@FuzzyPatternScanMethod(2) -@HideInfocardSuggestionsCompatibility -@Version("0.0.1") -object HideInfocardSuggestionsFingerprint : MethodFingerprint( - "Ljava/lang/Boolean;", - AccessFlags.PUBLIC or AccessFlags.FINAL, - strings = listOf("vibrator") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsParentFingerprint.kt deleted file mode 100644 index 034eb301..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsParentFingerprint.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patches.youtube.ad.infocardsuggestions.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.impl.MethodFingerprint -import app.revanced.patches.youtube.ad.infocardsuggestions.annotations.HideInfocardSuggestionsCompatibility -import org.jf.dexlib2.AccessFlags - -@Name("hide-infocard-suggestions-parent-fingerprint") -@FuzzyPatternScanMethod(2) -@HideInfocardSuggestionsCompatibility -@Version("0.0.1") -object HideInfocardSuggestionsParentFingerprint : MethodFingerprint( - "Ljava/lang/String;", - AccessFlags.PUBLIC or AccessFlags.FINAL, - strings = listOf("player_overlay_info_card_teaser"), -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/patch/HideInfocardSuggestionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/patch/HideInfocardSuggestionsPatch.kt deleted file mode 100644 index a5b0fed0..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/patch/HideInfocardSuggestionsPatch.kt +++ /dev/null @@ -1,67 +0,0 @@ -package app.revanced.patches.youtube.ad.infocardsuggestions.patch - -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.replaceInstruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.ad.infocardsuggestions.annotations.HideInfocardSuggestionsCompatibility -import app.revanced.patches.youtube.ad.infocardsuggestions.fingerprints.HideInfocardSuggestionsFingerprint -import app.revanced.patches.youtube.ad.infocardsuggestions.fingerprints.HideInfocardSuggestionsParentFingerprint -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -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.builder.instruction.BuilderInstruction35c - -@Patch -@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) -@Name("hide-infocard-suggestions") -@Description("Hides infocards in videos.") -@HideInfocardSuggestionsCompatibility -@Version("0.0.1") -class HideInfocardSuggestionsPatch : BytecodePatch( - listOf( - HideInfocardSuggestionsParentFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - SettingsPatch.PreferenceScreen.ADS.addPreferences( - SwitchPreference( - "revanced_info_cards_enabled", - StringResource("revanced_info_cards_enabled_title", "Show info-cards"), - false, - StringResource("revanced_info_cards_enabled_summary_on", "Info-cards are shown"), - StringResource("revanced_info_cards_enabled_summary_off", "Info-cards are hidden") - ) - ) - - val parentResult = HideInfocardSuggestionsParentFingerprint.result - ?: return PatchResultError("Parent fingerprint not resolved!") - - - HideInfocardSuggestionsFingerprint.resolve(context, parentResult.classDef) - val result = HideInfocardSuggestionsFingerprint.result - ?: return PatchResultError("Required parent method could not be found.") - - val method = result.mutableMethod - val implementation = method.implementation - ?: return PatchResultError("Implementation not found.") - - val index = implementation.instructions.indexOfFirst { ((it as? BuilderInstruction35c)?.reference.toString() == "Landroid/view/View;->setVisibility(I)V") } - - method.replaceInstruction(index, """ - invoke-static {p1}, Lapp/revanced/integrations/patches/HideInfoCardSuggestionsPatch;->hideInfoCardSuggestions(Landroid/view/View;)V - """) - - return PatchResultSuccess() - } - -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/annotations/HideInfocardsCompatibility.kt similarity index 69% rename from src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/annotations/HideInfocardsCompatibility.kt index 0ec47f8a..4c9049d7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/annotations/HideInfocardsCompatibility.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.ad.infocardsuggestions.annotations +package app.revanced.patches.youtube.layout.hideinfocards.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package @@ -10,4 +10,4 @@ import app.revanced.patcher.annotation.Package ) @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) -internal annotation class HideInfocardSuggestionsCompatibility +internal annotation class HideInfocardsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoFingerprint.kt new file mode 100644 index 00000000..cf034ef7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.layout.hideinfocards.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.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.annotations.HideInfocardsCompatibility +import org.jf.dexlib2.AccessFlags + +@Name("infocards-incognito-fingerprint") +@HideInfocardsCompatibility +@Version("0.0.1") +object InfocardsIncognitoFingerprint : MethodFingerprint( + "Ljava/lang/Boolean;", + AccessFlags.PUBLIC or AccessFlags.FINAL, + strings = listOf("vibrator") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoParentFingerprint.kt new file mode 100644 index 00000000..4de1fd61 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsIncognitoParentFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.layout.hideinfocards.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.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.annotations.HideInfocardsCompatibility +import org.jf.dexlib2.AccessFlags + +@Name("infocards-incognito-parent-fingerprint") +@HideInfocardsCompatibility +@Version("0.0.1") +object InfocardsIncognitoParentFingerprint : MethodFingerprint( + "Ljava/lang/String;", + AccessFlags.PUBLIC or AccessFlags.FINAL, + strings = listOf("player_overlay_info_card_teaser"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsMethodCallFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsMethodCallFingerprint.kt new file mode 100644 index 00000000..a5f4178c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/fingerprints/InfocardsMethodCallFingerprint.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtube.layout.hideinfocards.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.annotations.HideInfocardsCompatibility +import app.revanced.patches.youtube.layout.hideinfocards.resource.patch.HideInfocardsResourcePatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +@Name("infocards-method-call-fingerprint") +@HideInfocardsCompatibility +@Version("0.0.1") +object InfocardsMethodCallFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_INTERFACE, + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { instruction -> + (instruction as? WideLiteralInstruction)?.wideLiteral == HideInfocardsResourcePatch.drawerResourceId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/patch/HideInfocardsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/patch/HideInfocardsPatch.kt new file mode 100644 index 00000000..94de409d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/patch/HideInfocardsPatch.kt @@ -0,0 +1,71 @@ +package app.revanced.patches.youtube.layout.hideinfocards.patch + +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.addInstructions +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.extensions.replaceInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +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.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.layout.hideinfocards.annotations.HideInfocardsCompatibility +import app.revanced.patches.youtube.layout.hideinfocards.fingerprints.InfocardsIncognitoFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.fingerprints.InfocardsMethodCallFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.fingerprints.InfocardsIncognitoParentFingerprint +import app.revanced.patches.youtube.layout.hideinfocards.resource.patch.HideInfocardsResourcePatch +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c + +@Patch +@DependsOn([IntegrationsPatch::class, HideInfocardsResourcePatch::class]) +@Name("hide-info-cards") +@Description("Hides info-cards in videos.") +@HideInfocardsCompatibility +@Version("0.0.1") +class HideInfocardsPatch : BytecodePatch( + listOf( + InfocardsIncognitoParentFingerprint, + InfocardsMethodCallFingerprint, + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + with(InfocardsIncognitoFingerprint.also { + it.resolve(context, InfocardsIncognitoParentFingerprint.result!!.classDef) + }.result!!.mutableMethod) { + val invokeInstructionIndex = implementation!!.instructions.indexOfFirst { + it.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal && + ((it as? BuilderInstruction35c)?.reference.toString() == + "Landroid/view/View;->setVisibility(I)V") + } + + replaceInstruction(invokeInstructionIndex, """ + invoke-static {v${(instruction(invokeInstructionIndex) as? BuilderInstruction35c)?.registerC}}, Lapp/revanced/integrations/patches/HideInfocardsPatch;->hideInfocardsIncognito(Landroid/view/View;)V + """ + ) + } + + with(InfocardsMethodCallFingerprint.result!!) { + val hideInfocardsCallMethod = mutableMethod + + val invokeInterfaceIndex = scanResult.patternScanResult!!.endIndex + val toggleRegister = hideInfocardsCallMethod.implementation!!.registerCount - 1 + + hideInfocardsCallMethod.addInstructions( + invokeInterfaceIndex, """ + invoke-static {}, Lapp/revanced/integrations/patches/HideInfocardsPatch;->hideInfocardsMethodCall()Z + move-result v$toggleRegister + if-nez v$toggleRegister, :hide_info_cards + """, listOf(ExternalLabel("hide_info_cards", hideInfocardsCallMethod.instruction(invokeInterfaceIndex + 1))) + ) + } + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/resource/patch/HideInfocardsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/resource/patch/HideInfocardsResourcePatch.kt new file mode 100644 index 00000000..e7f12a9c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hideinfocards/resource/patch/HideInfocardsResourcePatch.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.youtube.layout.hideinfocards.resource.patch + +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.youtube.layout.hideinfocards.annotations.HideInfocardsCompatibility +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 + +@HideInfocardsCompatibility +@DependsOn([SettingsPatch::class, ResourceMappingResourcePatch::class]) +@Version("0.0.1") +class HideInfocardsResourcePatch : ResourcePatch { + internal companion object { + var drawerResourceId: Long = -1 + } + + override fun execute(context: ResourceContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_infocards", + StringResource("revanced_hide_infocards_title", "Hide info-cards"), + true, + StringResource("revanced_hide_infocards_summary_on", "Info-cards are hidden"), + StringResource("revanced_hide_infocards_summary_off", "Info-cards are shown") + ) + ) + + drawerResourceId = ResourceMappingResourcePatch.resourceMappings.single { + it.type == "id" && it.name == "info_cards_drawer_header" + }.id + + return PatchResultSuccess() + } +} \ No newline at end of file