Skip to content

Commit

Permalink
Unscramble obfuscated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dteviot committed Jul 24, 2021
1 parent a41ebeb commit 893e3bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
30 changes: 13 additions & 17 deletions plugin/js/parsers/MangaHereParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class MangaHereParser extends Parser {

static decryptChapterFun(js, prefix) {
let d = MangaHereParser.extractDataFromjs(js);
let clearText = MangaHereParser.decrypt(d[0], d[1], d[2], d[3].split("|"), 0, {});
let clearText = MangaHereParser.decrypt(d[0], d[1], d[2], d[3].split("|"));
return MangaHereParser.extractFilenameFromClearText(clearText, prefix);
}

Expand All @@ -152,23 +152,19 @@ class MangaHereParser extends Parser {
return urls.map(u => "http:" + prefix + u.replace(/"/g, ""));
}

// extracted from MangaHere
static decrypt(p, a, c, k, e, d) {
e = function (c) {
return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
// extracted from MangaHere (and deobfuscated)
static decrypt(p, max, len, fragments) {
let makeKey = function (index) {
return (index < max ? "" : makeKey(parseInt(index / max))) + ((index = index % max) > 35 ? String.fromCharCode(index + 29) : index.toString(36))
};
if (!"".replace(/^/, String)) {
while (c--)
d[e(c)] = k[c] || e(c);
k = [function (e) {
return d[e]
}];
e = function () { return "\\w+" };
c = 1;
};
while (c--)
if (k[c])
p = p.replace(new RegExp("\\b" + e(c) + "\\b", "g"), k[c]);
let replacements = {};
while (len--)
{
let key = makeKey(len);
replacements[key] = fragments[len] || key;
}
let replacerFunction = (key) => replacements[key];
p = p.replace(new RegExp("\\b\\w+\\b", "g"), replacerFunction);
return p;
}
}
Expand Down
4 changes: 1 addition & 3 deletions unitTest/UtestMangaHereParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ test("decrypt", function (assert) {
"l b(){3 4=\"//a.e.9/5/c/6/7.1/8\";3 2=[\"/k.j?o=n&m=h\"];f(3 i=0;i<2.g;i++){p(i==0){2[i]=\"//a.e.9/5/c/6/7.1/8\"+2[i];t}2[i]=4+2[i]}r 2}3 d;d=b();q=s;",
30,
30,
"||pvalue|var|pix|store|11110|061|compressed|cc||dm5imagefun|manga||mangahere|for|length|1548025200||jpg|k20190103_161010_2748|function|ttl|c9cbbe3a58535b9040d5d23708a3d5d7d6d2a89a|token|if|currentimageid|return|14300825|continue".split("|"),
0,
{}
"||pvalue|var|pix|store|11110|061|compressed|cc||dm5imagefun|manga||mangahere|for|length|1548025200||jpg|k20190103_161010_2748|function|ttl|c9cbbe3a58535b9040d5d23708a3d5d7d6d2a89a|token|if|currentimageid|return|14300825|continue".split("|")
);
let filtered = MangaHereParser.extractFilenameFromClearText(actual);
assert.equal(filtered, "http://a.mangahere.cc/store/manga/11110/061.1/compressed/k20190103_161010_2748.jpg?token=c9cbbe3a58535b9040d5d23708a3d5d7d6d2a89a&ttl=1548025200");
Expand Down

0 comments on commit 893e3bb

Please sign in to comment.