generated from ReVanced/revanced-patches-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
spoof-app-version
patch (#1449)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
1 parent
fd782aa
commit bd4d3b5
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...vanced/patches/youtube/layout/spoofappversion/annotations/SpoofAppVersionCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app.revanced.patches.youtube.layout.spoofappversion.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.49.37") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class SpoofAppVersionCompatibility | ||
|
19 changes: 19 additions & 0 deletions
19
...atches/youtube/layout/spoofappversion/bytecode/fingerprints/SpoofAppVersionFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.patches.youtube.layout.spoofappversion.bytecode.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
object SpoofAppVersionFingerprint : MethodFingerprint( | ||
"L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L"), listOf( | ||
Opcode.IGET_OBJECT, | ||
Opcode.GOTO, | ||
Opcode.CONST_STRING, | ||
), | ||
|
||
// Instead of applying a bytecode patch, it might be possible to only rely on code from the integrations and | ||
// manually set the desired version string as this keyed value in the SharedPreferences. | ||
// But, this bytecode patch is simple and it works. | ||
strings = listOf("pref_override_build_version_name") | ||
) |
64 changes: 64 additions & 0 deletions
64
...pp/revanced/patches/youtube/layout/spoofappversion/bytecode/patch/SpoofAppVersionPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package app.revanced.patches.youtube.layout.spoofappversion.bytecode.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.layout.spoofappversion.annotations.SpoofAppVersionCompatibility | ||
import app.revanced.patches.youtube.layout.spoofappversion.bytecode.fingerprints.SpoofAppVersionFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) | ||
@Name("spoof-app-version") | ||
@Description("Tricks YouTube into thinking, you are running an older version of the app. One of the side effects also includes restoring the old UI.") | ||
@SpoofAppVersionCompatibility | ||
@Version("0.0.1") | ||
class SpoofAppVersionPatch : BytecodePatch( | ||
listOf( | ||
SpoofAppVersionFingerprint | ||
) | ||
) { | ||
companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofAppVersionPatch" | ||
} | ||
|
||
override fun execute(context: BytecodeContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_spoof_app_version", | ||
StringResource("revanced_spoof_app_version_title", "Spoof app version"), | ||
false, | ||
StringResource("revanced_spoof_app_version_summary_on", "Version spoofed to 17.30.34. If switched off, the old UI layout may remain until logging out or clearing app data"), | ||
StringResource("revanced_spoof_app_version_summary_off", "Version not spoofed") | ||
) | ||
) | ||
|
||
SpoofAppVersionFingerprint.result?.apply { | ||
val insertIndex = scanResult.patternScanResult!!.startIndex + 1 | ||
val buildOverrideNameRegister = | ||
(mutableMethod.implementation!!.instructions[insertIndex - 1] as OneRegisterInstruction).registerA | ||
|
||
mutableMethod.addInstructions( | ||
insertIndex, | ||
""" | ||
invoke-static {v$buildOverrideNameRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR;->getYouTubeVersionOverride(Ljava/lang/String;)Ljava/lang/String; | ||
move-result-object v$buildOverrideNameRegister | ||
""" | ||
) | ||
} ?: return SpoofAppVersionFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |