mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-09 11:04:36 +02:00
Improve custom-video-buffer
patch
This commit is contained in:
parent
bcbb0059db
commit
841a4849e8
@ -1,26 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.misc.customvideobuffer.bytecode.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import org.jf.dexlib2.AccessFlags
|
|
||||||
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
|
|
||||||
object MaxBufferAltFingerprint : MethodFingerprint(
|
|
||||||
returnType = "I",
|
|
||||||
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
|
||||||
parameters = listOf(),
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.SGET_OBJECT,
|
|
||||||
Opcode.IGET,
|
|
||||||
Opcode.IF_EQZ,
|
|
||||||
Opcode.RETURN
|
|
||||||
),
|
|
||||||
customFingerprint = {
|
|
||||||
it.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;"
|
|
||||||
&& it.implementation!!.instructions.any { instruction ->
|
|
||||||
((instruction as? NarrowLiteralInstruction)?.narrowLiteral == 120000)
|
|
||||||
&& it.name == "t"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
@ -3,24 +3,16 @@ package app.revanced.patches.youtube.misc.customvideobuffer.bytecode.fingerprint
|
|||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
|
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
||||||
object MaxBufferFingerprint : MethodFingerprint(
|
object MaxBufferFingerprint : MethodFingerprint(
|
||||||
returnType = "I",
|
returnType = "Z",
|
||||||
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
parameters = listOf(),
|
parameters = listOf("J", "J", "F"),
|
||||||
opcodes = listOf(
|
opcodes = listOf(
|
||||||
Opcode.SGET_OBJECT,
|
Opcode.IGET_BOOLEAN,
|
||||||
Opcode.IGET,
|
Opcode.CONST_WIDE_16,
|
||||||
Opcode.IF_EQZ,
|
Opcode.IF_EQZ,
|
||||||
Opcode.RETURN
|
Opcode.INVOKE_VIRTUAL
|
||||||
),
|
)
|
||||||
customFingerprint = {
|
|
||||||
it.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;"
|
|
||||||
&& it.implementation!!.instructions.any { instruction ->
|
|
||||||
((instruction as? NarrowLiteralInstruction)?.narrowLiteral == 120000)
|
|
||||||
&& it.name == "r"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
@ -3,15 +3,17 @@ package app.revanced.patches.youtube.misc.customvideobuffer.bytecode.patch
|
|||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.data.toMethodWalker
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.instruction
|
import app.revanced.patcher.extensions.instruction
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patches.youtube.misc.customvideobuffer.bytecode.fingerprints.*
|
import app.revanced.patches.youtube.misc.customvideobuffer.bytecode.fingerprints.*
|
||||||
import app.revanced.shared.annotation.YouTubeCompatibility
|
import app.revanced.shared.annotation.YouTubeCompatibility
|
||||||
|
import app.revanced.shared.extensions.toErrorResult
|
||||||
import app.revanced.shared.util.integrations.Constants.MISC_PATH
|
import app.revanced.shared.util.integrations.Constants.MISC_PATH
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@ -20,7 +22,6 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
|||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class CustomVideoBufferBytecodePatch : BytecodePatch(
|
class CustomVideoBufferBytecodePatch : BytecodePatch(
|
||||||
listOf(
|
listOf(
|
||||||
MaxBufferAltFingerprint,
|
|
||||||
MaxBufferFingerprint,
|
MaxBufferFingerprint,
|
||||||
PlaybackBufferFingerprint,
|
PlaybackBufferFingerprint,
|
||||||
ReBufferFingerprint
|
ReBufferFingerprint
|
||||||
@ -28,18 +29,15 @@ class CustomVideoBufferBytecodePatch : BytecodePatch(
|
|||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
|
||||||
/**
|
MaxBufferFingerprint.result?.injectMaxBuffer(context) ?: return MaxBufferFingerprint.toErrorResult()
|
||||||
* Temporary try .. catch is used because priority of fingerprint properties are not implemented yet
|
|
||||||
* But it's not an ideal method
|
arrayOf(
|
||||||
* see https://github.com/revanced/revanced-patcher/issues/148
|
PlaybackBufferFingerprint to "setPlaybackBuffer",
|
||||||
*/
|
ReBufferFingerprint to "setReBuffer"
|
||||||
try {
|
).map { (fingerprint, name) ->
|
||||||
execMaxBuffer()
|
fingerprint.result?.mutableMethod?.insertOverride(name) ?: return fingerprint.toErrorResult()
|
||||||
} catch (_: Exception) {
|
|
||||||
execMaxBufferAlt()
|
|
||||||
}
|
}
|
||||||
execPlaybackBuffer()
|
|
||||||
execReBuffer()
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,65 +45,29 @@ class CustomVideoBufferBytecodePatch : BytecodePatch(
|
|||||||
const val INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR =
|
const val INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR =
|
||||||
"$MISC_PATH/CustomVideoBufferPatch;"
|
"$MISC_PATH/CustomVideoBufferPatch;"
|
||||||
}
|
}
|
||||||
private fun execMaxBufferAlt() {
|
|
||||||
val (method, result) = MaxBufferAltFingerprint.unwrap(true, -1)
|
|
||||||
val (index, register) = result
|
|
||||||
|
|
||||||
method.addInstructions(
|
private fun MethodFingerprintResult.injectMaxBuffer(
|
||||||
index + 1, """
|
context: BytecodeContext
|
||||||
invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->setMaxBuffer()I
|
) {
|
||||||
move-result v$register
|
val insertMethod = context.toMethodWalker(this.method)
|
||||||
"""
|
.nextMethod(this.scanResult.patternScanResult!!.endIndex, true)
|
||||||
)
|
.getMethod() as MutableMethod
|
||||||
|
|
||||||
|
insertMethod.insertOverride("setMaxBuffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun execMaxBuffer() {
|
private fun MutableMethod.insertOverride(
|
||||||
val (method, result) = MaxBufferFingerprint.unwrap(true, -1)
|
descriptor: String
|
||||||
val (index, register) = result
|
) {
|
||||||
|
val index = this.implementation!!.instructions.size - 1 - 2
|
||||||
|
val register = (this.instruction(index) as OneRegisterInstruction).registerA
|
||||||
|
|
||||||
method.addInstructions(
|
this.addInstructions(
|
||||||
index + 1, """
|
index,
|
||||||
invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->setMaxBuffer()I
|
"""
|
||||||
move-result v$register
|
invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->$descriptor()I
|
||||||
"""
|
move-result v$register
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun execPlaybackBuffer() {
|
|
||||||
val (method, result) = PlaybackBufferFingerprint.unwrap()
|
|
||||||
val (index, register) = result
|
|
||||||
|
|
||||||
method.addInstructions(
|
|
||||||
index + 1, """
|
|
||||||
invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->setPlaybackBuffer()I
|
|
||||||
move-result v$register
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun execReBuffer() {
|
|
||||||
val (method, result) = ReBufferFingerprint.unwrap()
|
|
||||||
val (index, register) = result
|
|
||||||
|
|
||||||
method.addInstructions(
|
|
||||||
index + 1, """
|
|
||||||
invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->setReBuffer()I
|
|
||||||
move-result v$register
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun MethodFingerprint.unwrap(
|
|
||||||
forEndIndex: Boolean = false,
|
|
||||||
offset: Int = 0
|
|
||||||
): Pair<MutableMethod, Pair<Int, Int>> {
|
|
||||||
val result = this.result!!
|
|
||||||
val method = result.mutableMethod
|
|
||||||
val scanResult = result.scanResult.patternScanResult!!
|
|
||||||
val index = (if (forEndIndex) scanResult.endIndex else scanResult.startIndex) + offset
|
|
||||||
|
|
||||||
val register = (method.instruction(index) as OneRegisterInstruction).registerA
|
|
||||||
|
|
||||||
return method to (index to register)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user