diff --git a/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/DebugMenuActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/AddPremiumNavbarTabParentFingerprint.kt similarity index 63% rename from src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/DebugMenuActivityFingerprint.kt rename to src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/AddPremiumNavbarTabParentFingerprint.kt index 8953ed687..cfff25e95 100644 --- a/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/DebugMenuActivityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/fingerprints/AddPremiumNavbarTabParentFingerprint.kt @@ -5,10 +5,9 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.spotify.premium_navbar_tab.annotations.PremiumNavbarTabCompatibility -@Name("debug-menu-activity-fingerprint") +@Name("add-premium-navbar-tab-parent-fingerprint") @Version("0.0.1") @PremiumNavbarTabCompatibility -object DebugMenuActivityFingerprint : MethodFingerprint( - strings = listOf("com.spotify.app.music.debugtools.menu.DebugMenuActivity"), - parameters = listOf("L", "L"), +object AddPremiumNavbarTabParentFingerprint : MethodFingerprint( + strings = listOf("com.samsung.android.samsungaccount.action.REQUEST_AUTHCODE") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/patch/PremiumNavbarTabPatch.kt b/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/patch/PremiumNavbarTabPatch.kt index d1ea08116..04e57a17a 100644 --- a/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/patch/PremiumNavbarTabPatch.kt +++ b/src/main/kotlin/app/revanced/patches/spotify/premium_navbar_tab/patch/PremiumNavbarTabPatch.kt @@ -13,40 +13,48 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patches.spotify.premium_navbar_tab.annotations.PremiumNavbarTabCompatibility import app.revanced.patches.spotify.premium_navbar_tab.fingerprints.AddPremiumNavbarTabFingerprint -import app.revanced.patches.spotify.premium_navbar_tab.fingerprints.DebugMenuActivityFingerprint +import app.revanced.patches.spotify.premium_navbar_tab.fingerprints.AddPremiumNavbarTabParentFingerprint import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Patch -@Name("hide-premium-nav-bar") +@Name("hide-premium-navbar") @Description("Removes the premium tab from the navbar.") @PremiumNavbarTabCompatibility @Version("0.0.1") @DependsOn([ResourceIdMappingProviderResourcePatch::class]) class PremiumNavbarTabPatch : BytecodePatch( listOf( - DebugMenuActivityFingerprint + AddPremiumNavbarTabParentFingerprint ) ) { override fun execute(data: BytecodeData): PatchResult { - val parentResult = DebugMenuActivityFingerprint.result!! + val parentResult = AddPremiumNavbarTabParentFingerprint.result!! AddPremiumNavbarTabFingerprint.resolve(data, parentResult.classDef) val result = AddPremiumNavbarTabFingerprint.result!! + val method = result.mutableMethod - - val premiumTabId = ResourceIdMappingProviderResourcePatch.resourceMappings.single{it.type == "id" && it.name == "premium_tab"}.id.toInt() - val methodInstructions = method.implementation!!.instructions + val lastInstructionIdx = methodInstructions.size - 1 + val premiumTabId = ResourceIdMappingProviderResourcePatch.resourceMappings.single{it.type == "id" && it.name == "premium_tab"}.id + + var removeAmount = 2 + // 2nd const remove method for ((i, instruction) in methodInstructions.asReversed().withIndex()) { if (instruction.opcode.ordinal != Opcode.CONST.ordinal) continue - if ((instruction as OneRegisterInstruction).registerA != premiumTabId) continue - val constIdx = methodInstructions.size - i - val methodIdx = constIdx + 8 - method.removeInstruction(methodIdx) - break + if ((instruction as WideLiteralInstruction).wideLiteral != premiumTabId) continue + + val findThreshold = 10 + val constIndex = lastInstructionIdx - i + val invokeInstruction = methodInstructions.subList(constIndex, constIndex + findThreshold).first { + it.opcode.ordinal == Opcode.INVOKE_VIRTUAL_RANGE.ordinal + } + method.removeInstruction(methodInstructions.indexOf(invokeInstruction)) + + if (--removeAmount == 0) break } return PatchResultSuccess()