mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-19 07:47:17 +02:00
refactor(hide-new-playlist): apply a much safer patching method
This commit is contained in:
parent
ab720b4381
commit
6e667c8173
@ -2,8 +2,6 @@ package app.revanced.patches.music.layout.floatingbutton.fingerprints
|
|||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
|
|
||||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
||||||
@ -11,20 +9,6 @@ object FloatingButtonFingerprint : MethodFingerprint(
|
|||||||
returnType = "V",
|
returnType = "V",
|
||||||
access = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
access = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||||
parameters = listOf("L"),
|
parameters = listOf("L"),
|
||||||
opcodes = listOf(
|
opcodes = listOf(Opcode.AND_INT_LIT16)
|
||||||
Opcode.CONST,
|
|
||||||
Opcode.INVOKE_VIRTUAL,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.MOVE_OBJECT,
|
|
||||||
Opcode.CHECK_CAST,
|
|
||||||
Opcode.CONST_4,
|
|
||||||
Opcode.INVOKE_VIRTUAL
|
|
||||||
),
|
|
||||||
customFingerprint = { methodDef ->
|
|
||||||
methodDef.implementation?.instructions?.any {
|
|
||||||
it.opcode.ordinal == Opcode.CONST.ordinal &&
|
|
||||||
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.floatingActionButtonLabelId
|
|
||||||
} == true
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package app.revanced.patches.music.layout.floatingbutton.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
|
||||||
|
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
|
||||||
|
|
||||||
|
object FloatingButtonParentFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||||
|
parameters = listOf("L"),
|
||||||
|
opcodes = listOf(Opcode.INVOKE_DIRECT),
|
||||||
|
customFingerprint = { methodDef ->
|
||||||
|
methodDef.implementation!!.instructions.any {
|
||||||
|
((it as? NarrowLiteralInstruction)?.narrowLiteral == 259982244)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
@ -7,18 +7,18 @@ import app.revanced.patcher.annotation.Version
|
|||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.instruction
|
import app.revanced.patcher.extensions.instruction
|
||||||
|
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.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
import app.revanced.patches.music.layout.floatingbutton.fingerprints.FloatingButtonFingerprint
|
import app.revanced.patches.music.layout.floatingbutton.fingerprints.*
|
||||||
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
|
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
|
||||||
import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch
|
import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch
|
||||||
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
|
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
|
||||||
import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH
|
import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("hide-new-playlist")
|
@Name("hide-new-playlist")
|
||||||
@ -33,28 +33,23 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
|||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class NewPlaylistButtonPatch : BytecodePatch(
|
class NewPlaylistButtonPatch : BytecodePatch(
|
||||||
listOf(
|
listOf(
|
||||||
FloatingButtonFingerprint
|
FloatingButtonParentFingerprint
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
|
||||||
FloatingButtonFingerprint.result?.let {
|
FloatingButtonParentFingerprint.result?.let { parentResult ->
|
||||||
with (it.mutableMethod) {
|
FloatingButtonFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let {
|
||||||
val targetIndex = it.scanResult.patternScanResult!!.endIndex
|
it.addInstructions(
|
||||||
|
1, """
|
||||||
val targetRegister = (instruction(targetIndex) as Instruction35c).registerC
|
|
||||||
val dummyRegister = (instruction(targetIndex) as Instruction35c).registerD
|
|
||||||
|
|
||||||
addInstructions(
|
|
||||||
targetIndex + 1, """
|
|
||||||
invoke-static {}, $MUSIC_SETTINGS_PATH->hideNewPlaylistButton()Z
|
invoke-static {}, $MUSIC_SETTINGS_PATH->hideNewPlaylistButton()Z
|
||||||
move-result v$dummyRegister
|
move-result v0
|
||||||
if-eqz v$dummyRegister, :show
|
if-eqz v0, :show
|
||||||
const/4 v$targetRegister, 0x0
|
return-void
|
||||||
""", listOf(ExternalLabel("show", instruction(targetIndex + 1)))
|
""", listOf(ExternalLabel("show", it.instruction(1)))
|
||||||
)
|
)
|
||||||
}
|
} ?: return FloatingButtonFingerprint.toErrorResult()
|
||||||
} ?: return FloatingButtonFingerprint.toErrorResult()
|
} ?: return FloatingButtonParentFingerprint.toErrorResult()
|
||||||
|
|
||||||
MusicSettingsPatch.addMusicPreference("navigation", "revanced_hide_new_playlist_button", "false")
|
MusicSettingsPatch.addMusicPreference("navigation", "revanced_hide_new_playlist_button", "false")
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ class SharedResourceIdPatch : ResourcePatch {
|
|||||||
var colorGreyLabelId: Long = -1
|
var colorGreyLabelId: Long = -1
|
||||||
var dialogSolidLabelId: Long = -1
|
var dialogSolidLabelId: Long = -1
|
||||||
var disabledIconLabelId: Long = -1
|
var disabledIconLabelId: Long = -1
|
||||||
var floatingActionButtonLabelId: Long = -1
|
|
||||||
var isTabletLabelId: Long = -1
|
var isTabletLabelId: Long = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ class SharedResourceIdPatch : ResourcePatch {
|
|||||||
colorGreyLabelId = find(COLOR, "ytm_color_grey_12")
|
colorGreyLabelId = find(COLOR, "ytm_color_grey_12")
|
||||||
dialogSolidLabelId = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
|
dialogSolidLabelId = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
|
||||||
disabledIconLabelId = find(DIMEN, "disabled_icon_alpha")
|
disabledIconLabelId = find(DIMEN, "disabled_icon_alpha")
|
||||||
floatingActionButtonLabelId = find(ID, "floating_action_button")
|
|
||||||
isTabletLabelId = find(BOOL, "is_tablet")
|
isTabletLabelId = find(BOOL, "is_tablet")
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
|
@ -36,8 +36,7 @@
|
|||||||
<string name="revanced_hide_music_ads_summary">"Hide ads before playing a track.
|
<string name="revanced_hide_music_ads_summary">"Hide ads before playing a track.
|
||||||
(requires an app restart)"</string>
|
(requires an app restart)"</string>
|
||||||
<string name="revanced_hide_music_ads_title">Hide music ads</string>
|
<string name="revanced_hide_music_ads_title">Hide music ads</string>
|
||||||
<string name="revanced_hide_new_playlist_button_summary">"Hide the New Playlist button in the Library tab.
|
<string name="revanced_hide_new_playlist_button_summary">Hide the New Playlist button in the Library tab.</string>
|
||||||
(requires an app restart)"</string>
|
|
||||||
<string name="revanced_hide_new_playlist_button_title">Hide new playlist button</string>
|
<string name="revanced_hide_new_playlist_button_title">Hide new playlist button</string>
|
||||||
<string name="revanced_hide_playlist_card_summary">"Hides the playlist card from homepage.
|
<string name="revanced_hide_playlist_card_summary">"Hides the playlist card from homepage.
|
||||||
(requires an app restart)"</string>
|
(requires an app restart)"</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user