mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2024-12-25 16:21:50 +01:00
parent
3883b1d254
commit
2c7a6cb2b7
@ -1,5 +0,0 @@
|
||||
package eu.kanade.tachiyomi.annotations
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
annotation class Nsfw
|
@ -7,11 +7,11 @@ package suwayomi.tachidesk
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import mu.KotlinLogging
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension.installAPK
|
||||
import java.io.File
|
||||
|
||||
@ -47,16 +47,14 @@ object InspectorMain {
|
||||
val name: String,
|
||||
val lang: String,
|
||||
val id: String,
|
||||
val baseUrl: String,
|
||||
val nsfw: Boolean
|
||||
val baseUrl: String
|
||||
) {
|
||||
constructor(loadedSource: Extension.LoadedSource) :
|
||||
constructor(source: HttpSource) :
|
||||
this(
|
||||
loadedSource.source.name,
|
||||
loadedSource.source.lang,
|
||||
loadedSource.source.id.toString(),
|
||||
loadedSource.source.baseUrl,
|
||||
loadedSource.isNsfw
|
||||
source.name,
|
||||
source.lang,
|
||||
source.id.toString(),
|
||||
source.baseUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,11 @@ package suwayomi.tachidesk.manga.impl.extension
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.annotations.Nsfw
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceFactory
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
@ -24,22 +23,7 @@ import java.io.File
|
||||
object Extension {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
fun isNsfw(sourceInstance: Any): Boolean {
|
||||
// Annotations are proxied, hence this janky way of checking for them
|
||||
return sourceInstance.javaClass.annotations
|
||||
.flatMap { it.javaClass.interfaces.map { it.simpleName } }
|
||||
.firstOrNull { it == Nsfw::class.java.simpleName } != null
|
||||
}
|
||||
|
||||
data class LoadedSource(
|
||||
val source: HttpSource,
|
||||
val isNsfw: Boolean
|
||||
) {
|
||||
constructor(source: HttpSource) :
|
||||
this(source, isNsfw(source))
|
||||
}
|
||||
|
||||
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<LoadedSource>> {
|
||||
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<HttpSource>> {
|
||||
val apkFile = fetcher()
|
||||
|
||||
val jarFile = File(tmpDir, "${apkFile.nameWithoutExtension}.jar")
|
||||
@ -77,18 +61,7 @@ object Extension {
|
||||
// collect sources from the extension
|
||||
return packageInfo.packageName to when (val instance = loadExtensionSources(jarFile.absolutePath, className)) {
|
||||
is Source -> listOf(instance).filterIsInstance<HttpSource>()
|
||||
.map { LoadedSource(it) }
|
||||
is SourceFactory -> {
|
||||
val isNsfw = isNsfw(instance)
|
||||
instance.createSources().filterIsInstance<HttpSource>()
|
||||
.map {
|
||||
if (isNsfw) {
|
||||
LoadedSource(it, true)
|
||||
} else {
|
||||
LoadedSource(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
is SourceFactory -> instance.createSources().filterIsInstance<HttpSource>()
|
||||
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import android.os.Bundle
|
||||
import com.googlecode.d2j.dex.Dex2jar
|
||||
import com.googlecode.d2j.reader.MultiDexFileReader
|
||||
import com.googlecode.dex2jar.tools.BaksmaliBaseDexExceptionHandler
|
||||
import eu.kanade.tachiyomi.util.lang.Hash
|
||||
import mu.KotlinLogging
|
||||
import net.dongliu.apk.parser.ApkFile
|
||||
import net.dongliu.apk.parser.ApkParsers
|
||||
@ -33,15 +32,9 @@ object PackageTools {
|
||||
|
||||
const val EXTENSION_FEATURE = "tachiyomi.extension"
|
||||
const val METADATA_SOURCE_CLASS = "tachiyomi.extension.class"
|
||||
const val METADATA_SOURCE_FACTORY = "tachiyomi.extension.factory"
|
||||
const val METADATA_NSFW = "tachiyomi.extension.nsfw"
|
||||
const val LIB_VERSION_MIN = 1.2
|
||||
const val LIB_VERSION_MAX = 1.2
|
||||
|
||||
private const val officialSignature = "7ce04da7773d41b489f4693a366c36bcd0a11fc39b547168553c285bd7348e23" // inorichi's key
|
||||
private const val unofficialSignature = "64feb21075ba97ebc9cc981243645b331595c111cef1b0d084236a0403b00581" // ArMor's key
|
||||
var trustedSignatures = mutableSetOf<String>() + officialSignature + unofficialSignature
|
||||
|
||||
/**
|
||||
* Convert dex to jar, a wrapper for the dex2jar library
|
||||
*/
|
||||
@ -120,15 +113,6 @@ object PackageTools {
|
||||
}
|
||||
}
|
||||
|
||||
fun getSignatureHash(pkgInfo: PackageInfo): String? {
|
||||
val signatures = pkgInfo.signatures
|
||||
return if (signatures != null && signatures.isNotEmpty()) {
|
||||
Hash.sha256(signatures.first().toByteArray())
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the extension main class called $className from the jar located at $jarPath
|
||||
* It may return an instance of HttpSource or SourceFactory depending on the extension.
|
||||
|
Loading…
Reference in New Issue
Block a user