From be59293def314adcf24810c2ad42cf5218f71e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 25 Nov 2020 11:26:26 +0100 Subject: [PATCH] [hentainexus] update data decoding procedure (#1125) --- gallery_dl/extractor/hentainexus.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/hentainexus.py b/gallery_dl/extractor/hentainexus.py index e08bb72880b..a6db0d50e71 100644 --- a/gallery_dl/extractor/hentainexus.py +++ b/gallery_dl/extractor/hentainexus.py @@ -73,11 +73,25 @@ def images(self, _): @staticmethod def _decode(data): + # https://hentainexus.com/static/js/reader.min.js?r=6 blob = binascii.a2b_base64(data) - return "".join( - chr(blob[i] ^ blob[i-64]) - for i in range(64, len(blob)) - ) + key = blob[0:64] + indices = list(range(256)) + result = "" + + x = 0 + for i in range(256): + x = (x + indices[i] + key[i % len(key)]) % 256 + indices[i], indices[x] = indices[x], indices[i] + + x = i = 0 + for n in range(64, len(blob)): + i = (i + 1) % 256 + x = (x + indices[i]) % 256 + indices[i], indices[x] = indices[x], indices[i] + result += chr(blob[n] ^ indices[(indices[i] + indices[x]) % 256]) + + return result @staticmethod def _join_title(data):