diff --git a/src/main/kotlin/app/revanced/patches/music/layout/premium/annotations/HideGetPremiumCompatibility.kt b/src/main/kotlin/app/revanced/patches/music/layout/premium/annotations/HideGetPremiumCompatibility.kt new file mode 100644 index 00000000..26b3d2fa --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/annotations/HideGetPremiumCompatibility.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.music.layout.premium.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.apps.youtube.music", arrayOf("5.14.53") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class HideGetPremiumCompatibility + 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 new file mode 100644 index 00000000..981c168c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.music.layout.premium.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patches.music.layout.premium.annotations.HideGetPremiumCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("hide-get-premium-fingerprint") +@MatchingMethod( + "Lktn;", "k" +) +@HideGetPremiumCompatibility +@Version("0.0.1") +object HideGetPremiumFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), listOf( + Opcode.IF_NEZ, + Opcode.CONST_16, + Opcode.GOTO, + Opcode.NOP, + Opcode.INVOKE_VIRTUAL + ) +) 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 new file mode 100644 index 00000000..8c77119f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/fingerprints/HideGetPremiumParentFingerprint.kt @@ -0,0 +1,29 @@ +package app.revanced.patches.music.layout.premium.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patches.music.layout.premium.annotations.HideGetPremiumCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("hide-get-premium-parent-fingerprint") +@MatchingMethod( + "Lktn;", "k" +) +@HideGetPremiumCompatibility +@Version("0.0.1") +object HideGetPremiumParentFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), 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 new file mode 100644 index 00000000..b8121bcc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/premium/patch/HideGetPremiumPatch.kt @@ -0,0 +1,49 @@ +package app.revanced.patches.music.layout.premium.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.replaceInstruction +import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patches.music.layout.premium.annotations.HideGetPremiumCompatibility +import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumFingerprint +import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumParentFingerprint + +@Patch +@Name("hide-get-premium") +@Description("Removes all \"Get Premium\" evidences from the avatar menu.") +@HideGetPremiumCompatibility +@Version("0.0.1") +class HideGetPremiumPatch : BytecodePatch( + listOf( + HideGetPremiumParentFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + val parentResult = HideGetPremiumParentFingerprint.result!! + HideGetPremiumFingerprint.resolve(data, parentResult.classDef) + + val parentMethod = parentResult.mutableMethod + parentMethod.replaceInstruction( + parentResult.patternScanResult!!.startIndex, """ + const/4 v1, 0x0 + """ + ) + + val result = HideGetPremiumFingerprint.result!! + val method = result.mutableMethod + method.addInstructions( + result.patternScanResult!!.startIndex, """ + const/16 v0, 0x8 + """ + ) + + return PatchResultSuccess() + } +}