diff --git a/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumFingerprint.kt index 231d258f5..e210ca65d 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumFingerprint.kt @@ -10,10 +10,13 @@ object HideGetPremiumFingerprint : MethodFingerprint( access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf(), opcodes = listOf( - Opcode.IF_NEZ, - Opcode.CONST_16, - Opcode.GOTO, - Opcode.NOP, - Opcode.INVOKE_VIRTUAL - ) + Opcode.IGET_BOOLEAN, + Opcode.CONST_4, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_STATIC + ), + listOf("FEmusic_history") ) diff --git a/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumParentFingerprint.kt deleted file mode 100644 index e9718037d..000000000 --- a/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumParentFingerprint.kt +++ /dev/null @@ -1,22 +0,0 @@ -package app.revanced.patches.music.layout.premium.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object HideGetPremiumParentFingerprint : MethodFingerprint( - returnType = "V", - access = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf(), - opcodes = listOf( - Opcode.IGET_BOOLEAN, - Opcode.CONST_4, - Opcode.IF_EQZ, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_STATIC - ), - listOf("FEmusic_history"), -) diff --git a/src/main/kotlin/app/revanced/patches/music/layout/premium/patch/HideGetPremiumPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/premium/patch/HideGetPremiumPatch.kt index 0f41c286f..e1eeb00e4 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/premium/patch/HideGetPremiumPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/patch/HideGetPremiumPatch.kt @@ -4,47 +4,85 @@ 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.addInstructions -import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumFingerprint -import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumParentFingerprint +import app.revanced.patches.music.misc.integrations.patch.MusicIntegrationsPatch import app.revanced.shared.annotation.YouTubeMusicCompatibility +import app.revanced.shared.extensions.findMutableMethodOf +import app.revanced.shared.extensions.toErrorResult +import app.revanced.shared.patches.mapping.ResourceMappingPatch +import app.revanced.shared.util.integrations.Constants.INTEGRATIONS_PATH +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.formats.Instruction22c +import org.jf.dexlib2.iface.instruction.formats.Instruction31i +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @Patch +@DependsOn([MusicIntegrationsPatch::class]) @Name("hide-get-premium") @Description("Removes all \"Get Premium\" evidences from the avatar menu.") @YouTubeMusicCompatibility @Version("0.0.1") class HideGetPremiumPatch : BytecodePatch( listOf( - HideGetPremiumParentFingerprint + HideGetPremiumFingerprint ) ) { + // list of resource names to get the id of + private val resourceIds = arrayOf( + "unlimited_panel" + ).map { name -> + ResourceMappingPatch.resourceMappings.single { it.name == name }.id + } + override fun execute(context: BytecodeContext): PatchResult { - val parentResult = HideGetPremiumParentFingerprint.result!! - HideGetPremiumFingerprint.resolve(context, parentResult.classDef) - val startIndex = parentResult.scanResult.patternScanResult!!.startIndex + HideGetPremiumFingerprint.result?.let { + with (it.mutableMethod) { + val insertIndex = it.scanResult.patternScanResult!!.startIndex + val register = (implementation!!.instructions[insertIndex] as TwoRegisterInstruction).registerA - val parentMethod = parentResult.mutableMethod - parentMethod.replaceInstruction( - startIndex, """ - const/4 v1, 0x0 - """ - ) + addInstruction( + insertIndex + 1, + "const/4 v$register, 0x0" + ) + } + } ?: return HideGetPremiumFingerprint.toErrorResult() - val result = HideGetPremiumFingerprint.result!! - val method = result.mutableMethod - method.addInstructions( - startIndex, """ - const/16 v0, 0x8 - """ - ) + context.classes.forEach { classDef -> + classDef.methods.forEach { method -> + with(method.implementation) { + this?.instructions?.forEachIndexed { index, instruction -> + when (instruction.opcode) { + Opcode.CONST -> { + when ((instruction as Instruction31i).wideLiteral) { + resourceIds[0] -> { + val insertIndex = index + 3 + val iPutInstruction = instructions.elementAt(insertIndex) + if (iPutInstruction.opcode != Opcode.IPUT_OBJECT) return@forEachIndexed + + val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method) + + val viewRegister = (iPutInstruction as Instruction22c).registerA + + mutableMethod.addInstruction( + insertIndex, + "invoke-static {v$viewRegister}, $INTEGRATIONS_PATH/adremover/AdRemoverAPI;->HideViewWithLayout1dp(Landroid/view/View;)V" + ) + } + } + } + else -> return@forEachIndexed + } + } + } + } + } return PatchResultSuccess() }