From 1fbb5c4beebb9b32d7bb015aadc4855381f80329 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sat, 5 Aug 2023 07:27:50 +0900 Subject: [PATCH] feat(youtube/hide-button-container): now it support versions other than YouTube v18.20.39 https://github.com/ReVanced/revanced-patches/pull/2723 --- .../fingerprints/litho/PbToFbFingerprint.kt | 17 ---- .../litho/PbToFbLegacyFingerprint.kt | 16 ---- .../patch/litho/ComponentParserPatch.kt | 80 +------------------ .../patch/ButtonContainerPatch.kt | 10 --- .../GeneralByteBufferFingerprint.kt} | 4 +- ...nt.kt => LowLevelByteBufferFingerprint.kt} | 2 +- .../utils/litho/patch/LithoFilterPatch.kt | 35 +++++--- .../settings/resource/patch/SettingsPatch.kt | 2 - .../youtube/settings/host/values/strings.xml | 3 - .../youtube/settings/xml/revanced_prefs.xml | 10 +-- 10 files changed, 33 insertions(+), 146 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbLegacyFingerprint.kt rename src/main/kotlin/app/revanced/patches/{shared/fingerprints/litho/ByteBufferHookFingerprint.kt => youtube/utils/litho/fingerprints/GeneralByteBufferFingerprint.kt} (72%) rename src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/{ByteBufferFingerprint.kt => LowLevelByteBufferFingerprint.kt} (92%) diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbFingerprint.kt deleted file mode 100644 index 97999469c..000000000 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbFingerprint.kt +++ /dev/null @@ -1,17 +0,0 @@ -package app.revanced.patches.shared.fingerprints.litho - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -object PbToFbFingerprint : MethodFingerprint( - returnType = "L", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("[B"), - opcodes = listOf( - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT - ), - strings = listOf("PbToFb failed: ") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbLegacyFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbLegacyFingerprint.kt deleted file mode 100644 index 1ef1b5963..000000000 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/PbToFbLegacyFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.shared.fingerprints.litho - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -object PbToFbLegacyFingerprint : MethodFingerprint( - returnType = "L", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT - ), - strings = listOf("Failed to convert Element to Flatbuffers: %s") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt b/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt index d949168fc..9311a8e5c 100644 --- a/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt @@ -6,37 +6,28 @@ import app.revanced.patcher.data.toMethodWalker 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.extensions.or 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.util.proxy.mutableTypes.MutableField.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.shared.fingerprints.litho.ByteBufferHookFingerprint import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint import app.revanced.patches.shared.fingerprints.litho.IdentifierFingerprint -import app.revanced.patches.shared.fingerprints.litho.PbToFbFingerprint -import app.revanced.patches.shared.fingerprints.litho.PbToFbLegacyFingerprint import app.revanced.util.bytecode.getStringIndex -import com.android.tools.smali.dexlib2.AccessFlags +import app.revanced.util.integrations.Constants.ADS_PATH import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference -import com.android.tools.smali.dexlib2.immutable.ImmutableField import kotlin.properties.Delegates class ComponentParserPatch : BytecodePatch( listOf( - ByteBufferHookFingerprint, EmptyComponentBuilderFingerprint, - IdentifierFingerprint, - PbToFbFingerprint, - PbToFbLegacyFingerprint + IdentifierFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -68,35 +59,6 @@ class ComponentParserPatch : BytecodePatch( } } ?: return EmptyComponentBuilderFingerprint.toErrorResult() - val pbToFbResult = PbToFbFingerprint.result - ?: PbToFbLegacyFingerprint.result - ?: throw PbToFbLegacyFingerprint.toErrorResult() - - pbToFbResult.let { - it.mutableMethod.apply { - val byteBufferClassIndex = it.scanResult.patternScanResult!!.startIndex - - byteBufferClassLabel = - getInstruction(byteBufferClassIndex).reference.toString() - } - } - - ByteBufferHookFingerprint.result?.let { - (context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) - .getMethod() as MutableMethod - ).apply { - val methodName = - EmptyComponentBuilderFingerprint.result!!.mutableMethod.definingClass - - addInstruction( - 0, - "sput-object p2, $methodName->buffer:Ljava/nio/ByteBuffer;" - ) - } - } ?: return ByteBufferHookFingerprint.toErrorResult() - IdentifierFingerprint.result?.let { it.mutableMethod.apply { insertMethod = this @@ -129,18 +91,6 @@ class ComponentParserPatch : BytecodePatch( register insertIndex = stringBuilderIndex + 1 - - it.mutableClass.staticFields.add( - ImmutableField( - definingClass, - "buffer", - "Ljava/nio/ByteBuffer;", - AccessFlags.PUBLIC or AccessFlags.STATIC, - null, - annotations, - null - ).toMutable() - ) } } ?: return IdentifierFingerprint.toErrorResult() @@ -148,7 +98,6 @@ class ComponentParserPatch : BytecodePatch( } internal companion object { - lateinit var byteBufferClassLabel: String lateinit var emptyComponentLabel: String lateinit var insertMethod: MutableMethod @@ -167,8 +116,7 @@ class ComponentParserPatch : BytecodePatch( addInstructionsWithLabels( insertIndex, """ - sget-object v$freeRegister, $definingClass->buffer:Ljava/nio/ByteBuffer; - invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$freeRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z + invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z move-result v$freeRegister if-eqz v$freeRegister, :unfiltered """ + emptyComponentLabel, @@ -192,27 +140,5 @@ class ComponentParserPatch : BytecodePatch( ) } } - - // only for YouTube v18.20.39 - fun legacyHook( - descriptor: String - ) { - insertMethod.apply { - addInstructionsWithLabels( - insertIndex, - """ - move-object/from16 v$freeRegister, p3 - iget-object v$freeRegister, v$freeRegister, ${parameters[2]}->b:Ljava/lang/Object; - if-eqz v$freeRegister, :unfiltered - check-cast v$freeRegister, $byteBufferClassLabel - iget-object v$freeRegister, v$freeRegister, $byteBufferClassLabel->b:Ljava/nio/ByteBuffer; - invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$freeRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z - move-result v$freeRegister - if-eqz v$freeRegister, :unfiltered - """ + emptyComponentLabel, - ExternalLabel("unfiltered", getInstruction(insertIndex)) - ) - } - } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt index 37cbe1f38..167d79c15 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt @@ -28,16 +28,6 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH class ButtonContainerPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - if (SettingsPatch.below1820) { - LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ActionButtonsFilter;") - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE: BOTTOM_PLAYER_SETTINGS", - "SETTINGS: EXPERIMENTAL_BUTTON_CONTAINER" - ) - ) - } - LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ButtonsFilter;") /** diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/ByteBufferHookFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/GeneralByteBufferFingerprint.kt similarity index 72% rename from src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/ByteBufferHookFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/GeneralByteBufferFingerprint.kt index 51b1b8fc0..ddd3205f2 100644 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/litho/ByteBufferHookFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/GeneralByteBufferFingerprint.kt @@ -1,9 +1,9 @@ -package app.revanced.patches.shared.fingerprints.litho +package app.revanced.patches.youtube.utils.litho.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.Opcode -object ByteBufferHookFingerprint : MethodFingerprint( +object GeneralByteBufferFingerprint : MethodFingerprint( returnType = "L", opcodes = listOf( Opcode.ADD_INT_2ADDR, diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LowLevelByteBufferFingerprint.kt similarity index 92% rename from src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LowLevelByteBufferFingerprint.kt index 0fa483e57..227436bae 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LowLevelByteBufferFingerprint.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -object ByteBufferFingerprint : MethodFingerprint( +object LowLevelByteBufferFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, parameters = listOf("L", "L"), diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt index efb5c7775..ee38046f0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt @@ -3,6 +3,7 @@ package app.revanced.patches.youtube.utils.litho.patch import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions @@ -11,12 +12,13 @@ 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.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.patch.litho.ComponentParserPatch import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.generalHook -import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.legacyHook import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility -import app.revanced.patches.youtube.utils.litho.fingerprints.ByteBufferFingerprint +import app.revanced.patches.youtube.utils.litho.fingerprints.GeneralByteBufferFingerprint import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint +import app.revanced.patches.youtube.utils.litho.fingerprints.LowLevelByteBufferFingerprint import app.revanced.patches.youtube.utils.playertype.patch.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.ADS_PATH @@ -33,22 +35,33 @@ import java.io.Closeable @Version("0.0.1") class LithoFilterPatch : BytecodePatch( listOf( - ByteBufferFingerprint, - LithoFilterFingerprint + GeneralByteBufferFingerprint, + LithoFilterFingerprint, + LowLevelByteBufferFingerprint ) ), Closeable { override fun execute(context: BytecodeContext): PatchResult { - ByteBufferFingerprint.result?.mutableMethod?.addInstruction( + LowLevelByteBufferFingerprint.result?.mutableMethod?.addInstruction( 0, - "sput-object p0, $ADS_PATH/LowLevelFilter;->byteBuffer:Ljava/nio/ByteBuffer;" - ) ?: return ByteBufferFingerprint.toErrorResult() + "invoke-static { p0 }, $ADS_PATH/LowLevelFilter;->setProtoBuffer(Ljava/nio/ByteBuffer;)V" + ) ?: return LowLevelByteBufferFingerprint.toErrorResult() - if (SettingsPatch.below1820) - legacyHook("$ADS_PATH/LithoFilterPatch;->filters") - else - generalHook("$ADS_PATH/LithoFilterPatch;->filters") + GeneralByteBufferFingerprint.result?.let { + (context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ).apply { + addInstruction( + 0, + "invoke-static { p2 }, $ADS_PATH/LithoFilterPatch;->setProtoBuffer(Ljava/nio/ByteBuffer;)V" + ) + } + } ?: return GeneralByteBufferFingerprint.toErrorResult() + + generalHook("$ADS_PATH/LithoFilterPatch;->filters") LithoFilterFingerprint.result?.mutableMethod?.apply { removeInstructions(2, 4) // Remove dummy filter. diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/resource/patch/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/resource/patch/SettingsPatch.kt index 355b436f8..f55680da9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/resource/patch/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/resource/patch/SettingsPatch.kt @@ -74,7 +74,6 @@ class SettingsPatch : AbstractSettingsResourcePatch( val playServicesVersion = node.textContent.toInt() - below1820 = playServicesVersion <= 232100000 upward1828 = playServicesVersion >= 232900000 break @@ -184,7 +183,6 @@ class SettingsPatch : AbstractSettingsResourcePatch( private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT) internal lateinit var contexts: ResourceContext - internal var below1820: Boolean = false internal var upward1828: Boolean = false internal fun addPreference(settingArray: Array) { diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 9cce69eee..aa4386ba8 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -163,9 +163,6 @@ Known issue: May not work in landscape mode or on high dpi devices Hide account menu Edit account menu filter - Action buttons are shown - Action buttons are hidden - Hide action buttons Album cards are shown Album cards are hidden Hide album cards diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 35583b0bd..e43ffdb2e 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -32,22 +32,18 @@ - - + SETTINGS: BUTTON_CONTAINER -->