From c8d409e1dbda6ac45fef01912ce7afad1022b4b7 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 19 Oct 2023 03:06:58 +0200 Subject: [PATCH] feat(YouTube): Add `Spoof device dimensions` patch --- .../spoof/SpoofDeviceDimensionsPatch.kt | 63 +++++++++++++++++++ ...eviceDimensionsModelToStringFingerprint.kt | 8 +++ 2 files changed, 71 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/fingerprints/DeviceDimensionsModelToStringFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt new file mode 100644 index 000000000..fe93dd149 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt @@ -0,0 +1,63 @@ +package app.revanced.patches.youtube.misc.dimensions.spoof + +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.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.misc.dimensions.spoof.fingerprints.DeviceDimensionsModelToStringFingerprint +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch + +@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 = [IntegrationsPatch::class, SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.38.44" + ] + ) + ] +) +object SpoofDeviceDimensionsPatch : BytecodePatch( + setOf(DeviceDimensionsModelToStringFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/patches/spoof/SpoofDeviceDimensionsPatch;" + + override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.MISC.addPreferences( + SwitchPreference( + "revanced_spoof_device_dimensions", + StringResource("revanced_spoof_device_dimensions_title", "Spoof device dimensions"), + StringResource("revanced_spoof_device_dimensions_summary_on", "Device dimensions spoofed"), + StringResource("revanced_spoof_device_dimensions_summary_off", "Device dimensions not spoofed"), + ) + ) + + DeviceDimensionsModelToStringFingerprint.result + ?.mutableClass?.methods?.find { method -> method.name == "" } + // Override the parameters containing the dimensions. + ?.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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/fingerprints/DeviceDimensionsModelToStringFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/fingerprints/DeviceDimensionsModelToStringFingerprint.kt new file mode 100644 index 000000000..ffdae94e3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/fingerprints/DeviceDimensionsModelToStringFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.misc.dimensions.spoof.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object DeviceDimensionsModelToStringFingerprint : MethodFingerprint( + returnType = "L", + strings = listOf("minh.", ";maxh.") +)