From bb355e7b7e78e602a10b346fe7e5795463615a81 Mon Sep 17 00:00:00 2001 From: Chris <52449218+shadow578@users.noreply.github.com> Date: Mon, 4 Jul 2022 18:10:49 +0200 Subject: [PATCH] feat: `enable-debugging` patch (#116) --- .../EnableDebuggingCompatibility.kt | 25 +++++++++++++ .../patch/EnableDebuggingPatch.kt | 35 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt new file mode 100644 index 00000000..d0a388c6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/annotations/EnableDebuggingCompatibility.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtube.misc.enabledebugging.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", + arrayOf( + "17.14.35", + "17.17.34", + "17.19.36", + "17.20.37", + "17.22.36", + "17.23.35", + "17.23.36", + "17.24.34", + "17.24.35", + "17.25.34" + ) + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class EnableDebuggingCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt new file mode 100644 index 00000000..cb5ef283 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/enabledebugging/patch/EnableDebuggingPatch.kt @@ -0,0 +1,35 @@ +package app.revanced.patches.youtube.misc.enabledebugging.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.ResourceData +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.ResourcePatch +import app.revanced.patches.youtube.misc.enabledebugging.annotations.EnableDebuggingCompatibility +import org.w3c.dom.Element + +@Patch(false) +@Name("enable-debugging") +@Description("Enable app debugging by patching the manifest file") +@EnableDebuggingCompatibility +@Version("0.0.1") +class EnableDebuggingPatch : ResourcePatch() { + override fun execute(data: ResourceData): PatchResult { + // create an xml editor instance + data.xmlEditor["AndroidManifest.xml"].use { dom -> + // get the application node + val applicationNode = dom + .file + .getElementsByTagName("application") + .item(0) as Element + + // set application as debuggable + applicationNode.setAttribute("android:debuggable", "true") + } + + return PatchResultSuccess() + } +} \ No newline at end of file