Skip to content

Commit

Permalink
fix(youtube/hide-layout-components): hide mix playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 8, 2023
1 parent 23c95b0 commit 33a87bd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit 33a87bd

Please sign in to comment.