From 6f3f00993d33be4efe6cac32182bde067979abf1 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 3 Jul 2023 19:15:49 +0900 Subject: [PATCH] fix(reddit/hide-comment-ads): patch is broken in certain versions --- .../fingerprints/HideCommentAdsFingerprint.kt | 16 +++++++++++++--- .../ad/comments/patch/HideCommentAdsPatch.kt | 13 ++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/fingerprints/HideCommentAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/fingerprints/HideCommentAdsFingerprint.kt index 5b282ea6d..b47279fa2 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/fingerprints/HideCommentAdsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/fingerprints/HideCommentAdsFingerprint.kt @@ -3,9 +3,19 @@ package app.revanced.patches.reddit.ad.comments.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode object HideCommentAdsFingerprint : MethodFingerprint( - returnType = "Ljava/lang/Object;", + returnType = "L", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("RedditCommentsPageAdRepository;") }, -) \ No newline at end of file + parameters = listOf("L"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.RETURN_OBJECT + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/PostDetailPresenter\$loadAd\$1;") + && methodDef.name == "invokeSuspend" + }, +) diff --git a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/patch/HideCommentAdsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/patch/HideCommentAdsPatch.kt index a3054e6e5..a6032b6f7 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/patch/HideCommentAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/patch/HideCommentAdsPatch.kt @@ -5,11 +5,13 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.RequiresIntegrations +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.reddit.ad.comments.fingerprints.HideCommentAdsFingerprint @Name("hide-comment-ads") @@ -21,10 +23,15 @@ class HideCommentAdsPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { HideCommentAdsFingerprint.result?.let { - it.mutableMethod.apply { + with( + context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.startIndex, true) + .getMethod() as MutableMethod + ) { + addInstructions( - 0, - """ + 0, """ new-instance v0, Ljava/lang/Object; invoke-direct {v0}, Ljava/lang/Object;->()V return-object v0