feat: add custom-video-buffer patch

This commit is contained in:
Joey Peter 2022-07-31 12:34:49 +02:00 committed by GitHub
parent 71b8d7bc12
commit 9f117c74cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 0 deletions

View file

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.videobuffer.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.25.34", "17.29.34")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class CustomVideoBufferCompatibility

View file

@ -0,0 +1,32 @@
package app.revanced.patches.youtube.misc.videobuffer.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.DirectPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
@Name("maxbuffer-fingerprint")
@MatchingMethod(
"Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;", "r"
)
@DirectPatternScanMethod
@CustomVideoBufferCompatibility
@Version("0.0.1")
object MaxBufferFingerprint : MethodFingerprint(
"I", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(),
listOf(Opcode.SGET_OBJECT, Opcode.IGET, Opcode.IF_EQZ, Opcode.RETURN),
null,
customFingerprint = { methodDef ->
methodDef.definingClass.equals("Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;")
&& methodDef.implementation!!.instructions.any {
((it as? NarrowLiteralInstruction)?.narrowLiteral == 120000)
&& methodDef.name.equals("r")
}
}
)

View file

@ -0,0 +1,31 @@
package app.revanced.patches.youtube.misc.videobuffer.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.DirectPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
@Name("playbackbuffer-fingerprint")
@MatchingMethod(
"Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;", "p"
)
@DirectPatternScanMethod
@CustomVideoBufferCompatibility
@Version("0.0.1")
object PlaybackBufferFingerprint : MethodFingerprint(
"I", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(),
listOf(Opcode.IF_LEZ, Opcode.RETURN),
null,
customFingerprint = { methodDef ->
methodDef.definingClass.equals("Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;")
&& methodDef.implementation!!.instructions.any {
((it as? NarrowLiteralInstruction)?.narrowLiteral == 1600)
}
}
)

View file

@ -0,0 +1,31 @@
package app.revanced.patches.youtube.misc.videobuffer.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.DirectPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
@Name("playbackbuffer-fingerprint")
@MatchingMethod(
"Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;", "t"
)
@DirectPatternScanMethod
@CustomVideoBufferCompatibility
@Version("0.0.1")
object ReBufferFingerprint : MethodFingerprint(
"I", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(),
listOf(Opcode.IF_LEZ, Opcode.RETURN),
null,
customFingerprint = { methodDef ->
methodDef.definingClass.equals("Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;")
&& methodDef.implementation!!.instructions.any {
((it as? NarrowLiteralInstruction)?.narrowLiteral == 5000)
}
}
)

View file

@ -0,0 +1,73 @@
package app.revanced.patches.youtube.misc.videobuffer.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.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.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility
import app.revanced.patches.youtube.misc.videobuffer.fingerprints.MaxBufferFingerprint
import app.revanced.patches.youtube.misc.videobuffer.fingerprints.PlaybackBufferFingerprint
import app.revanced.patches.youtube.misc.videobuffer.fingerprints.ReBufferFingerprint
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("custom-video-buffer")
@Description("Lets you change the buffers of videos. Has no use without settings yet.")
@CustomVideoBufferCompatibility
@Version("0.0.1")
class CustomVideoBufferPatch : BytecodePatch(
listOf(
MaxBufferFingerprint, PlaybackBufferFingerprint, ReBufferFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
execMaxBuffer(data)
execPlaybackBuffer(data)
execReBuffer(data)
return PatchResultSuccess()
}
private fun execMaxBuffer(data: BytecodeData) {
val result = MaxBufferFingerprint.result!!
val method = result.mutableMethod
val index = result.patternScanResult!!.endIndex - 1
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA
method.addInstructions(
index + 1, """
invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->getMaxBuffer()I
move-result v$register
"""
)
}
private fun execPlaybackBuffer(data: BytecodeData) {
val result = PlaybackBufferFingerprint.result!!
val method = result.mutableMethod
val index = result.patternScanResult!!.startIndex
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA
method.addInstructions(
index + 1, """
invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->getPlaybackBuffer()I
move-result v$register
"""
)
}
private fun execReBuffer(data: BytecodeData) {
val result = ReBufferFingerprint.result!!
val method = result.mutableMethod
val index = result.patternScanResult!!.startIndex
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA
method.addInstructions(
index + 1, """
invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->getReBuffer()I
move-result v$register
"""
)
}
}