fix(youtube/settings): resolve fingerprints robustly

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX 2023-01-28 03:55:20 +01:00
parent b5a407d5fe
commit 8e98605a74
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
5 changed files with 10 additions and 42 deletions

View File

@ -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

View File

@ -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")
)

View File

@ -6,7 +6,10 @@ import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
object ThemeSetterAppFingerprint : MethodFingerprint( 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.CONST, //target reference
Opcode.GOTO, Opcode.GOTO,
Opcode.CONST, //target reference Opcode.CONST, //target reference

View File

@ -7,24 +7,19 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions 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.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn 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.preference.impl.Preference
import app.revanced.patches.shared.settings.util.AbstractPreferenceScreen import app.revanced.patches.shared.settings.util.AbstractPreferenceScreen
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch 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.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.ThemeSetterAppFingerprint
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterSystemFingerprint import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterSystemFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch
import org.jf.dexlib2.util.MethodUtil import org.jf.dexlib2.util.MethodUtil
@Patch
@DependsOn( @DependsOn(
[ [
IntegrationsPatch::class, IntegrationsPatch::class,
@ -33,10 +28,9 @@ import org.jf.dexlib2.util.MethodUtil
) )
@Name("settings") @Name("settings")
@Description("Adds settings for ReVanced to YouTube.") @Description("Adds settings for ReVanced to YouTube.")
@SettingsCompatibility
@Version("0.0.1") @Version("0.0.1")
class SettingsPatch : BytecodePatch( class SettingsPatch : BytecodePatch(
listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeConstructorFingerprint) listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeSetterAppFingerprint)
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
fun buildInvokeInstructionsString( fun buildInvokeInstructionsString(
@ -60,11 +54,7 @@ class SettingsPatch : BytecodePatch(
} }
// set the theme based on the preference of the app // set the theme based on the preference of the app
with((ThemeConstructorFingerprint.result?.let { ThemeSetterAppFingerprint.result?.apply {
ThemeSetterAppFingerprint.apply {
if (!resolve(context, it.classDef)) return ThemeSetterAppFingerprint.toErrorResult()
}
} ?: return ThemeConstructorFingerprint.toErrorResult()).result!!) {
fun buildInstructionsString(theme: Int) = """ fun buildInstructionsString(theme: Int) = """
const/4 v0, 0x$theme const/4 v0, 0x$theme
${buildInvokeInstructionsString(parameters = "I")} ${buildInvokeInstructionsString(parameters = "I")}
@ -79,7 +69,6 @@ class SettingsPatch : BytecodePatch(
addInstructions( addInstructions(
patternScanResult.endIndex - 7, buildInstructionsString(0) patternScanResult.endIndex - 7, buildInstructionsString(0)
) )
addInstructions( addInstructions(
patternScanResult.endIndex - 9, buildInstructionsString(1) patternScanResult.endIndex - 9, buildInstructionsString(1)
) )
@ -87,12 +76,11 @@ class SettingsPatch : BytecodePatch(
implementation!!.instructions.size - 2, buildInstructionsString(0) implementation!!.instructions.size - 2, buildInstructionsString(0)
) )
} }
} ?: return ThemeSetterAppFingerprint.toErrorResult()
}
// set the theme based on the preference of the device // set the theme based on the preference of the device
with(LicenseActivityFingerprint.result!!) licenseActivity@{ LicenseActivityFingerprint.result!!.apply licenseActivity@{
with(mutableMethod) { mutableMethod.apply {
fun buildSettingsActivityInvokeString( fun buildSettingsActivityInvokeString(
registers: String = "p0", registers: String = "p0",
classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR, classDescriptor: String = SETTINGS_ACTIVITY_DESCRIPTOR,
@ -113,7 +101,7 @@ class SettingsPatch : BytecodePatch(
} }
// remove method overrides // remove method overrides
with(mutableClass) { mutableClass.apply {
methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) } methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) }
} }
} }

View File

@ -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.PreferenceScreen
import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.resource.patch.AbstractSettingsResourcePatch 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.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources import app.revanced.util.resources.ResourceUtils.copyResources
@ -23,7 +22,6 @@ import org.w3c.dom.Node
@Name("settings-resource-patch") @Name("settings-resource-patch")
@DependsOn([ResourceMappingPatch::class]) @DependsOn([ResourceMappingPatch::class])
@SettingsCompatibility
@Description("Applies mandatory patches to implement ReVanced settings into the application.") @Description("Applies mandatory patches to implement ReVanced settings into the application.")
@Version("0.0.1") @Version("0.0.1")
class SettingsResourcePatch : AbstractSettingsResourcePatch( class SettingsResourcePatch : AbstractSettingsResourcePatch(