From 73132e37cf83f4c1f05cf6a184dfd8e454f7456e Mon Sep 17 00:00:00 2001 From: Linus <23507341+Linus789@users.noreply.github.com> Date: Fri, 3 Feb 2023 03:48:28 +0000 Subject: [PATCH] feat(netguard): `remove-broadcasts-restriction` patch (#1581) Co-authored-by: Linus789 Co-authored-by: oSumAtrIX --- ...emoveBroadcastsRestrictionCompatibility.kt | 9 +++++ .../patch/RemoveBroadcastsRestrictionPatch.kt | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/annotations/RemoveBroadcastsRestrictionCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/patch/RemoveBroadcastsRestrictionPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/annotations/RemoveBroadcastsRestrictionCompatibility.kt b/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/annotations/RemoveBroadcastsRestrictionCompatibility.kt new file mode 100644 index 000000000..0a8a7e56a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/annotations/RemoveBroadcastsRestrictionCompatibility.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.netguard.broadcasts.removerestriction.resource.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("eu.faircode.netguard")]) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class RemoveBroadcastsRestrictionCompatibility diff --git a/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/patch/RemoveBroadcastsRestrictionPatch.kt b/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/patch/RemoveBroadcastsRestrictionPatch.kt new file mode 100644 index 000000000..728e44813 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/resource/patch/RemoveBroadcastsRestrictionPatch.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.netguard.broadcasts.removerestriction.resource.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.netguard.broadcasts.removerestriction.resource.annotations.RemoveBroadcastsRestrictionCompatibility +import org.w3c.dom.Element + +@Patch(false) +@Name("remove-broadcasts-restriction") +@Description("Enables starting/stopping NetGuard via broadcasts.") +@RemoveBroadcastsRestrictionCompatibility +@Version("0.0.1") +class RemoveBroadcastsRestrictionPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + context.xmlEditor["AndroidManifest.xml"].use { dom -> + val applicationNode = dom + .file + .getElementsByTagName("application") + .item(0) as Element + + applicationNode.getElementsByTagName("receiver").also { list -> + for (i in 0 until list.length) { + val element = list.item(i) as? Element ?: continue + if (element.getAttribute("android:name") == "eu.faircode.netguard.WidgetAdmin") { + element.removeAttribute("android:permission") + break + } + } + } + } + + return PatchResultSuccess() + } +}