mirror of
https://github.com/revanced/revanced-patches
synced 2024-11-08 14:57:03 +01:00
fix(youtube/settings): resolve fingerprints robustly
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
b5a407d5fe
commit
8e98605a74
@ -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
|
@ -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")
|
||||
)
|
@ -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
|
||||
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user