From 92b6e02039e6cb6d872af77d41e600ec4723c365 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Fri, 7 Jul 2023 15:20:45 +0900 Subject: [PATCH] feat(youtube): improve patching speed --- .../VideoIdWithoutShortsFingerprint.kt | 53 +++++++++++++++++++ .../VideoIdWithoutShortsParentFingerprint.kt | 23 -------- .../patch/VideoIdWithoutShortsPatch.kt | 13 ++--- 3 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsParentFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsFingerprint.kt new file mode 100644 index 000000000..2d50b557e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsFingerprint.kt @@ -0,0 +1,53 @@ +package app.revanced.patches.youtube.utils.videoid.withoutshorts.fingerprint + +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 VideoIdWithoutShortsFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.DECLARED_SYNCHRONIZED, + parameters = listOf("L"), + opcodes = listOf( + Opcode.MONITOR_ENTER, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_4, + Opcode.NEW_ARRAY, + Opcode.SGET_OBJECT, + Opcode.CONST_4, + Opcode.APUT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.CONST_4, + Opcode.IPUT_OBJECT, + Opcode.MONITOR_EXIT, + Opcode.RETURN_VOID, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.NEW_ARRAY, + Opcode.SGET_OBJECT, + Opcode.APUT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IF_EQZ, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.MONITOR_EXIT, + Opcode.RETURN_VOID, + Opcode.MONITOR_EXIT, + Opcode.RETURN_VOID, + Opcode.MOVE_EXCEPTION, + Opcode.MONITOR_EXIT, + Opcode.THROW + ), + customFingerprint = { methodDef, classDef -> + methodDef.name == "l" && classDef.methods.count() == 17 + } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsParentFingerprint.kt deleted file mode 100644 index fadbf21c2..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/fingerprint/VideoIdWithoutShortsParentFingerprint.kt +++ /dev/null @@ -1,23 +0,0 @@ -package app.revanced.patches.youtube.utils.videoid.withoutshorts.fingerprint - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.util.bytecode.isWideLiteralExists -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object VideoIdWithoutShortsParentFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.IGET_OBJECT, - Opcode.CHECK_CAST, - Opcode.CHECK_CAST, - Opcode.INVOKE_VIRTUAL, - Opcode.RETURN_VOID - ), - customFingerprint = { methodDef, _ -> - methodDef.isWideLiteralExists(78882851) - } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/patch/VideoIdWithoutShortsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/patch/VideoIdWithoutShortsPatch.kt index be96c0141..cbdcc2643 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/patch/VideoIdWithoutShortsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/patch/VideoIdWithoutShortsPatch.kt @@ -11,7 +11,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.youtube.utils.videoid.withoutshorts.fingerprint.VideoIdWithoutShortsParentFingerprint +import app.revanced.patches.youtube.utils.videoid.withoutshorts.fingerprint.VideoIdWithoutShortsFingerprint import app.revanced.util.integrations.Constants.VIDEO_PATH import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @@ -19,15 +19,12 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Name("video-id-without-shorts-hook") @Version("0.0.1") class VideoIdWithoutShortsPatch : BytecodePatch( - listOf(VideoIdWithoutShortsParentFingerprint) + listOf(VideoIdWithoutShortsFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - VideoIdWithoutShortsParentFingerprint.result?.let { - insertMethod = context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.startIndex + 3, true) - .getMethod() as MutableMethod + VideoIdWithoutShortsFingerprint.result?.let { + insertMethod = it.mutableMethod insertIndex = insertMethod.implementation!!.instructions.indexOfFirst { instruction -> instruction.opcode == Opcode.INVOKE_INTERFACE @@ -35,7 +32,7 @@ class VideoIdWithoutShortsPatch : BytecodePatch( insertRegister = insertMethod.getInstruction(insertIndex + 1).registerA - } ?: return VideoIdWithoutShortsParentFingerprint.toErrorResult() + } ?: return VideoIdWithoutShortsFingerprint.toErrorResult() injectCall("$VIDEO_PATH/VideoInformation;->setVideoId(Ljava/lang/String;)V")