From 4306f25d3f3b1afdbc75f48485b3897c15aa49e9 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+lisouseinaikyrios@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:15:26 +0100 Subject: [PATCH] feat(youtube): `spoof-signature-verification` patch (#1745) Co-authored-by: oSumAtrIX --- .../annotation/ProtobufSpoofCompatibility.kt | 21 ++++++++ .../ProtobufParameterBuilderFingerprint.kt | 31 +++++++++++ .../patch/SpoofSignatureVerificationPatch.kt | 53 +++++++++++++++++++ .../patch/bytecode/MicroGBytecodePatch.kt | 4 +- 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/annotation/ProtobufSpoofCompatibility.kt 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/SpoofSignatureVerificationPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/annotation/ProtobufSpoofCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/annotation/ProtobufSpoofCompatibility.kt new file mode 100644 index 000000000..1f7d7513d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/annotation/ProtobufSpoofCompatibility.kt @@ -0,0 +1,21 @@ +package app.revanced.patches.youtube.misc.fix.playback.annotation + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf( + "17.49.37", + "18.03.36", + "18.03.42", + "18.04.35", + "18.04.41", + "18.05.32", + "18.05.35", + "18.05.40" + ) + )] +) +@Target(AnnotationTarget.CLASS) +internal annotation class ProtobufSpoofCompatibility \ No newline at end of file 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..a9e58174f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/fingerprints/ProtobufParameterBuilderFingerprint.kt @@ -0,0 +1,31 @@ +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.MOVE_RESULT, + Opcode.CONST_16, + Opcode.MOVE_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT, + Opcode.MOVE_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_FROM16, + Opcode.MOVE_FROM16, + Opcode.MOVE_FROM16, + Opcode.INVOKE_VIRTUAL_RANGE, // target reference +// Opcode.MOVE_RESULT_OBJECT, +// Opcode.IPUT_OBJECT + ), + strings = listOf( + "Prefetch request are disabled.", + "Unexpected empty videoId.", + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/SpoofSignatureVerificationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/SpoofSignatureVerificationPatch.kt new file mode 100644 index 000000000..f8fce33bd --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/patch/SpoofSignatureVerificationPatch.kt @@ -0,0 +1,53 @@ +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.addInstructions +import app.revanced.patcher.extensions.instruction +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.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.misc.fix.playback.annotation.ProtobufSpoofCompatibility +import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ProtobufParameterBuilderFingerprint + +@Patch +@Name("spoof-signature-verification") +@Description("Spoofs the client to prevent playback issues.") +@ProtobufSpoofCompatibility +@Version("0.0.1") +class SpoofSignatureVerificationPatch : BytecodePatch( + listOf(ProtobufParameterBuilderFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ProtobufParameterBuilderFingerprint.result?.let { + val setParamMethod = context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true).getMethod() as MutableMethod + + setParamMethod.apply { + val protobufParameterRegister = 3 + val parameterValue = "8AEByAMTuAQP" /* Protobuf Parameter of shorts */ + + addInstructions( + 0, + """ + invoke-virtual { p$protobufParameterRegister }, Ljava/lang/String;->length()I + move-result v0 + const/16 v1, 0x10 + if-ge v0, v1, :not_spoof # bypass on feed + const-string p$protobufParameterRegister, "$parameterValue" + """, + listOf(ExternalLabel("not_spoof", instruction(0)))) + } + } ?: return ProtobufParameterBuilderFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index 992ab3cb2..9fc74c4ed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -12,6 +12,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.fingerprints.WatchWhileActivityFingerprint import app.revanced.patches.youtube.layout.buttons.cast.patch.HideCastButtonPatch import app.revanced.patches.youtube.misc.fix.spoof.patch.ClientSpoofPatch +import app.revanced.patches.youtube.misc.fix.playback.patch.SpoofSignatureVerificationPatch import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility import app.revanced.patches.youtube.misc.microg.fingerprints.* import app.revanced.patches.youtube.misc.microg.patch.resource.MicroGResourcePatch @@ -24,7 +25,8 @@ import app.revanced.util.microg.MicroGBytecodeHelper [ MicroGResourcePatch::class, HideCastButtonPatch::class, - ClientSpoofPatch::class + ClientSpoofPatch::class, + SpoofSignatureVerificationPatch::class ] ) @Name("microg-support")