feat(music): integrate hide-navigation-label, hide-sample-buttons, hide-upgrade-button into hide-navigation-bar-component

This commit is contained in:
inotia00 2023-09-18 18:55:09 +09:00
parent 46dda20e77
commit b82205482d
7 changed files with 156 additions and 234 deletions

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.fingerprints
package app.revanced.patches.music.navigation.component.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -0,0 +1,142 @@
package app.revanced.patches.music.navigation.component.patch
import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
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.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.navigation.component.fingerprints.TabLayoutTextFingerprint
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION
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.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch
@Name("Hide navigation bar component")
@Description("Hides navigation bar components.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@MusicCompatibility
class NavigationBarComponentPatch : BytecodePatch(
listOf(TabLayoutTextFingerprint)
) {
override fun execute(context: BytecodeContext) {
/**
* Hide navigation labels
*/
TabLayoutTextFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralIndex(SharedResourceIdPatch.Text1) + 3
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
if (!targetParameter.toString().endsWith("Landroid/widget/TextView;"))
throw PatchException("Method signature parameter did not match: $targetParameter")
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V"
)
}
} ?: throw TabLayoutTextFingerprint.exception
SettingsPatch.contexts.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
val document = editor.file
with(document.getElementsByTagName("ImageView").item(0)) {
if (attributes.getNamedItem(FLAG) != null)
return@with
document.createAttribute(FLAG)
.apply { value = "0.5" }
.let(attributes::setNamedItem)
}
}
/**
* Hide navigation bar & buttons
*/
TabLayoutTextFingerprint.result?.let {
it.mutableMethod.apply {
val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.AND_INT_LIT8
} - 2
val pivotTabIndex = implementation!!.instructions.indexOfFirst { instruction ->
((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "getVisibility"
}
val pivotTabRegister = getInstruction<Instruction35c>(pivotTabIndex).registerC
addInstruction(
pivotTabIndex,
"invoke-static {v$pivotTabRegister}, $MUSIC_NAVIGATION->hideNavigationButton(Landroid/view/View;)V"
)
addInstruction(
insertIndex,
"sput-object v$enumRegister, $MUSIC_NAVIGATION->lastPivotTab:Ljava/lang/Enum;"
)
}
} ?: throw TabLayoutTextFingerprint.exception
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_explore_button",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_home_button",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_library_button",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_navigation_bar",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_navigation_label",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_samples_button",
"false"
)
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_upgrade_button",
"true"
)
}
private companion object {
const val FLAG = "android:layout_weight"
const val RESOURCE_FILE_PATH = "res/layout/image_with_text_tab.xml"
}
}

View File

@ -1,79 +0,0 @@
package app.revanced.patches.music.navigation.label.patch
import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
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.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.fingerprints.TabLayoutTextFingerprint
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.Text1
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch.Companion.contexts
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@Patch
@Name("Hide navigation label")
@Description("Hide navigation bar labels.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@MusicCompatibility
class NavigationLabelPatch : BytecodePatch(
listOf(TabLayoutTextFingerprint)
) {
override fun execute(context: BytecodeContext) {
TabLayoutTextFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralIndex(Text1) + 3
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
if (!targetParameter.toString().endsWith("Landroid/widget/TextView;"))
throw PatchException("Method signature parameter did not match: $targetParameter")
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V"
)
}
} ?: throw TabLayoutTextFingerprint.exception
contexts.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
val document = editor.file
with(document.getElementsByTagName("ImageView").item(0)) {
if (attributes.getNamedItem(FLAG) != null) return@with
document.createAttribute(FLAG)
.apply { value = "0.5" }
.let(attributes::setNamedItem)
}
}
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_navigation_label",
"false"
)
}
private companion object {
const val FLAG = "android:layout_weight"
const val RESOURCE_FILE_PATH = "res/layout/image_with_text_tab.xml"
}
}

View File

@ -1,21 +0,0 @@
package app.revanced.patches.music.navigation.sample.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.util.bytecode.isNarrowLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object PivotBarConstructorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
opcodes = listOf(
Opcode.IPUT_OBJECT,
Opcode.RETURN_VOID
),
customFingerprint = { methodDef, _ ->
methodDef.name == "<init>" && methodDef.isNarrowLiteralExists(
117501096
)
}
)

View File

