fix(YouTube - Spoof streaming data): Change the default client to Android VR, add iOS TV to the selectable default clients, and add the Use Android clients only setting https://github.com/inotia00/ReVanced_Extended/issues/2593

This commit is contained in:
inotia00
2024-12-22 16:33:29 +09:00
parent 480d47587d
commit 89d038fdb8
18 changed files with 416 additions and 264 deletions

View File

@ -1,7 +1,5 @@
package app.revanced.patches.music.utils.fix.streamingdata
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.compatibility.Constants.YOUTUBE_MUSIC_PACKAGE_NAME
import app.revanced.patches.music.utils.patch.PatchList.SPOOF_STREAMING_DATA
@ -10,15 +8,8 @@ import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus
import app.revanced.patches.music.utils.settings.addPreferenceWithIntent
import app.revanced.patches.music.utils.settings.addSwitchPreference
import app.revanced.patches.music.utils.settings.settingsPatch
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.patches.shared.spoof.streamingdata.baseSpoofStreamingDataPatch
import app.revanced.patches.shared.spoof.useragent.baseSpoofUserAgentPatch
import app.revanced.util.findMethodOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
private const val DEFAULT_CLIENT_TYPE = "ANDROID_VR"
@Suppress("unused")
val spoofStreamingDataPatch = baseSpoofStreamingDataPatch(
@ -31,17 +22,6 @@ val spoofStreamingDataPatch = baseSpoofStreamingDataPatch(
)
},
{
findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "SpoofStreamingDataDefaultClient"
}.apply {
val register = getInstruction<OneRegisterInstruction>(0).registerA
val type = (getInstruction<ReferenceInstruction>(0).reference as FieldReference).type
replaceInstruction(
0,
"sget-object v$register, $type->$DEFAULT_CLIENT_TYPE:$type"
)
}
addSwitchPreference(
CategoryType.MISC,
"revanced_spoof_streaming_data",

View File

@ -1,57 +0,0 @@
package app.revanced.patches.shared.blockrequest
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
const val EXTENSION_CLASS_DESCRIPTOR =
"$PATCHES_PATH/BlockRequestPatch;"
val blockRequestPatch = bytecodePatch(
description = "blockRequestPatch"
) {
execute {
// region Block /initplayback requests to fall back to /get_watch requests.
buildInitPlaybackRequestFingerprint.matchOrThrow().let {
it.method.apply {
val moveUriStringIndex = it.patternMatch!!.startIndex
val targetRegister =
getInstruction<OneRegisterInstruction>(moveUriStringIndex).registerA
addInstructions(
moveUriStringIndex + 1,
"""
invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR->blockInitPlaybackRequest(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
""",
)
}
}
// endregion
// region Block /get_watch requests to fall back to /player requests.
buildPlayerRequestURIFingerprint.methodOrThrow().apply {
val invokeToStringIndex = indexOfToStringInstruction(this)
val uriRegister =
getInstruction<FiveRegisterInstruction>(invokeToStringIndex).registerC
addInstructions(
invokeToStringIndex,
"""
invoke-static { v$uriRegister }, $EXTENSION_CLASS_DESCRIPTOR->blockGetWatchRequest(Landroid/net/Uri;)Landroid/net/Uri;
move-result-object v$uriRegister
""",
)
}
// endregion
}
}

View File

@ -1,40 +0,0 @@
package app.revanced.patches.shared.blockrequest
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal val buildInitPlaybackRequestFingerprint = legacyFingerprint(
name = "buildInitPlaybackRequestFingerprint",
returnType = "Lorg/chromium/net/UrlRequest\$Builder;",
opcodes = listOf(
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT, // Moves the request URI string to a register to build the request with.
),
strings = listOf(
"Content-Type",
"Range",
),
)
internal val buildPlayerRequestURIFingerprint = legacyFingerprint(
name = "buildPlayerRequestURIFingerprint",
returnType = "Ljava/lang/String;",
strings = listOf(
"key",
"asig",
),
customFingerprint = { method, _ ->
indexOfToStringInstruction(method) >= 0
},
)
internal fun indexOfToStringInstruction(method: Method) =
method.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>().toString() == "Landroid/net/Uri;->toString()Ljava/lang/String;"
}

