fix(YouTube): Enable wide search bar and Hide search term thumbnail patches are not compatible with some versions

This commit is contained in:
inotia00 2023-12-04 08:57:48 +09:00
parent fa3acf8ffd
commit 78da7f9ccd
4 changed files with 19 additions and 44 deletions

View File

@ -11,7 +11,7 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fingerprints.CreateSearchSuggestionsFingerprint import app.revanced.patches.youtube.general.searchterm.fingerprints.CreateSearchSuggestionsFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL import app.revanced.util.integrations.Constants.GENERAL
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode

View File

@ -1,18 +1,12 @@
package app.revanced.patches.youtube.utils.fingerprints package app.revanced.patches.youtube.general.searchterm.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object CreateSearchSuggestionsFingerprint : MethodFingerprint( object CreateSearchSuggestionsFingerprint : MethodFingerprint(
returnType = "Landroid/view/View;", returnType = "Landroid/view/View;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("I", "Landroid/view/View;", "Landroid/view/ViewGroup;"), parameters = listOf("I", "Landroid/view/View;", "Landroid/view/ViewGroup;"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.CONST_4
),
strings = listOf("ss_rds") strings = listOf("ss_rds")
) )

View File

@ -4,7 +4,6 @@ import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
@ -12,7 +11,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint
import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetWordMarkHeaderFingerprint import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetWordMarkHeaderFingerprint
import app.revanced.patches.youtube.general.widesearchbar.fingerprints.YouActionBarFingerprint import app.revanced.patches.youtube.general.widesearchbar.fingerprints.YouActionBarFingerprint
import app.revanced.patches.youtube.utils.fingerprints.CreateSearchSuggestionsFingerprint import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
@ -57,33 +56,32 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Suppress("unused") @Suppress("unused")
object WideSearchBarPatch : BytecodePatch( object WideSearchBarPatch : BytecodePatch(
setOf( setOf(
CreateSearchSuggestionsFingerprint, LayoutSwitchFingerprint,
SetActionBarRingoFingerprint, SetActionBarRingoFingerprint,
SetWordMarkHeaderFingerprint SetWordMarkHeaderFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
val result = CreateSearchSuggestionsFingerprint.result // resolves fingerprints
?: throw CreateSearchSuggestionsFingerprint.exception
val parentClassDef = SetActionBarRingoFingerprint.result?.classDef val parentClassDef = SetActionBarRingoFingerprint.result?.classDef
?: throw CreateSearchSuggestionsFingerprint.exception ?: throw SetActionBarRingoFingerprint.exception
YouActionBarFingerprint.resolve(context, parentClassDef)
// patch methods // patch methods
mapOf( SetWordMarkHeaderFingerprint.result?.let {
SetWordMarkHeaderFingerprint to 1, val targetMethod =
CreateSearchSuggestionsFingerprint to result.scanResult.patternScanResult!!.startIndex context.toMethodWalker(it.method)
).forEach { (fingerprint, callIndex) -> .nextMethod(1, true)
context.walkMutable(callIndex, fingerprint).injectSearchBarHook() .getMethod() as MutableMethod
}
YouActionBarFingerprint.also { targetMethod.injectSearchBarHook()
it.resolve( } ?: throw SetWordMarkHeaderFingerprint.exception
context,
parentClassDef LayoutSwitchFingerprint.result?.mutableMethod?.injectSearchBarHook()
) ?: throw LayoutSwitchFingerprint.exception
}.result?.let {
YouActionBarFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertIndex = it.scanResult.patternScanResult!!.endIndex
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
@ -129,18 +127,6 @@ object WideSearchBarPatch : BytecodePatch(
private const val FLAG = "android:paddingStart" private const val FLAG = "android:paddingStart"
private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml" private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml"
/**
* Walk a fingerprints method at a given index mutably.
*
* @param index The index to walk at.
* @param fromFingerprint The fingerprint to walk the method on.
* @return The [MutableMethod] which was walked on.
*/
private fun BytecodeContext.walkMutable(index: Int, fromFingerprint: MethodFingerprint) =
fromFingerprint.result?.let {
toMethodWalker(it.method).nextMethod(index, true).getMethod() as MutableMethod
} ?: throw fromFingerprint.exception
/** /**
* Injects instructions required for certain methods. * Injects instructions required for certain methods.
*/ */

View File

@ -2,12 +2,9 @@ package app.revanced.patches.youtube.misc.layoutswitch
import app.revanced.extensions.exception import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
@ -16,8 +13,6 @@ import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.GetFormFactor
import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH import app.revanced.util.integrations.Constants.MISC_PATH
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction10x
@Patch( @Patch(
name = "Layout switch", name = "Layout switch",