From 23fff16e6ab02bf281d46d8b5f93788425d8b525 Mon Sep 17 00:00:00 2001 From: d4rkk3y <43563783+d4rkk3y@users.noreply.github.com> Date: Thu, 29 Sep 2022 22:23:58 +0700 Subject: [PATCH] feat: `tiktok-speed` patch (#668) --- .../speed/annotations/SpeedCompatibility.kt | 14 ++++++ .../SpeedControlParentFingerprint.kt | 24 ++++++++++ .../interaction/speed/patch/SpeedPatch.kt | 48 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/annotations/SpeedCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/SpeedControlParentFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/patch/SpeedPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/annotations/SpeedCompatibility.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/annotations/SpeedCompatibility.kt new file mode 100644 index 0000000000..af78df2f77 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/annotations/SpeedCompatibility.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.tiktok.interaction.speed.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [ + Package("com.ss.android.ugc.trill"), + Package("com.zhiliaoapp.musically") + ] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class SpeedCompatibility diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/SpeedControlParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/SpeedControlParentFingerprint.kt new file mode 100644 index 0000000000..73ea3df3a4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/fingerprints/SpeedControlParentFingerprint.kt @@ -0,0 +1,24 @@ +package app.revanced.patches.tiktok.interaction.speed.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.tiktok.interaction.speed.annotations.SpeedCompatibility +import org.jf.dexlib2.AccessFlags + +@Name("speed-control-parent-fingerprint") +@MatchingMethod("LX/4cP;", "LJIILL") +@SpeedCompatibility +@Version("0.0.1") +object SpeedControlParentFingerprint : MethodFingerprint( + returnType = "L", + access = AccessFlags.PRIVATE or AccessFlags.FINAL, + parameters = listOf( + "L" + ), + strings = listOf( + "playback_speed" + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/patch/SpeedPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/patch/SpeedPatch.kt new file mode 100644 index 0000000000..28152195ca --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/patch/SpeedPatch.kt @@ -0,0 +1,48 @@ +package app.revanced.patches.tiktok.interaction.speed.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.data.impl.toMethodWalker +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.tiktok.interaction.speed.annotations.SpeedCompatibility +import app.revanced.patches.tiktok.interaction.speed.fingerprints.SpeedControlParentFingerprint +import org.jf.dexlib2.Opcode + +@Patch +@Name("tiktok-speed") +@Description("Enables the playback speed option for all videos.") +@SpeedCompatibility +@Version("0.0.1") +class SpeedPatch : BytecodePatch( + listOf( + SpeedControlParentFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + val parentMethod = SpeedControlParentFingerprint.result!!.mutableMethod + val parentMethodInstructions = parentMethod.implementation!!.instructions + for ((index, instruction) in parentMethodInstructions.withIndex()) { + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) continue + val isSpeedEnableMethod = data + .toMethodWalker(parentMethod) + .nextMethod(index, true) + .getMethod() as MutableMethod + isSpeedEnableMethod.addInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) + break + } + return PatchResultSuccess() + } +} \ No newline at end of file