Skip to content

Commit

Permalink
fix(youtube/settings): resolve fingerprints robustly
Browse files Browse the repository at this point in the history
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
oSumAtrIX committed Jan 28, 2023
1 parent b5a407d commit 8e98605
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 42 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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")}
Expand All @@ -79,20 +69,18 @@ class SettingsPatch : BytecodePatch(
addInstructions(
patternScanResult.endIndex - 7, buildInstructionsString(0)
)

addInstructions(
patternScanResult.endIndex - 9, buildInstructionsString(1)
)
addInstructions(
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,
Expand All @@ -113,7 +101,7 @@ class SettingsPatch : BytecodePatch(
}

// remove method overrides
with(mutableClass) {
mutableClass.apply {
methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ 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
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(
Expand Down

0 comments on commit 8e98605

Please sign in to comment.