From 33a87bd6eac1639687ebdf96ef8924cd674f81e4 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 8 Jul 2023 04:27:45 +0200 Subject: [PATCH] fix(youtube/hide-layout-components): hide mix playlists --- .../ConvertElementToFlatBufferFingerprint.kt | 9 ++++ .../patch/HideLayoutComponentsPatch.kt | 45 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ConvertElementToFlatBufferFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ConvertElementToFlatBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ConvertElementToFlatBufferFingerprint.kt new file mode 100644 index 0000000000..a9ada6da1c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ConvertElementToFlatBufferFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.layout.hide.general.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object ConvertElementToFlatBufferFingerprint : MethodFingerprint( + strings = listOf("Failed to convert Element to Flatbuffers: %s"), + opcodes = listOf(Opcode.IGET_OBJECT) // Patched at this opcodes index +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/patch/HideLayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/patch/HideLayoutComponentsPatch.kt index 203d22ca53..00a0fd8176 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/patch/HideLayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/patch/HideLayoutComponentsPatch.kt @@ -1,18 +1,24 @@ package app.revanced.patches.youtube.layout.hide.general.patch +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.ResourceContext +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch 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.patcher.patch.annotations.Patch +import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.shared.settings.preference.impl.TextPreference import app.revanced.patches.youtube.layout.hide.general.annotations.HideLayoutComponentsCompatibility +import app.revanced.patches.youtube.layout.hide.general.fingerprints.ConvertElementToFlatBufferFingerprint import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch.PreferenceScreen @@ -23,8 +29,10 @@ import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch.P @DependsOn([LithoFilterPatch::class, SettingsPatch::class]) @HideLayoutComponentsCompatibility @Version("0.0.1") -class HideLayoutComponentsPatch : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { +class HideLayoutComponentsPatch : BytecodePatch( + listOf(ConvertElementToFlatBufferFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { PreferenceScreen.LAYOUT.addPreferences( SwitchPreference( "revanced_hide_gray_separator", @@ -237,6 +245,35 @@ class HideLayoutComponentsPatch : ResourcePatch { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) + // region Mix playlists + + ConvertElementToFlatBufferFingerprint.result?.let { + val returnEmptyComponentIndex = it.scanResult.stringsScanResult!!.matches.first().index + 2 + + it.mutableMethod.apply { + // The last virtual register (not parameter). Used to store the byte array + // that may contain information about a mix playlist. + val freeRegister = (implementation!!.registerCount - 1) - parameterTypes.size - 1 + + // Check if the byte array contains anything about a mix playlist. + addInstructionsWithLabels( + it.scanResult.patternScanResult!!.startIndex, + """ + invoke-static {v$freeRegister}, $FILTER_CLASS_DESCRIPTOR->filterMixPlaylists([B)Z + move-result v$freeRegister + if-nez v$freeRegister, :return_empty_component + """, + ExternalLabel("return_empty_component", getInstruction(returnEmptyComponentIndex)) + ) + + // Move the byte array to a free register. + addInstruction(0, "move-object/from16 v$freeRegister, p3") + } + + } ?: return ConvertElementToFlatBufferFingerprint.toErrorResult() + + // endregion + return PatchResultSuccess() }