From 31a767adbb152906303ab0ae5250769fc38d0625 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 3 Jul 2022 20:50:09 +0200 Subject: [PATCH] feat: `hide-infocard-suggestions` patch (#107) --- CHANGELOG.md | 2 +- gradle.properties | 2 +- .../HideInfocardSuggestionsCompatibility.kt | 13 ++++ .../HideInfocardSuggestionsFingerprint.kt | 24 +++++++ ...ideInfocardSuggestionsParentFingerprint.kt | 24 +++++++ .../patch/HideInfocardSuggestionsPatch.kt | 71 +++++++++++++++++++ 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsParentFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/patch/HideInfocardSuggestionsPatch.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2a0381a7..9cd36976f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -647,4 +647,4 @@ * add publishing to package registry ([b475e09](https://github.com/ReVancedTeam/revanced-patches/commit/b475e09577db4dda7bbb45dbf170d78772834a6d)) * add semantic-release ([d60f1d0](https://github.com/ReVancedTeam/revanced-patches/commit/d60f1d06798d312b158b71691ecc87e828dccbc1)) * Initial commit ([bee5f2f](https://github.com/ReVancedTeam/revanced-patches/commit/bee5f2faed882271ed059b0435e6e1aa91f93dbd)) -* MinimizedPlayback, CreateButtonRemover ([cc08c6c](https://github.com/ReVancedTeam/revanced-patches/commit/cc08c6c3d38879dd4672ec671631b34aa2e3cc77)) +* MinimizedPlayback, CreateButtonRemover ([cc08c6c](https://github.com/ReVancedTeam/revanced-patches/commit/cc08c6c3d38879dd4672ec671631b34aa2e3cc77)) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 434572a269..b6bb3f1d8d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style = official -version = 2.6.0 +version = 2.6.0 \ 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/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt new file mode 100644 index 0000000000..e3703f549a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/annotations/HideInfocardSuggestionsCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.ad.infocardsuggestions.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.25.34") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class HideInfocardSuggestionsCompatibility 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 new file mode 100644 index 0000000000..1240063958 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsFingerprint.kt @@ -0,0 +1,24 @@ +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.annotation.MatchingMethod +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") +@MatchingMethod("Liff;", "i") +@FuzzyPatternScanMethod(2) +@HideInfocardSuggestionsCompatibility +@Version("0.0.1") +object HideInfocardSuggestionsFingerprint : MethodFingerprint( + "Ljava/lang/Boolean;", + AccessFlags.PUBLIC or AccessFlags.FINAL, + null, + null, + listOf("vibrator"), + null +) \ 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 new file mode 100644 index 0000000000..6c68dd13ba --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/fingerprints/HideInfocardSuggestionsParentFingerprint.kt @@ -0,0 +1,24 @@ +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.impl.MethodFingerprint +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patches.youtube.ad.infocardsuggestions.annotations.HideInfocardSuggestionsCompatibility +import org.jf.dexlib2.AccessFlags + +@Name("hide-infocard-suggestions-parent-fingerprint") +@MatchingMethod("Liff;", "lE") +@FuzzyPatternScanMethod(2) +@HideInfocardSuggestionsCompatibility +@Version("0.0.1") +object HideInfocardSuggestionsParentFingerprint : MethodFingerprint( + "Ljava/lang/String;", + AccessFlags.PUBLIC or AccessFlags.FINAL, + listOf(), + null, + listOf("player_overlay_info_card_teaser"), + null +) \ 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 new file mode 100644 index 0000000000..26edb949a4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/infocardsuggestions/patch/HideInfocardSuggestionsPatch.kt @@ -0,0 +1,71 @@ +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.impl.BytecodeData +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.removeInstruction +import app.revanced.patcher.extensions.removeInstructions +import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve +import app.revanced.patcher.patch.annotations.Dependencies +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.smali.toBuilderInstruction +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 org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction21t +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c +import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction +import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@Dependencies(dependencies = [IntegrationsPatch::class]) +@Name("hide-infocard-suggestions") +@Description("Hides infocards in videos.") +@HideInfocardSuggestionsCompatibility +@Version("0.0.1") +class HideInfocardSuggestionsPatch : BytecodePatch( + listOf( + HideInfocardSuggestionsParentFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + val parentResult = HideInfocardSuggestionsParentFingerprint.result + ?: return PatchResultError("Parent fingerprint not resolved!") + + + HideInfocardSuggestionsFingerprint.resolve(data, 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") } + val register = "v" + (implementation.instructions.get(index) as FiveRegisterInstruction).registerD + + method.removeInstruction(index) + + method.addInstructions( + index, """ + invoke-static {}, Lapp/revanced/integrations/patches/HideInfoCardSuggestionsPatch;->hideInfoCardSuggestions()I + move-result $register + invoke-virtual {p1, $register}, Landroid/view/View;->setVisibility(I)V + """ + ) + + return PatchResultSuccess() + } + +} \ No newline at end of file