diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarFingerprint.kt new file mode 100644 index 00000000..572ec219 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.shared.fingerprints + + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object SeekbarFingerprint : MethodFingerprint( + "V", + strings = listOf("timed_markers_width") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarOnDrawFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarOnDrawFingerprint.kt new file mode 100644 index 00000000..7afcdae8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/SeekbarOnDrawFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.shared.fingerprints + + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object SeekbarOnDrawFingerprint : MethodFingerprint( + customFingerprint = { it.name == "onDraw" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidetimeandseekbar/patch/HideTimeAndSeekbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidetimeandseekbar/patch/HideTimeAndSeekbarPatch.kt index a616be48..8a7821ad 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hidetimeandseekbar/patch/HideTimeAndSeekbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidetimeandseekbar/patch/HideTimeAndSeekbarPatch.kt @@ -5,18 +5,20 @@ 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.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.youtube.layout.hidetimeandseekbar.annotations.HideTimeAndSeekbarCompatibility -import app.revanced.patches.youtube.layout.hidetimeandseekbar.fingerprints.TimeCounterFingerprint -import app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints.CreateVideoPlayerSeekbarFingerprint -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.shared.fingerprints.SeekbarFingerprint +import app.revanced.patches.shared.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.layout.hidetimeandseekbar.annotations.HideTimeAndSeekbarCompatibility +import app.revanced.patches.youtube.layout.hidetimeandseekbar.fingerprints.TimeCounterFingerprint +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @Patch @DependsOn([IntegrationsPatch::class, SettingsPatch::class]) @@ -26,7 +28,7 @@ import app.revanced.patches.shared.settings.preference.impl.SwitchPreference @Version("0.0.1") class HideTimeAndSeekbarPatch : BytecodePatch( listOf( - CreateVideoPlayerSeekbarFingerprint, TimeCounterFingerprint + SeekbarFingerprint, TimeCounterFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -40,7 +42,9 @@ class HideTimeAndSeekbarPatch : BytecodePatch( ) ) - val createVideoPlayerSeekbarMethod = CreateVideoPlayerSeekbarFingerprint.result!!.mutableMethod + val createVideoPlayerSeekbarMethod = SeekbarFingerprint.result!!.let { + SeekbarOnDrawFingerprint.apply { resolve(context, it.mutableClass) } + }.result!!.mutableMethod createVideoPlayerSeekbarMethod.addInstructions( 0, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/patch/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/patch/ReturnYouTubeDislikePatch.kt index 0cf0e2c8..de92cf14 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/patch/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/patch/ReturnYouTubeDislikePatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.returnyoutubedislike.patch +import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version @@ -51,8 +52,8 @@ class ReturnYouTubeDislikePatch : BytecodePatch( VideoIdPatch.injectCall("Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;->newVideoLoaded(Ljava/lang/String;)V") with(TextComponentFingerprint - .also { it.resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) } - .result ?: return PatchResultError("Could not find createComponent method") + .apply { resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) } + .result ?: return TextComponentFingerprint.toErrorResult() ) { val createComponentMethod = mutableMethod diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/CreateVideoPlayerSeekbarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/CreateVideoPlayerSeekbarFingerprint.kt deleted file mode 100644 index 3c021fce..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/CreateVideoPlayerSeekbarFingerprint.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints - - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint - -object CreateVideoPlayerSeekbarFingerprint : MethodFingerprint( - "V", - strings = listOf("timed_markers_width") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index 9b3d507c..15e40ffc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -16,12 +16,14 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.fingerprints.SeekbarFingerprint +import app.revanced.patches.shared.fingerprints.SeekbarOnDrawFingerprint +import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.youtube.layout.autocaptions.fingerprints.StartVideoInformerFingerprint import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility import app.revanced.patches.youtube.layout.sponsorblock.bytecode.fingerprints.* import app.revanced.patches.youtube.layout.sponsorblock.resource.patch.SponsorBlockResourcePatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.youtube.misc.playercontrols.bytecode.patch.PlayerControlsBytecodePatch import app.revanced.patches.youtube.misc.video.information.patch.VideoInformationPatch import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch @@ -48,7 +50,7 @@ import org.jf.dexlib2.iface.reference.StringReference @Version("0.0.1") class SponsorBlockBytecodePatch : BytecodePatch( listOf( - CreateVideoPlayerSeekbarFingerprint, + SeekbarFingerprint, NextGenWatchLayoutFingerprint, AppendTimeFingerprint, PlayerOverlaysLayoutInitFingerprint, @@ -85,7 +87,9 @@ class SponsorBlockBytecodePatch : BytecodePatch( /* Seekbar drawing */ - val seekbarSignatureResult = CreateVideoPlayerSeekbarFingerprint.result!! + val seekbarSignatureResult = SeekbarFingerprint.result!!.let { + SeekbarOnDrawFingerprint.apply { resolve(context, it.mutableClass) } + }.result!! val seekbarMethod = seekbarSignatureResult.mutableMethod val seekbarMethodInstructions = seekbarMethod.implementation!!.instructions @@ -96,7 +100,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( if (instruction.opcode != Opcode.MOVE_OBJECT_FROM16) continue seekbarMethod.addInstruction( index + 1, - "invoke-static {v0}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V" + "invoke-static/range {p0 .. p0}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V" ) break } @@ -120,10 +124,10 @@ class SponsorBlockBytecodePatch : BytecodePatch( /* Set rectangle absolute left and right positions */ - val drawRectangleInstructions = seekbarMethodInstructions.filter { - it is ReferenceInstruction && (it.reference as? MethodReference)?.name == "drawRect" && it is FiveRegisterInstruction - }.map { // TODO: improve code - seekbarMethodInstructions.indexOf(it) to (it as FiveRegisterInstruction).registerD + val drawRectangleInstructions = seekbarMethodInstructions.withIndex().filter { (_, instruction) -> + instruction is ReferenceInstruction && (instruction.reference as? MethodReference)?.name == "drawRect" + }.map { (index, instruction) -> // TODO: improve code + index to (instruction as FiveRegisterInstruction).registerD } val (indexRight, rectangleRightRegister) = drawRectangleInstructions[0] diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/DrawActionBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/DrawActionBarFingerprint.kt new file mode 100644 index 00000000..5ea1ffa3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/DrawActionBarFingerprint.kt @@ -0,0 +1,27 @@ +package app.revanced.patches.youtube.layout.widesearchbar.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 DrawActionBarFingerprint : MethodFingerprint( + "V", + AccessFlags.PRIVATE or AccessFlags.FINAL, + listOf("I", "I"), + listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_STATIC, + ), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckFingerprint.kt deleted file mode 100644 index 146bf238..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckFingerprint.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.revanced.patches.youtube.layout.widesearchbar.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint - -object IsInOfflineModeCheckFingerprint : MethodFingerprint( - "L", - strings = listOf("bundle_is_in_offline_mode") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckResultFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckResultFingerprint.kt deleted file mode 100644 index 37553c83..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/fingerprints/IsInOfflineModeCheckResultFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.youtube.layout.widesearchbar.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.Opcode - -object IsInOfflineModeCheckResultFingerprint : MethodFingerprint( - "L", - parameters = listOf("L", "L", "L", "L", "L"), - opcodes = listOf( - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT, - Opcode.IF_EQZ, - Opcode.NEW_INSTANCE, - Opcode.MOVE_OBJECT, - Opcode.MOVE_OBJECT, - Opcode.MOVE_OBJECT, - ), -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/patch/WideSearchbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/patch/WideSearchbarPatch.kt index 95ae7304..50263ba0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/patch/WideSearchbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/widesearchbar/patch/WideSearchbarPatch.kt @@ -8,7 +8,6 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -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 @@ -18,8 +17,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.layout.widesearchbar.annotations.WideSearchbarCompatibility -import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.IsInOfflineModeCheckFingerprint -import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.IsInOfflineModeCheckResultFingerprint +import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.DrawActionBarFingerprint import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.SetWordmarkHeaderFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @@ -32,7 +30,7 @@ import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @Version("0.0.1") class WideSearchbarPatch : BytecodePatch( listOf( - SetWordmarkHeaderFingerprint, IsInOfflineModeCheckFingerprint + SetWordmarkHeaderFingerprint, DrawActionBarFingerprint ) ) { private companion object { @@ -75,16 +73,12 @@ class WideSearchbarPatch : BytecodePatch( ) ) - // resolve fingerprints - IsInOfflineModeCheckFingerprint.result?.let { - if (!IsInOfflineModeCheckResultFingerprint.resolve(context, it.classDef)) - return IsInOfflineModeCheckResultFingerprint.toErrorResult() - } ?: return IsInOfflineModeCheckFingerprint.toErrorResult() + val result = DrawActionBarFingerprint.result ?: return DrawActionBarFingerprint.toErrorResult() // patch methods mapOf( SetWordmarkHeaderFingerprint to 1, - IsInOfflineModeCheckResultFingerprint to 0 + DrawActionBarFingerprint to result.scanResult.patternScanResult!!.endIndex ).forEach { (fingerprint, callIndex) -> context.walkMutable(callIndex, fingerprint).injectSearchBarHook() } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/patch/LithoFilterPatch.kt index caa22afd..9ea24e43 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/patch/LithoFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/patch/LithoFilterPatch.kt @@ -19,6 +19,7 @@ import app.revanced.patches.youtube.misc.litho.filter.fingerprints.EmptyComponen import org.jf.dexlib2.iface.instruction.Instruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction import org.jf.dexlib2.iface.reference.FieldReference import org.jf.dexlib2.iface.reference.MethodReference @@ -44,14 +45,16 @@ class LithoFilterPatch : BytecodePatch( val builderMethodDescriptor = instruction(builderMethodIndex).toDescriptor() val emptyComponentFieldDescriptor = instruction(emptyComponentFieldIndex).toDescriptor() + val stringBuilderRegister = (instruction(insertHookIndex - 1) as TwoRegisterInstruction).registerA + addInstructions( insertHookIndex, // right after setting the component.pathBuilder field, """ - invoke-static {v5, v2}, Lapp/revanced/integrations/patches/LithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;)Z + invoke-static {v$stringBuilderRegister, v0}, Lapp/revanced/integrations/patches/LithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;)Z move-result v$clobberedRegister if-eqz v$clobberedRegister, :not_an_ad - move-object/from16 v2, p1 - invoke-static {v2}, $builderMethodDescriptor + move-object/from16 v0, p1 + invoke-static {v0}, $builderMethodDescriptor move-result-object v0 iget-object v0, v0, $emptyComponentFieldDescriptor return-object v0 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 new file mode 100644 index 00000000..599314a4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeConstructorFingerprint.kt @@ -0,0 +1,12 @@ +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 b999d4a0..9fc0065e 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,18 +6,7 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode object ThemeSetterAppFingerprint : MethodFingerprint( - "L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L", "L", "L"), listOf( - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.IF_EQZ, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.IF_EQZ, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.SGET_OBJECT, - Opcode.IF_NE, + "L", AccessFlags.PUBLIC or AccessFlags.STATIC, 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 9cac0592..2c1ee88b 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 @@ -1,11 +1,13 @@ package app.revanced.patches.youtube.misc.settings.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.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 @@ -16,6 +18,7 @@ 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 @@ -33,7 +36,7 @@ import org.jf.dexlib2.util.MethodUtil @SettingsCompatibility @Version("0.0.1") class SettingsPatch : BytecodePatch( - listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeSetterAppFingerprint) + listOf(LicenseActivityFingerprint, ThemeSetterSystemFingerprint, ThemeConstructorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { fun buildInvokeInstructionsString( @@ -44,48 +47,47 @@ class SettingsPatch : BytecodePatch( ) = "invoke-static {$registers}, $classDescriptor->$methodName($parameters)V" // apply the current theme of the settings page - with(ThemeSetterSystemFingerprint.result!!) { - with(mutableMethod) { - val call = buildInvokeInstructionsString() - + ThemeSetterSystemFingerprint.result!!.let { result -> + val call = buildInvokeInstructionsString() + result.mutableMethod.apply { addInstruction( - scanResult.patternScanResult!!.startIndex, - call + result.scanResult.patternScanResult!!.startIndex, call ) - - addInstruction( - mutableMethod.implementation!!.instructions.size - 1, - call + addInstructions( + implementation!!.instructions.size - 1, call ) } } // set the theme based on the preference of the app - with(ThemeSetterAppFingerprint.result!!) { - with(mutableMethod) { - fun buildInstructionsString(theme: Int) = """ + with((ThemeConstructorFingerprint.result?.let { + ThemeSetterAppFingerprint.apply { + if (!resolve(context, it.classDef)) return ThemeSetterAppFingerprint.toErrorResult() + } + } ?: return ThemeConstructorFingerprint.toErrorResult()).result!!) { + fun buildInstructionsString(theme: Int) = """ const/4 v0, 0x$theme ${buildInvokeInstructionsString(parameters = "I")} """ + val patternScanResult = scanResult.patternScanResult!! + + mutableMethod.apply { addInstructions( - scanResult.patternScanResult!!.endIndex + 1, - buildInstructionsString(1) + patternScanResult.endIndex + 1, buildInstructionsString(1) ) addInstructions( - scanResult.patternScanResult!!.endIndex - 7, - buildInstructionsString(0) + patternScanResult.endIndex - 7, buildInstructionsString(0) ) addInstructions( - scanResult.patternScanResult!!.endIndex - 9, - buildInstructionsString(1) + patternScanResult.endIndex - 9, buildInstructionsString(1) ) addInstructions( - mutableMethod.implementation!!.instructions.size - 2, - buildInstructionsString(0) + implementation!!.instructions.size - 2, buildInstructionsString(0) ) } + } // set the theme based on the preference of the device @@ -100,8 +102,7 @@ class SettingsPatch : BytecodePatch( // initialize the settings addInstructions( - 1, - """ + 1, """ ${buildSettingsActivityInvokeString()} return-void """ @@ -134,8 +135,7 @@ class SettingsPatch : BytecodePatch( fun addPreferenceScreen(preferenceScreen: app.revanced.patches.shared.settings.preference.impl.PreferenceScreen) = SettingsResourcePatch.addPreferenceScreen(preferenceScreen) - fun addPreference(preference: Preference) = - SettingsResourcePatch.addPreference(preference) + fun addPreference(preference: Preference) = SettingsResourcePatch.addPreference(preference) fun renameIntentsTargetPackage(newPackage: String) { SettingsResourcePatch.overrideIntentsTargetPackage = newPackage