use jar instead of jadx

This commit is contained in:
C10udburst 2022-08-06 12:00:02 +02:00
parent 900dd79458
commit b33cad4ce8
6 changed files with 13 additions and 41 deletions

View file

@ -11,8 +11,8 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
var apkinfo: ApkInfo? = null
internal set
fun overrideUrl(url: String) {
apkinfo!!.url = url
fun overrideUrlPrefix(url: String) {
apkinfo!!.urlPrefix = url
}
internal var pluginClassName: String? = null
@ -21,8 +21,7 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
class ApkInfo(extension: CloudstreamExtension, release: String) {
val cache = extension.userCache.resolve("cloudstream")
var url = "https://github.com/recloudstream/cloudstream/releases/download/${release}/app-debug.apk"
val apkFile = cache.resolve("cloudstream.apk")
var urlPrefix = "https://github.com/recloudstream/cloudstream/releases/download/${release}"
val jarFile = cache.resolve("cloudstream.jar")
}

View file

@ -39,7 +39,7 @@ fun URL.download(file: File, progressLogger: ProgressLogger) {
while (inputStream.read(buf).also { read = it } >= 0) {
os.write(buf, 0, read)
processedBytes += read
progressLogger.progress("Downloading apk ${toLengthText(processedBytes)}/$sizeText")
progressLogger.progress("Downloading ${toLengthText(processedBytes)}/$sizeText")
}
os.flush()
finished = true

View file

@ -26,19 +26,11 @@ class ApkConfigurationProvider : IConfigurationProvider {
apkinfo.cache.mkdirs()
if (!apkinfo.apkFile.exists()) {
project.logger.lifecycle("Downloading apk")
val url = URL(apkinfo.url)
url.download(apkinfo.apkFile, createProgressLogger(project, "Download apk"))
}
if (!apkinfo.jarFile.exists()) {
project.logger.lifecycle("Converting apk to jar")
project.logger.lifecycle("Fetching JAR")
val reader: BaseDexFileReader = MultiDexFileReader.open(Files.readAllBytes(apkinfo.apkFile.toPath()))
Dex2jar.from(reader).topoLogicalSort().skipDebug(false).noCode(true).to(apkinfo.jarFile.toPath())
val url = URL("${apkinfo.urlPrefix}/classes.jar")
url.download(apkinfo.jarFile, createProgressLogger(project, "Download JAR"))
}
project.dependencies.add("compileOnly", project.files(apkinfo.jarFile))

View file

@ -14,9 +14,6 @@ abstract class CleanCacheTask : DefaultTask() {
val extension = project.extensions.getCloudstream()
val apkinfo = extension.apkinfo
if (apkinfo == null) return;
if (apkinfo.apkFile.exists()) {
apkinfo.apkFile.delete()
}
if (apkinfo.jarFile.exists()) {
apkinfo.jarFile.delete()

View file

@ -32,8 +32,7 @@ abstract class CompileDexTask : DefaultTask() {
@get:OutputFile
abstract val pluginClassFile: RegularFileProperty
@Suppress("UnstableApiUsage")
@TaskAction
fun compileDex() {
val android = project.extensions.getByName("android") as BaseExtension

View file

@ -9,6 +9,9 @@ import jadx.plugins.input.dex.DexInputPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.util.function.Function
import java.net.URL
import com.lagradost.cloudstream3.gradle.download
import com.lagradost.cloudstream3.gradle.createProgressLogger
abstract class GenSourcesTask : DefaultTask() {
@TaskAction
@ -18,26 +21,8 @@ abstract class GenSourcesTask : DefaultTask() {
val sourcesJarFile = apkinfo.cache.resolve("cloudstream-sources.jar")
val args = JadxArgs()
args.setInputFile(apkinfo.apkFile)
args.outDirSrc = sourcesJarFile
args.isSkipResources = true
args.isShowInconsistentCode = true
args.isRespectBytecodeAccModifiers = true
args.isFsCaseSensitive = true
args.isGenerateKotlinMetadata = false
args.isDebugInfo = false
args.isInlineAnonymousClasses = false
args.isInlineMethods = false
args.isReplaceConsts = false
val url = URL("${apkinfo.urlPrefix}/app-sources.jar")
args.codeCache = NoOpCodeCache()
args.codeWriterProvider = Function { SimpleCodeWriter(it) }
JadxDecompiler(args).use { decompiler ->
decompiler.registerPlugin(DexInputPlugin())
decompiler.load()
decompiler.save()
}
url.download(sourcesJarFile, createProgressLogger(project, "Download sources"))
}
}