From 0b35694d18958f3787128bb88187db661c098dd4 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 30 May 2024 19:20:12 +0900 Subject: [PATCH] fix(YouTube/Spoof client): player gestures not working when spoofing with `Android VR` client --- .../utils/fix/client/SpoofClientPatch.kt | 27 +++++++++ ...PlayerGestureConfigSyntheticFingerprint.kt | 57 +++++++++++++++++++ .../youtube/settings/host/values/strings.xml | 1 - 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/SpoofClientPatch.kt index 6d7f0832b..5a3ca9388 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/SpoofClientPatch.kt @@ -14,6 +14,7 @@ import app.revanced.patches.youtube.utils.compatibility.Constants import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildInitPlaybackRequestFingerprint import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildPlayerRequestURIFingerprint import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlayerRequestBodyFingerprint +import app.revanced.patches.youtube.utils.fix.client.fingerprints.PlayerGestureConfigSyntheticFingerprint import app.revanced.patches.youtube.utils.fix.client.fingerprints.SetPlayerRequestClientTypeFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch @@ -22,6 +23,7 @@ import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHookPatch import app.revanced.util.getReference import app.revanced.util.getStringInstructionIndex +import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags @@ -47,11 +49,15 @@ object SpoofClientPatch : BaseBytecodePatch( ), compatiblePackages = Constants.COMPATIBLE_PACKAGE, fingerprints = setOf( + // Client type spoof. BuildInitPlaybackRequestFingerprint, BuildPlayerRequestURIFingerprint, SetPlayerRequestClientTypeFingerprint, CreatePlayerRequestBodyFingerprint, CreatePlayerRequestBodyWithModelFingerprint, + + // Player gesture config. + PlayerGestureConfigSyntheticFingerprint, ) ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = @@ -224,6 +230,27 @@ object SpoofClientPatch : BaseBytecodePatch( // endregion + // region fix player gesture. + + PlayerGestureConfigSyntheticFingerprint.resultOrThrow().let { + arrayOf(3, 9).forEach { offSet -> + it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex - offSet).apply { + val index = implementation!!.instructions.size - 1 + val register = getInstruction(index).registerA + + addInstructions( + index, + """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->enablePlayerGesture(Z)Z + move-result v$register + """ + ) + } + } + } + + // endregion + /** * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt new file mode 100644 index 000000000..0e50596bf --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/client/fingerprints/PlayerGestureConfigSyntheticFingerprint.kt @@ -0,0 +1,57 @@ +package app.revanced.patches.youtube.utils.fix.client.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.patches.youtube.utils.fix.client.fingerprints.PlayerGestureConfigSyntheticFingerprint.indexOfDownAndOutAllowedInstruction +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstruction +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +/** + * Annotation [FuzzyPatternScanMethod] is required to maintain compatibility with YouTube v18.29.38 ~ v18.32.39. + * + * TODO: Remove this annotation if support for YouTube v18.29.38 to v18.32.39 is dropped. + */ +@FuzzyPatternScanMethod(5) +internal object PlayerGestureConfigSyntheticFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/Object;"), + opcodes = listOf( + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutLandscapeAllowed + Opcode.MOVE_RESULT, + Opcode.CHECK_CAST, + Opcode.IPUT_BOOLEAN, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutPortraitAllowed + Opcode.MOVE_RESULT, + Opcode.IPUT_BOOLEAN, + Opcode.RETURN_VOID, + ), + customFingerprint = { methodDef, classDef -> + indexOfDownAndOutAllowedInstruction(methodDef) > 0 && + // This method is always called "a" because this kind of class always has a single method. + methodDef.name == "a" && classDef.methods.count() == 2 + } +) { + fun indexOfDownAndOutAllowedInstruction(methodDef: Method) = + methodDef.indexOfFirstInstruction { + val reference = getReference() + reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" && + reference.parameterTypes.isEmpty() && + reference.returnType == "Z" + } +} \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 401dc9a1c..f517bb4b9 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -1429,7 +1429,6 @@ Side effects include: "Client is currently spoofed to Android VR. (iOS client is used for Clips or Shorts) Side effects include: -• Player swipe gestures do not work. • Kids videos do not playback. • Paused videos can randomly resume." Spoof player parameter