From f0dba52004c40cbe1f1ad9c079786ae59d335d67 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 12 Jan 2023 18:20:55 +0900 Subject: [PATCH] fix: some fingerprints are broken --- .../fingerprints/MaxBufferAltFingerprint.kt | 26 +++++++++++++++++++ .../patch/CustomVideoBufferBytecodePatch.kt | 25 +++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/fingerprints/MaxBufferAltFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/fingerprints/MaxBufferAltFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/fingerprints/MaxBufferAltFingerprint.kt new file mode 100644 index 000000000..3163f6982 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/fingerprints/MaxBufferAltFingerprint.kt @@ -0,0 +1,26 @@ +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" + } + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/patch/CustomVideoBufferBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/patch/CustomVideoBufferBytecodePatch.kt index 1f13c5151..b5e7472bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/patch/CustomVideoBufferBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/customvideobuffer/bytecode/patch/CustomVideoBufferBytecodePatch.kt @@ -20,13 +20,24 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Version("0.0.1") class CustomVideoBufferBytecodePatch : BytecodePatch( listOf( + MaxBufferAltFingerprint, MaxBufferFingerprint, PlaybackBufferFingerprint, ReBufferFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { - execMaxBuffer() + + /** + * Temporary try .. catch is used because priority of fingerprint properties are not implemented yet + * But it's not an ideal method + * see https://github.com/revanced/revanced-patcher/issues/148 + */ + try { + execMaxBuffer() + } catch (_: Exception) { + execMaxBufferAlt() + } execPlaybackBuffer() execReBuffer() return PatchResultSuccess() @@ -36,6 +47,18 @@ class CustomVideoBufferBytecodePatch : BytecodePatch( const val INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR = "$MISC_PATH/CustomVideoBufferPatch;" } + private fun execMaxBufferAlt() { + val (method, result) = MaxBufferAltFingerprint.unwrap(true, -1) + val (index, register) = result + + method.addInstructions( + index + 1, """ + invoke-static {}, $INTEGRATIONS_BUFFER_CLASS_DESCRIPTOR->setMaxBuffer()I + move-result v$register + """ + ) + } + private fun execMaxBuffer() { val (method, result) = MaxBufferFingerprint.unwrap(true, -1) val (index, register) = result