From 204053aa15e36692ac6123b171a2a6cc25ef7d32 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Fri, 18 Mar 2022 19:40:00 -0400 Subject: [PATCH 1/4] WIP proguard --- build.gradle.kts | 12 ++++ server/build.gradle.kts | 22 ++++++ server/proguard-rules.pro | 138 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 server/proguard-rules.pro diff --git a/build.gradle.kts b/build.gradle.kts index 6b583e2b2..2b49b02aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,18 @@ plugins { kotlin("plugin.serialization") version kotlinVersion id("org.jmailen.kotlinter") version "3.8.0" id("com.github.gmazzo.buildconfig") version "3.0.3" apply false + id("com.github.ben-manes.versions") version "0.39.0" +} + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("com.guardsquare:proguard-gradle:7.2.1") { + exclude("com.android.tools.build") + } + } } allprojects { diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 8efc89de9..9c7a786eb 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -1,4 +1,5 @@ import de.undercouch.gradle.tasks.download.Download +import proguard.gradle.ProGuardTask import java.time.Instant plugins { @@ -175,4 +176,25 @@ tasks { ) } } + + register("optimizeShadowJar") { + group = "shadow" + val shadowJar = getByName("shadowJar") + dependsOn(shadowJar) + val shadowJars = shadowJar.outputs.files.onEach { println(it.absolutePath) } + injars(shadowJars) + outjars( + shadowJars.map { file -> + File(file.parentFile, "min/" + file.name) + } + ) + val javaHome = System.getProperty("java.home") + if (JavaVersion.current().isJava9Compatible) { + libraryjars("$javaHome/jmods") + } else { + libraryjars("$javaHome/lib/rt.jar") + //libraryjars("$javaHome/lib/jce.jar") + } + configuration("proguard-rules.pro") + } } diff --git a/server/proguard-rules.pro b/server/proguard-rules.pro new file mode 100644 index 000000000..4c9cd8c3b --- /dev/null +++ b/server/proguard-rules.pro @@ -0,0 +1,138 @@ +-dontobfuscate +-keepattributes Signature,LineNumberTable + +-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; } +-keep,allowoptimization class suwayomi.tachidesk.** { public protected *; } +-keep class suwayomi.tachidesk.manga.model.dataclass.* { *; } +-keep class suwayomi.tachidesk.MainKt { + public static void main(java.lang.String[]); +} +-keepdirectories suwayomi/tachidesk/** +-keepdirectories META-INF/** + + +# java.lang.ClassCastException: class javax.servlet.SessionTrackingMode not an enum +-keepclassmembers class * extends java.lang.Enum { + ; + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Jackston +#-keep class kotlin.Metadata { *; } +#-keep class kotlin.reflect.** { *; } + + +# Kotlin Serialization +-keepattributes *Annotation*, InnerClasses +-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations + +# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer +-keepclassmembers class kotlinx.serialization.json.** { + *** Companion; +} +-keepclasseswithmembers class kotlinx.serialization.json.** { + kotlinx.serialization.KSerializer serializer(...); +} + +-keep,includedescriptorclasses class eu.kanade.tachiyomi.**$$serializer { *; } +-keepclassmembers class eu.kanade.tachiyomi.** { + *** Companion; +} +-keepclasseswithmembers class eu.kanade.tachiyomi.** { + kotlinx.serialization.KSerializer serializer(...); +} + +-keep,includedescriptorclasses class suwayomi.tachidesk.**$$serializer { *; } +-keepclassmembers class suwayomi.tachidesk.** { + *** Companion; +} +-keepclasseswithmembers class suwayomi.tachidesk.** { + kotlinx.serialization.KSerializer serializer(...); +} + +# Keep extension's common dependencies +-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; } +-keep,allowoptimization class androidx.preference.** { *; } +-keep,allowoptimization class kotlin.** { public protected *; } +-keep,allowoptimization class kotlinx.coroutines.** { public protected *; } +-keep,allowoptimization class okhttp3.** { public protected *; } +-keep,allowoptimization class okio.** { public protected *; } +-keep,allowoptimization class rx.** { public protected *; } +-keep,allowoptimization class org.jsoup.** { public protected *; } +-keep,allowoptimization class com.google.gson.** { public protected *; } +-keep,allowoptimization class com.github.salomonbrys.kotson.** { public protected *; } +-keep,allowoptimization class com.squareup.duktape.** { public protected *; } +-keep,allowoptimization class app.cash.quickjs.** { public protected *; } +-keep,allowoptimization class uy.kohesive.injekt.** { public protected *; } +-keep,allowoptimization class kotlinx.serialization.** { public protected *; } + +# Coroutines +-dontwarn kotlinx.coroutines.** + +# OKHTTP +-dontwarn org.codehaus.mojo.animal_sniffer.* +-dontwarn okhttp3.internal.platform.** + +# Exposted +-keep class org.jetbrains.exposed.** { *; } +-keep class de.neonew.exposed.migrations.** { *; } + +# H2 +-keep class org.h2.Driver { *; } + +# Javalin +-keep class org.eclipse.jetty.** { *; } +-dontwarn io.javalin.http.LeveledBrotliStream +-dontwarn io.javalin.plugin.metrics.** +-dontwarn io.javalin.plugin.rendering.** +-dontwarn com.nixxcode.jvmbrotli.common.BrotliLoader +-dontwarn com.nixxcode.jvmbrotli.enc.BrotliOutputStream + +# Xml +-keep class org.apache.xerces.** { *; } +-dontwarn javax.xml.** +-dontwarn com.sun.xml.** +-dontwarn com.sun.org.apache.** +-dontwarn jdk.xml.internal.ErrorHandlerProxy +-dontwarn com.sun.beans.decoder.DocumentHandler +-dontwarn org.apache.xerces.** + +# org.json +-dontwarn org.json.XMLTokener +-dontwarn org.json.JSONWriter + +# Android +-dontwarn com.android.** +-dontwarn android.** +-dontwarn androidx.annotation.* + +# Logback +-keep class ch.qos.logback.** { *; } +-dontwarn ch.qos.logback.** +-dontwarn org.apache.commons.logging.** +-dontwarn org.slf4j.MDC +-dontwarn org.slf4j.MarkerFactory + +# Dorkbox +-keep class dorkbox.systemTray.ui.** { + public (...); +} +-keep class dorkbox.jna.** { *; } +-dontwarn dorkbox.** + +# Java +-dontwarn javax.imageio.** +-dontwarn javax.swing.** +-dontwarn java.util.prefs.** + +# Joda time +-dontwarn org.joda.convert.* + +# Other +-keep class com.sun.jna.** { *; } +-dontwarn com.sun.rowset.** +-dontwarn com.reprezen.jsonoverlay.gen.** +-dontwarn org.h2.** +-dontwarn org.eclipse.jetty.** +-dontwarn org.antlr.runtime.tree.DOTTreeGenerator From e0aed030f60c65fb3089e2b492b86a58102722cb Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Thu, 31 Mar 2022 13:11:01 -0400 Subject: [PATCH 2/4] Remove gradle versions --- build.gradle.kts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2b49b02aa..f686c6d18 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,6 @@ plugins { kotlin("plugin.serialization") version kotlinVersion id("org.jmailen.kotlinter") version "3.8.0" id("com.github.gmazzo.buildconfig") version "3.0.3" apply false - id("com.github.ben-manes.versions") version "0.39.0" } buildscript { @@ -124,4 +123,4 @@ configure(projects) { // dependency both in AndroidCompat and server, version locked by javalin implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4") } -} \ No newline at end of file +} From 0ec6ad5a66ce5c33abcd4c3343587a9c61b68362 Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Thu, 31 Mar 2022 13:11:41 -0400 Subject: [PATCH 3/4] Update build.gradle.kts From 77a2134fb720254e3b3f7e711a8b7e42cb3e9f2d Mon Sep 17 00:00:00 2001 From: Mitchell Syer Date: Thu, 31 Mar 2022 13:11:58 -0400 Subject: [PATCH 4/4] Update build.gradle.kts --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index f686c6d18..b297bc9de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -124,3 +124,4 @@ configure(projects) { implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4") } } +