fix(Pixiv - Hide ads): Fix for latest version (#3616)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
Itroublve 2024-09-06 09:13:57 +02:00 committed by GitHub
parent 3a537c70db
commit 98956e8f1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 32 deletions

View file

@ -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
}
""",
) ?: throw ShouldShowAdsFingerprint.exception
}

View file

@ -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"
}
}
)

View file

@ -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"
}
)