Mangas.in: Fix chapter decrypt (#2120)

Smh
This commit is contained in:
bapeey 2024-03-26 07:45:11 -05:00 committed by Draff
parent 3bb82737b7
commit 142b22b440
2 changed files with 16 additions and 13 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.MangasIn' extClass = '.MangasIn'
themePkg = 'mmrcms' themePkg = 'mmrcms'
baseUrl = 'https://mangas.in' baseUrl = 'https://mangas.in'
overrideVersionCode = 2 overrideVersionCode = 3
isNsfw = true isNsfw = true
} }

View File

@ -89,20 +89,27 @@ class MangasIn : MMRCMS(
private var key = "" private var key = ""
private fun getKey(): String { private fun getKey(): String {
val script = client.newCall(GET("$baseUrl/js/datachs.js")).execute().body.string() val script = client.newCall(GET("$baseUrl/js/ads2.js")).execute().body.string()
val deobfuscatedScript = Deobfuscator.deobfuscateScript(script) val deobfuscatedScript = Deobfuscator.deobfuscateScript(script)
?: throw Exception("No se pudo desofuscar el script") ?: throw Exception("No se pudo desofuscar el script")
return KEY_REGEX.find(deobfuscatedScript)?.groupValues?.get(1) val variable = KEY_REGEX.find(deobfuscatedScript)?.groupValues?.get(1)
?: throw Exception("No se pudo encontrar la clave")
if (variable.startsWith("'")) return variable.removeSurrounding("'")
if (variable.startsWith("\"")) return variable.removeSurrounding("\"")
val varRegex = """(?:let|var|const)\s+$variable\s*=\s*['|"](.*)['|"]""".toRegex()
return varRegex.find(deobfuscatedScript)?.groupValues?.get(1)
?: throw Exception("No se pudo encontrar la clave") ?: throw Exception("No se pudo encontrar la clave")
} }
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup() val document = response.asJsoup()
val mangaUrl = document.location().removeSuffix("/") val mangaUrl = document.location().removeSuffix("/")
val receivedData = RECEIVED_DATA_REGEX.find(document.html())?.groupValues?.get(1) ?: throw Exception("No se pudo encontrar la lista de capítulos") val encodeChapterData = CHAPTER_DATA_REGEX.find(document.html())?.value ?: throw Exception("No se pudo encontrar la lista de capítulos")
val unescapedReceivedData = receivedData.unescape() val unescapedChapterData = encodeChapterData.unescape()
val chapterData = json.decodeFromString<CDT>(unescapedReceivedData) val chapterData = json.decodeFromString<CDT>(unescapedChapterData)
val salt = chapterData.s.decodeHex() val salt = chapterData.s.decodeHex()
val unsaltedCipherText = Base64.decode(chapterData.ct, Base64.DEFAULT) val unsaltedCipherText = Base64.decode(chapterData.ct, Base64.DEFAULT)
@ -111,7 +118,7 @@ class MangasIn : MMRCMS(
val decrypted = CryptoAES.decrypt(Base64.encodeToString(cipherText, Base64.DEFAULT), key).ifEmpty { val decrypted = CryptoAES.decrypt(Base64.encodeToString(cipherText, Base64.DEFAULT), key).ifEmpty {
key = getKey() key = getKey()
CryptoAES.decrypt(Base64.encodeToString(cipherText, Base64.DEFAULT), key) CryptoAES.decrypt(Base64.encodeToString(cipherText, Base64.DEFAULT), key)
} }.ifEmpty { throw Exception("No se pudo desencriptar los capítulos") }
val unescaped = decrypted.unescapeJava().removeSurrounding("\"").unescape() val unescaped = decrypted.unescapeJava().removeSurrounding("\"").unescape()
@ -158,10 +165,6 @@ class MangasIn : MMRCMS(
return builder.toString() return builder.toString()
} }
private fun String.parseDate(): Long {
return dateFormat.parse(this)?.time ?: 0L
}
private fun String.decodeHex(): ByteArray { private fun String.decodeHex(): ByteArray {
check(length % 2 == 0) { "Must have an even length" } check(length % 2 == 0) { "Must have an even length" }
@ -172,6 +175,6 @@ class MangasIn : MMRCMS(
} }
private val UNESCAPE_REGEX = """\\(.)""".toRegex() private val UNESCAPE_REGEX = """\\(.)""".toRegex()
private val RECEIVED_DATA_REGEX = """receivedData\s*=\s*["'](.*)["']\s*;""".toRegex() private val CHAPTER_DATA_REGEX = """\{(?=.*\\"ct\\")(?=.*\\"iv\\")(?=.*\\"s\\").*?\}""".toRegex()
private val KEY_REGEX = """decrypt\(.*'(.*)'.*\)""".toRegex() private val KEY_REGEX = """decrypt\(.*?,\s*(.*?)\s*,.*\)""".toRegex()
private val SALTED = "Salted__".toByteArray(Charsets.UTF_8) private val SALTED = "Salted__".toByteArray(Charsets.UTF_8)