From 995f6a6c0660d8ea78a772aacc83176d73806584 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 14 Mar 2023 10:41:57 +0900 Subject: [PATCH] add `protobuf-spoof` patch --- .../ProtobufParameterBuilderFingerprint.kt | 13 ++++++ .../fix/playback/patch/ProtobufSpoofPatch.kt | 46 +++++++++++++++++++ .../bytecode/patch/MicroGBytecodePatch.kt | 4 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/fingerprints/ProtobufParameterBuilderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/ProtobufSpoofPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/fingerprints/ProtobufParameterBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/fingerprints/ProtobufParameterBuilderFingerprint.kt new file mode 100644 index 000000000..393db9eb5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/fingerprints/ProtobufParameterBuilderFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.misc.fix.playback.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object ProtobufParameterBuilderFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.INVOKE_VIRTUAL_RANGE, // target reference + Opcode.MOVE_RESULT_OBJECT, + Opcode.IPUT_OBJECT + ), + strings = listOf("Unexpected empty videoId.", "Prefetch request are disabled.") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/ProtobufSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/ProtobufSpoofPatch.kt new file mode 100644 index 000000000..a7a515ef3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/ProtobufSpoofPatch.kt @@ -0,0 +1,46 @@ +package app.revanced.patches.youtube.misc.fix.playback.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ProtobufParameterBuilderFingerprint + +@Patch +@Name("protobuf-spoof") +@Description("Spoofs the protobuf to prevent playback issues.") +@YouTubeCompatibility +@Version("0.0.1") +class ProtobufSpoofPatch : BytecodePatch( + listOf(ProtobufParameterBuilderFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + ProtobufParameterBuilderFingerprint.result?.let { + with (context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.startIndex, true) + .getMethod() as MutableMethod + ) { + val protobufParam = 3 + val protobufParameter = "8AEByAMTuAQP" /* Protobuf Parameter of shorts */ + + addInstruction( + 0, + "const-string p$protobufParam, \"$protobufParameter\"" + ) + } + } ?: return ProtobufParameterBuilderFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt index 4910c56f0..b5a90fe73 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt @@ -11,6 +11,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.patch.options.PatchOptions import app.revanced.patches.youtube.layout.player.castbutton.patch.HideCastButtonPatch import app.revanced.patches.youtube.misc.clientspoof.patch.ClientSpoofPatch +import app.revanced.patches.youtube.misc.fix.playback.patch.ProtobufSpoofPatch import app.revanced.patches.youtube.misc.microg.bytecode.fingerprints.* import app.revanced.patches.youtube.misc.microg.shared.Constants.PACKAGE_NAME import app.revanced.util.bytecode.BytecodeHelper.injectInit @@ -21,7 +22,8 @@ import app.revanced.util.microg.MicroGBytecodeHelper [ ClientSpoofPatch::class, HideCastButtonPatch::class, - PatchOptions::class + PatchOptions::class, + ProtobufSpoofPatch::class ] ) @YouTubeCompatibility