From bf45817677fd058f9b255dbef5c1ca9aaec95531 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:53:10 +0400 Subject: [PATCH 01/23] fix(twitter/hide-views-stats): constrain to last working version (#1522) --- .../layout/hideviews/annotations/HideViewsCompatibility.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/twitter/layout/hideviews/annotations/HideViewsCompatibility.kt b/src/main/kotlin/app/revanced/patches/twitter/layout/hideviews/annotations/HideViewsCompatibility.kt index 44c21454..0a88046b 100644 --- a/src/main/kotlin/app/revanced/patches/twitter/layout/hideviews/annotations/HideViewsCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/twitter/layout/hideviews/annotations/HideViewsCompatibility.kt @@ -3,7 +3,11 @@ package app.revanced.patches.twitter.layout.hideviews.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package -@Compatibility([Package("com.twitter.android")]) +@Compatibility( + [Package( + "com.twitter.android", arrayOf("9.69.1-release.0") + )] +) @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) internal annotation class HideViewsCompatibility \ No newline at end of file From 39521386c2296f46479e31c39ab245c2778ebd65 Mon Sep 17 00:00:00 2001 From: 1fexd Date: Sat, 21 Jan 2023 05:51:04 +0100 Subject: [PATCH 02/23] feat(finanzonline): `remove-bootloader-detection` patch Signed-off-by: oSumAtrIX --- .../fingerprints/BootStateFingerprint.kt | 13 +++++++ .../BootloaderDetectionFingerprint.kt | 13 +++++++ .../patch/BootloaderDetectionPatch.kt | 38 +++++++++++++++++++ .../fingerprints/RootDetectionFingerprint.kt | 10 +++++ .../root/patch/RootDetectionPatch.kt | 34 +++++++++++++++++ .../annotations/DetectionCompatibility.kt | 9 +++++ 6 files changed, 117 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootStateFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootloaderDetectionFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/root/fingerprints/RootDetectionFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/root/patch/RootDetectionPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/finanzonline/detection/shared/annotations/DetectionCompatibility.kt diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootStateFingerprint.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootStateFingerprint.kt new file mode 100644 index 00000000..766147ac --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootStateFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.finanzonline.detection.bootloader.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags + +object BootStateFingerprint : MethodFingerprint( + "Z", + access = AccessFlags.PUBLIC.value, + strings = listOf("Boot state of device: %s"), + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("/AttestationHelper;") + } +) diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootloaderDetectionFingerprint.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootloaderDetectionFingerprint.kt new file mode 100644 index 00000000..2d24a6cc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/fingerprints/BootloaderDetectionFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.finanzonline.detection.bootloader.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags + +object BootloaderDetectionFingerprint : MethodFingerprint( + "Z", + access = AccessFlags.PUBLIC.value, + strings = listOf("Creation of attestation key succeeded", "Creation of attestation key failed"), + customFingerprint = { methodDef -> + methodDef.definingClass.endsWith("/AttestationHelper;") + } +) diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt new file mode 100644 index 00000000..f608d752 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.finanzonline.detection.bootloader.patch + +import app.revanced.extensions.toErrorResult +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.addInstruction +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.finanzonline.detection.bootloader.fingerprints.BootStateFingerprint +import app.revanced.patches.finanzonline.detection.bootloader.fingerprints.BootloaderDetectionFingerprint +import app.revanced.patches.finanzonline.detection.shared.annotations.DetectionCompatibility + + +@Patch +@Name("remove-bootloader-detection") +@Description("Removes the check for an unlocked bootloader.") +@DetectionCompatibility +@Version("0.0.1") +class BootloaderDetectionPatch : BytecodePatch( + listOf(BootloaderDetectionFingerprint, BootStateFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + arrayOf(BootloaderDetectionFingerprint, BootStateFingerprint).forEach { fingerprint -> + fingerprint.result?.mutableMethod?.addInstruction( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) ?: return fingerprint.toErrorResult() + } + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/fingerprints/RootDetectionFingerprint.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/fingerprints/RootDetectionFingerprint.kt new file mode 100644 index 00000000..b2e793da --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/fingerprints/RootDetectionFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.finanzonline.detection.root.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object RootDetectionFingerprint : MethodFingerprint( + "L", + customFingerprint = { methodDef -> + methodDef.definingClass == "Lat/gv/bmf/bmf2go/tools/utils/z;" + } +) diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/patch/RootDetectionPatch.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/patch/RootDetectionPatch.kt new file mode 100644 index 00000000..216ba2cd --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/patch/RootDetectionPatch.kt @@ -0,0 +1,34 @@ +package app.revanced.patches.finanzonline.detection.root.patch + +import app.revanced.extensions.toErrorResult +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.finanzonline.detection.root.fingerprints.RootDetectionFingerprint +import app.revanced.patches.finanzonline.detection.shared.annotations.DetectionCompatibility + +@Patch +@Name("remove-root-detection") +@Description("Removes the check for root permissions") +@DetectionCompatibility +@Version("0.0.1") +class RootDetectionPatch : BytecodePatch( + listOf(RootDetectionFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + RootDetectionFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + sget-object v0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean; + return-object v0 + """ + ) ?: return RootDetectionFingerprint.toErrorResult() + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/shared/annotations/DetectionCompatibility.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/shared/annotations/DetectionCompatibility.kt new file mode 100644 index 00000000..6bbc5897 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/shared/annotations/DetectionCompatibility.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.finanzonline.detection.shared.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("at.gv.bmf.bmf2go", arrayOf("2.2.0"))]) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class DetectionCompatibility From 1d46d63fdcf3cbce53a7719f4490225368c4d5ae Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 21 Jan 2023 05:52:01 +0100 Subject: [PATCH 03/23] feat(finanzonline): `remove-root-detection` patch Signed-off-by: oSumAtrIX --- .../detection/bootloader/patch/BootloaderDetectionPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt index f608d752..0c763d62 100644 --- a/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/patch/BootloaderDetectionPatch.kt @@ -30,7 +30,7 @@ class BootloaderDetectionPatch : BytecodePatch( """ const/4 v0, 0x1 return v0 - """ + """ ) ?: return fingerprint.toErrorResult() } return PatchResultSuccess() From caf3d70c30bc440923c0e76e7331010905f6e729 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:43:55 +0500 Subject: [PATCH 04/23] feat(youtube): `open-links-externally` patch (#1524) Signed-off-by: oSumAtrIX Co-authored-by: oSumAtrIX --- .../OpenLinksExternallyCompatibility.kt | 13 ++++ .../BindSessionServiceFingerprint.kt | 17 +++++ .../GetCustomTabPackageNameFingerprint.kt | 18 +++++ .../InitializeCustomTabSupportFingerprint.kt | 18 +++++ .../open/patch/OpenLinksExternallyPatch.kt | 65 +++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/links/open/annotations/OpenLinksExternallyCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/BindSessionServiceFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/GetCustomTabPackageNameFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/InitializeCustomTabSupportFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/links/open/patch/OpenLinksExternallyPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/annotations/OpenLinksExternallyCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/annotations/OpenLinksExternallyCompatibility.kt new file mode 100644 index 00000000..6818f9e8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/annotations/OpenLinksExternallyCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.misc.links.open.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.49.37") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class OpenLinksExternallyCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/BindSessionServiceFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/BindSessionServiceFingerprint.kt new file mode 100644 index 00000000..f7b41a24 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/BindSessionServiceFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.misc.links.open.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object BindSessionServiceFingerprint : MethodFingerprint( + returnType = "L", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + opcodes = listOf( + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.CONST_STRING + ), + strings = listOf("android.support.customtabs.action.CustomTabsService") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/GetCustomTabPackageNameFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/GetCustomTabPackageNameFingerprint.kt new file mode 100644 index 00000000..ffacf035 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/GetCustomTabPackageNameFingerprint.kt @@ -0,0 +1,18 @@ +package app.revanced.patches.youtube.misc.links.open.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object GetCustomTabPackageNameFingerprint : MethodFingerprint( + returnType = "L", + access = AccessFlags.PUBLIC or AccessFlags.STATIC, + opcodes = listOf( + Opcode.CHECK_CAST, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.CONST_STRING + ), + strings = listOf("android.support.customtabs.action.CustomTabsService") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/InitializeCustomTabSupportFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/InitializeCustomTabSupportFingerprint.kt new file mode 100644 index 00000000..0901efbb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/fingerprints/InitializeCustomTabSupportFingerprint.kt @@ -0,0 +1,18 @@ +package app.revanced.patches.youtube.misc.links.open.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object InitializeCustomTabSupportFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + opcodes = listOf( + Opcode.CHECK_CAST, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.CONST_STRING + ), + strings = listOf("android.support.customtabs.action.CustomTabsService") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/patch/OpenLinksExternallyPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/patch/OpenLinksExternallyPatch.kt new file mode 100644 index 00000000..ec2e2b5f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/open/patch/OpenLinksExternallyPatch.kt @@ -0,0 +1,65 @@ +package app.revanced.patches.youtube.misc.links.open.patch + +import app.revanced.extensions.toErrorResult +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.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.misc.links.open.annotations.OpenLinksExternallyCompatibility +import app.revanced.patches.youtube.misc.links.open.fingerprints.BindSessionServiceFingerprint +import app.revanced.patches.youtube.misc.links.open.fingerprints.GetCustomTabPackageNameFingerprint +import app.revanced.patches.youtube.misc.links.open.fingerprints.InitializeCustomTabSupportFingerprint +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import org.jf.dexlib2.iface.instruction.formats.Instruction21c + +@Patch +@Name("open-links-externally") +@Description("Open links outside of the app directly in your browser.") +@OpenLinksExternallyCompatibility +@Version("0.0.1") +class OpenLinksExternallyPatch : BytecodePatch( + listOf( + GetCustomTabPackageNameFingerprint, + BindSessionServiceFingerprint, + InitializeCustomTabSupportFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + SettingsPatch.PreferenceScreen.MISC.addPreferences( + SwitchPreference( + "revanced_enable_external_browser", + StringResource("revanced_enable_external_browser_title", "Open links in browser"), + true, + StringResource("revanced_enable_external_browser_summary_on", "Opening links externally"), + StringResource("revanced_enable_external_browser_summary_off", "Opening links in app") + ) + ) + + arrayOf( + GetCustomTabPackageNameFingerprint, + BindSessionServiceFingerprint, + InitializeCustomTabSupportFingerprint + ).forEach { + val result = it.result ?: return it.toErrorResult() + val insertIndex = result.scanResult.patternScanResult!!.endIndex + 1 + with(result.mutableMethod) { + val register = (implementation!!.instructions[insertIndex - 1] as Instruction21c).registerA + addInstructions( + insertIndex, """ + invoke-static {v$register}, Lapp/revanced/integrations/patches/OpenLinksExternallyPatch;->enableExternalBrowser(Ljava/lang/String;)Ljava/lang/String; + move-result-object v$register + """ + ) + } + } + + return PatchResultSuccess() + } +} \ No newline at end of file From 81934efb39b8ed9b0a523ffd7c4d841227ac141f Mon Sep 17 00:00:00 2001 From: reis Date: Sun, 22 Jan 2023 19:28:46 +0300 Subject: [PATCH 05/23] feat(youtube/microg-support): check if Vanced MicroG is running in the background (#1531) Co-authored-by: oSumAtrIX --- src/main/resources/microg/host/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/microg/host/values/strings.xml b/src/main/resources/microg/host/values/strings.xml index c5c1f69b..6d4c0743 100644 --- a/src/main/resources/microg/host/values/strings.xml +++ b/src/main/resources/microg/host/values/strings.xml @@ -1,4 +1,5 @@ Vanced MicroG is not installed. Please install it. + Vanced MicroG is failing to run. Please follow the "Don't kill my app" guide for Vanced MicroG. From 66cd88f4d8a9161a4c51b70f2384dcee92fe2aea Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 22 Jan 2023 15:38:12 +0100 Subject: [PATCH 06/23] fix: parse any kind of patch version Signed-off-by: oSumAtrIX --- build.gradle.kts | 2 +- .../kotlin/app/revanced/meta/JsonGenerator.kt | 70 +++++++++++++++++++ src/main/kotlin/app/revanced/meta/Meta.kt | 27 ------- .../app/revanced/meta/PatchesFileGenerator.kt | 25 +++++++ .../app/revanced/meta/ReadmeGenerator.kt | 69 ++++++++++++++++++ .../app/revanced/meta/json/Generator.kt | 48 ------------- .../app/revanced/meta/json/JsonPatch.kt | 26 ------- .../app/revanced/meta/readme/Extensions.kt | 10 --- .../app/revanced/meta/readme/Generator.kt | 42 ----------- .../revanced/meta/readme/SemanticVersion.kt | 22 ------ .../app/revanced/meta/readme/Template.kt | 12 ---- 11 files changed, 165 insertions(+), 188 deletions(-) create mode 100644 src/main/kotlin/app/revanced/meta/JsonGenerator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/Meta.kt create mode 100644 src/main/kotlin/app/revanced/meta/PatchesFileGenerator.kt create mode 100644 src/main/kotlin/app/revanced/meta/ReadmeGenerator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/json/Generator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/json/JsonPatch.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Extensions.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Generator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/SemanticVersion.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Template.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8978489a..ae1de6cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ tasks { dependsOn(build) classpath = sourceSets["main"].runtimeClasspath - mainClass.set("app.revanced.meta.Meta") + mainClass.set("app.revanced.meta.PatchesFileGenerator") } // Dummy task to fix the Gradle semantic-release plugin. // Remove this if you forked it to support building only. diff --git a/src/main/kotlin/app/revanced/meta/JsonGenerator.kt b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt new file mode 100644 index 00000000..49c7a2c9 --- /dev/null +++ b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt @@ -0,0 +1,70 @@ +package app.revanced.meta + +import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages +import app.revanced.patcher.extensions.PatchExtensions.dependencies +import app.revanced.patcher.extensions.PatchExtensions.description +import app.revanced.patcher.extensions.PatchExtensions.include +import app.revanced.patcher.extensions.PatchExtensions.options +import app.revanced.patcher.extensions.PatchExtensions.patchName +import app.revanced.patcher.extensions.PatchExtensions.version +import app.revanced.patcher.patch.PatchOption +import com.google.gson.GsonBuilder +import java.io.File + +internal class JsonGenerator : PatchesFileGenerator { + override fun generate(bundle: PatchBundlePatches) { + val patches = bundle.map { + JsonPatch( + it.patchName, + it.description ?: "This patch has no description.", + it.version ?: "0.0.0", + !it.include, + it.options?.map { option -> + Option( + option.key, + option.title, + option.description, + option.required, + option.let { lo -> + if (lo is PatchOption.ListOption<*>) { + lo.options.toMutableList().toTypedArray() + } else null + } + ) + }?.toTypedArray() ?: emptyArray(), + it.dependencies?.map { dep -> + dep.java.patchName + }?.toTypedArray() ?: emptyArray(), + it.compatiblePackages?.map { pkg -> + CompatiblePackage(pkg.name, pkg.versions) + }?.toTypedArray() ?: emptyArray() + ) + } + + val json = File("patches.json") + json.writeText(GsonBuilder().serializeNulls().create().toJson(patches)) + } + + data class JsonPatch( + val name: String, + val description: String, + val version: String, + val excluded: Boolean, + val options: Array