Fire Scans: Fix empty JSON input (#19023)

* Decode chapterProtectorData

* Rebuild
This commit is contained in:
bapeey 2023-11-20 11:35:32 -05:00 committed by GitHub
parent e1f29d314a
commit 823b9cb733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View File

@ -1,8 +1,15 @@
package eu.kanade.tachiyomi.extension.en.firescans
import android.util.Base64
import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES
import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.model.Page
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.OkHttpClient
import org.jsoup.nodes.Document
class FireScans : Madara("Fire Scans", "https://firescans.xyz", "en") {
@ -11,4 +18,50 @@ class FireScans : Madara("Fire Scans", "https://firescans.xyz", "en") {
.build()
override val useNewChapterEndpoint: Boolean = true
override fun pageListParse(document: Document): List<Page> {
countViews(document)
val chapterProtector = document.selectFirst(chapterProtectorSelector)
?: return document.select(pageListParseSelector).mapIndexed { index, element ->
val imageUrl = element.selectFirst("img")?.let { imageFromElement(it) }
Page(index, document.location(), imageUrl)
}
val chapterProtectorHtml = if (chapterProtector.attr("src").startsWith("data:text/javascript;base64,")) {
Base64.decode(chapterProtector.attr("src").substringAfter(","), Base64.DEFAULT).decodeToString()
} else {
chapterProtector.html()
}
val password = chapterProtectorHtml
.substringAfter("wpmangaprotectornonce='")
.substringBefore("';")
val chapterData = json.parseToJsonElement(
chapterProtectorHtml
.substringAfter("chapter_data='")
.substringBefore("';")
.replace("\\/", "/"),
).jsonObject
val unsaltedCiphertext = Base64.decode(chapterData["ct"]!!.jsonPrimitive.content, Base64.DEFAULT)
val salt = chapterData["s"]!!.jsonPrimitive.content.decodeHex()
val ciphertext = SALTED + salt + unsaltedCiphertext
val rawImgArray = CryptoAES.decrypt(Base64.encodeToString(ciphertext, Base64.DEFAULT), password)
val imgArrayString = json.parseToJsonElement(rawImgArray).jsonPrimitive.content
val imgArray = json.parseToJsonElement(imgArrayString).jsonArray
return imgArray.mapIndexed { idx, it ->
Page(idx, document.location(), it.jsonPrimitive.content)
}
}
private fun String.decodeHex(): ByteArray {
check(length % 2 == 0) { "Must have an even length" }
return chunked(2)
.map { it.toInt(16).toByte() }
.toByteArray()
}
}

View File

@ -106,7 +106,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("FaeStorm", "https://faestormmanga.com", "tr"),
SingleLang("Fay Scans", "https://fayscans.com.br", "pt-BR", overrideVersionCode = 1),
SingleLang("Final Scans", "https://finalscans.com", "pt-BR", isNsfw = true, overrideVersionCode = 1),
SingleLang("Fire Scans", "https://firescans.xyz", "en"),
SingleLang("Fire Scans", "https://firescans.xyz", "en", overrideVersionCode = 1),
SingleLang("Fleur Blanche", "https://fbsquads.com", "pt-BR", isNsfw = true, overrideVersionCode = 2),
SingleLang("Flex Tape Scans", "https://flextapescans.com", "en", isNsfw = true),
SingleLang("Flower Manga", "https://flowermanga.com", "pt-BR"),