From 8e98605a7491d69e99c6b1aeb2de3db9396faa20 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 28 Jan 2023 03:55:20 +0100 Subject: [PATCH] fix(youtube/settings): resolve fingerprints robustly Signed-off-by: oSumAtrIX --- .../annotations/SettingsCompatibility.kt | 9 ------- .../ThemeConstructorFingerprint.kt | 12 ---------- .../fingerprints/ThemeSetterAppFingerprint.kt | 5 +++- .../settings/bytecode/patch/SettingsPatch.kt | 24 +++++-------------- .../resource/patch/SettingsResourcePatch.kt | 2 -- 5 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/settings/annotations/SettingsCompatibility.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeConstructorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/annotations/SettingsCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/annotations/SettingsCompatibility.kt deleted file mode 100644 index 5fa1408ad..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/annotations/SettingsCompatibility.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.patches.youtube.misc.settings.annotations - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Package - -@Compatibility([Package("com.google.android.youtube")]) -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -internal annotation class SettingsCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeConstructorFingerprint.kt deleted file mode 100644 index 599314a4f..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeConstructorFingerprint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package app.revanced.patches.youtube.misc.settings.bytecode.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags - -object ThemeConstructorFingerprint : MethodFingerprint( - "L", - AccessFlags.PUBLIC or AccessFlags.STATIC, - listOf("L"), - strings = listOf("settings.SettingsActivity", ":android:show_fragment", "settings.GeneralPrefsFragment") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterAppFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterAppFingerprint.kt index 9fc0065e7..01c4c1087 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterAppFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterAppFingerprint.kt @@ -6,7 +6,10 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode object ThemeSetterAppFingerprint : MethodFingerprint( - "L", AccessFlags.PUBLIC or AccessFlags.STATIC, opcodes = listOf( + "L", + AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("L", "L", "L", "L"), + opcodes = listOf( Opcode.CONST, //target reference Opcode.GOTO, Opcode.CONST, //target reference diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt index 2c1ee88ba..331389068 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsPatch.kt @@ -7,24 +7,19 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve 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.Preference import app.revanced.patches.shared.settings.util.AbstractPreferenceScreen import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.annotations.SettingsCompatibility import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.LicenseActivityFingerprint -import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeConstructorFingerprint import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterAppFingerprint import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterSystemFingerprint import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch import org.jf.dexlib2.util.MethodUtil -@Patch @DependsOn( [ IntegrationsPatch::class, @@ -33,10 +28,9 @@ import org.jf.dexlib2.util.MethodUtil ) @Name("settings") @Description("Adds settings for ReVanced to YouTube.") -@SettingsCompatibility @Version("0.0.1") class SettingsPatch : BytecodePatch( - listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeConstructorFingerprint) + listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeSetterAppFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { fun buildInvokeInstructionsString( @@ -60,11 +54,7 @@ class SettingsPatch : BytecodePatch( } // set the theme based on the preference of the app - with((ThemeConstructorFingerprint.result?.let { - ThemeSetterAppFingerprint.apply { - if (!resolve(context, it.classDef)) return ThemeSetterAppFingerprint.toErrorResult() - } - } ?: return ThemeConstructorFingerprint.toErrorResult()).result!!) { + ThemeSetterAppFingerprint.result?.apply { fun buildInstructionsString(theme: Int) = """ const/4 v0, 0x$theme ${buildInvokeInstructionsString(parameters = "I")} @@ -79,7 +69,6 @@ class SettingsPatch : BytecodePatch( addInstructions( patternScanResult.endIndex - 7, buildInstructionsString(0) ) - addInstructions( patternScanResult.endIndex - 9, buildInstructionsString(1) ) @@ -87,12 +76,11 @@ class SettingsPatch : BytecodePatch( implementation!!.instructions.size - 2, buildInstructionsString(0) ) } - - } + } ?: return ThemeSetterAppFingerprint.toErrorResult() // set the theme based on the preference of the device - with(LicenseActivityFingerprint.result!!) licenseActivity@{ - with(mutableMethod) { + LicenseActivityFingerprint.result!!.apply licenseActivity@{ + mutableMethod.apply { fun buildSettingsActivityInvokeString( registers: String = "p0", classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR, @@ -113,7 +101,7 @@ class SettingsPatch : BytecodePatch( } // remove method overrides - with(mutableClass) { + mutableClass.apply { methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt index 2bd580d34..eee608081 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/resource/patch/SettingsResourcePatch.kt @@ -15,7 +15,6 @@ import app.revanced.patches.shared.settings.preference.impl.Preference import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.resource.patch.AbstractSettingsResourcePatch -import app.revanced.patches.youtube.misc.settings.annotations.SettingsCompatibility import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils.copyResources @@ -23,7 +22,6 @@ import org.w3c.dom.Node @Name("settings-resource-patch") @DependsOn([ResourceMappingPatch::class]) -@SettingsCompatibility @Description("Applies mandatory patches to implement ReVanced settings into the application.") @Version("0.0.1") class SettingsResourcePatch : AbstractSettingsResourcePatch(