fix(YouTube Music/Hide action bar label): patch breaks in v6.31.55+

This commit is contained in:
inotia00
2023-12-08 11:33:58 +09:00
parent 515ad09e2c
commit 4f70eb2398
2 changed files with 35 additions and 20 deletions

View File

@ -1,11 +1,13 @@
package app.revanced.patches.music.actionbar.label
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.actionbar.label.fingerprints.ActionBarLabelFingerprint
import app.revanced.patches.music.utils.fingerprints.ActionsBarParentFingerprint
import app.revanced.patches.music.utils.integrations.Constants.ACTIONBAR
@ -13,7 +15,9 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch(
name = "Hide action bar label",
@ -29,24 +33,36 @@ object ActionBarLabelPatch : BytecodePatch(
setOf(ActionsBarParentFingerprint)
) {
override fun execute(context: BytecodeContext) {
ActionsBarParentFingerprint.result?.let { parentResult ->
ActionBarLabelFingerprint.also {
it.resolve(
context,
parentResult.classDef
)
}.result?.let {
ActionsBarParentFingerprint.result?.classDef?.let { parentClassDef ->
ActionBarLabelFingerprint.resolve(context, parentClassDef)
ActionBarLabelFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetRegister =
getInstruction<OneRegisterInstruction>(targetIndex).registerA
val instructions = implementation!!.instructions
addInstructions(
targetIndex, """
invoke-static {v$targetRegister}, $ACTIONBAR->hideActionBarLabel(Z)Z
move-result v$targetRegister
"""
val noLabelIndex = instructions.indexOfFirst { instruction ->
val reference = (instruction as? ReferenceInstruction)?.reference.toString()
instruction.opcode == Opcode.INVOKE_DIRECT
&& reference.endsWith("<init>(Landroid/content/Context;)V")
&& !reference.contains("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;")
} - 2
val replaceIndex = instructions.indexOfFirst { instruction ->
val reference = (instruction as? ReferenceInstruction)?.reference.toString()
instruction.opcode == Opcode.INVOKE_DIRECT
&& reference.endsWith("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;-><init>(Landroid/content/Context;)V")
} - 2
val replaceInstruction = getInstruction<TwoRegisterInstruction>(replaceIndex)
val replaceReference = getInstruction<ReferenceInstruction>(replaceIndex).reference
addInstructionsWithLabels(
replaceIndex + 1, """
invoke-static {}, $ACTIONBAR->hideActionBarLabel()Z
move-result v${replaceInstruction.registerA}
if-nez v${replaceInstruction.registerA}, :hidden
iget-object v${replaceInstruction.registerA}, v${replaceInstruction.registerB}, $replaceReference
""", ExternalLabel("hidden", getInstruction(noLabelIndex))
)
removeInstruction(replaceIndex)
}
} ?: throw ActionBarLabelFingerprint.exception
} ?: throw ActionsBarParentFingerprint.exception

View File

@ -10,10 +10,9 @@ object ActionBarLabelFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "L"),
opcodes = listOf(
Opcode.INVOKE_INTERFACE,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.INVOKE_VIRTUAL,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
)