mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-21 18:03:56 +00:00
refactor(reddit): HideAdsPatch
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
package app.revanced.patches.reddit.ad.general
|
||||
package app.revanced.patches.nunl.ads
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
|
||||
import app.revanced.patcher.definingClass
|
||||
import app.revanced.patcher.instructions
|
||||
import app.revanced.patcher.invoke
|
||||
import app.revanced.patcher.patch.BytecodePatchContext
|
||||
import app.revanced.patcher.returnType
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal val adPostFingerprint = fingerprint {
|
||||
returns("V")
|
||||
internal val BytecodePatchContext.adPostMethod by gettingFirstMutableMethodDeclaratively("children") {
|
||||
returnType("V")
|
||||
// "children" are present throughout multiple versions
|
||||
strings("children")
|
||||
custom { _, classDef -> classDef.endsWith("Listing;") }
|
||||
instructions("children"())
|
||||
definingClass { endsWith("Listing;") }
|
||||
}
|
||||
|
||||
internal val newAdPostFingerprint = fingerprint {
|
||||
opcodes(Opcode.INVOKE_VIRTUAL)
|
||||
strings("feedElement", "com.reddit.cookie")
|
||||
internal val BytecodePatchContext.newAdPostMethod by gettingFirstMutableMethodDeclaratively(
|
||||
"feedElement", "com.reddit.cookie"
|
||||
) {
|
||||
instructions(Opcode.INVOKE_VIRTUAL())
|
||||
instructions("feedElement"())
|
||||
instructions("com.reddit.cookie"())
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package app.revanced.patches.reddit.ad.general
|
||||
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.extensions.removeInstruction
|
||||
import app.revanced.patcher.patch.bytecodePatch
|
||||
import app.revanced.patches.reddit.ad.comments.hideCommentAdsPatch
|
||||
import app.revanced.patcher.patch.creatingBytecodePatch
|
||||
import app.revanced.patches.nunl.ads.adPostMethod
|
||||
import app.revanced.patches.nunl.ads.newAdPostMethod
|
||||
import app.revanced.patches.reddit.ad.comments.`Hide comment ads`
|
||||
import app.revanced.patches.reddit.misc.extension.sharedExtensionPatch
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
@@ -11,11 +13,11 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c
|
||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
@Suppress("unused")
|
||||
val hideAdsPatch = bytecodePatch(
|
||||
name = "Hide ads",
|
||||
@Suppress("unused", "ObjectPropertyName")
|
||||
val `Hide ads` by creatingBytecodePatch(
|
||||
description = "Hide ads"
|
||||
) {
|
||||
dependsOn(hideCommentAdsPatch, sharedExtensionPatch)
|
||||
dependsOn(`Hide comment ads`, sharedExtensionPatch)
|
||||
|
||||
compatibleWith("com.reddit.frontpage")
|
||||
|
||||
@@ -26,7 +28,7 @@ val hideAdsPatch = bytecodePatch(
|
||||
"Lapp/revanced/extension/reddit/patches/FilterPromotedLinksPatch;" +
|
||||
"->filterChildren(Ljava/lang/Iterable;)Ljava/util/List;"
|
||||
|
||||
adPostFingerprint.method.apply {
|
||||
adPostMethod.apply {
|
||||
val setPostsListChildren = implementation!!.instructions.first { instruction ->
|
||||
if (instruction.opcode != Opcode.IPUT_OBJECT) return@first false
|
||||
|
||||
@@ -58,7 +60,7 @@ val hideAdsPatch = bytecodePatch(
|
||||
// AdElementConverter is conveniently responsible for inserting all feed ads.
|
||||
// By removing the appending instruction no ad posts gets appended to the feed.
|
||||
|
||||
val index = newAdPostFingerprint.originalMethod.implementation!!.instructions.indexOfFirst {
|
||||
val index = newAdPostMethod.implementation!!.instructions.indexOfFirst {
|
||||
if (it.opcode != Opcode.INVOKE_VIRTUAL) return@indexOfFirst false
|
||||
|
||||
val reference = (it as ReferenceInstruction).reference as MethodReference
|
||||
@@ -66,7 +68,7 @@ val hideAdsPatch = bytecodePatch(
|
||||
reference.name == "add" && reference.definingClass == "Ljava/util/ArrayList;"
|
||||
}
|
||||
|
||||
newAdPostFingerprint.method.removeInstruction(index)
|
||||
newAdPostMethod.removeInstruction(index)
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
Reference in New Issue
Block a user