From c514860bc4a46295b11f09df9ffc1c556b798eb3 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Sun, 13 Nov 2022 02:26:14 +0100 Subject: [PATCH] feat(twitch): `debug-mode` patch (#1031) Co-authored-by: oSumAtrIX --- .../annotations/DebugModeCompatibility.kt | 10 ++++ .../IsDebugConfigEnabledFingerprint.kt | 16 ++++++ .../IsOmVerificationEnabledFingerprint.kt | 16 ++++++ .../ShouldShowDebugOptionsFingerprint.kt | 16 ++++++ .../twitch/debug/patch/DebugModePatch.kt | 49 +++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/twitch/debug/annotations/DebugModeCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsDebugConfigEnabledFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsOmVerificationEnabledFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/ShouldShowDebugOptionsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/debug/patch/DebugModePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/twitch/debug/annotations/DebugModeCompatibility.kt b/src/main/kotlin/app/revanced/patches/twitch/debug/annotations/DebugModeCompatibility.kt new file mode 100644 index 000000000..394b9e904 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/debug/annotations/DebugModeCompatibility.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.twitch.debug.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("tv.twitch.android.app")]) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class DebugModeCompatibility + diff --git a/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsDebugConfigEnabledFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsDebugConfigEnabledFingerprint.kt new file mode 100644 index 000000000..b0072e890 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsDebugConfigEnabledFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.twitch.debug.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.twitch.debug.annotations.DebugModeCompatibility + +@Name("is-debug-config-enabled-fingerprint") +@DebugModeCompatibility +@Version("0.0.1") +object IsDebugConfigEnabledFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "isDebugConfigEnabled" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsOmVerificationEnabledFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsOmVerificationEnabledFingerprint.kt new file mode 100644 index 000000000..b8e108534 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/IsOmVerificationEnabledFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.twitch.debug.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.twitch.debug.annotations.DebugModeCompatibility + +@Name("is-om-verification-enabled-fingerprint") +@DebugModeCompatibility +@Version("0.0.1") +object IsOmVerificationEnabledFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "isOmVerificationEnabled" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/ShouldShowDebugOptionsFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/ShouldShowDebugOptionsFingerprint.kt new file mode 100644 index 000000000..6006fcba5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/debug/fingerprints/ShouldShowDebugOptionsFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.twitch.debug.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.twitch.debug.annotations.DebugModeCompatibility + +@Name("should-show-debug-options-fingerprint") +@DebugModeCompatibility +@Version("0.0.1") +object ShouldShowDebugOptionsFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "shouldShowDebugOptions" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/twitch/debug/patch/DebugModePatch.kt b/src/main/kotlin/app/revanced/patches/twitch/debug/patch/DebugModePatch.kt new file mode 100644 index 000000000..2829b97fd --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/debug/patch/DebugModePatch.kt @@ -0,0 +1,49 @@ +package app.revanced.patches.twitch.debug.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.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.Patch +import app.revanced.patches.twitch.debug.annotations.DebugModeCompatibility +import app.revanced.patches.twitch.debug.fingerprints.IsDebugConfigEnabledFingerprint +import app.revanced.patches.twitch.debug.fingerprints.IsOmVerificationEnabledFingerprint +import app.revanced.patches.twitch.debug.fingerprints.ShouldShowDebugOptionsFingerprint + +@Patch(false) +@Name("debug-mode") +@Description("Enables Twitch's internal debugging mode.") +@DebugModeCompatibility +@Version("0.0.1") +class DebugModePatch : BytecodePatch( + listOf( + IsDebugConfigEnabledFingerprint, + IsOmVerificationEnabledFingerprint, + ShouldShowDebugOptionsFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + listOf( + IsDebugConfigEnabledFingerprint, + IsOmVerificationEnabledFingerprint, + ShouldShowDebugOptionsFingerprint + ).forEach { + with(it.result!!) { + with(mutableMethod) { + addInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) + } + } + } + return PatchResultSuccess() + } +}