diff --git a/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt b/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt index b0479749ce..b5b7459757 100644 --- a/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt @@ -1,28 +1,25 @@ package app.revanced.patches.pixiv.ads -import app.revanced.util.exception import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.pixiv.ads.fingerprints.IsNotPremiumFingerprint +import app.revanced.patches.pixiv.ads.fingerprints.ShouldShowAdsFingerprint +import app.revanced.util.exception @Patch( name = "Hide ads", - compatiblePackages = [CompatiblePackage("jp.pxv.android")] + compatiblePackages = [CompatiblePackage("jp.pxv.android")], ) @Suppress("unused") -object HideAdsPatch : BytecodePatch(setOf(IsNotPremiumFingerprint)) { - // Always return false in the "isNotPremium" method which normally returns !this.accountManager.isPremium. - // However, this is not the method that controls the user's premium status. - // Instead, this method is used to determine whether ads should be shown. +object HideAdsPatch : BytecodePatch(setOf(ShouldShowAdsFingerprint)) { override fun execute(context: BytecodeContext) = - IsNotPremiumFingerprint.result?.mutableClass?.virtualMethods?.first()?.addInstructions( + ShouldShowAdsFingerprint.result?.mutableMethod?.addInstructions( 0, """ const/4 v0, 0x0 return v0 - """ - ) ?: throw IsNotPremiumFingerprint.exception -} \ No newline at end of file + """, + ) ?: throw ShouldShowAdsFingerprint.exception +} diff --git a/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/IsNotPremiumFingerprint.kt b/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/IsNotPremiumFingerprint.kt deleted file mode 100644 index 6618af0ed7..0000000000 --- a/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/IsNotPremiumFingerprint.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.revanced.patches.pixiv.ads.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags - - -internal object IsNotPremiumFingerprint : MethodFingerprint( - "V", - AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - listOf("L"), - strings = listOf("pixivAccountManager"), - customFingerprint = custom@{ _, classDef -> - // The "isNotPremium" method is the only method in the class. - if (classDef.virtualMethods.count() != 1) return@custom false - - classDef.virtualMethods.first().let { isNotPremiumMethod -> - isNotPremiumMethod.parameterTypes.size == 0 && isNotPremiumMethod.returnType == "Z" - } - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/ShouldShowAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/ShouldShowAdsFingerprint.kt new file mode 100644 index 0000000000..cd8d303bc2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/pixiv/ads/fingerprints/ShouldShowAdsFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.pixiv.ads.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + + +internal object ShouldShowAdsFingerprint : MethodFingerprint( + "Z", + AccessFlags.PUBLIC or AccessFlags.FINAL, + customFingerprint = { methodDef, classDef -> + classDef.type.endsWith("AdUtils;") && methodDef.name == "shouldShowAds" + } +) \ No newline at end of file