From 4e19cab824b64be56a3f38826b9c248ca69fa900 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 21 Oct 2023 10:48:33 +0900 Subject: [PATCH] feat(YouTube): add `Spoof device dimensions` patch --- .../SpoofDeviceDimensionsPatch.kt | 79 +++++++++++++++++++ ...eviceDimensionsModelToStringFingerprint.kt | 8 ++ .../youtube/settings/host/values/strings.xml | 2 + .../youtube/settings/xml/revanced_prefs.xml | 4 + 4 files changed, 93 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/fingerprints/DeviceDimensionsModelToStringFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt new file mode 100644 index 000000000..1c3d0fc51 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt @@ -0,0 +1,79 @@ +package app.revanced.patches.youtube.misc.spoofdimensions + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.misc.spoofdimensions.fingerprints.DeviceDimensionsModelToStringFingerprint +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.integrations.Constants.MISC_PATH +import com.android.tools.smali.dexlib2.util.MethodUtil + +@Patch( + name = "Spoof device dimensions", + description = "Spoofs the device dimensions in order to unlock higher video qualities " + + "that may not be available on your device.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.24.37", + "18.25.40", + "18.27.36", + "18.29.38", + "18.30.37", + "18.31.40", + "18.32.39", + "18.33.40", + "18.34.38", + "18.35.36", + "18.36.39", + "18.37.36", + "18.38.44", + "18.39.41", + "18.40.34" + ] + ) + ] +) +object SpoofDeviceDimensionsPatch : BytecodePatch( + setOf(DeviceDimensionsModelToStringFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$MISC_PATH/SpoofDeviceDimensionsPatch;" + + override fun execute(context: BytecodeContext) { + DeviceDimensionsModelToStringFingerprint.result?.let { result -> + result.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } + .addInstructions( + 1, // Add after super call. + mapOf( + 1 to "MinHeightOrWidth", // p1 = min height + 2 to "MaxHeightOrWidth", // p2 = max height + 3 to "MinHeightOrWidth", // p3 = min width + 4 to "MaxHeightOrWidth" // p4 = max width + ).map { (parameter, method) -> + """ + invoke-static { p$parameter }, $INTEGRATIONS_CLASS_DESCRIPTOR->get$method(I)I + move-result p$parameter + """ + }.joinToString("\n") { it } + ) + } ?: throw DeviceDimensionsModelToStringFingerprint.exception + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "SETTINGS: EXPERIMENTAL_FLAGS", + "SETTINGS: SPOOF_DEVICE_DIMENSIONS" + ) + ) + + SettingsPatch.updatePatchStatus("Spoof device dimensions") + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/fingerprints/DeviceDimensionsModelToStringFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/fingerprints/DeviceDimensionsModelToStringFingerprint.kt new file mode 100644 index 000000000..fb2180f7d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/fingerprints/DeviceDimensionsModelToStringFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.misc.spoofdimensions.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object DeviceDimensionsModelToStringFingerprint : MethodFingerprint( + returnType = "L", + strings = listOf("minh.", ";maxh.") +) diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 527bb4c0e..f4ab8e9b6 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -669,6 +669,8 @@ If later turned off, the old UI may remain until clear the app data" Type the spoof app version target Edit spoof app version Spoof app version + Spoofs the device dimensions in order to unlock higher video qualities that may not be available on your device + Spoof device dimensions "Player parameter not spoofed for feed videos Known issues diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 26dd196dc..0140da3fe 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -313,6 +313,9 @@ SETTINGS: SPOOF_APP_VERSION --> + + @@ -382,6 +385,7 @@ +