From d9d5e32740227fb98ca21be6a2f6a905d923f290 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sat, 26 Nov 2022 19:08:28 +0500 Subject: [PATCH] feat(crunchyroll): `enable-downloads` patch (#1119) Co-authored-by: oSumAtrIX --- .../annotations/DownloadsCompatibility.kt | 13 +++++++ .../fingerprints/DownloadsFingerprint.kt | 23 ++++++++++++ .../downloads/patch/DownloadsPatch.kt | 37 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/crunchyroll/downloads/annotations/DownloadsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/crunchyroll/downloads/fingerprints/DownloadsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/crunchyroll/downloads/patch/DownloadsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/annotations/DownloadsCompatibility.kt b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/annotations/DownloadsCompatibility.kt new file mode 100644 index 000000000..deb5d7859 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/annotations/DownloadsCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.crunchyroll.downloads.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [ + Package("com.crunchyroll.crunchyroid") + ] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class DownloadsCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/fingerprints/DownloadsFingerprint.kt b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/fingerprints/DownloadsFingerprint.kt new file mode 100644 index 000000000..12bfec818 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/fingerprints/DownloadsFingerprint.kt @@ -0,0 +1,23 @@ +package app.revanced.patches.crunchyroll.downloads.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.crunchyroll.downloads.annotations.DownloadsCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("downloads-fingerprint") +@DownloadsCompatibility +@Version("0.0.1") +object DownloadsFingerprint : MethodFingerprint( + "Z", AccessFlags.PUBLIC or AccessFlags.FINAL, null, + opcodes = listOf( + Opcode.CONST_STRING, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.RETURN + ), + strings = listOf("offline_viewing"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/patch/DownloadsPatch.kt b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/patch/DownloadsPatch.kt new file mode 100644 index 000000000..8b9f50859 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/crunchyroll/downloads/patch/DownloadsPatch.kt @@ -0,0 +1,37 @@ +package app.revanced.patches.crunchyroll.downloads.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.replaceInstruction +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.crunchyroll.downloads.annotations.DownloadsCompatibility +import app.revanced.patches.crunchyroll.downloads.fingerprints.DownloadsFingerprint + +@Patch +@Name("enable-downloads") +@Description("Enables downloads for Crunchyroll.") +@DownloadsCompatibility +@Version("0.0.1") +class DownloadsPatch : BytecodePatch( + listOf( + DownloadsFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + with(DownloadsFingerprint.result!!.mutableMethod) { + val index = implementation!!.instructions.lastIndex + replaceInstruction( + index - 1, + """ + const/4 v0, 0x1 + """ + ) + } + return PatchResultSuccess() + } +} \ No newline at end of file