From 823b9cb73350e3310d3ba0b1a19f8ebad453ee67 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:35:32 -0500 Subject: [PATCH] Fire Scans: Fix empty JSON input (#19023) * Decode chapterProtectorData * Rebuild --- .../madara/firescans/src/FireScans.kt | 53 +++++++++++++++++++ .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/multisrc/overrides/madara/firescans/src/FireScans.kt b/multisrc/overrides/madara/firescans/src/FireScans.kt index cd1046577..a91394af4 100644 --- a/multisrc/overrides/madara/firescans/src/FireScans.kt +++ b/multisrc/overrides/madara/firescans/src/FireScans.kt @@ -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 { + 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() + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index 42b8c99e4..6714c263a 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -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"),