mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-07 10:04:35 +02:00
feat(YouTube): add Spoof test client
patch
This commit is contained in:
parent
215a709b13
commit
e051136de8
@ -0,0 +1,111 @@
|
|||||||
|
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.youtube.misc.test.fingerprints.ClientNamelEnumConstructorFingerprint
|
||||||
|
import app.revanced.patches.youtube.misc.test.fingerprints.OverrideBuildVersionFingerprint
|
||||||
|
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.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.OneRegisterInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
object SpoofTestClientPatch : BaseBytecodePatch(
|
||||||
|
name = "Spoof test client",
|
||||||
|
description = "Adds an option to spoof as test client.",
|
||||||
|
dependencies = setOf(SettingsPatch::class),
|
||||||
|
compatiblePackages = COMPATIBLE_PACKAGE,
|
||||||
|
fingerprints = setOf(
|
||||||
|
ClientNamelEnumConstructorFingerprint,
|
||||||
|
OverrideBuildVersionFingerprint,
|
||||||
|
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<ReferenceInstruction>(testClientEnumIndex).reference.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region override client name
|
||||||
|
|
||||||
|
SetClientNameFingerprint.resultOrThrow().let {
|
||||||
|
it.mutableMethod.apply {
|
||||||
|
val walkerIndex = it.scanResult.patternScanResult!!.startIndex + 2
|
||||||
|
val walkerReference = getInstruction<ReferenceInstruction>(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
|
||||||
|
|
||||||
|
OverrideBuildVersionFingerprint.resultOrThrow().let {
|
||||||
|
it.mutableMethod.apply {
|
||||||
|
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||||
|
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex + 1).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)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
|
)
|
@ -0,0 +1,18 @@
|
|||||||
|
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 OverrideBuildVersionFingerprint : MethodFingerprint(
|
||||||
|
returnType = "L",
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||||
|
parameters = listOf("L"),
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
|
Opcode.GOTO,
|
||||||
|
Opcode.CONST_STRING,
|
||||||
|
),
|
||||||
|
strings = listOf("pref_override_build_version_name")
|
||||||
|
)
|
@ -0,0 +1,18 @@
|
|||||||
|
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")
|
||||||
|
)
|
@ -1388,6 +1388,11 @@ Limitation: Automatically played feed videos will show up in your watch history.
|
|||||||
<string name="revanced_spoof_player_parameter_in_feed_summary_off">"Player parameter not spoofed for feed videos.
|
<string name="revanced_spoof_player_parameter_in_feed_summary_off">"Player parameter not spoofed for feed videos.
|
||||||
|
|
||||||
Limitation: Feed videos will play for less than 1 minute before encountering playback issues."</string>
|
Limitation: Feed videos will play for less than 1 minute before encountering playback issues."</string>
|
||||||
|
<string name="revanced_spoof_test_client_title">Spoof test client</string>
|
||||||
|
<string name="revanced_spoof_test_client_summary">"Spoof 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."</string>
|
||||||
|
|
||||||
<!-- PreferenceScreen: Miscellaneous, PreferenceCategory: Miscellaneous, PreferenceScreen: Import / Export settings -->
|
<!-- PreferenceScreen: Miscellaneous, PreferenceCategory: Miscellaneous, PreferenceScreen: Import / Export settings -->
|
||||||
<string name="revanced_preference_screen_import_export_title">Import / Export settings</string>
|
<string name="revanced_preference_screen_import_export_title">Import / Export settings</string>
|
||||||
|
@ -557,7 +557,10 @@
|
|||||||
<!-- SETTINGS: SPOOF_PLAYER_PARAMETER
|
<!-- SETTINGS: SPOOF_PLAYER_PARAMETER
|
||||||
<SwitchPreference android:title="@string/revanced_spoof_player_parameter_title" android:key="revanced_spoof_player_parameter" android:defaultValue="false" android:summary="@string/revanced_spoof_player_parameter_summary" />
|
<SwitchPreference android:title="@string/revanced_spoof_player_parameter_title" android:key="revanced_spoof_player_parameter" android:defaultValue="false" android:summary="@string/revanced_spoof_player_parameter_summary" />
|
||||||
<SwitchPreference android:title="@string/revanced_spoof_player_parameter_in_feed_title" android:key="revanced_spoof_player_parameter_in_feed" android:defaultValue="false" android:summaryOn="@string/revanced_spoof_player_parameter_in_feed_summary_on" android:summaryOff="@string/revanced_spoof_player_parameter_in_feed_summary_off" android:dependency="revanced_spoof_player_parameter" />SETTINGS: SPOOF_PLAYER_PARAMETER -->
|
<SwitchPreference android:title="@string/revanced_spoof_player_parameter_in_feed_title" android:key="revanced_spoof_player_parameter_in_feed" android:defaultValue="false" android:summaryOn="@string/revanced_spoof_player_parameter_in_feed_summary_on" android:summaryOff="@string/revanced_spoof_player_parameter_in_feed_summary_off" android:dependency="revanced_spoof_player_parameter" />SETTINGS: SPOOF_PLAYER_PARAMETER -->
|
||||||
|
|
||||||
|
<!-- SETTINGS: SPOOF_TEST_CLIENT
|
||||||
|
<SwitchPreference android:title="@string/revanced_spoof_test_client_title" android:key="revanced_spoof_test_client" android:defaultValue="false" android:summary="@string/revanced_spoof_test_client_summary" />SETTINGS: SPOOF_TEST_CLIENT -->
|
||||||
|
|
||||||
<PreferenceScreen android:title="@string/revanced_preference_screen_patch_information_title" android:key="revanced_preference_screen_patch_information" android:summary="@string/revanced_preference_screen_patch_information_summary" >
|
<PreferenceScreen android:title="@string/revanced_preference_screen_patch_information_title" android:key="revanced_preference_screen_patch_information" android:summary="@string/revanced_preference_screen_patch_information_summary" >
|
||||||
<PreferenceCategory android:title="@string/revanced_preference_category_tool_used" android:layout="@layout/revanced_settings_preferences_category" >
|
<PreferenceCategory android:title="@string/revanced_preference_category_tool_used" android:layout="@layout/revanced_settings_preferences_category" >
|
||||||
<Preference android:title="ReVanced Patches" android:selectable="false" android:summary="" />
|
<Preference android:title="ReVanced Patches" android:selectable="false" android:summary="" />
|
||||||
@ -630,6 +633,7 @@
|
|||||||
<Preference android:title="Enable open links directly" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
<Preference android:title="Enable open links directly" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||||
<Preference android:title="Sanitize sharing links" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
<Preference android:title="Sanitize sharing links" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||||
<Preference android:title="Spoof format stream data" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
<Preference android:title="Spoof format stream data" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||||
|
<Preference android:title="Spoof test client" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/revanced_preference_category_others" android:layout="@layout/revanced_settings_preferences_category">
|
<PreferenceCategory android:title="@string/revanced_preference_category_others" android:layout="@layout/revanced_settings_preferences_category">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user