From 6eb7e2081b31bf6d2fed2594fa00f27e7b356eae Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sun, 6 Nov 2022 16:58:43 +0500 Subject: [PATCH] feat(hexeditor): `disable-ads` patch (#973) Co-authored-by: oSumAtrIX --- .../annotations/HexEditorAdsCompatibility.kt | 13 +++++++ .../ad/fingerprints/PrimaryAdsFingerprint.kt | 15 +++++++ .../hexeditor/ad/patch/HexEditorAdsPatch.kt | 39 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/hexeditor/ad/annotations/HexEditorAdsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/hexeditor/ad/fingerprints/PrimaryAdsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/hexeditor/ad/patch/HexEditorAdsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/hexeditor/ad/annotations/HexEditorAdsCompatibility.kt b/src/main/kotlin/app/revanced/patches/hexeditor/ad/annotations/HexEditorAdsCompatibility.kt new file mode 100644 index 000000000..e0ae0e0be --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/hexeditor/ad/annotations/HexEditorAdsCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.hexeditor.ad.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [ + Package("com.myprog.hexedit") + ] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class HexEditorAdsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/hexeditor/ad/fingerprints/PrimaryAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/hexeditor/ad/fingerprints/PrimaryAdsFingerprint.kt new file mode 100644 index 000000000..a01991a06 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/hexeditor/ad/fingerprints/PrimaryAdsFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.hexeditor.ad.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.hexeditor.ad.annotations.HexEditorAdsCompatibility + +@Name("ads-fingerprint-primary") +@HexEditorAdsCompatibility +@Version("0.0.1") +object PrimaryAdsFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("PreferencesHelper;") && methodDef.name == "isAdsDisabled" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/hexeditor/ad/patch/HexEditorAdsPatch.kt b/src/main/kotlin/app/revanced/patches/hexeditor/ad/patch/HexEditorAdsPatch.kt new file mode 100644 index 000000000..67bc0940d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/hexeditor/ad/patch/HexEditorAdsPatch.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.hexeditor.ad.patch + +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.removeInstruction +import app.revanced.patcher.extensions.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.hexeditor.ad.annotations.HexEditorAdsCompatibility +import app.revanced.patches.hexeditor.ad.fingerprints.PrimaryAdsFingerprint + +@Patch +@Name("disable-ads") +@Description("Disables ads in HexEditor.") +@HexEditorAdsCompatibility +@Version("0.0.1") +class HexEditorAdsPatch : BytecodePatch( + listOf( + PrimaryAdsFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + val method = PrimaryAdsFingerprint.result!!.mutableMethod + + method.replaceInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) + + return PatchResultSuccess() + } +}