add change-homepage patch

This commit is contained in:
inotia00
2023-04-08 07:46:52 +09:00
parent f56d1b35c0
commit 4321b57351
5 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package app.revanced.patches.youtube.layout.navigation.homepage.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object IntentExceptionFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L", "L"),
opcodes = listOf(Opcode.MOVE_EXCEPTION),
strings = listOf("Failed to resolve intent")
)

View File

@ -0,0 +1,8 @@
package app.revanced.patches.youtube.layout.navigation.homepage.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object LauncherActivityFingerprint : MethodFingerprint(
returnType = "V",
strings = listOf("forLauncherActivity", "Launcher config used on invalid activity: %s")
)

View File

@ -0,0 +1,73 @@
package app.revanced.patches.youtube.layout.navigation.homepage.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.addInstructions
import app.revanced.patcher.extensions.instruction
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.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.navigation.homepage.fingerprints.IntentExceptionFingerprint
import app.revanced.patches.youtube.layout.navigation.homepage.fingerprints.LauncherActivityFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.NAVIGATION
@Patch
@Name("change-homepage")
@Description("Change home page to subscription feed.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class ChangeHomePagePatch : BytecodePatch(
listOf(
IntentExceptionFingerprint,
LauncherActivityFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LauncherActivityFingerprint.result?.mutableMethod?.let {
it.addInstructions(
it.implementation!!.instructions.size - 1, """
move-object/from16 v0, p1
invoke-static {v0}, $NAVIGATION->changeHomePage(Lcom/google/android/apps/youtube/app/watchwhile/WatchWhileActivity;)V
"""
)
} ?: return LauncherActivityFingerprint.toErrorResult()
IntentExceptionFingerprint.result?.let {
with (it.mutableMethod) {
val index = it.scanResult.patternScanResult!!.endIndex + 1
addInstructions(
index, """
invoke-static {}, $NAVIGATION->changeHomePage()Z
move-result v0
if-eqz v0, :default
return-void
""", listOf(ExternalLabel("default", instruction(index)))
)
}
} ?: return IntentExceptionFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: CHANGE_HOMEPAGE_TO_SUBSCRIPTION"
)
)
SettingsPatch.updatePatchStatus("change-homepage")
return PatchResultSuccess()
}
}