refactor(enable-auto-repeat): changed so that patches are made in the correct path

This commit is contained in:
inotia00
2023-03-04 02:35:27 +09:00
parent c641d0f625
commit 3177034060
4 changed files with 63 additions and 15 deletions

View File

@ -1,12 +0,0 @@
package app.revanced.patches.youtube.button.autorepeat.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
object AutoRepeatFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
customFingerprint = { methodDef -> methodDef.implementation!!.instructions.count() == 3 && methodDef.annotations.isEmpty()}
)

View File

@ -1,14 +0,0 @@
package app.revanced.patches.youtube.button.autorepeat.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
object AutoRepeatParentFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
strings = listOf(
"play() called when the player wasn't loaded.",
"play() blocked because Background Playability failed"
)
)

View File

@ -0,0 +1,21 @@
package app.revanced.patches.youtube.button.autorepeat.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 RepeatListenerFingerprint : MethodFingerprint(
returnType = "Z",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.INVOKE_VIRTUAL_RANGE,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.CHECK_CAST,
Opcode.CONST_WIDE_32
),
strings = listOf(
"ppoobsa"
)
)

View File

@ -4,43 +4,70 @@ import app.revanced.extensions.toErrorResult
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.extensions.*
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.PatchResultSuccess
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.VideoEndFingerprint
import app.revanced.patches.shared.fingerprints.VideoEndParentFingerprint
import app.revanced.patches.youtube.button.autorepeat.fingerprints.*
import app.revanced.util.integrations.Constants.UTILS_PATH
import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
@Name("always-autorepeat")
@YouTubeCompatibility
@Version("0.0.1")
class AutoRepeatPatch : BytecodePatch(
listOf(
AutoRepeatParentFingerprint,
AutoNavInformerFingerprint
AutoNavInformerFingerprint,
RepeatListenerFingerprint,
VideoEndParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
AutoRepeatParentFingerprint.result?.classDef?.let { classDef ->
AutoRepeatFingerprint.also {
VideoEndParentFingerprint.result?.classDef?.let { classDef ->
VideoEndFingerprint.also {
it.resolve(context, classDef)
}.result?.mutableMethod?.let {
it.addInstructions(
0, """
invoke-static {}, $VIDEO_PATH/VideoInformation;->videoEnded()Z
invoke-static {}, $VIDEO_PATH/VideoInformation;->shouldAutoRepeat()Z
move-result v0
if-eqz v0, :noautorepeat
if-eqz v0, :notrepeat
return-void
""", listOf(ExternalLabel("noautorepeat", it.instruction(0)))
""", listOf(ExternalLabel("notrepeat", it.instruction(0)))
)
} ?: return AutoRepeatFingerprint.toErrorResult()
} ?: return AutoRepeatParentFingerprint.toErrorResult()
} ?: return VideoEndFingerprint.toErrorResult()
} ?: return VideoEndParentFingerprint.toErrorResult()
RepeatListenerFingerprint.result?.let {
val targetIndex = it.scanResult.patternScanResult!!.startIndex - 1
val endIndex = it.scanResult.patternScanResult!!.endIndex
with (it.mutableMethod) {
val targetReference = (instruction(targetIndex) as BuilderInstruction35c).reference.toString()
val firstRegister = (instruction(targetIndex) as BuilderInstruction35c).registerC
val secondRegister = (instruction(targetIndex) as BuilderInstruction35c).registerD
val dummyRegister = (instruction(endIndex) as Instruction31i).registerA
addInstructions(
targetIndex + 1, """
invoke-static {}, $UTILS_PATH/EnableAutoRepeatPatch;->shouldAutoRepeat()Z
move-result v$dummyRegister
if-nez v$dummyRegister, :bypass
invoke-virtual {v$firstRegister, v$secondRegister}, $targetReference
""", listOf(ExternalLabel("bypass", instruction(targetIndex + 1)))
)
removeInstruction(targetIndex)
}
} ?: return RepeatListenerFingerprint.toErrorResult()
AutoNavInformerFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {