feat: tiktok-speed patch (#668)

This commit is contained in:
d4rkk3y 2022-09-29 22:23:58 +07:00 committed by GitHub
parent 7069df4a80
commit 23fff16e6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 0 deletions

View file

@ -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

View file

@ -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"
)
)

View file

@ -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()
}
}