From 3177034060bd832297e738156ad6d441c97cf3f2 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sat, 4 Mar 2023 02:35:27 +0900 Subject: [PATCH] refactor(enable-auto-repeat): changed so that patches are made in the correct path --- .../fingerprints/VideoEndFingerprint.kt} | 4 +- .../VideoEndParentFingerprint.kt} | 4 +- .../fingerprints/RepeatListenerFingerprint.kt | 21 ++++++++ .../autorepeat/patch/AutoRepeatPatch.kt | 49 ++++++++++++++----- 4 files changed, 63 insertions(+), 15 deletions(-) rename src/main/kotlin/app/revanced/patches/{youtube/button/autorepeat/fingerprints/AutoRepeatFingerprint.kt => shared/fingerprints/VideoEndFingerprint.kt} (76%) rename src/main/kotlin/app/revanced/patches/{youtube/button/autorepeat/fingerprints/AutoRepeatParentFingerprint.kt => shared/fingerprints/VideoEndParentFingerprint.kt} (75%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndFingerprint.kt similarity index 76% rename from src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndFingerprint.kt index a0a2617b2..dcc3c95b3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndFingerprint.kt @@ -1,10 +1,10 @@ -package app.revanced.patches.youtube.button.autorepeat.fingerprints +package app.revanced.patches.shared.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags -object AutoRepeatFingerprint : MethodFingerprint( +object VideoEndFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf(), diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndParentFingerprint.kt similarity index 75% rename from src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndParentFingerprint.kt index a7093eab7..9ca7f0859 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/AutoRepeatParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/VideoEndParentFingerprint.kt @@ -1,10 +1,10 @@ -package app.revanced.patches.youtube.button.autorepeat.fingerprints +package app.revanced.patches.shared.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags -object AutoRepeatParentFingerprint : MethodFingerprint( +object VideoEndParentFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, strings = listOf( diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt new file mode 100644 index 000000000..c835f81bc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt @@ -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" + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt index c77e6772c..d34276a26 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt @@ -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) {