fix(youtube/hide-layout-components): hide mix playlists

This commit is contained in:
oSumAtrIX 2023-07-08 04:27:45 +02:00
parent 23c95b0940
commit 33a87bd6ea
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 50 additions and 4 deletions

View File

@ -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
)

View File

@ -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()
}