View File

@ -4,15 +4,14 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.instructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatchBuilder
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patches.shared.blockrequest.blockRequestPatch
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.patches.shared.extension.Constants.SPOOF_PATH
import app.revanced.patches.shared.formatStreamModelConstructorFingerprint
@ -45,11 +44,47 @@ fun baseSpoofStreamingDataPatch(
name = "Spoof streaming data",
description = "Adds options to spoof the streaming data to allow playback."
) {
dependsOn(blockRequestPatch)
block()
execute {
// region Block /initplayback requests to fall back to /get_watch requests.
buildInitPlaybackRequestFingerprint.matchOrThrow().let {
it.method.apply {
val moveUriStringIndex = it.patternMatch!!.startIndex
val targetRegister =
getInstruction<OneRegisterInstruction>(moveUriStringIndex).registerA
addInstructions(
moveUriStringIndex + 1,
"""
invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR->blockInitPlaybackRequest(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
""",
)
}
}
// endregion
// region Block /get_watch requests to fall back to /player requests.
buildPlayerRequestURIFingerprint.methodOrThrow().apply {
val invokeToStringIndex = indexOfToStringInstruction(this)
val uriRegister =
getInstruction<FiveRegisterInstruction>(invokeToStringIndex).registerC
addInstructions(
invokeToStringIndex,
"""
invoke-static { v$uriRegister }, $EXTENSION_CLASS_DESCRIPTOR->blockGetWatchRequest(Landroid/net/Uri;)Landroid/net/Uri;
move-result-object v$uriRegister
""",
)
}
// endregion
// region Get replacement streams at player requests.
buildRequestFingerprint.methodOrThrow().apply {
@ -154,7 +189,7 @@ fun baseSpoofStreamingDataPatch(
"$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V",
)
resultClassDef.methods.add(
result.classDef.methods.add(
ImmutableMethod(
resultMethodType,
setStreamDataMethodName,

View File

@ -15,6 +15,37 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
const val STREAMING_DATA_INTERFACE =
"Lcom/google/protos/youtube/api/innertube/StreamingDataOuterClass${'$'}StreamingData;"
internal val buildInitPlaybackRequestFingerprint = legacyFingerprint(
name = "buildInitPlaybackRequestFingerprint",
returnType = "Lorg/chromium/net/UrlRequest\$Builder;",
opcodes = listOf(
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT, // Moves the request URI string to a register to build the request with.
),
strings = listOf(
"Content-Type",
"Range",
),
)
internal val buildPlayerRequestURIFingerprint = legacyFingerprint(
name = "buildPlayerRequestURIFingerprint",
returnType = "Ljava/lang/String;",
strings = listOf(
"key",
"asig",
),
customFingerprint = { method, _ ->
indexOfToStringInstruction(method) >= 0
},
)
internal fun indexOfToStringInstruction(method: Method) =
method.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>().toString() == "Landroid/net/Uri;->toString()Ljava/lang/String;"
}
internal val buildMediaDataSourceFingerprint = legacyFingerprint(
name = "buildMediaDataSourceFingerprint",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,

View File

@ -1,5 +1,7 @@
package app.revanced.patches.youtube.utils.fix.streamingdata
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.patches.shared.spoof.streamingdata.baseSpoofStreamingDataPatch
import app.revanced.patches.shared.spoof.useragent.baseSpoofUserAgentPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
@ -7,6 +9,7 @@ import app.revanced.patches.youtube.utils.compatibility.Constants.YOUTUBE_PACKAG
import app.revanced.patches.youtube.utils.patch.PatchList.SPOOF_STREAMING_DATA
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.findMethodOrThrow
val spoofStreamingDataPatch = baseSpoofStreamingDataPatch(
{
@ -18,6 +21,13 @@ val spoofStreamingDataPatch = baseSpoofStreamingDataPatch(
)
},
{
findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "SpoofStreamingDataAndroidOnlyDefaultBoolean"
}.replaceInstruction(
0,
"const/4 v0, 0x1"
)
addPreference(
arrayOf(
"SETTINGS: SPOOF_STREAMING_DATA"