-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaadecode.js
37 lines (32 loc) · 1.26 KB
/
aadecode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* AADecode - Decode encoded-as-aaencode JavaScript program.
*
* Copyright (C) 2010,2016 @cat_in_136
*
* This software is released under the MIT License.
* http://opensource.org/licenses/mit-license.php
*/
const AADecode = {
decode: function(text) {
var evalPreamble = "(\uFF9F\u0414\uFF9F) ['_'] ( (\uFF9F\u0414\uFF9F) ['_'] (";
var decodePreamble = "( (\uFF9F\u0414\uFF9F) ['_'] (";
var evalPostamble = ") (\uFF9F\u0398\uFF9F)) ('_');";
var decodePostamble = ") ());";
// strip beginning/ending space.
text = text.replace(/^\s*/, "").replace(/\s*$/, "");
// returns empty text for empty input.
if (/^\s*$/.test(text)) {
return "";
}
// check if it is encoded.
if (text.lastIndexOf(evalPreamble) < 0) {
throw new Error("Given code is not encoded as aaencode.");
}
if (text.lastIndexOf(evalPostamble) != text.length - evalPostamble.length) {
throw new Error("Given code is not encoded as aaencode.");
}
var decodingScript = text.replace(evalPreamble, decodePreamble)
.replace(evalPostamble, decodePostamble);
return eval(decodingScript);
}
};
exports.decode = AADecode.decode;