fix(YouTube - Client spoof): Correctly play more livestreams using Android VR (#3316)

This commit is contained in:
LisoUseInAIKyrios 2024-06-09 11:31:14 +03:00 committed by GitHub
parent 89f6158149
commit c05264af39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,11 +8,14 @@ import app.revanced.patches.all.misc.transformation.IMethodCall
import app.revanced.patches.all.misc.transformation.Instruction35cInfo import app.revanced.patches.all.misc.transformation.Instruction35cInfo
import app.revanced.patches.all.misc.transformation.filterMapInstruction35c import app.revanced.patches.all.misc.transformation.filterMapInstruction35c
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.ClassDef import com.android.tools.smali.dexlib2.iface.ClassDef
import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.instruction.Instruction import com.android.tools.smali.dexlib2.iface.instruction.Instruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
object UserAgentClientSpoofPatch : BaseTransformInstructionsPatch<Instruction35cInfo>() { object UserAgentClientSpoofPatch : BaseTransformInstructionsPatch<Instruction35cInfo>() {
private const val ORIGINAL_PACKAGE_NAME = "com.google.android.youtube" private const val ORIGINAL_PACKAGE_NAME = "com.google.android.youtube"
@ -42,20 +45,31 @@ object UserAgentClientSpoofPatch : BaseTransformInstructionsPatch<Instruction35c
as? OneRegisterInstruction ?: return as? OneRegisterInstruction ?: return
).registerA ).registerA
// IndexOutOfBoundsException is not possible here, // IndexOutOfBoundsException is possible here,
// but no such occurrences are present in the app. // but no such occurrences are present in the app.
val referee = getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString() val referee = getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
// This can technically also match non-user agent string builder append methods, // Only replace string builder usage.
// but no such occurrences are present in the app.
if (referee != USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE) { if (referee != USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE) {
return return
} }
// Do not change the package name in methods that use resources, or for methods that use GmsCore.
// Changing these package names will result in playback limitations,
// particularly Android VR background audio only playback.
val resourceOrGmsStringInstructionIndex = indexOfFirstInstruction {
val reference = getReference<StringReference>()
opcode == Opcode.CONST_STRING &&
(reference?.string == "android.resource://" || reference?.string == "gcore_")
}
if (resourceOrGmsStringInstructionIndex >= 0) {
return
}
// Overwrite the result of context.getPackageName() with the original package name. // Overwrite the result of context.getPackageName() with the original package name.
replaceInstruction( replaceInstruction(
instructionIndex + 1, instructionIndex + 1,
"const-string v$targetRegister, \"${ORIGINAL_PACKAGE_NAME}\"", "const-string v$targetRegister, \"$ORIGINAL_PACKAGE_NAME\"",
) )
} }
} }