mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-24 19:02:11 +02:00
feat(reddit/hide-ads): implementing with settings
This commit is contained in:
parent
8c90204f08
commit
263a3c5c8c
@ -3,11 +3,13 @@ package app.revanced.patches.reddit.ad.comments.patch
|
|||||||
import app.revanced.extensions.toErrorResult
|
import app.revanced.extensions.toErrorResult
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.data.toMethodWalker
|
import app.revanced.patcher.data.toMethodWalker
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
import app.revanced.patches.reddit.ad.comments.fingerprints.HideCommentAdsFingerprint
|
import app.revanced.patches.reddit.ad.comments.fingerprints.HideCommentAdsFingerprint
|
||||||
|
|
||||||
class HideCommentAdsPatch : BytecodePatch(
|
class HideCommentAdsPatch : BytecodePatch(
|
||||||
@ -21,17 +23,25 @@ class HideCommentAdsPatch : BytecodePatch(
|
|||||||
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
|
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
|
||||||
.getMethod() as MutableMethod
|
.getMethod() as MutableMethod
|
||||||
) {
|
) {
|
||||||
|
addInstructionsWithLabels(
|
||||||
addInstructions(
|
|
||||||
0, """
|
0, """
|
||||||
|
invoke-static {}, $INTEGRATION_METHOD_DESCRIPTOR
|
||||||
|
move-result v0
|
||||||
|
if-eqz v0, :show
|
||||||
new-instance v0, Ljava/lang/Object;
|
new-instance v0, Ljava/lang/Object;
|
||||||
invoke-direct {v0}, Ljava/lang/Object;-><init>()V
|
invoke-direct {v0}, Ljava/lang/Object;-><init>()V
|
||||||
return-object v0
|
return-object v0
|
||||||
"""
|
""", ExternalLabel("show", getInstruction(0))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} ?: return HideCommentAdsFingerprint.toErrorResult()
|
} ?: return HideCommentAdsFingerprint.toErrorResult()
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
private const val INTEGRATION_METHOD_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/reddit/patches/GeneralAdsPatch;" +
|
||||||
|
"->hideCommentAds()Z"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import app.revanced.patcher.annotation.Name
|
|||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
import app.revanced.patcher.patch.PatchResultError
|
||||||
@ -15,11 +15,14 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
|||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
||||||
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
import app.revanced.patches.reddit.ad.banner.patch.HideBannerPatch
|
import app.revanced.patches.reddit.ad.banner.patch.HideBannerPatch
|
||||||
import app.revanced.patches.reddit.ad.comments.patch.HideCommentAdsPatch
|
import app.revanced.patches.reddit.ad.comments.patch.HideCommentAdsPatch
|
||||||
import app.revanced.patches.reddit.ad.general.fingerprints.AdPostFingerprint
|
import app.revanced.patches.reddit.ad.general.fingerprints.AdPostFingerprint
|
||||||
import app.revanced.patches.reddit.ad.general.fingerprints.NewAdPostFingerprint
|
import app.revanced.patches.reddit.ad.general.fingerprints.NewAdPostFingerprint
|
||||||
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
||||||
|
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c
|
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.FieldReference
|
||||||
@ -54,14 +57,12 @@ class HideAdsPatch : BytecodePatch(
|
|||||||
if (targetReferenceName != "children")
|
if (targetReferenceName != "children")
|
||||||
throw PatchResultError("Method signature reference name did not match: $targetReferenceName")
|
throw PatchResultError("Method signature reference name did not match: $targetReferenceName")
|
||||||
|
|
||||||
val castedInstruction = getInstruction<Instruction22c>(targetIndex)
|
val targetRegister = getInstruction<Instruction22c>(targetIndex).registerA
|
||||||
|
|
||||||
removeInstruction(targetIndex)
|
|
||||||
addInstructions(
|
addInstructions(
|
||||||
targetIndex, """
|
targetIndex, """
|
||||||
invoke-static {v${castedInstruction.registerA}}, $FILTER_METHOD_DESCRIPTOR
|
invoke-static {v$targetRegister}, $INTEGRATIONS_OLD_METHOD_DESCRIPTOR
|
||||||
move-result-object v0
|
move-result-object v$targetRegister
|
||||||
iput-object v0, v${castedInstruction.registerB}, ${castedInstruction.reference}
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -79,16 +80,31 @@ class HideAdsPatch : BytecodePatch(
|
|||||||
if (!targetParameter.endsWith("Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z"))
|
if (!targetParameter.endsWith("Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z"))
|
||||||
throw PatchResultError("Method signature parameter did not match: $targetParameter")
|
throw PatchResultError("Method signature parameter did not match: $targetParameter")
|
||||||
|
|
||||||
removeInstruction(targetIndex)
|
val targetRegister =
|
||||||
|
getInstruction<FiveRegisterInstruction>(targetIndex).registerD + 1
|
||||||
|
|
||||||
|
addInstructionsWithLabels(
|
||||||
|
targetIndex, """
|
||||||
|
invoke-static {}, $INTEGRATIONS_NEW_METHOD_DESCRIPTOR
|
||||||
|
move-result v$targetRegister
|
||||||
|
if-nez v$targetRegister, :show
|
||||||
|
""", ExternalLabel("show", getInstruction(targetIndex + 1))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} ?: return NewAdPostFingerprint.toErrorResult()
|
} ?: return NewAdPostFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
updateSettingsStatus("GeneralAds")
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
private const val FILTER_METHOD_DESCRIPTOR =
|
private const val INTEGRATIONS_OLD_METHOD_DESCRIPTOR =
|
||||||
"Lapp/revanced/reddit/patches/FilterPromotedLinksPatch;" +
|
"Lapp/revanced/reddit/patches/GeneralAdsPatch;" +
|
||||||
"->filterChildren(Ljava/lang/Iterable;)Ljava/util/List;"
|
"->hideOldPostAds(Ljava/util/List;)Ljava/util/List;"
|
||||||
|
|
||||||
|
private const val INTEGRATIONS_NEW_METHOD_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/reddit/patches/GeneralAdsPatch;" +
|
||||||
|
"->hideNewPostAds()Z"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user