add support YouTube v18.19.36, v18.20.39, v18.21.35, v18.22.37

This commit is contained in:
inotia00 2023-06-20 17:35:36 +09:00
parent aceaf2dade
commit 8f11b4e327
3 changed files with 54 additions and 20 deletions

View File

@ -6,12 +6,10 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[Package( [Package(
"com.google.android.youtube", arrayOf( "com.google.android.youtube", arrayOf(
"18.12.35", "18.19.36",
"18.13.38", "18.20.39",
"18.14.41", "18.21.35",
"18.15.40", "18.22.37"
"18.16.39",
"18.17.43"
) )
)] )]
) )

View File

@ -0,0 +1,14 @@
package app.revanced.patches.youtube.misc.layoutswitch.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object ClientFormFactorWalkerFingerprint : MethodFingerprint(
returnType = "L",
parameters = listOf(),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT
)
)

View File

@ -5,6 +5,7 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
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
@ -14,12 +15,16 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
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.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.shared.fingerprints.LayoutSwitchFingerprint
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.* import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorFingerprint
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorParentFingerprint
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorWalkerFingerprint
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH import app.revanced.util.integrations.Constants.MISC_PATH
import org.jf.dexlib2.Opcode
@Patch @Patch
@Name("layout-switch") @Name("layout-switch")
@ -35,19 +40,36 @@ class LayoutSwitchPatch : BytecodePatch(
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
ClientFormFactorParentFingerprint.result?.let { parentResult -> fun MutableMethod.injectTabletLayout(jumpIndex: Int) {
ClientFormFactorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { addInstructionsWithLabels(
it.mutableMethod.apply { 0, """
val jumpIndex = it.scanResult.patternScanResult!!.startIndex + 1 invoke-static {}, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z
addInstructionsWithLabels( move-result v0
1, """ if-nez v0, :tablet_layout
invoke-static {}, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z """, ExternalLabel("tablet_layout", getInstruction(jumpIndex))
move-result v2 )
if-nez v2, :tablet_layout }
""", ExternalLabel("tablet_layout", getInstruction(jumpIndex))
) ClientFormFactorParentFingerprint.result?.classDef?.let { classDef ->
try {
ClientFormFactorFingerprint.also { it.resolve(context, classDef) }.result!!.apply {
mutableMethod.injectTabletLayout(scanResult.patternScanResult!!.startIndex + 1)
} }
} ?: return ClientFormFactorFingerprint.toErrorResult() } catch (_: Exception) {
ClientFormFactorWalkerFingerprint.also { it.resolve(context, classDef) }.result?.let {
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
.getMethod() as MutableMethod).apply {
val jumpIndex = implementation!!.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.RETURN_OBJECT
} - 1
injectTabletLayout(jumpIndex)
}
} ?: return ClientFormFactorWalkerFingerprint.toErrorResult()
}
} ?: return ClientFormFactorParentFingerprint.toErrorResult() } ?: return ClientFormFactorParentFingerprint.toErrorResult()
LayoutSwitchFingerprint.result?.mutableMethod?.addInstructions( LayoutSwitchFingerprint.result?.mutableMethod?.addInstructions(
@ -57,7 +79,7 @@ class LayoutSwitchPatch : BytecodePatch(
""" """
) ?: return LayoutSwitchFingerprint.toErrorResult() ) ?: return LayoutSwitchFingerprint.toErrorResult()
/*( /**
* Add settings * Add settings
*/ */
SettingsPatch.addPreference( SettingsPatch.addPreference(