Skip to content

Commit

Permalink
feat: tiktok-speed patch (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkk3y committed Sep 29, 2022
1 parent 1a9d942 commit 9746b50
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
)
)
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 9746b50

Please sign in to comment.