forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(syncforreddit): add
disable-ads
patch (ReVanced#2066)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...main/kotlin/app/revanced/patches/syncforreddit/ads/annotations/DisableAdsCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.patches.syncforreddit.ads.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility([Package("com.laurencedawson.reddit_sync")]) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class DisableAdsCompatibility |
11 changes: 11 additions & 0 deletions
11
...ain/kotlin/app/revanced/patches/syncforreddit/ads/fingerprints/IsAdsEnabledFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.revanced.patches.syncforreddit.ads.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.AccessFlags | ||
|
||
object IsAdsEnabledFingerprint : MethodFingerprint( | ||
returnType = "Z", | ||
access = AccessFlags.PUBLIC or AccessFlags.STATIC, | ||
strings = listOf("SyncIapHelper") | ||
) |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/app/revanced/patches/syncforreddit/ads/patch/DisableAdsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package app.revanced.patches.syncforreddit.ads.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
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.extensions.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.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.syncforreddit.ads.annotations.DisableAdsCompatibility | ||
import app.revanced.patches.syncforreddit.ads.fingerprints.IsAdsEnabledFingerprint | ||
import app.revanced.patches.syncforreddit.detection.piracy.patch.DisablePiracyDetectionPatch | ||
|
||
@Patch | ||
@Name("disable-ads") | ||
@DependsOn([DisablePiracyDetectionPatch::class]) | ||
@Description("Disables ads.") | ||
@Version("0.0.1") | ||
@DisableAdsCompatibility | ||
class DisableAdsPatch : BytecodePatch(listOf(IsAdsEnabledFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
IsAdsEnabledFingerprint.result?.mutableMethod?.apply { | ||
addInstructions( | ||
0, | ||
""" | ||
const/4 v0, 0x0 | ||
return v0 | ||
""" | ||
) | ||
} ?: return IsAdsEnabledFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...evanced/patches/syncforreddit/detection/piracy/fingerprints/PiracyDetectionFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package app.revanced.patches.syncforreddit.detection.piracy.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 | ||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction | ||
import org.jf.dexlib2.iface.reference.TypeReference | ||
|
||
object PiracyDetectionFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
access = AccessFlags.PRIVATE or AccessFlags.FINAL, | ||
opcodes = listOf( | ||
Opcode.NEW_INSTANCE, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.NEW_INSTANCE, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.INVOKE_VIRTUAL | ||
), | ||
customFingerprint = { method -> | ||
method.implementation?.instructions?.any { | ||
if (it.opcode != Opcode.NEW_INSTANCE) return@any false | ||
|
||
val reference = (it as ReferenceInstruction).reference | ||
|
||
reference.toString() == "Lcom/github/javiersantos/piracychecker/PiracyChecker;" | ||
} ?: false | ||
} | ||
) |
28 changes: 28 additions & 0 deletions
28
.../app/revanced/patches/syncforreddit/detection/piracy/patch/DisablePiracyDetectionPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package app.revanced.patches.syncforreddit.detection.piracy.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patches.syncforreddit.detection.piracy.fingerprints.PiracyDetectionFingerprint | ||
|
||
@Description("Disables detection of modified versions.") | ||
@Version("0.0.1") | ||
class DisablePiracyDetectionPatch : BytecodePatch(listOf(PiracyDetectionFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
PiracyDetectionFingerprint.result?.mutableMethod?.apply { | ||
addInstructions( | ||
0, | ||
""" | ||
return-void | ||
""" | ||
) | ||
} ?: return PiracyDetectionFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |