chore: lint code

This commit is contained in:
inotia00 2024-03-23 01:12:25 +09:00
parent 3f7803c5b8
commit b593fa302f
10 changed files with 142 additions and 187 deletions

View File

@ -2,34 +2,34 @@ package app.revanced.patches.music.flyoutpanel.component
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.flyoutpanel.component.fingerprints.EndButtonsContainerFingerprint
import app.revanced.patches.music.flyoutpanel.component.fingerprints.SleepTimerFingerprint import app.revanced.patches.music.flyoutpanel.component.fingerprints.SleepTimerFingerprint
import app.revanced.patches.music.flyoutpanel.utils.EnumUtils.getEnumIndex import app.revanced.patches.music.flyoutpanel.shared.FlyoutPanelMenuItemPatch
import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.utils.flyoutbutton.FlyoutButtonContainerPatch
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.integrations.Constants.FLYOUT import app.revanced.patches.music.utils.integrations.Constants.FLYOUT
import app.revanced.patches.music.utils.litho.LithoFilterPatch import app.revanced.patches.music.utils.litho.LithoFilterPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.EndButtonsContainer
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getTargetIndex
import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch( @Patch(
name = "Hide flyout panel", name = "Hide flyout panel",
description = "Adds options to hide flyout panel components.", description = "Adds options to hide flyout panel components.",
dependencies = [ dependencies = [
FlyoutButtonContainerPatch::class, FlyoutPanelMenuItemPatch::class,
LithoFilterPatch::class, LithoFilterPatch::class,
SettingsPatch::class SettingsPatch::class,
SharedResourceIdPatch::class
], ],
compatiblePackages = [ compatiblePackages = [
CompatiblePackage( CompatiblePackage(
@ -52,37 +52,29 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Suppress("unused") @Suppress("unused")
object FlyoutPanelPatch : BytecodePatch( object FlyoutPanelPatch : BytecodePatch(
setOf( setOf(
MenuItemFingerprint, EndButtonsContainerFingerprint,
SleepTimerFingerprint SleepTimerFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
MenuItemFingerprint.result?.let { FlyoutPanelMenuItemPatch.hideComponents()
EndButtonsContainerFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val freeIndex = implementation!!.instructions.indexOfFirst { instruction -> val startIndex = getWideLiteralInstructionIndex(EndButtonsContainer)
instruction.opcode == Opcode.OR_INT_LIT16 val targetIndex = getTargetIndex(startIndex, Opcode.MOVE_RESULT_OBJECT)
} val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val freeRegister = getInstruction<TwoRegisterInstruction>(freeIndex).registerA
val enumIndex = getEnumIndex() addInstruction(
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA targetIndex + 1,
"invoke-static {v$targetRegister}, $FLYOUT->hideLikeDislikeContainer(Landroid/view/View;)V"
val jumpInstruction =
getInstruction<Instruction>(implementation!!.instructions.size - 1)
addInstructionsWithLabels(
enumIndex + 1, """
invoke-static {v$enumRegister}, $FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z
move-result v$freeRegister
if-nez v$freeRegister, :hide
""", ExternalLabel("hide", jumpInstruction)
) )
} }
} ?: throw MenuItemFingerprint.exception } ?: throw EndButtonsContainerFingerprint.exception
/** /**
* Forces sleep timer menu to be enabled. * Forces sleep timer menu to be enabled.
* This method may be deperated in the future. * This method may be desperate in the future.
*/ */
SleepTimerFingerprint.result?.let { SleepTimerFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
@ -166,13 +158,11 @@ object FlyoutPanelPatch : BytecodePatch(
"revanced_hide_flyout_panel_like_dislike", "revanced_hide_flyout_panel_like_dislike",
"false" "false"
) )
if (!SettingsPatch.upward0636) {
SettingsPatch.addMusicPreferenceWithoutSummary( SettingsPatch.addMusicPreferenceWithoutSummary(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_hide_flyout_panel_play_next", "revanced_hide_flyout_panel_play_next",
"false" "false"
) )
}
SettingsPatch.addMusicPreferenceWithoutSummary( SettingsPatch.addMusicPreferenceWithoutSummary(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_hide_flyout_panel_quality", "revanced_hide_flyout_panel_quality",
@ -203,7 +193,6 @@ object FlyoutPanelPatch : BytecodePatch(
"revanced_hide_flyout_panel_save_to_library", "revanced_hide_flyout_panel_save_to_library",
"false" "false"
) )
if (!SettingsPatch.upward0636) {
SettingsPatch.addMusicPreferenceWithoutSummary( SettingsPatch.addMusicPreferenceWithoutSummary(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_hide_flyout_panel_save_to_playlist", "revanced_hide_flyout_panel_save_to_playlist",
@ -214,7 +203,6 @@ object FlyoutPanelPatch : BytecodePatch(
"revanced_hide_flyout_panel_share", "revanced_hide_flyout_panel_share",
"false" "false"
) )
}
SettingsPatch.addMusicPreferenceWithoutSummary( SettingsPatch.addMusicPreferenceWithoutSummary(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_hide_flyout_panel_shuffle_play", "revanced_hide_flyout_panel_shuffle_play",

View File

@ -0,0 +1,10 @@
package app.revanced.patches.music.flyoutpanel.component.fingerprints
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.EndButtonsContainer
import app.revanced.util.fingerprint.LiteralValueFingerprint
object EndButtonsContainerFingerprint : LiteralValueFingerprint(
returnType = "V",
literalSupplier = { EndButtonsContainer }
)

View File

@ -1,24 +1,19 @@
package app.revanced.patches.music.flyoutpanel.replace package app.revanced.patches.music.flyoutpanel.replace
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.flyoutpanel.utils.EnumUtils.getEnumIndex import app.revanced.patches.music.flyoutpanel.shared.FlyoutPanelMenuItemPatch
import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.utils.integrations.Constants.FLYOUT
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Patch( @Patch(
name = "Replace dismiss queue", name = "Replace dismiss queue",
description = "Adds an option to replace \"Dismiss queue\" with \"Watch on YouTube\" in the flyout menu.", description = "Adds an option to replace \"Dismiss queue\" with \"Watch on YouTube\" in the flyout menu.",
dependencies = [ dependencies = [
FlyoutPanelMenuItemPatch::class,
SettingsPatch::class, SettingsPatch::class,
VideoInformationPatch::class VideoInformationPatch::class
], ],
@ -41,36 +36,15 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
] ]
) )
@Suppress("unused") @Suppress("unused")
object ReplaceDismissQueuePatch : BytecodePatch( object ReplaceDismissQueuePatch : BytecodePatch(emptySet()) {
setOf(MenuItemFingerprint)
) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
MenuItemFingerprint.result?.let { FlyoutPanelMenuItemPatch.replaceComponents()
it.mutableMethod.apply {
val enumIndex = getEnumIndex()
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
val textViewIndex = it.scanResult.patternScanResult!!.startIndex
val imageViewIndex = it.scanResult.patternScanResult!!.endIndex
val textViewRegister =
getInstruction<OneRegisterInstruction>(textViewIndex).registerA
val imageViewRegister =
getInstruction<OneRegisterInstruction>(imageViewIndex).registerA
addInstruction(
enumIndex + 1,
"invoke-static {v$enumRegister, v$textViewRegister, v$imageViewRegister}, $FLYOUT->replaceDismissQueue(Ljava/lang/Enum;Landroid/widget/TextView;Landroid/widget/ImageView;)V"
)
}
} ?: throw MenuItemFingerprint.exception
SettingsPatch.addMusicPreference( SettingsPatch.addMusicPreference(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_replace_flyout_panel_dismiss_queue", "revanced_replace_flyout_panel_dismiss_queue",
"false" "false"
) )
SettingsPatch.addMusicPreference( SettingsPatch.addMusicPreference(
CategoryType.FLYOUT, CategoryType.FLYOUT,
"revanced_replace_flyout_panel_dismiss_queue_continue_watch", "revanced_replace_flyout_panel_dismiss_queue_continue_watch",

View File

@ -0,0 +1,83 @@
package app.revanced.patches.music.flyoutpanel.shared
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.flyoutpanel.shared.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.utils.integrations.Constants.FLYOUT
import app.revanced.util.exception
import app.revanced.util.getTargetIndex
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import kotlin.properties.Delegates
object FlyoutPanelMenuItemPatch : BytecodePatch(
setOf(MenuItemFingerprint)
) {
private lateinit var menuItemMethod: MutableMethod
private var freeRegister by Delegates.notNull<Int>()
private var textViewRegister by Delegates.notNull<Int>()
private var imageViewRegister by Delegates.notNull<Int>()
private var instructionAdded = false
override fun execute(context: BytecodeContext) {
MenuItemFingerprint.result?.let {
it.mutableMethod.apply {
val freeIndex = getTargetIndex(Opcode.OR_INT_LIT16)
val textViewIndex = it.scanResult.patternScanResult!!.startIndex
val imageViewIndex = it.scanResult.patternScanResult!!.endIndex
freeRegister =
getInstruction<TwoRegisterInstruction>(freeIndex).registerA
textViewRegister =
getInstruction<OneRegisterInstruction>(textViewIndex).registerA
imageViewRegister =
getInstruction<OneRegisterInstruction>(imageViewIndex).registerA
menuItemMethod = this
}
} ?: throw MenuItemFingerprint.exception
}
private fun MutableMethod.getEnumIndex() = indexOfFirstInstruction {
opcode == Opcode.INVOKE_STATIC
&& (this as? ReferenceInstruction)?.reference.toString().contains("(I)L")
} + 1
internal fun hideComponents() {
menuItemMethod.apply {
val enumIndex = getEnumIndex()
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
addInstructionsWithLabels(
enumIndex + 1, """
invoke-static {v$enumRegister}, $FLYOUT->hideComponents(Ljava/lang/Enum;)Z
move-result v$freeRegister
if-nez v$freeRegister, :hide
""", ExternalLabel("hide", getInstruction(implementation!!.instructions.size - 1))
)
}
}
internal fun replaceComponents() {
if (!instructionAdded) {
menuItemMethod.apply {
val enumIndex = getEnumIndex()
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
addInstruction(
enumIndex + 1,
"invoke-static {v$enumRegister, v$textViewRegister, v$imageViewRegister}, $FLYOUT->replaceComponents(Ljava/lang/Enum;Landroid/widget/TextView;Landroid/widget/ImageView;)V"
)
}
instructionAdded = true
}
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.fingerprints package app.revanced.patches.music.flyoutpanel.shared.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint

View File

@ -1,28 +0,0 @@
package app.revanced.patches.music.flyoutpanel.utils
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
internal object EnumUtils {
fun MutableMethod.getEnumIndex(): Int {
var targetIndex = 0
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_STATIC) continue
val targetParameter = getInstruction<ReferenceInstruction>(index).reference
if (!targetParameter.toString().contains("(I)")) continue
targetIndex = index + 1
break
}
if (targetIndex == 0)
throw PatchException("Target reference not found!")
return targetIndex
}
}

View File

@ -1,52 +0,0 @@
package app.revanced.patches.music.utils.flyoutbutton
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.utils.flyoutbutton.fingerprints.FlyoutPanelLikeButtonFingerprint
import app.revanced.patches.music.utils.integrations.Constants.FLYOUT
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicMenuLikeButtons
import app.revanced.util.exception
import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Patch(
dependencies = [
SharedResourceIdPatch::class
]
)
object FlyoutButtonContainerPatch : BytecodePatch(
setOf(FlyoutPanelLikeButtonFingerprint)
) {
override fun execute(context: BytecodeContext) {
FlyoutPanelLikeButtonFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(MusicMenuLikeButtons)
var insertIndex = -1
for (index in targetIndex until targetIndex + 5) {
if (getInstruction(index).opcode != Opcode.MOVE_RESULT_OBJECT) continue
val register = getInstruction<OneRegisterInstruction>(index).registerA
insertIndex = index
addInstruction(
index + 1,
"invoke-static {v$register}, $FLYOUT->setFlyoutButtonContainer(Landroid/view/View;)V"
)
break
}
if (insertIndex == -1)
throw PatchException("Couldn't find target Index")
}
} ?: throw FlyoutPanelLikeButtonFingerprint.exception
}
}

View File

@ -1,14 +0,0 @@
package app.revanced.patches.music.utils.flyoutbutton.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicMenuLikeButtons
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
object FlyoutPanelLikeButtonFingerprint : LiteralValueFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC,
parameters = listOf("L", "Ljava/lang/Object;"),
literalSupplier = { MusicMenuLikeButtons }
)

View File

@ -22,6 +22,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var ColorGrey: Long = -1 var ColorGrey: Long = -1
var DesignBottomSheetDialog: Long = -1 var DesignBottomSheetDialog: Long = -1
var DialogSolid: Long = -1 var DialogSolid: Long = -1
var EndButtonsContainer: Long = -1
var FloatingLayout: Long = -1 var FloatingLayout: Long = -1
var HistoryMenuItem: Long = -1 var HistoryMenuItem: Long = -1
var InlineTimeBarAdBreakMarkerColor: Long = -1 var InlineTimeBarAdBreakMarkerColor: Long = -1
@ -30,7 +31,6 @@ object SharedResourceIdPatch : ResourcePatch() {
var MenuEntry: Long = -1 var MenuEntry: Long = -1
var MiniPlayerMdxPlaying: Long = -1 var MiniPlayerMdxPlaying: Long = -1
var MiniPlayerPlayPauseReplayButton: Long = -1 var MiniPlayerPlayPauseReplayButton: Long = -1
var MusicMenuLikeButtons: Long = -1
var MusicNotifierShelf: Long = -1 var MusicNotifierShelf: Long = -1
var MusicTasteBuilderShelf: Long = -1 var MusicTasteBuilderShelf: Long = -1
var NamesInactiveAccountThumbnailSize: Long = -1 var NamesInactiveAccountThumbnailSize: Long = -1
@ -59,6 +59,7 @@ object SharedResourceIdPatch : ResourcePatch() {
ColorGrey = find(COLOR, "ytm_color_grey_12") ColorGrey = find(COLOR, "ytm_color_grey_12")
DesignBottomSheetDialog = find(LAYOUT, "design_bottom_sheet_dialog") DesignBottomSheetDialog = find(LAYOUT, "design_bottom_sheet_dialog")
DialogSolid = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid") DialogSolid = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
EndButtonsContainer = find(ID, "end_buttons_container")
FloatingLayout = find(ID, "floating_layout") FloatingLayout = find(ID, "floating_layout")
HistoryMenuItem = find(ID, "history_menu_item") HistoryMenuItem = find(ID, "history_menu_item")
InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color") InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color")
@ -67,7 +68,6 @@ object SharedResourceIdPatch : ResourcePatch() {
MenuEntry = find(LAYOUT, "menu_entry") MenuEntry = find(LAYOUT, "menu_entry")
MiniPlayerMdxPlaying = find(STRING, "mini_player_mdx_playing") MiniPlayerMdxPlaying = find(STRING, "mini_player_mdx_playing")
MiniPlayerPlayPauseReplayButton = find(ID, "mini_player_play_pause_replay_button") MiniPlayerPlayPauseReplayButton = find(ID, "mini_player_play_pause_replay_button")
MusicMenuLikeButtons = find(LAYOUT, "music_menu_like_buttons")
MusicNotifierShelf = find(LAYOUT, "music_notifier_shelf") MusicNotifierShelf = find(LAYOUT, "music_notifier_shelf")
MusicTasteBuilderShelf = find(LAYOUT, "music_tastebuilder_shelf") MusicTasteBuilderShelf = find(LAYOUT, "music_tastebuilder_shelf")
NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size") NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size")

View File

@ -91,19 +91,13 @@ fun Method.getWideLiteralInstructionIndex(literal: Long) = implementation?.let {
} }
} ?: -1 } ?: -1
fun Method.getEmptyStringInstructionIndex() = implementation?.let { fun MutableMethod.getEmptyStringInstructionIndex()
it.instructions.indexOfFirst { instruction -> = getStringInstructionIndex("")
instruction.opcode == Opcode.CONST_STRING
&& (instruction as? BuilderInstruction21c)?.reference.toString().isEmpty()
}
} ?: -1
fun Method.getStringInstructionIndex(value: String) = implementation?.let { fun MutableMethod.getStringInstructionIndex(value: String) = indexOfFirstInstruction {
it.instructions.indexOfFirst { instruction -> opcode == Opcode.CONST_STRING
instruction.opcode == Opcode.CONST_STRING && (this as? BuilderInstruction21c)?.reference.toString() == value
&& (instruction as? BuilderInstruction21c)?.reference.toString() == value
} }
} ?: -1
/** /**
* Check if the method contains a literal with the given value. * Check if the method contains a literal with the given value.