Fix Mangago chapter image URLs parsing and image descrambling (#374)

Fix Mangago chapter image URLs parsing and image descrambling
This commit is contained in:
Eugene 2018-06-30 00:27:51 -04:00 committed by Carlos
parent 4f160a2dfe
commit 43b841363f
2 changed files with 42 additions and 13 deletions

View File

@ -5,8 +5,8 @@ ext {
appName = 'Tachiyomi: Mangago' appName = 'Tachiyomi: Mangago'
pkgNameSuffix = "en.mangago" pkgNameSuffix = "en.mangago"
extClass = '.Mangago' extClass = '.Mangago'
extVersionCode = 5 extVersionCode = 6
extVersionSuffix = 4 extVersionSuffix = 5
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -198,6 +198,9 @@ class Mangago : ParsedHttpSource() {
} ?: throw IllegalArgumentException("Cannot decode imgsrcs!") } ?: throw IllegalArgumentException("Cannot decode imgsrcs!")
val res = Duktape.create().use { val res = Duktape.create().use {
it.evaluate(getCryptoJSLib())
it.evaluate(getCryptoJSZeroPaddingLib())
it.evaluate(imgSrc + IMGSRCS_DECODE_JS) as String it.evaluate(imgSrc + IMGSRCS_DECODE_JS) as String
} }
@ -313,21 +316,33 @@ class Mangago : ParsedHttpSource() {
fun addToUri(uri: Uri.Builder) fun addToUri(uri: Uri.Builder)
} }
private var libCryptoJS: String? = null
private fun getCryptoJSLib(): String {
if (libCryptoJS == null) {
libCryptoJS = client.newCall(GET("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js", headers)).execute().body()!!.string()
}
return checkNotNull(libCryptoJS)
}
private var libCryptoJSZeroPadding: String? = null
private fun getCryptoJSZeroPaddingLib(): String {
if (libCryptoJSZeroPadding == null) {
libCryptoJSZeroPadding = client.newCall(GET("https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/pad-zeropadding-min.js", headers)).execute().body()!!.string()
}
return checkNotNull(libCryptoJSZeroPadding)
}
companion object { companion object {
// https://codepen.io/Th3-822/pen/BVVVGW/
private const val IMGSRCS_DECODE_JS = """ private const val IMGSRCS_DECODE_JS = """
function replacePos(a, b, c) function replacePos(a, b, c) {
{
return (a.substr(0, b) + c) + a.substring((b + 1), a.length); return (a.substr(0, b) + c) + a.substring((b + 1), a.length);
} }
function dorder(a, b) function dorder(a, b) {
{ for (j = (b.length - 1); j >= 0; j--) {
for (j = (b.length - 1); j >= 0; j--) for (i = (a.length - 1); (i - b[j]) >= 0; i--) {
{ if ((i % 2) != 0) {
for (i = (a.length - 1); (i - b[j]) >= 0; i--)
{
if ((i % 2) != 0)
{
temp = a[i - b[j]]; temp = a[i - b[j]];
a = replacePos(a, (i - b[j]), a[i]); a = replacePos(a, (i - b[j]), a[i]);
a = replacePos(a, i, temp); a = replacePos(a, i, temp);
@ -337,8 +352,19 @@ class Mangago : ParsedHttpSource() {
return a; return a;
} }
function decrypt(a, b, c) {
return CryptoJS.AES.decrypt(a, b, {'iv': c, 'padding': CryptoJS.pad.ZeroPadding}).toString(CryptoJS.enc.Utf8);
}
(function() { (function() {
return dorder(imgsrcs, "2617"); var aesKey = CryptoJS.enc.Hex.parse('e10adc3949ba59abbe56e057f20f883e');
var aesIV = CryptoJS.enc.Hex.parse('1234567890abcdef1234567890abcdef');
var decrypted = decrypt(imgsrcs, aesKey, aesIV);
var code = decrypted.charAt(19) + decrypted.charAt(23) + decrypted.charAt(31) + decrypted.charAt(39);
decrypted = decrypted.slice(0, 19) + decrypted.slice(20, 23) + decrypted.slice(24, 31) + decrypted.slice(32, 39) + decrypted.slice(40);
return dorder(decrypted, code);
})(); })();
""" """
@ -363,6 +389,9 @@ _deskeys["9ae6640761b947e61624671ef841ee78"] = "62a25a21a75a42a61a73a59a23a19a66
_deskeys.f4ab0903149b5d94baba796a5cf05938 = "40a37a55a73a18a42a15a59a50a13a22a63a52a58a6a80a47a17a38a71a74a70a30a11a10a19a0a31a36a21a51a68a1a3a14a66a45a2a79a7a76a75a8a67a20a78a25a69a43a28a35a60a4a23a65a54a34a9a5a39a27a57a26a33a12a24a46a72a56a44a49a61a64a29a53a48a32a62a41a16a77"; _deskeys.f4ab0903149b5d94baba796a5cf05938 = "40a37a55a73a18a42a15a59a50a13a22a63a52a58a6a80a47a17a38a71a74a70a30a11a10a19a0a31a36a21a51a68a1a3a14a66a45a2a79a7a76a75a8a67a20a78a25a69a43a28a35a60a4a23a65a54a34a9a5a39a27a57a26a33a12a24a46a72a56a44a49a61a64a29a53a48a32a62a41a16a77";
_deskeys.f5baf770212313f5e9532ec5e6103b61 = "55a69a78a75a38a25a20a60a6a80a46a5a48a18a23a24a17a67a64a70a63a57a22a10a49a19a8a16a11a12a61a76a34a27a54a73a44a0a56a3a15a29a28a13a4a2a7a77a74a35a37a26a30a58a9a71a50a1a43a79a47a32a14a53a52a66a72a59a68a31a42a45a62a51a40a39a33a65a41a36a21"; _deskeys.f5baf770212313f5e9532ec5e6103b61 = "55a69a78a75a38a25a20a60a6a80a46a5a48a18a23a24a17a67a64a70a63a57a22a10a49a19a8a16a11a12a61a76a34a27a54a73a44a0a56a3a15a29a28a13a4a2a7a77a74a35a37a26a30a58a9a71a50a1a43a79a47a32a14a53a52a66a72a59a68a31a42a45a62a51a40a39a33a65a41a36a21";
_deskeys.e2169a4bfd805e9aa21d3112d498d68c = "54a34a68a69a26a20a66a1a67a74a22a39a63a70a5a37a75a15a6a14a62a50a46a35a44a45a28a8a40a25a29a76a51a77a17a47a0a42a2a9a48a27a13a64a58a57a18a30a80a23a61a36a60a59a71a32a7a38a41a78a12a49a43a79a24a31a52a19a3a53a72a10a73a11a33a16a4a55a65a21a56"; _deskeys.e2169a4bfd805e9aa21d3112d498d68c = "54a34a68a69a26a20a66a1a67a74a22a39a63a70a5a37a75a15a6a14a62a50a46a35a44a45a28a8a40a25a29a76a51a77a17a47a0a42a2a9a48a27a13a64a58a57a18a30a80a23a61a36a60a59a71a32a7a38a41a78a12a49a43a79a24a31a52a19a3a53a72a10a73a11a33a16a4a55a65a21a56";
_deskeys['1796550d20f64decb317f9b770ba0e78'] = '37a55a39a79a2a53a75a1a30a32a3a13a25a49a45a5a60a62a71a78a63a24a27a33a19a64a67a57a0a8a54a9a41a61a50a73a7a65a58a51a15a14a43a4a35a77a68a72a34a80a22a17a48a10a70a46a40a28a20a74a52a23a38a76a42a18a66a11a59a6a69a31a56a16a47a21a12a44a36a29a26';
_deskeys['bf53be6753a0037c6d80ca670f5d12d5'] = '55a41a18a19a4a13a36a12a56a69a64a80a30a39a57a50a48a26a46a73a17a52a49a66a11a25a61a51a68a24a70a7a67a53a43a8a29a75a65a42a38a58a9a28a0a78a54a31a22a5a15a3a79a77a59a23a45a40a47a44a6a2a1a35a14a62a63a76a20a16a32a21a71a10a74a60a34a37a33a72a27';
_deskeys['6c41ff7fbed622aa76e19f3564e5d52a'] = '40a3a13a59a68a34a66a43a67a14a26a46a8a24a33a73a69a31a2a57a10a51a62a77a74a41a47a35a64a52a15a53a6a80a76a50a28a75a56a79a17a45a25a49a48a65a78a27a9a63a12a55a32a21a58a38a0a71a44a30a61a36a16a23a20a70a22a37a4a19a7a60a11a5a18a39a1a54a72a29a42';
var l = "18a72a69a64a13a1a43a3aa42a23a66a26a19a51a54a78a34a17a31a35a15a58a29a61a48a73a74a44a52a60a24a63a20a32a7a45a53a75a55a62a59a41a76a68a2a36a21a10a38a33a71a40a67a22a4a50a80a65a27a37a47a70a14a28a16a6a56a30a57a5a11a79a9a77a46a39a25a49a8a12"; var l = "18a72a69a64a13a1a43a3aa42a23a66a26a19a51a54a78a34a17a31a35a15a58a29a61a48a73a74a44a52a60a24a63a20a32a7a45a53a75a55a62a59a41a76a68a2a36a21a10a38a33a71a40a67a22a4a50a80a65a27a37a47a70a14a28a16a6a56a30a57a5a11a79a9a77a46a39a25a49a8a12";
for (mk in _deskeys) { for (mk in _deskeys) {
if (img.indexOf(mk) > 0) { if (img.indexOf(mk) > 0) {