2023-09-20 05:33:02 +02:00
|
|
|
package app.revanced.patches.youtube.misc.fix.playback
|
2023-03-14 13:15:26 +01:00
|
|
|
|
2023-12-02 22:35:13 +01:00
|
|
|
import app.revanced.util.exception
|
2023-03-14 13:15:26 +01:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
2023-06-07 03:46:13 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
2023-09-25 16:28:11 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
2023-07-20 01:17:47 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
2023-03-14 13:15:26 +01:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2023-09-25 16:28:11 +02:00
|
|
|
import app.revanced.patcher.util.smali.ExternalLabel
|
2023-09-26 00:46:35 +02:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
2023-09-25 16:28:11 +02:00
|
|
|
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.*
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
|
2023-09-26 00:46:35 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
2023-10-25 20:19:41 +02:00
|
|
|
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
2023-09-26 00:46:35 +02:00
|
|
|
import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHookPatch
|
2023-09-25 16:28:11 +02:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
2023-11-11 19:22:53 +01:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
2023-03-14 13:15:26 +01:00
|
|
|
|
2023-09-20 05:33:02 +02:00
|
|
|
@Patch(
|
2023-09-23 23:48:45 +02:00
|
|
|
description = "Spoofs the signature to prevent playback issues.",
|
2023-09-20 05:33:02 +02:00
|
|
|
dependencies = [
|
2023-09-26 00:46:35 +02:00
|
|
|
SettingsPatch::class,
|
2023-09-25 16:28:11 +02:00
|
|
|
PlayerTypeHookPatch::class,
|
2023-09-26 00:46:35 +02:00
|
|
|
PlayerResponseMethodHookPatch::class,
|
2023-10-25 20:19:41 +02:00
|
|
|
VideoInformationPatch::class,
|
2023-11-11 19:22:53 +01:00
|
|
|
SpoofSignatureResourcePatch::class
|
2023-09-20 05:33:02 +02:00
|
|
|
]
|
|
|
|
)
|
2023-09-23 23:48:45 +02:00
|
|
|
object SpoofSignaturePatch : BytecodePatch(
|
2023-09-20 05:33:02 +02:00
|
|
|
setOf(
|
2023-11-11 19:22:53 +01:00
|
|
|
PlayerResponseModelImplGeneralFingerprint,
|
|
|
|
PlayerResponseModelImplLiveStreamFingerprint,
|
2023-12-02 22:35:13 +01:00
|
|
|
PlayerResponseModelImplRecommendedLevelFingerprint,
|
2023-09-25 16:28:11 +02:00
|
|
|
StoryboardRendererSpecFingerprint,
|
2023-11-11 19:22:53 +01:00
|
|
|
StoryboardRendererDecoderSpecFingerprint,
|
|
|
|
StoryboardRendererDecoderRecommendedLevelFingerprint,
|
|
|
|
StoryboardThumbnailParentFingerprint,
|
|
|
|
ScrubbedPreviewLayoutFingerprint,
|
2023-03-17 18:58:41 +01:00
|
|
|
)
|
2023-03-14 13:15:26 +01:00
|
|
|
) {
|
2023-09-20 05:33:02 +02:00
|
|
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
2023-09-25 16:28:11 +02:00
|
|
|
"Lapp/revanced/integrations/patches/spoof/SpoofSignaturePatch;"
|
2023-09-20 05:33:02 +02:00
|
|
|
|
2023-08-27 21:40:49 +02:00
|
|
|
override fun execute(context: BytecodeContext) {
|
2023-09-26 00:46:35 +02:00
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
PreferenceScreen(
|
2023-11-18 05:05:37 +01:00
|
|
|
"revanced_spoof_signature_verification",
|
|
|
|
StringResource(
|
2023-09-26 00:46:35 +02:00
|
|
|
"revanced_spoof_signature_verification_title",
|
|
|
|
"Spoof app signature"
|
|
|
|
),
|
2023-11-18 05:05:37 +01:00
|
|
|
listOf(
|
2023-09-26 00:46:35 +02:00
|
|
|
SwitchPreference(
|
|
|
|
"revanced_spoof_signature_verification_enabled",
|
|
|
|
StringResource("revanced_spoof_signature_verification_enabled_title", "Spoof app signature"),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_verification_enabled_summary_on",
|
|
|
|
"App signature spoofed\\n\\n"
|
|
|
|
+ "Side effects include:\\n"
|
|
|
|
+ "• Enhanced bitrate is not available\\n"
|
2023-09-27 16:31:27 +02:00
|
|
|
+ "• Videos cannot be downloaded\\n"
|
2023-09-26 20:27:12 +02:00
|
|
|
+ "• No seekbar thumbnails for paid videos"
|
2023-09-26 00:46:35 +02:00
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_verification_enabled_summary_off",
|
|
|
|
"App signature not spoofed\\n\\nVideo playback may not work"
|
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_verification_enabled_user_dialog_message",
|
|
|
|
"Turning off this setting will cause video playback issues."
|
|
|
|
)
|
|
|
|
),
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_spoof_signature_in_feed_enabled",
|
|
|
|
StringResource("revanced_spoof_signature_in_feed_enabled_title", "Spoof app signature in feed"),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_in_feed_enabled_summary_on",
|
|
|
|
"App signature spoofed\\n\\n"
|
|
|
|
+ "Side effects include:\\n"
|
|
|
|
+ "• Feed videos are missing subtitles\\n"
|
|
|
|
+ "• Automatically played feed videos will show up in your watch history"
|
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_in_feed_enabled_summary_off",
|
2023-09-26 20:27:12 +02:00
|
|
|
"App signature not spoofed for feed videos\\n\\n"
|
2023-09-26 00:46:35 +02:00
|
|
|
+ "Feed videos will play for less than 1 minute before encountering playback issues"
|
|
|
|
)
|
2023-11-11 19:22:53 +01:00
|
|
|
),
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_spoof_storyboard",
|
|
|
|
StringResource("revanced_spoof_storyboard_title", "Spoof storyboard"),
|
|
|
|
StringResource("revanced_spoof_storyboard_summary_on", "Storyboard spoofed"),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_storyboard_summary_off",
|
|
|
|
"Storyboard not spoofed\\n\\n"
|
|
|
|
+ "Side effects include:\\n"
|
|
|
|
+ "• No ambient mode\\n"
|
|
|
|
+ "• Seekbar thumbnails are hidden"
|
|
|
|
)
|
2023-09-26 00:46:35 +02:00
|
|
|
)
|
2023-11-18 05:05:37 +01:00
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_spoof_signature_verification_summary",
|
|
|
|
"Spoof the app signature to prevent playback issues"
|
2023-03-15 18:39:03 +01:00
|
|
|
)
|
2023-09-26 00:46:35 +02:00
|
|
|
)
|
|
|
|
)
|
2023-03-14 13:15:26 +01:00
|
|
|
|
2023-09-26 00:46:35 +02:00
|
|
|
// Hook the player parameters.
|
2023-10-02 15:34:14 +02:00
|
|
|
PlayerResponseMethodHookPatch += PlayerResponseMethodHookPatch.Hook.ProtoBufferParameter(
|
2023-12-04 09:47:41 +01:00
|
|
|
"$INTEGRATIONS_CLASS_DESCRIPTOR->spoofParameter(Ljava/lang/String;Z)Ljava/lang/String;"
|
2023-09-28 15:11:58 +02:00
|
|
|
)
|
2023-09-26 00:46:35 +02:00
|
|
|
|
2023-09-26 20:27:12 +02:00
|
|
|
// Force the seekbar time and chapters to always show up.
|
2023-11-11 19:22:53 +01:00
|
|
|
// This is used if the storyboard spec fetch fails, for viewing paid videos,
|
|
|
|
// or if storyboard spoofing is turned off.
|
2023-09-25 16:28:11 +02:00
|
|
|
StoryboardThumbnailParentFingerprint.result?.classDef?.let { classDef ->
|
|
|
|
StoryboardThumbnailFingerprint.also {
|
|
|
|
it.resolve(
|
|
|
|
context,
|
|
|
|
classDef
|
|
|
|
)
|
|
|
|
}.result?.let {
|
|
|
|
val endIndex = it.scanResult.patternScanResult!!.endIndex
|
|
|
|
// Replace existing instruction to preserve control flow label.
|
|
|
|
// The replaced return instruction always returns false
|
|
|
|
// (it is the 'no thumbnails found' control path),
|
|
|
|
// so there is no need to pass the existing return value to integrations.
|
|
|
|
it.mutableMethod.replaceInstruction(
|
|
|
|
endIndex,
|
|
|
|
"""
|
|
|
|
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarThumbnailOverrideValue()Z
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
// Since this is end of the method must replace one line then add the rest.
|
|
|
|
it.mutableMethod.addInstructions(
|
|
|
|
endIndex + 1,
|
|
|
|
"""
|
|
|
|
move-result v0
|
|
|
|
return v0
|
2023-07-20 01:17:47 +02:00
|
|
|
"""
|
2023-09-25 16:28:11 +02:00
|
|
|
)
|
|
|
|
} ?: throw StoryboardThumbnailFingerprint.exception
|
2023-09-26 00:46:35 +02:00
|
|
|
}
|
2023-07-20 01:17:47 +02:00
|
|
|
|
2023-11-11 19:22:53 +01:00
|
|
|
// If storyboard spoofing is turned off, then hide the empty seekbar thumbnail view.
|
|
|
|
ScrubbedPreviewLayoutFingerprint.result?.apply {
|
|
|
|
val endIndex = scanResult.patternScanResult!!.endIndex
|
|
|
|
mutableMethod.apply {
|
|
|
|
val imageViewFieldName = getInstruction<ReferenceInstruction>(endIndex).reference
|
|
|
|
addInstructions(
|
|
|
|
implementation!!.instructions.lastIndex,
|
|
|
|
"""
|
|
|
|
iget-object v0, p0, $imageViewFieldName # copy imageview field to a register
|
|
|
|
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->seekbarImageViewCreated(Landroid/widget/ImageView;)V
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} ?: throw ScrubbedPreviewLayoutFingerprint.exception
|
|
|
|
|
2023-09-26 00:46:35 +02:00
|
|
|
/**
|
|
|
|
* Hook StoryBoard renderer url
|
|
|
|
*/
|
2023-11-11 19:22:53 +01:00
|
|
|
arrayOf(
|
|
|
|
PlayerResponseModelImplGeneralFingerprint,
|
|
|
|
PlayerResponseModelImplLiveStreamFingerprint
|
|
|
|
).forEach { fingerprint ->
|
|
|
|
fingerprint.result?.let {
|
|
|
|
it.mutableMethod.apply {
|
|
|
|
val getStoryBoardIndex = it.scanResult.patternScanResult!!.endIndex
|
|
|
|
val getStoryBoardRegister =
|
|
|
|
getInstruction<OneRegisterInstruction>(getStoryBoardIndex).registerA
|
2023-07-20 01:17:47 +02:00
|
|
|
|
2023-11-11 19:22:53 +01:00
|
|
|
addInstructions(
|
|
|
|
getStoryBoardIndex,
|
|
|
|
"""
|
2023-09-25 23:50:42 +02:00
|
|
|
invoke-static { v$getStoryBoardRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getStoryboardRendererSpec(Ljava/lang/String;)Ljava/lang/String;
|
2023-09-25 16:28:11 +02:00
|
|
|
move-result-object v$getStoryBoardRegister
|
2023-07-20 01:17:47 +02:00
|
|
|
"""
|
2023-11-11 19:22:53 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
} ?: throw fingerprint.exception
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook recommended seekbar thumbnails quality level.
|
|
|
|
StoryboardRendererDecoderRecommendedLevelFingerprint.result?.let {
|
|
|
|
val moveOriginalRecommendedValueIndex = it.scanResult.patternScanResult!!.endIndex
|
|
|
|
val originalValueRegister = it.mutableMethod
|
|
|
|
.getInstruction<OneRegisterInstruction>(moveOriginalRecommendedValueIndex).registerA
|
|
|
|
|
|
|
|
it.mutableMethod.addInstructions(
|
|
|
|
moveOriginalRecommendedValueIndex + 1, """
|
|
|
|
invoke-static { v$originalValueRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getRecommendedLevel(I)I
|
|
|
|
move-result v$originalValueRegister
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
} ?: throw StoryboardRendererDecoderRecommendedLevelFingerprint.exception
|
|
|
|
|
|
|
|
// Hook the recommended precise seeking thumbnails quality level.
|
2023-12-02 22:35:13 +01:00
|
|
|
PlayerResponseModelImplRecommendedLevelFingerprint.result?.let {
|
2023-11-11 19:22:53 +01:00
|
|
|
it.mutableMethod.apply {
|
|
|
|
val moveOriginalRecommendedValueIndex = it.scanResult.patternScanResult!!.endIndex
|
|
|
|
val originalValueRegister =
|
|
|
|
getInstruction<OneRegisterInstruction>(moveOriginalRecommendedValueIndex).registerA
|
|
|
|
|
|
|
|
addInstructions(
|
|
|
|
moveOriginalRecommendedValueIndex, """
|
|
|
|
invoke-static { v$originalValueRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getRecommendedLevel(I)I
|
|
|
|
move-result v$originalValueRegister
|
|
|
|
"""
|
2023-09-26 00:46:35 +02:00
|
|
|
)
|
|
|
|
}
|
2023-12-02 22:35:13 +01:00
|
|
|
} ?: throw PlayerResponseModelImplRecommendedLevelFingerprint.exception
|
2023-09-25 16:28:11 +02:00
|
|
|
|
2023-09-26 00:46:35 +02:00
|
|
|
StoryboardRendererSpecFingerprint.result?.let {
|
|
|
|
it.mutableMethod.apply {
|
|
|
|
val storyBoardUrlParams = 0
|
2023-09-25 16:28:11 +02:00
|
|
|
|
2023-09-26 00:46:35 +02:00
|
|
|
addInstructionsWithLabels(
|
|
|
|
0,
|
|
|
|
"""
|
2023-09-25 16:28:11 +02:00
|
|
|
if-nez p$storyBoardUrlParams, :ignore
|
2023-09-25 23:50:42 +02:00
|
|
|
invoke-static { p$storyBoardUrlParams }, $INTEGRATIONS_CLASS_DESCRIPTOR->getStoryboardRendererSpec(Ljava/lang/String;)Ljava/lang/String;
|
2023-09-25 16:28:11 +02:00
|
|
|
move-result-object p$storyBoardUrlParams
|
|
|
|
""",
|
2023-09-26 00:46:35 +02:00
|
|
|
ExternalLabel("ignore", getInstruction(0))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} ?: throw StoryboardRendererSpecFingerprint.exception
|
2023-09-25 23:50:42 +02:00
|
|
|
|
2023-11-11 19:22:53 +01:00
|
|
|
// Hook the seekbar thumbnail decoder and use a NULL spec for live streams.
|
|
|
|
StoryboardRendererDecoderSpecFingerprint.result?.let {
|
|
|
|
val storyBoardUrlIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
|
|
|
val storyboardUrlRegister =
|
|
|
|
it.mutableMethod.getInstruction<OneRegisterInstruction>(storyBoardUrlIndex).registerA
|
2023-09-25 23:50:42 +02:00
|
|
|
|
2023-11-11 19:22:53 +01:00
|
|
|
it.mutableMethod.addInstructions(
|
|
|
|
storyBoardUrlIndex + 1, """
|
|
|
|
invoke-static { v$storyboardUrlRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getStoryboardDecoderRendererSpec(Ljava/lang/String;)Ljava/lang/String;
|
|
|
|
move-result-object v$storyboardUrlRegister
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
} ?: throw StoryboardRendererDecoderSpecFingerprint.exception
|
2023-03-14 13:15:26 +01:00
|
|
|
}
|
2023-09-26 00:46:35 +02:00
|
|
|
}
|