feat(songpal): add `remove-badge-tab` patch

This commit is contained in:
Your Name 2023-06-06 18:31:10 +02:00 committed by oSumAtrIX
parent cc66b1fc62
commit bde9053f04
3 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package app.revanced.patches.songpal.badge.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility([Package("com.sony.songpal.mdr")])
@Target(AnnotationTarget.CLASS)
internal annotation class BadgeCompatibility

View File

@ -0,0 +1,31 @@
package app.revanced.patches.songpal.badge.fingerprints
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
// Located @ ub.i0.h#p (9.5.0)
@FuzzyPatternScanMethod(2)
object CreateTabsFingerprint : MethodFingerprint(
"L",
accessFlags = AccessFlags.PRIVATE.value,
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.RETURN_OBJECT
)
)

View File

@ -0,0 +1,66 @@
package app.revanced.patches.songpal.badge.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.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.songpal.badge.annotations.BadgeCompatibility
import app.revanced.patches.songpal.badge.fingerprints.CreateTabsFingerprint
@Patch
@Name("remove-badge-tab")
@Description("Removes the badge tab from the activity tab.")
@BadgeCompatibility
@Version("0.0.1")
class BadgeTabPatch : BytecodePatch(
listOf(CreateTabsFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
CreateTabsFingerprint.result?.mutableMethod?.apply {
removeInstructions(0, 2)
val arrayRegister = 0
val indexRegister = 1
val arrayItemRegister = 2
// First insert the array of tabs...
arrayTabs.withIndex().forEach { (index, tab) ->
addInstructions(
0,
"""
const/4 v$indexRegister, $index
sget-object v$arrayItemRegister, $ACTIVITY_TAB_DESCRIPTOR->$tab:$ACTIVITY_TAB_DESCRIPTOR
aput-object v$arrayItemRegister, v$arrayRegister, v$indexRegister
"""
)
}
// Then add the instructions to initialize the array.
// This is done so that the order of instructions is correct.
addInstructions(
0,
"""
const/4 v$arrayRegister, ${arrayTabs.size}
new-array v$arrayRegister, v$arrayRegister, [$ACTIVITY_TAB_DESCRIPTOR
"""
)
} ?: return CreateTabsFingerprint.toErrorResult()
return PatchResultSuccess()
}
companion object {
const val ACTIVITY_TAB_DESCRIPTOR = "Ljp/co/sony/vim/framework/ui/yourheadphones/YhContract\$Tab;"
val arrayTabs = listOf("Log", "HealthCare")
}
}