@ -1,66 +0,0 @@
package app.revanced.patches.music.navigation.sample.patch
import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.navigation.sample.fingerprints.PivotBarConstructorFingerprint
import app.revanced.patches.music.navigation.upgrade.patch.UpgradeButtonPatch
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch
@Name("Hide sample buttons")
@Description("Adds options to hide sample buttons.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class,
UpgradeButtonPatch::class
]
)
@MusicCompatibility
class SampleButtonPatch : BytecodePatch(
listOf(PivotBarConstructorFingerprint)
) {
override fun execute(context: BytecodeContext) {
PivotBarConstructorFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
val targetRegisterA = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
val targetRegisterB = getInstruction<TwoRegisterInstruction>(targetIndex).registerB
val replaceReference =
getInstruction<ReferenceInstruction>(targetIndex).reference.toString()
replaceInstruction(
targetIndex,
"invoke-static {v$targetRegisterA}, $MUSIC_NAVIGATION->hideSampleButton(Ljava/util/List;)V"
)
addInstruction(
targetIndex + 1,
"iput-object v$targetRegisterA, v$targetRegisterB, $replaceReference"
)
}
} ?: throw PivotBarConstructorFingerprint.exception
SettingsPatch.addMusicPreference(
CategoryType.NAVIGATION,
"revanced_hide_sample_button",
"false"
)
}
}

View File

@ -1,64 +0,0 @@
package app.revanced.patches.music.navigation.upgrade.patch
import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
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.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.fingerprints.TabLayoutTextFingerprint
import app.revanced.patches.music.utils.integrations.patch.IntegrationsPatch
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch
@Name("Hide upgrade button")
@Description("Hides upgrade button from navigation bar.")
@DependsOn(
[
IntegrationsPatch::class,
SharedResourceIdPatch::class
]
)
@MusicCompatibility
class UpgradeButtonPatch : BytecodePatch(
listOf(TabLayoutTextFingerprint)
) {
override fun execute(context: BytecodeContext) {
TabLayoutTextFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.AND_INT_LIT8
} - 2
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_INTERFACE) continue
if ((getInstruction<Instruction35c>(index).reference as MethodReference).name != "hasNext") continue
addInstructionsWithLabels(
insertIndex, """
invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideUpgradeButton(Ljava/lang/Enum;)Z
move-result v$targetRegister
if-nez v$targetRegister, :hide
""", ExternalLabel("hide", getInstruction(index))
)
break
}
}
} ?: throw TabLayoutTextFingerprint.exception
}
}

View File

@ -78,6 +78,8 @@
<string name="revanced_hide_channel_guidelines_title">Hide channel guidelines</string>
<string name="revanced_hide_emoji_picker_summary">Hides emoji picker at the comments box.</string>
<string name="revanced_hide_emoji_picker_title">Hide emoji picker</string>
<string name="revanced_hide_explore_button_summary">Hides the explore button in navigation bar.</string>
<string name="revanced_hide_explore_button_title">Hide explore button</string>
<string name="revanced_hide_flyout_panel_add_to_queue_title">Hide add to queue menu</string>
<string name="revanced_hide_flyout_panel_dismiss_queue_title">Hide dismiss queue menu</string>
<string name="revanced_hide_flyout_panel_download_title">Hide download menu</string>
@ -92,16 +94,24 @@
<string name="revanced_hide_flyout_panel_share_title">Hide share menu</string>
<string name="revanced_hide_flyout_panel_start_radio_title">Hide start radio menu</string>
<string name="revanced_hide_flyout_panel_view_song_credit_title">Hide view song credit menu</string>
<string name="revanced_hide_home_button_summary">Hides the home button.</string>
<string name="revanced_hide_home_button_title">Hide home button</string>
<string name="revanced_hide_library_button_summary">Hides the library button.</string>
<string name="revanced_hide_library_button_title">Hide library button</string>
<string name="revanced_hide_music_ads_summary">Hides ads before playing a music.</string>
<string name="revanced_hide_music_ads_title">Hide music ads</string>
<string name="revanced_hide_navigation_bar_summary">Hides navigation bar.</string>
<string name="revanced_hide_navigation_bar_title">Hide navigation bar</string>
<string name="revanced_hide_navigation_label_summary">Hide labels in navigation bar.</string>
<string name="revanced_hide_navigation_label_title">Hide navigation bar labels</string>
<string name="revanced_hide_navigation_label_title">Hide navigation label</string>
<string name="revanced_hide_new_playlist_button_summary">Hide the \"New playlist\" button in the library.</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>
<string name="revanced_hide_playlist_card_title">Hide playlist card</string>
<string name="revanced_hide_sample_button_summary">Hides the sample button in navigation bar.</string>
<string name="revanced_hide_sample_button_title">Hide sample button</string>
<string name="revanced_hide_samples_button_summary">Hides the samples button.</string>
<string name="revanced_hide_samples_button_title">Hide samples button</string>
<string name="revanced_hide_upgrade_button_summary">Hides the upgrade button.</string>
<string name="revanced_hide_upgrade_button_title">Hide upgrade button</string>
<string name="revanced_hook_action_bar_download_summary">Replaces the offline download button with an external download button.</string>
<string name="revanced_hook_action_bar_download_title">Hook download button</string>
<string name="revanced_reboot_first_run">Restart to load the layout normally</string>