From 8e533821947df8c2a26ddb6fad5ddb67c83203b3 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 23 May 2024 01:16:01 +0900 Subject: [PATCH] feat(YouTube): remove `Spoof test client` patch --- .../youtube/misc/test/SpoofTestClientPatch.kt | 119 ------------------ .../ClientNamelEnumConstructorFingerprint.kt | 11 -- .../fingerprints/SetClientNameFingerprint.kt | 18 --- .../youtube/settings/host/values/strings.xml | 5 - .../youtube/settings/xml/revanced_prefs.xml | 4 - 5 files changed, 157 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/test/SpoofTestClientPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/ClientNamelEnumConstructorFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/SetClientNameFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/test/SpoofTestClientPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/test/SpoofTestClientPatch.kt deleted file mode 100644 index 40e34a5d3..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/test/SpoofTestClientPatch.kt +++ /dev/null @@ -1,119 +0,0 @@ -package app.revanced.patches.youtube.misc.test - -import app.revanced.patcher.data.BytecodeContext -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.patch.PatchException -import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.shared.spoofappversion.fingerprints.ClientInfoFingerprint -import app.revanced.patches.shared.spoofappversion.fingerprints.ClientInfoParentFingerprint -import app.revanced.patches.youtube.misc.test.fingerprints.ClientNamelEnumConstructorFingerprint -import app.revanced.patches.youtube.misc.test.fingerprints.SetClientNameFingerprint -import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH -import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.getStringInstructionIndex -import app.revanced.util.getTargetIndex -import app.revanced.util.getTargetIndexReversed -import app.revanced.util.getTargetIndexWithFieldReferenceName -import app.revanced.util.getWalkerMethod -import app.revanced.util.patch.BaseBytecodePatch -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -@Suppress("unused") -object SpoofTestClientPatch : BaseBytecodePatch( - name = "Spoof test client", - description = "Adds an option to spoof the client as a test client.", - dependencies = setOf(SettingsPatch::class), - compatiblePackages = COMPATIBLE_PACKAGE, - fingerprints = setOf( - ClientInfoParentFingerprint, - ClientNamelEnumConstructorFingerprint, - SetClientNameFingerprint, - ) -) { - private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "$MISC_PATH/SpoofTestClientPatch;" - - override fun execute(context: BytecodeContext) { - var clientNameEnumClass: String - var testClientEnumReference: String - - // region get test client enum and reference - - ClientNamelEnumConstructorFingerprint.resultOrThrow().mutableMethod.apply { - clientNameEnumClass = definingClass - - val testClientStringIndex = getStringInstructionIndex("ANDROID_TESTSUITE") - val testClientEnumIndex = getTargetIndex(testClientStringIndex, Opcode.SPUT_OBJECT) - testClientEnumReference = getInstruction(testClientEnumIndex).reference.toString() - } - - // endregion - - // region override client name - - SetClientNameFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val walkerIndex = it.scanResult.patternScanResult!!.startIndex + 2 - val walkerReference = getInstruction(walkerIndex).reference as MethodReference - if (walkerReference.parameterTypes[2].toString() != clientNameEnumClass) - throw PatchException("parameterType does not match") - - val walkerMethod = getWalkerMethod(context, walkerIndex) - walkerMethod.apply { - addInstructionsWithLabels( - 0, """ - invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->spoofTestClient()Z - move-result v0 - if-eqz v0, :ignore - sget-object p2, $testClientEnumReference - """, ExternalLabel("ignore", getInstruction(0)) - ) - } - } - } - - // endregion - - // region override client version - - ClientInfoParentFingerprint.resultOrThrow().let { parentResult -> - ClientInfoFingerprint.resolve(context, parentResult.classDef) - - ClientInfoFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val versionIndex = getTargetIndexWithFieldReferenceName("RELEASE") + 1 - val insertIndex = getTargetIndexReversed(versionIndex, Opcode.IPUT_OBJECT) - val insertRegister = getInstruction(insertIndex).registerA - - addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->spoofTestClient(Ljava/lang/String;)Ljava/lang/String; - move-result-object v$insertRegister - """ - ) - } - } - } - - // endregion - - /** - * Add settings - */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS", - "SETTINGS: SPOOF_TEST_CLIENT" - ) - ) - - SettingsPatch.updatePatchStatus(this) - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/ClientNamelEnumConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/ClientNamelEnumConstructorFingerprint.kt deleted file mode 100644 index 00f50acd1..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/ClientNamelEnumConstructorFingerprint.kt +++ /dev/null @@ -1,11 +0,0 @@ -package app.revanced.patches.youtube.misc.test.fingerprints - -import app.revanced.patcher.fingerprint.MethodFingerprint - -internal object ClientNamelEnumConstructorFingerprint : MethodFingerprint( - returnType = "V", - strings = listOf( - "UNKNOWN_INTERFACE", - "ANDROID_TESTSUITE" - ) -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/SetClientNameFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/SetClientNameFingerprint.kt deleted file mode 100644 index 928872a05..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/test/fingerprints/SetClientNameFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.youtube.misc.test.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -internal object SetClientNameFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.CONST_HIGH16, - Opcode.CONST_HIGH16, - Opcode.INVOKE_STATIC, - ), - strings = listOf("_partition") -) \ 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 39a0dc50d..d0f146bb0 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -1411,11 +1411,6 @@ Limitation: Automatically played feed videos will show up in your watch history. "Player parameter not spoofed for feed videos. Limitation: Feed videos will play for less than 1 minute before encountering playback issues." - Spoof test client - "Spoofs the client as a test client. - -• This client is used for testing purposes, so most YouTube features are not available. -• There are no playback buffer issues in the test client." Import / Export settings diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index d271b8ae8..fe83a5478 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -566,9 +566,6 @@ SETTINGS: SPOOF_PLAYER_PARAMETER --> - - @@ -641,7 +638,6 @@ -