From d16980ef2f18b7b5752be36f0183985c6c398ea1 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Fri, 17 Mar 2023 21:59:04 +0400 Subject: [PATCH] feat(youtube/spoof-signature-verification): automatic signature spoofing Co-authored-by: oSumAtrIX --- .../SpoofSignatureVerificationPatch.java | 77 +++++++++++++++---- .../integrations/settings/SettingsEnum.java | 2 +- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java b/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java index 7a77f48e..43e123dc 100644 --- a/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java @@ -1,40 +1,83 @@ package app.revanced.integrations.patches; -import app.revanced.integrations.shared.PlayerType; +import android.widget.Toast; + +import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.utils.LogHelper; +import app.revanced.integrations.utils.ReVancedUtils; public class SpoofSignatureVerificationPatch { - /** * Protobuf parameters used by the player. - * Known issue: YouTube client recognizes generic player as shorts video. + * Known issue: video preview not showing when using the seekbar. */ - private static final String GENERAL_PROTOBUF_PARAMETER = "CgIQBg"; + private static final String PROTOBUF_PARAMETER_GENERAL = "CgIQBg"; /** - * Protobuf parameter of short and YouTube story. + * Protobuf parameter of shorts and YouTube stories. + * Known issue: captions are positioned on upper area in the player. */ - private static final String SHORTS_PROTOBUF_PARAMETER = "8AEB"; // "8AEByAMTuAQP" + private static final String PROTOBUF_PARAMETER_SHORTS = "8AEB"; // "8AEByAMTuAQP" /** * Target Protobuf parameters. * Used by the generic player. */ - private static final String TARGET_PROTOBUF_PARAMETER = "YADI"; + private static final String PROTOBUF_PARAMETER_TARGET = "YADI"; - public static String getVerificationSpoofOverride(String original) { - PlayerType player = PlayerType.getCurrent(); - LogHelper.printDebug(() -> "Original protobuf parameter value: " + original + " PlayerType: " + player); - if (original.startsWith(TARGET_PROTOBUF_PARAMETER) || original.length() == 0) { - if (player == PlayerType.INLINE_MINIMAL) { - return GENERAL_PROTOBUF_PARAMETER; // home feed autoplay + /** + * Injection point. + * + * @param originalValue originalValue protobuf parameter + */ + public static String overrideProtobufParameter(String originalValue) { + try { + if (!SettingsEnum.SIGNATURE_SPOOFING.getBoolean()) { + return originalValue; } - if (player.isNoneOrHidden()) { - return SHORTS_PROTOBUF_PARAMETER; // short or story + LogHelper.printDebug(() -> "Original protobuf parameter value: " + originalValue); + if (originalValue.startsWith(PROTOBUF_PARAMETER_TARGET) || originalValue.isEmpty()) { + return PROTOBUF_PARAMETER_SHORTS; } - return SHORTS_PROTOBUF_PARAMETER; // regular video player + } catch (Exception ex) { + LogHelper.printException(() -> "overrideProtobufParameter failure", ex); } - return original; + return originalValue; } + + + /** + * Injection point. Runs off the main thread. + *

+ * Used to check the response code of video playback requests made by YouTube. + * Response code of interest is 403 that indicate a signature verification failure for the current request + * + * @param responseCode HTTP status code of the completed YouTube connection + */ + public static void onResponse(int responseCode) { + try { + if (responseCode < 400 || responseCode >= 500) { + return; // everything normal + } + LogHelper.printDebug(() -> "YouTube HTTP status code: " + responseCode); + + if (SettingsEnum.SIGNATURE_SPOOFING.getBoolean()) { + return; // already enabled + } + + SettingsEnum.SIGNATURE_SPOOFING.saveValue(true); + ReVancedUtils.runOnMainThread(() -> { + Toast.makeText( + ReVancedUtils.getContext(), + "Spoofing app signature to prevent playback issues", Toast.LENGTH_LONG + ).show(); + // it would be great if the video could be forcefully reloaded, but currently there is no code to do this + }); + + } catch (Exception ex) { + LogHelper.printException(() -> "onResponse failure", ex); + } + } + } diff --git a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java index e427e5bd..f1e1892f 100644 --- a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java +++ b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java @@ -96,7 +96,7 @@ public enum SettingsEnum { HIDE_FLOATING_MICROPHONE_BUTTON("revanced_hide_floating_microphone_button", true, ReturnType.BOOLEAN, true), // Misc. Settings - FIX_PLAYBACK("revanced_fix_playback", false, ReturnType.BOOLEAN), + SIGNATURE_SPOOFING("revanced_spoof_signature_verification", false, ReturnType.BOOLEAN), CAPTIONS_ENABLED("revanced_autocaptions_enabled", false, ReturnType.BOOLEAN), PREFERRED_AUTO_REPEAT("revanced_pref_auto_repeat", false, ReturnType.BOOLEAN), USE_HDR_AUTO_BRIGHTNESS("revanced_pref_hdr_autobrightness", true, ReturnType.BOOLEAN),