fix(lib/lycoris&lulu): small change v2
This commit is contained in:
parent
de4383ff6f
commit
cfdcc6480a
1 changed files with 15 additions and 14 deletions
|
@ -104,26 +104,27 @@ class LuluExtractor(private val client: OkHttpClient) {
|
||||||
|
|
||||||
object JavaScriptUnpacker {
|
object JavaScriptUnpacker {
|
||||||
private val UNPACK_REGEX by lazy {
|
private val UNPACK_REGEX by lazy {
|
||||||
Regex("""\}\('(.*)', *(\d+), *(\d+), *'(.*?)'\.split\('\|'\)""")
|
Regex("""\}\('(.*)', *(\d+), *(\d+), *'(.*?)'\.split\('\|'\)""",
|
||||||
|
RegexOption.DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
fun unpack(encodedJs: String): String? {
|
fun unpack(encodedJs: String): String? {
|
||||||
val match = UNPACK_REGEX.find(encodedJs) ?: return null
|
val match = UNPACK_REGEX.find(encodedJs) ?: return null
|
||||||
val (payload, radixStr, countStr, symtabStr) = match.destructured
|
val (payload, radixStr, countStr, symtabStr) = match.destructured
|
||||||
|
|
||||||
val radix = radixStr.toIntOrNull() ?: return null
|
val radix = radixStr.toIntOrNull() ?: return null
|
||||||
val count = countStr.toIntOrNull() ?: return null
|
val count = countStr.toIntOrNull() ?: return null
|
||||||
val symtab = symtabStr.split('|')
|
val symtab = symtabStr.split('|')
|
||||||
|
|
||||||
if (symtab.size != count) throw IllegalArgumentException("Invalid symtab size")
|
if (symtab.size != count) throw IllegalArgumentException("Invalid symtab size")
|
||||||
|
|
||||||
val baseDict = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
val baseDict = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
.take(radix)
|
.take(radix)
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.associate { it.value to it.index }
|
.associate { it.value to it.index }
|
||||||
|
|
||||||
return Regex("""\b\w+\b""").replace(payload) { mr ->
|
return Regex("""\b\w+\b""").replace(payload) { mr ->
|
||||||
symtab.getOrNull(unbase(mr.value, radix, baseDict)) ?: mr.value
|
symtab.getOrNull(unbase(mr.value, radix, baseDict)) ?: mr.value
|
||||||
}.replace("\\", "")
|
}.replace("\\", "")
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun unbase(value: String, radix: Int, dict: Map<Char, Int>): Int {
|
private fun unbase(value: String, radix: Int, dict: Map<Char, Int>): Int {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue