feat(youtube/spoof-signature-verification): automatic signature spoofing

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
LisoUseInAIKyrios 2023-03-17 21:59:04 +04:00 committed by GitHub
parent 83510e51b3
commit d16980ef2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 18 deletions

View File

@ -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.
* <p>
* 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);
}
}
}

View File

@ -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),