mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-03 21:32:53 +01:00
feat(youtube): support version 18.08.37
This commit is contained in:
parent
b0834faa69
commit
4f4ceab2cc
@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
@ -20,6 +21,7 @@ import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutC
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import org.jf.dexlib2.iface.instruction.Instruction
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
import org.jf.dexlib2.iface.reference.MethodReference
|
||||
@ -66,12 +68,15 @@ class HideAutoplayButtonPatch : BytecodePatch(
|
||||
|
||||
val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction
|
||||
|
||||
// can be clobbered because this register is overwritten after the injected code
|
||||
val clobberRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA
|
||||
|
||||
addInstructions(
|
||||
insertIndex,
|
||||
"""
|
||||
invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z
|
||||
move-result v11
|
||||
if-eqz v11, :hidden
|
||||
move-result v$clobberRegister
|
||||
if-eqz v$clobberRegister, :hidden
|
||||
""", listOf(ExternalLabel("hidden", jumpInstruction))
|
||||
)
|
||||
} ?: return LayoutConstructorFingerprint.toErrorResult()
|
||||
|
@ -6,14 +6,15 @@ import app.revanced.patcher.annotation.Package
|
||||
@Compatibility(
|
||||
[Package(
|
||||
"com.google.android.youtube", arrayOf(
|
||||
"17.49.37",
|
||||
"17.49.37",
|
||||
"18.03.36",
|
||||
"18.03.42",
|
||||
"18.04.35",
|
||||
"18.04.41",
|
||||
"18.05.32",
|
||||
"18.05.35",
|
||||
"18.05.40"
|
||||
"18.05.40",
|
||||
"18.08.37"
|
||||
)
|
||||
)]
|
||||
)
|
||||
|
@ -7,12 +7,9 @@ import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
object CrowdfundingBoxFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.CONST_4,
|
||||
Opcode.CONST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.CONST,
|
||||
),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation?.instructions?.any { instruction ->
|
||||
|
@ -1,5 +1,6 @@
|
||||
package app.revanced.patches.youtube.layout.hide.crowdfundingbox.bytecode.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
@ -15,7 +16,7 @@ import app.revanced.patches.youtube.layout.hide.crowdfundingbox.annotations.Crow
|
||||
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.bytecode.fingerprints.CrowdfundingBoxFingerprint
|
||||
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.resource.patch.CrowdfundingBoxResourcePatch
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
|
||||
@Patch
|
||||
@DependsOn([IntegrationsPatch::class, CrowdfundingBoxResourcePatch::class])
|
||||
@ -29,18 +30,20 @@ class CrowdfundingBoxPatch : BytecodePatch(
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
val crowdfundingBoxResult = CrowdfundingBoxFingerprint.result!!
|
||||
val crowdfundingBoxMethod = crowdfundingBoxResult.mutableMethod
|
||||
CrowdfundingBoxFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex = it.scanResult.patternScanResult!!.endIndex
|
||||
val objectRegister = (instruction(insertIndex) as TwoRegisterInstruction).registerA
|
||||
|
||||
val moveResultObjectIndex =
|
||||
crowdfundingBoxResult.scanResult.patternScanResult!!.endIndex - 2
|
||||
|
||||
crowdfundingBoxMethod.addInstruction(
|
||||
moveResultObjectIndex + 1, """
|
||||
invoke-static {v${(crowdfundingBoxMethod.instruction(moveResultObjectIndex) as OneRegisterInstruction).registerA}}, Lapp/revanced/integrations/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V
|
||||
"""
|
||||
)
|
||||
addInstruction(insertIndex, "invoke-static {v$objectRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR")
|
||||
}
|
||||
} ?: return CrowdfundingBoxFingerprint.toErrorResult()
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val INTEGRATIONS_METHOD_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V"
|
||||
}
|
||||
}
|
||||
|
@ -3,19 +3,6 @@ package app.revanced.patches.youtube.layout.returnyoutubedislike.annotations
|
||||
import app.revanced.patcher.annotation.Compatibility
|
||||
import app.revanced.patcher.annotation.Package
|
||||
|
||||
@Compatibility(
|
||||
[Package(
|
||||
"com.google.android.youtube", arrayOf(
|
||||
"17.49.37",
|
||||
"18.03.36",
|
||||
"18.03.42",
|
||||
"18.04.35",
|
||||
"18.04.41",
|
||||
"18.05.32",
|
||||
"18.05.35",
|
||||
"18.05.40"
|
||||
)
|
||||
)]
|
||||
)
|
||||
@Compatibility([Package("com.google.android.youtube", arrayOf("18.08.37"))])
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
internal annotation class ReturnYouTubeDislikeCompatibility
|
@ -1,11 +1,8 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
object DislikeFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
|
||||
strings = listOf("like/dislike")
|
||||
)
|
@ -1,14 +1,11 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
|
||||
@FuzzyPatternScanMethod(2)
|
||||
object LikeFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
|
||||
strings = listOf("like/like")
|
||||
)
|
@ -1,11 +1,8 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
object RemoveLikeFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
|
||||
strings = listOf("like/removelike")
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
object TextComponentConstructorFingerprint : MethodFingerprint(
|
||||
access = AccessFlags.CONSTRUCTOR or AccessFlags.PRIVATE,
|
||||
strings = listOf("TextComponent")
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object TextComponentFingerprint : MethodFingerprint(
|
||||
strings = listOf("com.google.android.apps.youtube.music")
|
||||
)
|
@ -1,8 +0,0 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object TextComponentSpecParentFingerprint : MethodFingerprint(
|
||||
strings = listOf("TextComponentSpec: No converter for extension: ")
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object TextReferenceFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_STATIC_RANGE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
)
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object TextReferenceParamFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.MOVE_OBJECT_FROM16 // the first occurrence of this instruction uses the register for the text object
|
||||
)
|
||||
)
|
@ -25,7 +25,9 @@ import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
|
||||
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
|
||||
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
|
||||
@Patch
|
||||
@DependsOn(
|
||||
@ -42,7 +44,7 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
@Version("0.0.1")
|
||||
class ReturnYouTubeDislikePatch : BytecodePatch(
|
||||
listOf(
|
||||
TextComponentSpecParentFingerprint,
|
||||
TextComponentConstructorFingerprint,
|
||||
ShortsTextComponentParentFingerprint,
|
||||
LikeFingerprint,
|
||||
DislikeFingerprint,
|
||||
@ -78,27 +80,37 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
||||
|
||||
// region Hook components
|
||||
|
||||
TextComponentFingerprint.also { it.resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) }
|
||||
.result?.let {
|
||||
with(it.mutableMethod) {
|
||||
val createComponentMethod = this
|
||||
TextReferenceFingerprint.also {
|
||||
it.resolve(
|
||||
context,
|
||||
TextComponentConstructorFingerprint.result!!.classDef
|
||||
)
|
||||
}.result?.let { result ->
|
||||
val moveTextRefParamInstructionIndex = TextReferenceParamFingerprint.also {
|
||||
if (!TextReferenceParamFingerprint.resolve(context, result.method, result.classDef))
|
||||
return TextReferenceParamFingerprint.toErrorResult()
|
||||
}.result!!.scanResult.patternScanResult!!.endIndex
|
||||
|
||||
val conversionContextParam = 5
|
||||
val textRefParam = createComponentMethod.parameters.size - 2
|
||||
// Insert index must be 0, otherwise UI does not updated correctly in some situations
|
||||
// such as switching from full screen or when using previous/next overlay buttons.
|
||||
val insertIndex = 0
|
||||
result.mutableMethod.apply {
|
||||
val insertIndex = result.scanResult.patternScanResult!!.endIndex
|
||||
|
||||
createComponentMethod.addInstructions(
|
||||
insertIndex,
|
||||
"""
|
||||
move-object/from16 v7, p$conversionContextParam
|
||||
move-object/from16 v8, p$textRefParam
|
||||
invoke-static {v7, v8}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V
|
||||
"""
|
||||
)
|
||||
}
|
||||
} ?: return TextComponentFingerprint.toErrorResult()
|
||||
val atomicReferenceInstruction = (instruction(insertIndex - 1) as FiveRegisterInstruction)
|
||||
val conversionContextParam = atomicReferenceInstruction.registerC
|
||||
val textRefParam = (instruction(moveTextRefParamInstructionIndex) as TwoRegisterInstruction).registerA
|
||||
|
||||
// Overwritten after injected code, which is why it can be used.
|
||||
val clobberRegister = atomicReferenceInstruction.registerD
|
||||
|
||||
addInstructions(
|
||||
insertIndex,
|
||||
"""
|
||||
# required instruction, otherwise register might be out of range
|
||||
move-object/from16 v$clobberRegister, v$textRefParam
|
||||
invoke-static {v$clobberRegister, v$conversionContextParam}, $ON_COMPONENT_CREATED_DESCRIPTOR
|
||||
"""
|
||||
)
|
||||
}
|
||||
} ?: return TextReferenceFingerprint.toErrorResult()
|
||||
|
||||
ShortsTextComponentParentFingerprint.result?.let {
|
||||
context
|
||||
@ -138,6 +150,9 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
||||
const val INTEGRATIONS_PATCH_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;"
|
||||
|
||||
const val ON_COMPONENT_CREATED_DESCRIPTOR =
|
||||
"$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V"
|
||||
|
||||
private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,6 @@ class SpoofAppVersionPatch : BytecodePatch(
|
||||
SpoofAppVersionFingerprint
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofAppVersionPatch"
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
||||
SwitchPreference(
|
||||
@ -61,4 +57,8 @@ class SpoofAppVersionPatch : BytecodePatch(
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofAppVersionPatch"
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
|
||||
@FuzzyPatternScanMethod(2) // TODO: Find a good threshold value
|
||||
@FuzzyPatternScanMethod(2)
|
||||
object MiniPlayerDimensionsCalculatorFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
|
@ -0,0 +1,13 @@
|
||||
package app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
|
||||
object MiniPlayerOverrideParentFingerprint : MethodFingerprint(
|
||||
returnType = "L",
|
||||
access = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("L"),
|
||||
strings = listOf("VIDEO_QUALITIES_QUICK_MENU_BOTTOM_SHEET_FRAGMENT")
|
||||
)
|
@ -1,5 +1,6 @@
|
||||
package app.revanced.patches.youtube.layout.tabletminiplayer.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
@ -16,10 +17,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerDimensionsCalculatorFingerprint
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideFingerprint
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideNoContextFingerprint
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerResponseModelSizeCheckFingerprint
|
||||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.*
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
@ -33,7 +31,8 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
class TabletMiniPlayerPatch : BytecodePatch(
|
||||
listOf(
|
||||
MiniPlayerDimensionsCalculatorFingerprint,
|
||||
MiniPlayerResponseModelSizeCheckFingerprint
|
||||
MiniPlayerResponseModelSizeCheckFingerprint,
|
||||
MiniPlayerOverrideParentFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
@ -47,33 +46,42 @@ class TabletMiniPlayerPatch : BytecodePatch(
|
||||
)
|
||||
)
|
||||
|
||||
// first resolve the fingerprints via the parent fingerprint
|
||||
// First resolve the fingerprints via the parent fingerprint.
|
||||
val miniPlayerClass = MiniPlayerDimensionsCalculatorFingerprint.result!!.classDef
|
||||
|
||||
/*
|
||||
* no context parameter method
|
||||
* No context parameter method.
|
||||
*/
|
||||
MiniPlayerOverrideNoContextFingerprint.resolve(context, miniPlayerClass)
|
||||
val (method, _, parameterRegister) = MiniPlayerOverrideNoContextFingerprint.addProxyCall()
|
||||
// - 1 means to insert before the return instruction
|
||||
|
||||
// Insert right before the return instruction.
|
||||
val secondInsertIndex = method.implementation!!.instructions.size - 1
|
||||
method.insertOverride(secondInsertIndex, parameterRegister /** same register used to return **/)
|
||||
method.insertOverride(
|
||||
secondInsertIndex, parameterRegister
|
||||
/** same register used to return **/
|
||||
)
|
||||
|
||||
/*
|
||||
* method with context parameter
|
||||
* Method with context parameter.
|
||||
*/
|
||||
MiniPlayerOverrideFingerprint.resolve(context, miniPlayerClass)
|
||||
val (_, _, _) = MiniPlayerOverrideFingerprint.addProxyCall()
|
||||
MiniPlayerOverrideParentFingerprint.result?.let {
|
||||
if (!MiniPlayerOverrideFingerprint.resolve(context, it.classDef))
|
||||
return MiniPlayerOverrideFingerprint.toErrorResult()
|
||||
|
||||
MiniPlayerOverrideFingerprint.addProxyCall()
|
||||
|
||||
} ?: return MiniPlayerOverrideParentFingerprint.toErrorResult()
|
||||
|
||||
/*
|
||||
* size check return value override
|
||||
* Size check return value override.
|
||||
*/
|
||||
val (_, _, _) = MiniPlayerResponseModelSizeCheckFingerprint.addProxyCall()
|
||||
MiniPlayerResponseModelSizeCheckFingerprint.addProxyCall()
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
// helper methods
|
||||
// Helper methods.
|
||||
private companion object {
|
||||
fun MethodFingerprint.addProxyCall(): Triple<MutableMethod, Int, Int> {
|
||||
val (method, scanIndex, parameterRegister) = this.unwrap()
|
||||
|
@ -6,14 +6,15 @@ import app.revanced.patcher.annotation.Package
|
||||
@Compatibility(
|
||||
[Package(
|
||||
"com.google.android.youtube", arrayOf(
|
||||
"17.49.37",
|
||||
"17.49.37",
|
||||
"18.03.36",
|
||||
"18.03.42",
|
||||
"18.04.35",
|
||||
"18.04.41",
|
||||
"18.05.32",
|
||||
"18.05.35",
|
||||
"18.05.40"
|
||||
"18.05.40",
|
||||
"18.08.37"
|
||||
)
|
||||
)]
|
||||
)
|
||||
|
@ -107,7 +107,7 @@ class SpoofSignatureVerificationPatch : BytecodePatch(
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private companion object {
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofSignatureVerificationPatch;"
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,15 @@ import app.revanced.patcher.annotation.Package
|
||||
@Compatibility(
|
||||
[Package(
|
||||
"com.google.android.youtube", arrayOf(
|
||||
"17.49.37",
|
||||
"17.49.37",
|
||||
"18.03.36",
|
||||
"18.03.42",
|
||||
"18.04.35",
|
||||
"18.04.41",
|
||||
"18.05.32",
|
||||
"18.05.35",
|
||||
"18.05.40"
|
||||
"18.05.40",
|
||||
"18.08.37"
|
||||
)
|
||||
)]
|
||||
)
|
||||
|
@ -3,5 +3,5 @@ package app.revanced.patches.youtube.misc.integrations.fingerprints
|
||||
import app.revanced.patches.shared.integrations.patch.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||
|
||||
object InitFingerprint : IntegrationsFingerprint(
|
||||
strings = listOf("Application creation"),
|
||||
strings = listOf("Application creation", "Application.onCreate"),
|
||||
)
|
@ -5,13 +5,6 @@ import org.jf.dexlib2.Opcode
|
||||
|
||||
object ComponentContextParserFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.GOTO,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.CONST_16,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IPUT_OBJECT,
|
||||
Opcode.NEW_INSTANCE
|
||||
|
@ -5,6 +5,7 @@ import org.jf.dexlib2.Opcode
|
||||
|
||||
object EmptyComponentBuilderFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.INVOKE_STATIC_RANGE
|
||||
),
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
package app.revanced.patches.youtube.misc.litho.filter.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object ReadComponentIdentifierFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.IF_NEZ,
|
||||
null,
|
||||
Opcode.MOVE_RESULT_OBJECT // Register stores the component identifier string
|
||||
)
|
||||
)
|
@ -1,10 +1,12 @@
|
||||
package app.revanced.patches.youtube.misc.litho.filter.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
@ -16,12 +18,10 @@ import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.litho.filter.annotation.LithoFilterCompatibility
|
||||
import app.revanced.patches.youtube.misc.litho.filter.fingerprints.ComponentContextParserFingerprint
|
||||
import app.revanced.patches.youtube.misc.litho.filter.fingerprints.EmptyComponentBuilderFingerprint
|
||||
import app.revanced.patches.youtube.misc.litho.filter.fingerprints.ReadComponentIdentifierFingerprint
|
||||
import org.jf.dexlib2.iface.instruction.Instruction
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
import org.jf.dexlib2.iface.reference.FieldReference
|
||||
import org.jf.dexlib2.iface.reference.MethodReference
|
||||
|
||||
@DependsOn([IntegrationsPatch::class])
|
||||
@Description("Hooks the method which parses the bytes into a ComponentContext to filter components.")
|
||||
@ -31,33 +31,40 @@ class LithoFilterPatch : BytecodePatch(
|
||||
listOf(ComponentContextParserFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
ComponentContextParserFingerprint.result?.let { result ->
|
||||
val builderMethodIndex = EmptyComponentBuilderFingerprint
|
||||
.also { it.resolve(context, result.mutableMethod, result.mutableClass) }
|
||||
.let { it.result!!.scanResult.patternScanResult!!.startIndex }
|
||||
|
||||
ComponentContextParserFingerprint.result?.also {
|
||||
arrayOf(EmptyComponentBuilderFingerprint, ReadComponentIdentifierFingerprint).forEach { fingerprint ->
|
||||
if (!fingerprint.resolve(context, it.mutableMethod, it.mutableClass))
|
||||
return fingerprint.toErrorResult()
|
||||
}
|
||||
}?.let { result ->
|
||||
val builderMethodIndex = EmptyComponentBuilderFingerprint.patternScanEndIndex
|
||||
val emptyComponentFieldIndex = builderMethodIndex + 2
|
||||
|
||||
with(result.mutableMethod) {
|
||||
result.mutableMethod.apply {
|
||||
val insertHookIndex = result.scanResult.patternScanResult!!.endIndex
|
||||
val clobberedRegister = (instruction(insertHookIndex - 3) as OneRegisterInstruction).registerA
|
||||
val builderMethodDescriptor = instruction(builderMethodIndex).descriptor
|
||||
val emptyComponentFieldDescriptor = instruction(emptyComponentFieldIndex).descriptor
|
||||
// Register is overwritten right after it is used for this patch, therefore free to clobber.
|
||||
val clobberedRegister = instruction(insertHookIndex).oneRegister
|
||||
|
||||
val builderMethodDescriptor = instruction(builderMethodIndex).toDescriptor()
|
||||
val emptyComponentFieldDescriptor = instruction(emptyComponentFieldIndex).toDescriptor()
|
||||
@Suppress("UnnecessaryVariable")
|
||||
// The register, this patch clobbers, is previously used for the StringBuilder,
|
||||
// later on a new StringBuilder is instantiated on it.
|
||||
val stringBuilderRegister = clobberedRegister
|
||||
|
||||
val stringBuilderRegister = (instruction(insertHookIndex - 1) as TwoRegisterInstruction).registerA
|
||||
val identifierRegister = instruction(ReadComponentIdentifierFingerprint.patternScanEndIndex).oneRegister
|
||||
|
||||
addInstructions(
|
||||
insertHookIndex, // right after setting the component.pathBuilder field,
|
||||
"""
|
||||
invoke-static {v$stringBuilderRegister, v0}, Lapp/revanced/integrations/patches/LithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;)Z
|
||||
invoke-static {v$stringBuilderRegister, v$identifierRegister}, Lapp/revanced/integrations/patches/LithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;)Z
|
||||
move-result v$clobberedRegister
|
||||
if-eqz v$clobberedRegister, :not_an_ad
|
||||
move-object/from16 v0, p1
|
||||
invoke-static {v0}, $builderMethodDescriptor
|
||||
move-result-object v0
|
||||
iget-object v0, v0, $emptyComponentFieldDescriptor
|
||||
return-object v0
|
||||
move-object/from16 v$clobberedRegister, p1
|
||||
invoke-static {v$clobberedRegister}, $builderMethodDescriptor
|
||||
move-result-object v$clobberedRegister
|
||||
iget-object v$clobberedRegister, v$clobberedRegister, $emptyComponentFieldDescriptor
|
||||
return-object v$clobberedRegister
|
||||
""",
|
||||
listOf(ExternalLabel("not_an_ad", instruction(insertHookIndex)))
|
||||
)
|
||||
@ -68,14 +75,14 @@ class LithoFilterPatch : BytecodePatch(
|
||||
}
|
||||
|
||||
private companion object {
|
||||
fun Instruction.toDescriptor() = when (val reference = (this as? ReferenceInstruction)?.reference) {
|
||||
is MethodReference -> "${reference.definingClass}->${reference.name}(${
|
||||
reference.parameterTypes.joinToString(
|
||||
""
|
||||
) { it }
|
||||
})${reference.returnType}"
|
||||
is FieldReference -> "${reference.definingClass}->${reference.name}:${reference.type}"
|
||||
else -> throw PatchResultError("Unsupported reference type")
|
||||
}
|
||||
val MethodFingerprint.patternScanEndIndex
|
||||
get() = result!!.scanResult.patternScanResult!!.endIndex
|
||||
|
||||
val Instruction.descriptor
|
||||
get() = (this as ReferenceInstruction).reference.toString()
|
||||
|
||||
val Instruction.oneRegister
|
||||
get() = (this as OneRegisterInstruction).registerA
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package app.revanced.patches.youtube.misc.microg.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
object IntegrityCheckFingerprint : MethodFingerprint(
|
||||
"L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L", "L"),
|
||||
strings = listOf("This should never happen.", "GooglePlayServicesUtil", "Google Play Store signature invalid.")
|
||||
)
|
@ -10,8 +10,8 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.shared.fingerprints.WatchWhileActivityFingerprint
|
||||
import app.revanced.patches.youtube.layout.buttons.cast.patch.HideCastButtonPatch
|
||||
import app.revanced.patches.shared.misc.fix.spoof.patch.ClientSpoofPatch
|
||||
import app.revanced.patches.youtube.layout.buttons.cast.patch.HideCastButtonPatch
|
||||
import app.revanced.patches.youtube.misc.fix.playback.patch.SpoofSignatureVerificationPatch
|
||||
import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility
|
||||
import app.revanced.patches.youtube.misc.microg.fingerprints.*
|
||||
@ -34,7 +34,6 @@ import app.revanced.util.microg.MicroGBytecodeHelper
|
||||
@Version("0.0.1")
|
||||
class MicroGBytecodePatch : BytecodePatch(
|
||||
listOf(
|
||||
IntegrityCheckFingerprint,
|
||||
ServiceCheckFingerprint,
|
||||
GooglePlayUtilityFingerprint,
|
||||
CastDynamiteModuleFingerprint,
|
||||
@ -59,7 +58,6 @@ class MicroGBytecodePatch : BytecodePatch(
|
||||
REVANCED_PACKAGE_NAME
|
||||
),
|
||||
listOf(
|
||||
IntegrityCheckFingerprint,
|
||||
ServiceCheckFingerprint,
|
||||
GooglePlayUtilityFingerprint,
|
||||
CastDynamiteModuleFingerprint,
|
||||
|
@ -10,16 +10,16 @@ object ThemeSetterAppFingerprint : MethodFingerprint(
|
||||
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("L", "L", "L", "L"),
|
||||
opcodes = listOf(
|
||||
Opcode.CONST, //target reference
|
||||
Opcode.CONST, // target reference
|
||||
Opcode.GOTO,
|
||||
Opcode.CONST, //target reference
|
||||
Opcode.CONST, // target reference
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.RETURN_OBJECT,
|
||||
Opcode.NEW_INSTANCE,
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
null, // changed from invoke interface to invoke virtual
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.IF_NE,
|
||||
Opcode.CONST, //target reference
|
||||
Opcode.CONST, // target reference
|
||||
)
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
package app.revanced.patches.youtube.misc.video.quality.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object SetQualityByIndexMethodClassFieldReferenceFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
parameters = listOf("L"),
|
||||
opcodes = listOf(
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
|
||||
package app.revanced.patches.youtube.misc.video.quality.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object VideoQualityItemOnClickParentFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
strings = listOf("VIDEO_QUALITIES_MENU_BOTTOM_SHEET_FRAGMENT")
|
||||
)
|
@ -1,12 +0,0 @@
|
||||
package app.revanced.patches.youtube.misc.video.quality.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object VideoQualityReferenceFingerprint : MethodFingerprint(
|
||||
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L"), listOf(
|
||||
Opcode.IPUT_OBJECT, Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
@ -9,12 +9,13 @@ import org.jf.dexlib2.Opcode
|
||||
object VideoQualitySetterFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
listOf("[L", "I", "I", "Z", "I"),
|
||||
listOf("[L", "I", "Z"),
|
||||
listOf(
|
||||
Opcode.IF_EQZ,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.IPUT_BOOLEAN,
|
||||
)
|
||||
),
|
||||
strings = listOf("menu_item_video_quality"),
|
||||
)
|
@ -1,20 +0,0 @@
|
||||
|
||||
package app.revanced.patches.youtube.misc.video.quality.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object VideoUserQualityChangeFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
listOf("L","L","I","J"),
|
||||
listOf(
|
||||
Opcode.MOVE,
|
||||
Opcode.MOVE_WIDE,
|
||||
Opcode.INVOKE_INTERFACE_RANGE,
|
||||
Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
@ -1,5 +1,6 @@
|
||||
package app.revanced.patches.youtube.misc.video.quality.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
@ -9,6 +10,7 @@ import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
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.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
@ -17,9 +19,9 @@ import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import app.revanced.patches.youtube.misc.video.quality.annotations.RememberVideoQualityCompatibility
|
||||
import app.revanced.patches.youtube.misc.video.quality.fingerprints.VideoQualityReferenceFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.quality.fingerprints.SetQualityByIndexMethodClassFieldReferenceFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.quality.fingerprints.VideoQualityItemOnClickParentFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.quality.fingerprints.VideoQualitySetterFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.quality.fingerprints.VideoUserQualityChangeFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import org.jf.dexlib2.iface.reference.FieldReference
|
||||
@ -32,14 +34,18 @@ import org.jf.dexlib2.iface.reference.FieldReference
|
||||
@Version("0.0.1")
|
||||
class RememberVideoQualityPatch : BytecodePatch(
|
||||
listOf(
|
||||
VideoQualitySetterFingerprint
|
||||
VideoQualitySetterFingerprint,
|
||||
VideoQualityItemOnClickParentFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
||||
SwitchPreference(
|
||||
"revanced_remember_video_quality_last_selected",
|
||||
StringResource("revanced_remember_video_quality_last_selected_title", "Remember video quality changes"),
|
||||
StringResource(
|
||||
"revanced_remember_video_quality_last_selected_title",
|
||||
"Remember video quality changes"
|
||||
),
|
||||
true,
|
||||
StringResource(
|
||||
"revanced_remember_video_quality_last_selected_summary_on",
|
||||
@ -52,37 +58,80 @@ class RememberVideoQualityPatch : BytecodePatch(
|
||||
)
|
||||
)
|
||||
|
||||
val setterMethod = VideoQualitySetterFingerprint.result!!
|
||||
/*
|
||||
* The following code works by hooking the method which is called when the user selects a video quality
|
||||
* to remember the last selected video quality.
|
||||
*
|
||||
* It also hooks the method which is called when the video quality to set is determined.
|
||||
* Conveniently, at this point the video quality is overridden to the remembered playback speed.
|
||||
*/
|
||||
|
||||
VideoUserQualityChangeFingerprint.resolve(context, setterMethod.classDef)
|
||||
val userQualityMethod = VideoUserQualityChangeFingerprint.result!!
|
||||
VideoIdPatch.injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
|
||||
|
||||
VideoQualityReferenceFingerprint.resolve(context, setterMethod.classDef)
|
||||
val qualityFieldReference =
|
||||
VideoQualityReferenceFingerprint.result!!.method.let { method ->
|
||||
(method.implementation!!.instructions.elementAt(0) as ReferenceInstruction).reference as FieldReference
|
||||
}
|
||||
// Inject a call to set the remembered quality once a video loads.
|
||||
VideoQualitySetterFingerprint.result?.also {
|
||||
if (!SetQualityByIndexMethodClassFieldReferenceFingerprint.resolve(context, it.classDef))
|
||||
return PatchResultError("Could not resolve fingerprint to find setQualityByIndex method")
|
||||
}?.let {
|
||||
// This instruction refers to the field with the type that contains the setQualityByIndex method.
|
||||
val instructions = SetQualityByIndexMethodClassFieldReferenceFingerprint.result!!
|
||||
.method.implementation!!.instructions
|
||||
|
||||
VideoIdPatch.injectCall("Lapp/revanced/integrations/patches/playback/quality/RememberVideoQualityPatch;->newVideoStarted(Ljava/lang/String;)V")
|
||||
val getOnItemClickListenerClassReference =
|
||||
(instructions.elementAt(0) as ReferenceInstruction).reference
|
||||
val getSetQualityByIndexMethodClassFieldReference =
|
||||
(instructions.elementAt(1) as ReferenceInstruction).reference
|
||||
|
||||
val qIndexMethodName =
|
||||
context.classes.single { it.type == qualityFieldReference.type }.methods.single { it.parameterTypes.first() == "I" }.name
|
||||
val setQualityByIndexMethodClassFieldReference =
|
||||
getSetQualityByIndexMethodClassFieldReference as FieldReference
|
||||
|
||||
setterMethod.mutableMethod.addInstructions(
|
||||
0,
|
||||
"""
|
||||
iget-object v0, p0, ${setterMethod.classDef.type}->${qualityFieldReference.name}:${qualityFieldReference.type}
|
||||
const-string v1, "$qIndexMethodName"
|
||||
invoke-static {p1, p2, v0, v1}, Lapp/revanced/integrations/patches/playback/quality/RememberVideoQualityPatch;->setVideoQuality([Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/String;)I
|
||||
move-result p2
|
||||
""",
|
||||
)
|
||||
val setQualityByIndexMethodClass = context.classes
|
||||
.find { classDef -> classDef.type == setQualityByIndexMethodClassFieldReference.type }!!
|
||||
|
||||
userQualityMethod.mutableMethod.addInstruction(
|
||||
0,
|
||||
"invoke-static {p3}, Lapp/revanced/integrations/patches/playback/quality/RememberVideoQualityPatch;->userChangedQuality(I)V"
|
||||
)
|
||||
// Get the name of the setQualityByIndex method.
|
||||
val setQualityByIndexMethod = setQualityByIndexMethodClass.methods
|
||||
.find { method -> method.parameterTypes.first() == "I" }
|
||||
?: return PatchResultError("Could not find setQualityByIndex method")
|
||||
|
||||
it.mutableMethod.addInstructions(
|
||||
0,
|
||||
"""
|
||||
# Get the object instance to invoke the setQualityByIndex method on.
|
||||
iget-object v0, p0, $getOnItemClickListenerClassReference
|
||||
iget-object v0, v0, $getSetQualityByIndexMethodClassFieldReference
|
||||
|
||||
# Get the method name.
|
||||
const-string v1, "${setQualityByIndexMethod.name}"
|
||||
|
||||
# Set the quality.
|
||||
# The first parameter is the array list of video qualities.
|
||||
# The second parameter is the index of the selected quality.
|
||||
# The register v0 stores the object instance to invoke the setQualityByIndex method on.
|
||||
# The register v1 stores the name of the setQualityByIndex method.
|
||||
invoke-static {p1, p2, v0, v1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoQuality([Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/String;)I
|
||||
move-result p2
|
||||
""",
|
||||
)
|
||||
} ?: return VideoQualitySetterFingerprint.toErrorResult()
|
||||
|
||||
// Inject a call to remember the selected quality.
|
||||
VideoQualityItemOnClickParentFingerprint.result?.let {
|
||||
val onItemClickMethod = it.mutableClass.methods.find { method -> method.name == "onItemClick" }
|
||||
|
||||
onItemClickMethod?.apply {
|
||||
val listItemIndexParameter = 3
|
||||
|
||||
addInstruction(
|
||||
0,
|
||||
"invoke-static {p$listItemIndexParameter}, $INTEGRATIONS_CLASS_DESCRIPTOR->userChangedQuality(I)V"
|
||||
)
|
||||
} ?: return PatchResultError("Failed to find onItemClick method")
|
||||
} ?: return VideoQualityItemOnClickParentFingerprint.toErrorResult()
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/patches/playback/quality/RememberVideoQualityPatch;"
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package app.revanced.patches.youtube.misc.video.speed.remember.fingerprint
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object ChangePlaybackSpeedFragmentStateFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
strings = listOf("PLAYBACK_RATE_MENU_BOTTOM_SHEET_FRAGMENT")
|
||||
)
|
@ -3,5 +3,6 @@ package app.revanced.patches.youtube.misc.video.speed.remember.fingerprint
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
|
||||
object InitializePlaybackSpeedValuesFingerprint : MethodFingerprint(
|
||||
parameters = listOf("[L", "I")
|
||||
parameters = listOf("[L", "I"),
|
||||
strings = listOf("menu_item_playback_speed")
|
||||
)
|
@ -6,7 +6,9 @@ import org.jf.dexlib2.Opcode
|
||||
object OnPlaybackSpeedItemClickFingerprint : MethodFingerprint(
|
||||
customFingerprint = { it.name == "onItemClick" },
|
||||
opcodes = listOf(
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.RETURN_VOID
|
||||
)
|
||||
)
|
@ -8,8 +8,6 @@ import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstruction
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
@ -19,12 +17,12 @@ import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import app.revanced.patches.youtube.misc.video.speed.remember.annotation.RememberPlaybackSpeedCompatibility
|
||||
import app.revanced.patches.youtube.misc.video.speed.remember.fingerprint.ChangePlaybackSpeedFragmentStateFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.speed.remember.fingerprint.InitializePlaybackSpeedValuesFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.speed.remember.fingerprint.OnPlaybackSpeedItemClickFingerprint
|
||||
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.Instruction
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
|
||||
@Patch
|
||||
@ -34,7 +32,10 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
@RememberPlaybackSpeedCompatibility
|
||||
@Version("0.0.1")
|
||||
class RememberPlaybackSpeedPatch : BytecodePatch(
|
||||
listOf(ChangePlaybackSpeedFragmentStateFingerprint)
|
||||
listOf(
|
||||
OnPlaybackSpeedItemClickFingerprint,
|
||||
InitializePlaybackSpeedValuesFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
||||
@ -56,54 +57,67 @@ class RememberPlaybackSpeedPatch : BytecodePatch(
|
||||
)
|
||||
)
|
||||
|
||||
context.resolveFingerprints()
|
||||
|
||||
VideoIdPatch.injectCall("${INTEGRATIONS_CLASS_DESCRIPTOR}->newVideoLoaded(Ljava/lang/String;)V")
|
||||
|
||||
/*
|
||||
* The following code works by hooking the method which is called when the user selects a playback speed
|
||||
* to remember the last selected playback speed.
|
||||
*
|
||||
* It also hooks the method which is called when the playback speeds are initialized.
|
||||
* Conveniently, at this point the playback speed is set to the remembered playback speed.
|
||||
*/
|
||||
|
||||
|
||||
// Set the remembered playback speed.
|
||||
InitializePlaybackSpeedValuesFingerprint.result!!.apply {
|
||||
// Infer everything necessary for setPlaybackSate()
|
||||
InitializePlaybackSpeedValuesFingerprint.result?.apply {
|
||||
// Infer everything necessary for calling the method setPlaybackSpeed().
|
||||
val instructions = OnPlaybackSpeedItemClickFingerprint.result!!.mutableMethod.implementation!!.instructions
|
||||
fun getReference(offset: Int = 0, opcode: Opcode) =
|
||||
instructions[instructions.indexOfFirst { it.opcode == opcode } + offset].reference
|
||||
|
||||
val playbackHandlerWrapperFieldReference =
|
||||
(object : MethodFingerprint(opcodes = listOf(Opcode.IF_EQZ)) {}).apply {
|
||||
OnPlaybackSpeedItemClickFingerprint.result!!.apply {
|
||||
resolve(
|
||||
context,
|
||||
method,
|
||||
classDef
|
||||
)
|
||||
}
|
||||
}.getReference(-1)
|
||||
val playbackHandlerWrapperImplementorClassReference = OnPlaybackSpeedItemClickFingerprint
|
||||
.getReference(-1)
|
||||
val playbackHandlerFieldReference = OnPlaybackSpeedItemClickFingerprint
|
||||
.getReference()
|
||||
val setPlaybackSpeedMethodReference = OnPlaybackSpeedItemClickFingerprint
|
||||
.getReference(1)
|
||||
val setPlaybackSpeedContainerClassFieldReference =
|
||||
getReference(-1, Opcode.IF_EQZ)
|
||||
|
||||
val setPlaybackSpeedClassFieldReference =
|
||||
getReference(1, Opcode.IGET)
|
||||
|
||||
val setPlaybackSpeedMethodReference =
|
||||
getReference(2, Opcode.IGET)
|
||||
|
||||
val onItemClickListenerClassFieldReference = mutableMethod.instruction(0).reference
|
||||
|
||||
// Registers are not used at index 0, so they can be freely used.
|
||||
mutableMethod.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->getCurrentPlaybackSpeed()F
|
||||
move-result v0
|
||||
# check if the playback speed is not 1.0x
|
||||
|
||||
# Check if the playback speed is not 1.0x.
|
||||
const/high16 v1, 0x3f800000 # 1.0f
|
||||
cmpg-float v1, v0, v1
|
||||
if-eqz v1, :do_not_override
|
||||
|
||||
# Get the instance of the class which has the container class field below.
|
||||
iget-object v1, p0, $onItemClickListenerClassFieldReference
|
||||
|
||||
# invoke setPlaybackSpeed
|
||||
iget-object v1, p0, $playbackHandlerWrapperFieldReference
|
||||
check-cast v1, $playbackHandlerWrapperImplementorClassReference
|
||||
iget-object v2, v1, $playbackHandlerFieldReference
|
||||
# Get the container class field.
|
||||
iget-object v1, v1, $setPlaybackSpeedContainerClassFieldReference
|
||||
|
||||
# Get the field from its class.
|
||||
iget-object v2, v1, $setPlaybackSpeedClassFieldReference
|
||||
|
||||
# Invoke setPlaybackSpeed on that class.
|
||||
invoke-virtual {v2, v0}, $setPlaybackSpeedMethodReference
|
||||
""".trimIndent(),
|
||||
listOf(ExternalLabel("do_not_override", mutableMethod.instruction(0)))
|
||||
)
|
||||
}
|
||||
} ?: return InitializePlaybackSpeedValuesFingerprint.toErrorResult()
|
||||
|
||||
// Remember the selected playback speed.
|
||||
OnPlaybackSpeedItemClickFingerprint.result!!.apply {
|
||||
val setPlaybackSpeedIndex = scanResult.patternScanResult!!.endIndex
|
||||
OnPlaybackSpeedItemClickFingerprint.result?.apply {
|
||||
val setPlaybackSpeedIndex = scanResult.patternScanResult!!.startIndex - 3
|
||||
|
||||
val selectedPlaybackSpeedRegister =
|
||||
(mutableMethod.instruction(setPlaybackSpeedIndex) as FiveRegisterInstruction).registerD
|
||||
|
||||
@ -111,8 +125,7 @@ class RememberPlaybackSpeedPatch : BytecodePatch(
|
||||
setPlaybackSpeedIndex,
|
||||
"invoke-static { v$selectedPlaybackSpeedRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlaybackSpeed(F)V"
|
||||
)
|
||||
}
|
||||
|
||||
} ?: return OnPlaybackSpeedItemClickFingerprint.toErrorResult()
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
@ -121,20 +134,6 @@ class RememberPlaybackSpeedPatch : BytecodePatch(
|
||||
const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/integrations/patches/playback/speed/RememberPlaybackSpeedPatch;"
|
||||
|
||||
fun MethodFingerprint.getReference(offsetFromPatternScanResultStartIndex: Int = 0) = this.result!!.let {
|
||||
val referenceInstruction = it.mutableMethod
|
||||
.instruction(it.scanResult.patternScanResult!!.startIndex + offsetFromPatternScanResultStartIndex) as ReferenceInstruction
|
||||
referenceInstruction.reference.toString()
|
||||
}
|
||||
|
||||
fun BytecodeContext.resolveFingerprints() {
|
||||
ChangePlaybackSpeedFragmentStateFingerprint.result?.also {
|
||||
fun MethodFingerprint.resolve() = resolve(this@resolveFingerprints, it.classDef)
|
||||
|
||||
OnPlaybackSpeedItemClickFingerprint.resolve()
|
||||
InitializePlaybackSpeedValuesFingerprint.resolve()
|
||||
|
||||
} ?: throw ChangePlaybackSpeedFragmentStateFingerprint.toErrorResult()
|
||||
}
|
||||
val Instruction.reference get() = (this as ReferenceInstruction).reference.toString()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user