├── package.json ├── test ├── source.js ├── preprocess.js ├── output.js └── main.js ├── tools ├── env.js └── dump.js ├── README.md ├── pass ├── SHA1.js ├── SHA256.js ├── MD5.js ├── SM3.js ├── HMAC-SHA256.js └── SM4.js ├── index.html └── LICENSE /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "faceless_jsvmp", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "@babel/generator": "^7.22.10", 6 | "@babel/parser": "^7.22.10", 7 | "@babel/template": "^7.22.5", 8 | "@babel/traverse": "^7.22.10", 9 | "@babel/types": "^7.22.10", 10 | "figlet": "^1.6.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/source.js: -------------------------------------------------------------------------------- 1 | // 测试代码 2 | var {a, b} = {a: 0, b: 1}; 3 | console.log(a, b); 4 | [c, d] = [2, 3]; 5 | console.log(c, d); 6 | let arr = {a: 0, b: 1, c: 2} 7 | let pro = {d: 3, e: 4} 8 | arr.__proto__ = pro; 9 | for (const element in arr) { 10 | console.log(element) 11 | } 12 | const set = new Set([1, 2, 3]); 13 | for (let element of set) { 14 | console.log(element); 15 | } 16 | const str = 'Hello'; 17 | for (let char of str) { 18 | console.log(char); 19 | } 20 | 21 | (0, 0, function (x) { 22 | console.log(x) 23 | })(123) -------------------------------------------------------------------------------- /tools/env.js: -------------------------------------------------------------------------------- 1 | const parser = require("@babel/parser"); 2 | const traverse = require("@babel/traverse").default; 3 | const types = require("@babel/types"); 4 | const generator = require("@babel/generator").default; 5 | const template = require("@babel/template").default; 6 | const facelessLogo = ` __ _ 7 | / _| __ _ ___ ___| | ___ ___ ___ 8 | | |_ / _\` |/ __/ _ \\ |/ _ \\/ __/ __| 9 | | _| (_| | (_| __/ | __/\\__ \\__ \\ 10 | |_| \\__,_|\\___\\___|_|\\___||___/___/ 11 | ` 12 | let astGlobal = null; 13 | 14 | if (typeof window !== 'undefined') { 15 | astGlobal = window; 16 | } else if (typeof global !== 'undefined') { 17 | astGlobal = global; 18 | } else { 19 | astGlobal = this; 20 | } 21 | 22 | astGlobal.parser = parser; 23 | astGlobal.traverse = traverse; 24 | astGlobal.types = types; 25 | astGlobal.generator = generator; 26 | astGlobal.template = template; 27 | astGlobal.facelessLogo = facelessLogo; 28 | // browserify ./tools/env.js -o ./tools/babelPlugins.js -------------------------------------------------------------------------------- /test/preprocess.js: -------------------------------------------------------------------------------- 1 | var a, b; 2 | function _faceless_all_keys(o) { 3 | let _keys = [], 4 | l; 5 | while (1) { 6 | l = Object.keys(o); 7 | _keys = _keys.concat(l); 8 | o = o.__proto__; 9 | if (!l.length) { 10 | break; 11 | } 12 | } 13 | return _keys; 14 | } 15 | a = { 16 | a: 0, 17 | b: 1 18 | }.a; 19 | b = { 20 | a: 0, 21 | b: 1 22 | }.b; // 测试代码 23 | console.log(a, b); 24 | c = [2, 3][0]; 25 | d = [2, 3][1]; 26 | console.log(c, d); 27 | let arr = { 28 | a: 0, 29 | b: 1, 30 | c: 2 31 | }; 32 | let pro = { 33 | d: 3, 34 | e: 4 35 | }; 36 | arr.__proto__ = pro; 37 | for (let _F_i = 0, _F_li = _faceless_all_keys(arr); _F_i < _F_li.length; _F_i++) { 38 | let element = _F_li[_F_i]; 39 | console.log(element); 40 | } 41 | const set = new Set([1, 2, 3]); 42 | for (let _F_iterator = set[Symbol.iterator](), _F_i = _F_iterator.next(); !_F_i.done; _F_i = _F_iterator.next()) { 43 | let element = _F_i.value; 44 | console.log(element); 45 | } 46 | const str = 'Hello'; 47 | for (let _F_iterator = str[Symbol.iterator](), _F_i = _F_iterator.next(); !_F_i.done; _F_i = _F_iterator.next()) { 48 | let char = _F_i.value; 49 | console.log(char); 50 | } 51 | (0, 0, function (x) { 52 | console.log(x); 53 | })(123); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # facelessJsvmp是什么? 3 | > 单栈实现的js代码虚拟化保护程序,加固代码支持在浏览器和nodejs中运行 4 | 5 | 6 | # 使用说明 7 | 8 | 9 | ### 一.WEB页面步骤 10 | 11 | 1. 打开链接 [https://alanhays.github.io/facelessJsvmp/](https://alanhays.github.io/facelessJsvmp/) 12 | 2. 在源代码框(左边)粘贴需要加固的代码 13 | 3. 点击执行加固按钮进行加固(如出现“未解析”则表示有未适配的语法) 14 | 4. 加固代码输出后,更具需要可选择“下载代码”或“复制代码” 15 | 16 | ### 二.项目文件步骤(环境:安装了nodejs即可) 17 | 18 | 1. test目录下的source.js文件替换为待加固的代码 19 | 2. 执行目录下的main.js进行加固(报错则表示有未适配的语法) 20 | 3. 加固结果为目录下的output.js文件 21 | 22 | # 文件目录 23 | ``` 24 | ├── test // 测试目录 25 | │ ├── source.js // 待加固的js源文件 26 | │ ├── preprocess.js // 编译前预处理的源文件 27 | │ ├── main.js // js代码加固程序-jsvmp (直接run即可) 28 | │ └── output.js // 输出的加固文件 29 | ├── pass // 测试通过文件目录 30 | │ ├── HMAC-SHA256.js 31 | │ ├── MD5.js 32 | │ ├── SHA1.js 33 | │ ├── SHA256.js 34 | │ ├── SM3.js 35 | │ └── SM4.js 36 | ├── tools // 工具目录 37 | │ ├── babelPlugins.js // 打包好的环境 38 | │ ├── dump.js // 反编译脚本 39 | │ └── env.js 40 | ├── index.html 41 | ├── README.md // 项目的说明文档 42 | ├── package.json // npm包配置文件,里面定义了项目的npm脚本,依赖包等信息 43 | └── package-lock.json 44 | ``` 45 | 46 | # 更新日志 47 | **1.0.3 日志:**
1.新发现一个bug(解释器bug)
2.新增dump脚本(MD5反编译示例)
**1.0.2 日志:**
1.修复一个let变量相关的问题
2.新增web页面(丑)[https://alanhays.github.io/facelessJsvmp/](https://alanhays.github.io/facelessJsvmp/)
**1.0.1 日志:**
1.新增适配SM4加密算法
2.修复自执行语法执行异常问题 48 | ```javascript 49 | (function (x) { 50 | console.log(x) 51 | })(0) 52 | ``` 53 | **1.0.0 日志:**
1.加固代码支持在浏览器和nodejs中运行 54 | 55 | # 已知问题 56 | > YieldExpression 语法未实现 :yield 57 | 58 | ```javascript 59 | function* generatorFunction() { 60 | yield 1; 61 | yield 2; 62 | yield 3; 63 | } 64 | ``` 65 | > SpreadElement 语法未实现:...args 66 | 67 | ```javascript 68 | f(...args) 69 | ``` 70 | > 解释器bug示例,由[零点大佬](https://wx.zsxq.com/dweb2/index/footprint/51514454824814)发现。表现:加固后与执行源代码结果不一致。 71 | 72 | ``` 73 | function test() { 74 | var list = [1, 2]; 75 | test = function () { 76 | return list; 77 | }; 78 | return test(); 79 | } 80 | 81 | let y = test(); 82 | y.push(3); 83 | console.log(test()); 84 | ``` 85 | 86 | 87 | # 参考文献 88 | JSVMP论文和专利:[https://surans.lanzouw.com/inJf30zj41je](https://surans.lanzouw.com/inJf30zj41je)
大语言模型机器人AI 89 | -------------------------------------------------------------------------------- /pass/SHA1.js: -------------------------------------------------------------------------------- 1 | function encodeUTF8(s) { 2 | var i, r = [], c, x; 3 | for (i = 0; i < s.length; i++) 4 | if ((c = s.charCodeAt(i)) < 0x80) r.push(c); 5 | else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F)); 6 | else { 7 | if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode 8 | c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000, 9 | r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F)); 10 | else r.push(0xE0 + (c >> 12 & 0xF)); 11 | r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F)); 12 | } 13 | ; 14 | return r; 15 | } 16 | 17 | // 字符串加密成 hex 字符串 18 | function sha1(s) { 19 | var data = new Uint8Array(encodeUTF8(s)) 20 | var i, j, t; 21 | var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2); 22 | s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer); 23 | for (t = new DataView(s.buffer), i = 0; i < l; i++) s[i] = t.getUint32(i << 2); 24 | s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8); 25 | s[l - 1] = data.length << 3; 26 | var w = [], f = [ 27 | function () { 28 | return m[1] & m[2] | ~m[1] & m[3]; 29 | }, 30 | function () { 31 | return m[1] ^ m[2] ^ m[3]; 32 | }, 33 | function () { 34 | return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; 35 | }, 36 | function () { 37 | return m[1] ^ m[2] ^ m[3]; 38 | } 39 | ], rol = function (n, c) { 40 | return n << c | n >>> (32 - c); 41 | }, 42 | k = [1518500249, 1859775393, -1894007588, -899497514], 43 | m = [1732584193, -271733879, null, null, -1009589776]; 44 | m[2] = ~m[0], m[3] = ~m[1]; 45 | for (i = 0; i < s.length; i += 16) { 46 | var o = m.slice(0); 47 | for (j = 0; j < 80; j++) 48 | w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1), 49 | t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0, 50 | m[1] = rol(m[1], 30), m.pop(), m.unshift(t); 51 | for (j = 0; j < 5; j++) m[j] = m[j] + o[j] | 0; 52 | } 53 | ; 54 | t = new DataView(new Uint32Array(m).buffer); 55 | for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2); 56 | 57 | var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) { 58 | return (e < 16 ? "0" : "") + e.toString(16); 59 | }).join(""); 60 | return hex; 61 | } 62 | 63 | let txt = sha1("123465") 64 | console.log(txt, txt == "210a28f50a8e9a0986df287ac9ae224de95b8978") -------------------------------------------------------------------------------- /pass/SHA256.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Secure Hash Algorithm (SHA256) 4 | * http://www.webtoolkit.info/ 5 | * 6 | * Original code by Angel Marin, Paul Johnston. 7 | * 8 | **/ 9 | function SHA256(s) { 10 | const chrsz = 8 11 | const hexcase = 0 12 | 13 | function safe_add(x, y) { 14 | const lsw = (x & 0xFFFF) + (y & 0xFFFF) 15 | const msw = (x >> 16) + (y >> 16) + (lsw >> 16) 16 | return (msw << 16) | (lsw & 0xFFFF) 17 | } 18 | 19 | function S(X, n) { 20 | return (X >>> n) | (X << (32 - n)) 21 | } 22 | 23 | function R(X, n) { 24 | return (X >>> n) 25 | } 26 | 27 | function Ch(x, y, z) { 28 | return ((x & y) ^ ((~x) & z)) 29 | } 30 | 31 | function Maj(x, y, z) { 32 | return ((x & y) ^ (x & z) ^ (y & z)) 33 | } 34 | 35 | function Sigma0256(x) { 36 | return (S(x, 2) ^ S(x, 13) ^ S(x, 22)) 37 | } 38 | 39 | function Sigma1256(x) { 40 | return (S(x, 6) ^ S(x, 11) ^ S(x, 25)) 41 | } 42 | 43 | function Gamma0256(x) { 44 | return (S(x, 7) ^ S(x, 18) ^ R(x, 3)) 45 | } 46 | 47 | function Gamma1256(x) { 48 | return (S(x, 17) ^ S(x, 19) ^ R(x, 10)) 49 | } 50 | 51 | function core_sha256(m, l) { 52 | const K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2] 53 | const HASH = [0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19] 54 | const W = new Array(64) 55 | let a, b, c, d, e, f, g, h, i, j 56 | let T1, T2 57 | m[l >> 5] |= 0x80 << (24 - l % 32) 58 | m[((l + 64 >> 9) << 4) + 15] = l 59 | for (i = 0; i < m.length; i += 16) { 60 | a = HASH[0] 61 | b = HASH[1] 62 | c = HASH[2] 63 | d = HASH[3] 64 | e = HASH[4] 65 | f = HASH[5] 66 | g = HASH[6] 67 | h = HASH[7] 68 | for (j = 0; j < 64; j++) { 69 | if (j < 16) { 70 | W[j] = m[j + i] 71 | } else { 72 | W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]) 73 | } 74 | T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]) 75 | T2 = safe_add(Sigma0256(a), Maj(a, b, c)) 76 | h = g 77 | g = f 78 | f = e 79 | e = safe_add(d, T1) 80 | d = c 81 | c = b 82 | b = a 83 | a = safe_add(T1, T2) 84 | } 85 | HASH[0] = safe_add(a, HASH[0]) 86 | HASH[1] = safe_add(b, HASH[1]) 87 | HASH[2] = safe_add(c, HASH[2]) 88 | HASH[3] = safe_add(d, HASH[3]) 89 | HASH[4] = safe_add(e, HASH[4]) 90 | HASH[5] = safe_add(f, HASH[5]) 91 | HASH[6] = safe_add(g, HASH[6]) 92 | HASH[7] = safe_add(h, HASH[7]) 93 | } 94 | return HASH 95 | } 96 | 97 | function str2binb(str) { 98 | const bin = [] 99 | const mask = (1 << chrsz) - 1 100 | for (let i = 0; i < str.length * chrsz; i += chrsz) { 101 | bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i % 32) 102 | } 103 | return bin 104 | } 105 | 106 | function Utf8Encode(string) { 107 | string = string.replace(/\r\n/g, '\n') 108 | let utfText = '' 109 | for (let n = 0; n < string.length; n++) { 110 | const c = string.charCodeAt(n) 111 | if (c < 128) { 112 | utfText += String.fromCharCode(c) 113 | } else if ((c > 127) && (c < 2048)) { 114 | utfText += String.fromCharCode((c >> 6) | 192) 115 | utfText += String.fromCharCode((c & 63) | 128) 116 | } else { 117 | utfText += String.fromCharCode((c >> 12) | 224) 118 | utfText += String.fromCharCode(((c >> 6) & 63) | 128) 119 | utfText += String.fromCharCode((c & 63) | 128) 120 | } 121 | } 122 | return utfText 123 | } 124 | 125 | function binb2hex(binarray) { 126 | const hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef' 127 | let str = '' 128 | for (let i = 0; i < binarray.length * 4; i++) { 129 | str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + 130 | hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF) 131 | } 132 | return str 133 | } 134 | 135 | 136 | return binb2hex(core_sha256(str2binb(Utf8Encode(s)), s.length * chrsz)) 137 | } 138 | 139 | let txt = SHA256("123465") 140 | console.log(txt, txt == "52f1476494897c64f417deb7ef7cd690f1cea9edce638746c420f1240d3d39dc") -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Faceless man - JSVMP 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 40 | 41 | 42 | 43 |
44 |
45 |
46 |
47 |
48 | 49 | 52 |
53 |
54 | 55 |
56 |
57 |
58 |
59 |
60 |
61 | 62 | 65 |
66 |
67 | 68 |
69 |
70 |
71 |
72 | 73 | 89 |
90 | 176 | 177 | -------------------------------------------------------------------------------- /pass/MD5.js: -------------------------------------------------------------------------------- 1 | console.time("执行耗时") 2 | function toMd5Hex(text) { 3 | var hexcase = 0; 4 | var chrsz = 8; 5 | 6 | function core_md5(x, len) { 7 | x[len >> 5] |= 0x80 << ((len) % 32); 8 | x[(((len + 64) >>> 9) << 4) + 14] = len; 9 | var a = 1732584193; 10 | var b = -271733879; 11 | var c = -1732584194; 12 | var d = 271733878; 13 | for (var i = 0; i < x.length; i += 16) { 14 | var olda = a; 15 | var oldb = b; 16 | var oldc = c; 17 | var oldd = d; 18 | a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936); 19 | d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586); 20 | c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819); 21 | b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330); 22 | a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897); 23 | d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426); 24 | c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341); 25 | b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983); 26 | a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416); 27 | d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417); 28 | c = md5_ff(c, d, a, b, x[i + 10], 17, -42063); 29 | b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162); 30 | a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682); 31 | d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101); 32 | c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290); 33 | b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329); 34 | a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510); 35 | d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632); 36 | c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713); 37 | b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302); 38 | a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691); 39 | d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083); 40 | c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335); 41 | b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848); 42 | a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438); 43 | d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690); 44 | c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961); 45 | b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501); 46 | a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467); 47 | d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784); 48 | c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473); 49 | b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734); 50 | a = md5_hh(a, b, c, d, x[i + 5], 4, -378558); 51 | d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463); 52 | c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562); 53 | b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556); 54 | a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060); 55 | d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353); 56 | c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632); 57 | b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640); 58 | a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174); 59 | d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222); 60 | c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979); 61 | b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189); 62 | a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487); 63 | d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835); 64 | c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520); 65 | b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651); 66 | a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844); 67 | d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415); 68 | c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905); 69 | b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055); 70 | a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571); 71 | d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606); 72 | c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523); 73 | b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799); 74 | a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359); 75 | d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744); 76 | c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380); 77 | b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649); 78 | a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070); 79 | d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379); 80 | c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259); 81 | b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551); 82 | a = safe_add(a, olda); 83 | b = safe_add(b, oldb); 84 | c = safe_add(c, oldc); 85 | d = safe_add(d, oldd); 86 | } 87 | return Array(a, b, c, d); 88 | } 89 | 90 | function md5_cmn(q, a, b, x, s, t) { 91 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b); 92 | } 93 | 94 | function md5_ff(a, b, c, d, x, s, t) { 95 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); 96 | } 97 | 98 | function md5_gg(a, b, c, d, x, s, t) { 99 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); 100 | } 101 | 102 | function md5_hh(a, b, c, d, x, s, t) { 103 | return md5_cmn(b ^ c ^ d, a, b, x, s, t); 104 | } 105 | 106 | function md5_ii(a, b, c, d, x, s, t) { 107 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 108 | } 109 | 110 | function safe_add(x, y) { 111 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); 112 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); 113 | return (msw << 16) | (lsw & 0xFFFF); 114 | } 115 | 116 | function bit_rol(num, cnt) { 117 | return (num << cnt) | (num >>> (32 - cnt)); 118 | } 119 | 120 | function str2binl(str) { 121 | var bin = Array(); 122 | var mask = (1 << chrsz) - 1; 123 | for (var i = 0; i < str.length * chrsz; i += chrsz) 124 | bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32); 125 | return bin; 126 | } 127 | 128 | function binl2hex(binarray) { 129 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; 130 | var str = ""; 131 | for (var i = 0; i < binarray.length * 4; i++) { 132 | str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) + 133 | hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF); 134 | } 135 | return str; 136 | } 137 | 138 | return binl2hex(core_md5(str2binl(text), text.length * chrsz)); 139 | } 140 | 141 | let text = toMd5Hex("123456") 142 | console.log(text, text == "e10adc3949ba59abbe56e057f20f883e") 143 | console.timeEnd("执行耗时") -------------------------------------------------------------------------------- /pass/SM3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 国密SM3加密{JS实现} 3 | * 4 | * 参考 https://blog.csdn.net/Shen_yuanjia/article/details/111879819 5 | * 6 | * @returns 7 | */ 8 | function SM3() { 9 | if (!(this instanceof SM3)) { 10 | return new SM3(); 11 | } 12 | 13 | this.reg = new Array(8); 14 | this.chunk = []; 15 | this.size = 0; 16 | 17 | this.reset(); 18 | } 19 | 20 | SM3.prototype.reset = function () { 21 | this.reg[0] = 0x7380166f; 22 | this.reg[1] = 0x4914b2b9; 23 | this.reg[2] = 0x172442d7; 24 | this.reg[3] = 0xda8a0600; 25 | this.reg[4] = 0xa96f30bc; 26 | this.reg[5] = 0x163138aa; 27 | this.reg[6] = 0xe38dee4d; 28 | this.reg[7] = 0xb0fb0e4e; 29 | this.chunk = []; 30 | this.size = 0; 31 | }; 32 | 33 | /** 34 | * 字符串转byte数组 35 | */ 36 | SM3.prototype.strToBytes = function (s) { 37 | var ch, st, re = []; 38 | for (var i = 0; i < s.length; i++) { 39 | ch = s.charCodeAt(i); 40 | st = []; 41 | do { 42 | st.push(ch & 0xFF); 43 | ch = ch >> 8; 44 | } 45 | while (ch); 46 | re = re.concat(st.reverse()); 47 | } 48 | return re; 49 | }; 50 | 51 | SM3.prototype.write = function (msg) { 52 | var m = (typeof msg === 'string') ? this.strToBytes(msg) : msg; 53 | this.size += m.length; 54 | var i = 64 - this.chunk.length; 55 | if (m.length < i) { 56 | this.chunk = this.chunk.concat(m); 57 | return; 58 | } 59 | 60 | this.chunk = this.chunk.concat(m.slice(0, i)); 61 | while (this.chunk.length >= 64) { 62 | this._compress(this.chunk); 63 | if (i < m.length) { 64 | this.chunk = m.slice(i, Math.min(i + 64, m.length)); 65 | } else { 66 | this.chunk = []; 67 | } 68 | i += 64; 69 | } 70 | }; 71 | 72 | /** 73 | * 计算hash值 74 | */ 75 | SM3.prototype.sum = function (msg, enc) { 76 | if (msg) { 77 | this.reset(); 78 | this.write(msg); 79 | } 80 | 81 | this._fill(); 82 | for (var i = 0; i < this.chunk.length; i += 64) { 83 | this._compress(this.chunk.slice(i, i + 64)); 84 | } 85 | 86 | var digest = null; 87 | if (enc == 'hex') { 88 | digest = ""; 89 | for (var i = 0; i < 8; i++) { 90 | digest += this.reg[i].toString(16); 91 | } 92 | } else { 93 | var digest = new Array(32); 94 | for (var i = 0; i < 8; i++) { 95 | var h; 96 | h = this.reg[i]; 97 | digest[i * 4 + 3] = (h & 0xff) >>> 0; 98 | h >>>= 8; 99 | digest[i * 4 + 2] = (h & 0xff) >>> 0; 100 | h >>>= 8; 101 | digest[i * 4 + 1] = (h & 0xff) >>> 0; 102 | h >>>= 8; 103 | digest[i * 4] = (h & 0xff) >>> 0; 104 | } 105 | } 106 | 107 | this.reset(); 108 | return digest; 109 | }; 110 | 111 | SM3.prototype._compress = function (m) { 112 | if (m < 64) { 113 | console.error("compress error: not enough data"); 114 | return; 115 | } 116 | var w = this._expand(m); 117 | var r = this.reg.slice(0); 118 | for (var j = 0; j < 64; j++) { 119 | var ss1 = this._rotl(r[0], 12) + r[4] + this._rotl(this._t(j), j) 120 | ss1 = (ss1 & 0xffffffff) >>> 0; 121 | ss1 = this._rotl(ss1, 7); 122 | 123 | var ss2 = (ss1 ^ this._rotl(r[0], 12)) >>> 0; 124 | var tt1 = this._ff(j, r[0], r[1], r[2]); 125 | tt1 = tt1 + r[3] + ss2 + w[j + 68]; 126 | tt1 = (tt1 & 0xffffffff) >>> 0; 127 | var tt2 = this._gg(j, r[4], r[5], r[6]); 128 | tt2 = tt2 + r[7] + ss1 + w[j]; 129 | tt2 = (tt2 & 0xffffffff) >>> 0; 130 | r[3] = r[2]; 131 | r[2] = this._rotl(r[1], 9); 132 | r[1] = r[0]; 133 | r[0] = tt1; 134 | r[7] = r[6] 135 | r[6] = this._rotl(r[5], 19); 136 | r[5] = r[4]; 137 | r[4] = (tt2 ^ this._rotl(tt2, 9) ^ this._rotl(tt2, 17)) >>> 0; 138 | } 139 | 140 | for (var i = 0; i < 8; i++) { 141 | this.reg[i] = (this.reg[i] ^ r[i]) >>> 0; 142 | } 143 | }; 144 | 145 | SM3.prototype._fill = function () { 146 | var l = this.size * 8; 147 | var len = this.chunk.push(0x80) % 64; 148 | if (64 - len < 8) { 149 | len -= 64; 150 | } 151 | for (; len < 56; len++) { 152 | this.chunk.push(0x00); 153 | } 154 | 155 | for (var i = 0; i < 4; i++) { 156 | var hi = Math.floor(l / 0x100000000); 157 | this.chunk.push((hi >>> ((3 - i) * 8)) & 0xff); 158 | } 159 | for (var i = 0; i < 4; i++) { 160 | this.chunk.push((l >>> ((3 - i) * 8)) & 0xff); 161 | } 162 | }; 163 | 164 | SM3.prototype._expand = function (b) { 165 | var w = new Array(132); 166 | for (var i = 0; i < 16; i++) { 167 | w[i] = b[i * 4] << 24; 168 | w[i] |= b[i * 4 + 1] << 16; 169 | w[i] |= b[i * 4 + 2] << 8; 170 | w[i] |= b[i * 4 + 3]; 171 | w[i] >>>= 0; 172 | } 173 | 174 | for (var j = 16; j < 68; j++) { 175 | var x; 176 | x = w[j - 16] ^ w[j - 9] ^ this._rotl(w[j - 3], 15); 177 | x = x ^ this._rotl(x, 15) ^ this._rotl(x, 23); 178 | w[j] = (x ^ this._rotl(w[j - 13], 7) ^ w[j - 6]) >>> 0; 179 | } 180 | 181 | for (var j = 0; j < 64; j++) { 182 | w[j + 68] = (w[j] ^ w[j + 4]) >>> 0; 183 | } 184 | 185 | return w; 186 | }; 187 | 188 | SM3.prototype._rotl = function (x, n) { 189 | n %= 32; 190 | return ((x << n) | (x >>> (32 - n))) >>> 0; 191 | }; 192 | 193 | SM3.prototype._t = function (j) { 194 | if (0 <= j && j < 16) { 195 | return 0x79cc4519; 196 | } else if (16 <= j && j < 64) { 197 | return 0x7a879d8a; 198 | } else { 199 | console.error("invalid j for constant Tj"); 200 | } 201 | }; 202 | 203 | SM3.prototype._ff = function (j, x, y, z) { 204 | if (0 <= j && j < 16) { 205 | return (x ^ y ^ z) >>> 0; 206 | } else if (16 <= j && j < 64) { 207 | return ((x & y) | (x & z) | (y & z)) >>> 0; 208 | } else { 209 | console.error("invalid j for bool function FF"); 210 | return 0; 211 | } 212 | }; 213 | 214 | SM3.prototype._gg = function (j, x, y, z) { 215 | if (0 <= j && j < 16) { 216 | return (x ^ y ^ z) >>> 0; 217 | } else if (16 <= j && j < 64) { 218 | return ((x & y) | (~x & z)) >>> 0; 219 | } else { 220 | console.error("invalid j for bool function GG"); 221 | return 0; 222 | } 223 | }; 224 | 225 | /** 226 | * 等效于Array.from目的是做浏览器兼容处理 Array.from IE浏览器不支持 227 | */ 228 | SM3.prototype.toArray = function (s, f) { 229 | var a = []; 230 | for (var i = 0; i < s.length; i++) { 231 | var t = s[i]; 232 | if (f) { 233 | t = f(t); 234 | } 235 | a.push(t); 236 | } 237 | return a; 238 | }; 239 | 240 | /** 241 | * SM3加密主函数 242 | * 243 | * @param msg 244 | * @returns 245 | */ 246 | function sm3Digest(msg) { 247 | var _sm3 = new SM3(); 248 | var digest = _sm3.sum(msg); 249 | var hashHex = _sm3.toArray(digest, function (byte) { 250 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 251 | }).join(''); 252 | return hashHex; 253 | } 254 | 255 | let txt = sm3Digest("123456") 256 | console.log(txt, txt == "207cf410532f92a47dee245ce9b11ff71f578ebd763eb3bbea44ebd043d018fb") 257 | 258 | 259 | -------------------------------------------------------------------------------- /pass/HMAC-SHA256.js: -------------------------------------------------------------------------------- 1 | // To ensure cross-browser support even without a proper SubtleCrypto 2 | // impelmentation (or without access to the impelmentation, as is the case with 3 | // Chrome loaded over HTTP instead of HTTPS), this library can create SHA-256 4 | // HMAC signatures using nothing but raw JavaScript 5 | 6 | /* eslint-disable no-magic-numbers, id-length, no-param-reassign, new-cap */ 7 | 8 | // By giving internal functions names that we can mangle, future calls to 9 | // them are reduced to a single byte (minor space savings in minified file) 10 | var uint8Array = Uint8Array; 11 | var uint32Array = Uint32Array; 12 | var pow = Math.pow; 13 | 14 | // Will be initialized below 15 | // Using a Uint32Array instead of a simple array makes the minified code 16 | // a bit bigger (we lose our `unshift()` hack), but comes with huge 17 | // performance gains 18 | var DEFAULT_STATE = new uint32Array(8); 19 | var ROUND_CONSTANTS = []; 20 | 21 | // Reusable object for expanded message 22 | // Using a Uint32Array instead of a simple array makes the minified code 23 | // 7 bytes larger, but comes with huge performance gains 24 | var M = new uint32Array(64); 25 | 26 | // After minification the code to compute the default state and round 27 | // constants is smaller than the output. More importantly, this serves as a 28 | // good educational aide for anyone wondering where the magic numbers come 29 | // from. No magic numbers FTW! 30 | function getFractionalBits(n) { 31 | return ((n - (n | 0)) * pow(2, 32)) | 0; 32 | } 33 | 34 | var n = 2, nPrime = 0; 35 | while (nPrime < 64) { 36 | // isPrime() was in-lined from its original function form to save 37 | // a few bytes 38 | var isPrime = true; 39 | // Math.sqrt() was replaced with pow(n, 1/2) to save a few bytes 40 | // var sqrtN = pow(n, 1 / 2); 41 | // So technically to determine if a number is prime you only need to 42 | // check numbers up to the square root. However this function only runs 43 | // once and we're only computing the first 64 primes (up to 311), so on 44 | // any modern CPU this whole function runs in a couple milliseconds. 45 | // By going to n / 2 instead of sqrt(n) we net 8 byte savings and no 46 | // scaling performance cost 47 | for (var factor = 2; factor <= n / 2; factor++) { 48 | if (n % factor === 0) { 49 | isPrime = false; 50 | } 51 | } 52 | if (isPrime) { 53 | if (nPrime < 8) { 54 | DEFAULT_STATE[nPrime] = getFractionalBits(pow(n, 1 / 2)); 55 | } 56 | ROUND_CONSTANTS[nPrime] = getFractionalBits(pow(n, 1 / 3)); 57 | 58 | nPrime++; 59 | } 60 | 61 | n++; 62 | } 63 | 64 | // For cross-platform support we need to ensure that all 32-bit words are 65 | // in the same endianness. A UTF-8 TextEncoder will return BigEndian data, 66 | // so upon reading or writing to our ArrayBuffer we'll only swap the bytes 67 | // if our system is LittleEndian (which is about 99% of CPUs) 68 | var LittleEndian = !!new uint8Array(new uint32Array([1]).buffer)[0]; 69 | 70 | function convertEndian(word) { 71 | if (LittleEndian) { 72 | return ( 73 | // byte 1 -> byte 4 74 | (word >>> 24) | 75 | // byte 2 -> byte 3 76 | (((word >>> 16) & 0xff) << 8) | 77 | // byte 3 -> byte 2 78 | ((word & 0xff00) << 8) | 79 | // byte 4 -> byte 1 80 | (word << 24) 81 | ); 82 | } else { 83 | return word; 84 | } 85 | } 86 | 87 | function rightRotate(word, bits) { 88 | return (word >>> bits) | (word << (32 - bits)); 89 | } 90 | 91 | function sha256(data) { 92 | // Copy default state 93 | var STATE = DEFAULT_STATE.slice(); 94 | 95 | // Caching this reduces occurrences of ".length" in minified JavaScript 96 | // 3 more byte savings! :D 97 | var legth = data.length; 98 | 99 | // Pad data 100 | var bitLength = legth * 8; 101 | var newBitLength = (512 - ((bitLength + 64) % 512) - 1) + bitLength + 65; 102 | 103 | // "bytes" and "words" are stored BigEndian 104 | var bytes = new uint8Array(newBitLength / 8); 105 | var words = new uint32Array(bytes.buffer); 106 | 107 | bytes.set(data, 0); 108 | // Append a 1 109 | bytes[legth] = 0b10000000; 110 | // Store length in BigEndian 111 | words[words.length - 1] = convertEndian(bitLength); 112 | 113 | // Loop iterator (avoid two instances of "var") -- saves 2 bytes 114 | var round; 115 | 116 | // Process blocks (512 bits / 64 bytes / 16 words at a time) 117 | for (var block = 0; block < newBitLength / 32; block += 16) { 118 | var workingState = STATE.slice(); 119 | 120 | // Rounds 121 | for (round = 0; round < 64; round++) { 122 | var MRound; 123 | // Expand message 124 | if (round < 16) { 125 | // Convert to platform Endianness for later math 126 | MRound = convertEndian(words[block + round]); 127 | } else { 128 | var gamma0x = M[round - 15]; 129 | var gamma1x = M[round - 2]; 130 | MRound = 131 | M[round - 7] + M[round - 16] + ( 132 | rightRotate(gamma0x, 7) ^ 133 | rightRotate(gamma0x, 18) ^ 134 | (gamma0x >>> 3) 135 | ) + ( 136 | rightRotate(gamma1x, 17) ^ 137 | rightRotate(gamma1x, 19) ^ 138 | (gamma1x >>> 10) 139 | ) 140 | ; 141 | } 142 | 143 | // M array matches platform endianness 144 | M[round] = MRound |= 0; 145 | 146 | // Computation 147 | var t1 = 148 | ( 149 | rightRotate(workingState[4], 6) ^ 150 | rightRotate(workingState[4], 11) ^ 151 | rightRotate(workingState[4], 25) 152 | ) + 153 | ( 154 | (workingState[4] & workingState[5]) ^ 155 | (~workingState[4] & workingState[6]) 156 | ) + workingState[7] + MRound + ROUND_CONSTANTS[round] 157 | ; 158 | var t2 = 159 | ( 160 | rightRotate(workingState[0], 2) ^ 161 | rightRotate(workingState[0], 13) ^ 162 | rightRotate(workingState[0], 22) 163 | ) + 164 | ( 165 | (workingState[0] & workingState[1]) ^ 166 | (workingState[2] & (workingState[0] ^ 167 | workingState[1])) 168 | ) 169 | ; 170 | 171 | for (var i = 7; i > 0; i--) { 172 | workingState[i] = workingState[i - 1]; 173 | } 174 | workingState[0] = (t1 + t2) | 0; 175 | workingState[4] = (workingState[4] + t1) | 0; 176 | } 177 | 178 | // Update state 179 | for (round = 0; round < 8; round++) { 180 | STATE[round] = (STATE[round] + workingState[round]) | 0; 181 | } 182 | } 183 | 184 | // Finally the state needs to be converted to BigEndian for output 185 | // And we want to return a Uint8Array, not a Uint32Array 186 | return new uint8Array(new uint32Array( 187 | STATE.map(function (val) { 188 | return convertEndian(val); 189 | }) 190 | ).buffer); 191 | } 192 | 193 | function hmac(key, data) { 194 | if (key.length > 64) 195 | key = sha256(key); 196 | 197 | if (key.length < 64) { 198 | const tmp = new Uint8Array(64); 199 | tmp.set(key, 0); 200 | key = tmp; 201 | } 202 | 203 | // Generate inner and outer keys 204 | var innerKey = new Uint8Array(64); 205 | var outerKey = new Uint8Array(64); 206 | for (var i = 0; i < 64; i++) { 207 | innerKey[i] = 0x36 ^ key[i]; 208 | outerKey[i] = 0x5c ^ key[i]; 209 | } 210 | 211 | // Append the innerKey 212 | var msg = new Uint8Array(data.length + 64); 213 | msg.set(innerKey, 0); 214 | msg.set(data, 64); 215 | 216 | // Has the previous message and append the outerKey 217 | var result = new Uint8Array(64 + 32); 218 | result.set(outerKey, 0); 219 | result.set(sha256(msg), 64); 220 | 221 | // Hash the previous message 222 | return sha256(result); 223 | } 224 | 225 | // Convert a string to a Uint8Array, SHA-256 it, and convert back to string 226 | const encoder = new TextEncoder("utf-8"); 227 | 228 | function sign(inputKey, inputData) { 229 | const key = typeof inputKey === "string" ? encoder.encode(inputKey) : inputKey; 230 | const data = typeof inputData === "string" ? encoder.encode(inputData) : inputData; 231 | return hmac(key, data); 232 | } 233 | 234 | function hash(str) { 235 | return hex(sha256(encoder.encode(str))); 236 | } 237 | 238 | function hex(bin) { 239 | return bin.reduce((acc, val) => 240 | acc + ("00" + val.toString(16)).substr(-2) 241 | , ""); 242 | } 243 | 244 | let txt = hex(sign("alanhays", "123456")) 245 | console.log(txt, txt == "274adfa0e55926527cf2ef770a7ee422c4cd5ffcdd750c57fd69d7698db1a50d") 246 | -------------------------------------------------------------------------------- /pass/SM4.js: -------------------------------------------------------------------------------- 1 | var SM4 = {}; 2 | 3 | (function () { 4 | var SM4_ENCRYPT = 1 5 | var SM4_DECRYPT = 0 6 | 7 | function sm4_context() { 8 | this.mode = 0; 9 | this.sk = [] 10 | } 11 | 12 | function GET_ULONG_BE(n, b, i) { 13 | return (b[i] << 24) | (b[i + 1] << 16) | (b[i + 2]) << 8 | (b[i + 3]) 14 | } 15 | 16 | function PUT_ULONG_BE(n, b, i) { 17 | b[i] = n >>> 24 18 | b[i + 1] = n >>> 16 19 | b[i + 2] = n >>> 8 20 | b[i + 3] = n 21 | } 22 | 23 | function ROTL(x, n) { 24 | var a = (x & 0xFFFFFFFF) << n 25 | var b = x >>> (32 - n) 26 | 27 | return a | b 28 | } 29 | 30 | var SboxTable = [ 31 | [0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05], 32 | [0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99], 33 | [0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62], 34 | [0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6], 35 | [0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8], 36 | [0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35], 37 | [0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87], 38 | [0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e], 39 | [0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1], 40 | [0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3], 41 | [0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f], 42 | [0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51], 43 | [0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8], 44 | [0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0], 45 | [0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84], 46 | [0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48] 47 | ] 48 | 49 | var FK = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc]; 50 | var CK = [ 51 | 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, 52 | 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, 53 | 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, 54 | 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, 55 | 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, 56 | 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, 57 | 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, 58 | 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279 59 | ] 60 | 61 | function sm4Sbox(n) { 62 | var l = n >>> 4 63 | var r = n % 16 64 | return SboxTable[l][r] 65 | } 66 | 67 | function sm4Lt(ka) { 68 | var bb = 0; 69 | var c = 0; 70 | var a = new Uint8Array(4); 71 | var b = new Array(4); 72 | PUT_ULONG_BE(ka, a, 0) 73 | b[0] = sm4Sbox(a[0]) 74 | b[1] = sm4Sbox(a[1]) 75 | b[2] = sm4Sbox(a[2]) 76 | b[3] = sm4Sbox(a[3]) 77 | bb = GET_ULONG_BE(bb, b, 0) 78 | 79 | c = bb ^ (ROTL(bb, 2)) ^ (ROTL(bb, 10)) ^ (ROTL(bb, 18)) ^ (ROTL(bb, 24)) 80 | return c; 81 | } 82 | 83 | function sm4F(x0, x1, x2, x3, rk) { 84 | return (x0 ^ sm4Lt(x1 ^ x2 ^ x3 ^ rk)) 85 | } 86 | 87 | function sm4CalciRK(ka) { 88 | var bb = 0; 89 | var rk = 0; 90 | var a = new Uint8Array(4); 91 | var b = new Array(4); 92 | PUT_ULONG_BE(ka, a, 0) 93 | b[0] = sm4Sbox(a[0]); 94 | b[1] = sm4Sbox(a[1]); 95 | b[2] = sm4Sbox(a[2]); 96 | b[3] = sm4Sbox(a[3]); 97 | bb = GET_ULONG_BE(bb, b, 0) 98 | 99 | rk = bb ^ (ROTL(bb, 13)) ^ (ROTL(bb, 23)) 100 | 101 | return rk; 102 | } 103 | 104 | function sm4_setkey(SK, key) { 105 | var MK = new Array(4); 106 | var k = new Array(36); 107 | var i = 0; 108 | MK[0] = GET_ULONG_BE(MK[0], key, 0); 109 | MK[1] = GET_ULONG_BE(MK[1], key, 4); 110 | MK[2] = GET_ULONG_BE(MK[2], key, 8); 111 | MK[3] = GET_ULONG_BE(MK[3], key, 12); 112 | 113 | k[0] = MK[0] ^ FK[0] 114 | k[1] = MK[1] ^ FK[1] 115 | k[2] = MK[2] ^ FK[2] 116 | k[3] = MK[3] ^ FK[3] 117 | 118 | for (; i < 32; i++) { 119 | k[i + 4] = k[i] ^ (sm4CalciRK(k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ CK[i])) 120 | SK[i] = k[i + 4]; 121 | } 122 | } 123 | 124 | function sm4_one_round(sk, input, output) { 125 | var i = 0; 126 | var ulbuf = new Array(36); 127 | 128 | ulbuf[0] = GET_ULONG_BE(ulbuf[0], input, 0) 129 | ulbuf[1] = GET_ULONG_BE(ulbuf[1], input, 4) 130 | ulbuf[2] = GET_ULONG_BE(ulbuf[2], input, 8) 131 | ulbuf[3] = GET_ULONG_BE(ulbuf[3], input, 12) 132 | while (i < 32) { 133 | ulbuf[i + 4] = sm4F(ulbuf[i], ulbuf[i + 1], ulbuf[i + 2], ulbuf[i + 3], sk[i]); 134 | i++; 135 | } 136 | 137 | PUT_ULONG_BE(ulbuf[35], output, 0); 138 | PUT_ULONG_BE(ulbuf[34], output, 4); 139 | PUT_ULONG_BE(ulbuf[33], output, 8); 140 | PUT_ULONG_BE(ulbuf[32], output, 12); 141 | } 142 | 143 | function sm4_setkey_enc(ctx, key) { 144 | ctx.mode = SM4_ENCRYPT; 145 | sm4_setkey(ctx.sk, key); 146 | } 147 | 148 | function sm4_setkey_dec(ctx, key) { 149 | var i, j; 150 | ctx.mode = SM4_ENCRYPT; 151 | sm4_setkey(ctx.sk, key); 152 | for (i = 0; i < 16; i++) { 153 | j = ctx.sk[31 - i] 154 | ctx.sk[31 - i] = ctx.sk[i] 155 | ctx.sk[i] = j 156 | } 157 | } 158 | 159 | function sm4_crypt_ecb(ctx, mode, length, input, output) { 160 | var index = 0; 161 | while (length > 0) { 162 | var oneInput = input.slice(index, index + 16) 163 | var oneOutput = new Uint8Array(16) 164 | sm4_one_round(ctx.sk, oneInput, oneOutput); 165 | 166 | for (var i = 0; i < 16; i++) { 167 | output[index + i] = oneOutput[i] 168 | } 169 | index += 16; 170 | length -= 16; 171 | } 172 | } 173 | 174 | function sm4_crypt_cbc(ctx, mode, length, iv, input, output) { 175 | var i; 176 | var temp = new Array(16); 177 | var index = 0; 178 | 179 | if (mode == SM4_ENCRYPT) { 180 | while (length > 0) { 181 | var oneInput = input.slice(index, index + 16) 182 | var oneOutput = new Array(16) 183 | for (i = 0; i < 16; i++) { 184 | oneOutput[i] = oneInput[i] ^ iv[i] 185 | } 186 | 187 | sm4_one_round(ctx.sk, oneOutput, oneOutput); 188 | 189 | for (i = 0; i < 16; i++) { 190 | iv[i] = oneOutput[i] 191 | output[index + i] = oneOutput[i] 192 | } 193 | 194 | index += 16; 195 | length -= 16; 196 | } 197 | } else /* SM4_DECRYPT */ { 198 | while (length > 0) { 199 | var oneInput = input.slice(index, index + 16) 200 | var oneOutput = new Array(16) 201 | index += 16; 202 | for (i = 0; i < 16; i++) { 203 | temp[i] = oneInput[i] 204 | } 205 | 206 | sm4_one_round(ctx.sk, oneInput, oneOutput); 207 | 208 | for (i = 0; i < 16; i++) { 209 | oneOutput[i] = oneOutput[i] ^ iv[i] 210 | output[index + i] = oneOutput[i] 211 | } 212 | 213 | for (i = 0; i < 16; i++) { 214 | iv[i] = temp[i] 215 | } 216 | 217 | index += 16; 218 | length -= 16; 219 | } 220 | } 221 | } 222 | 223 | function strfix(str, len) { 224 | var length = len - str.length 225 | while (length-- > 0) { 226 | str = "0" + str 227 | } 228 | return str 229 | } 230 | 231 | function HEXStrXOR(str1, str2) { 232 | var buf1 = hex2Array(str1) 233 | var buf2 = hex2Array(str2) 234 | 235 | var result = '' 236 | for (var i = 0; i < 16; i++) { 237 | result += strfix((buf1[i] ^ buf2[i]).toString(16).toUpperCase(), 2) 238 | } 239 | 240 | return result 241 | } 242 | 243 | function hex2Array(str) { 244 | var len = str.length / 2, 245 | substr = '', 246 | result = new Array(len); 247 | for (var i = 0; i < len; i++) { 248 | substr = str.slice(2 * i, 2 * (i + 1)) 249 | result[i] = parseInt(substr, 16) || 0 250 | } 251 | return result 252 | } 253 | 254 | SM4.SM4CryptECB = function (szData, sCryptFlag, szSM4Key) { 255 | if (szSM4Key.length !== 32) { 256 | console.log("传入密钥[" + szSM4Key + "]长度不为32位"); 257 | return ""; 258 | } 259 | var len = szData.length 260 | var count = len % 32 261 | if (count !== 0) { 262 | count = 32 - count 263 | len += count 264 | while (count--) { 265 | szData += '0' 266 | } 267 | } 268 | 269 | var ctx = new sm4_context() 270 | var lpbKey = hex2Array(szSM4Key) 271 | if (sCryptFlag === SM4_ENCRYPT) { 272 | sm4_setkey_enc(ctx, lpbKey); //加密 273 | } else { 274 | sm4_setkey_dec(ctx, lpbKey); //解密 275 | } 276 | 277 | var lpbData = hex2Array(szData) 278 | var pbyCryptResult = new Array(len / 2) 279 | sm4_crypt_ecb(ctx, sCryptFlag, len / 2, lpbData, pbyCryptResult) 280 | var szResult = '' 281 | for (var i = 0; i < len / 2; i++) { 282 | szResult += strfix(pbyCryptResult[i].toString(16), 2).toUpperCase() 283 | } 284 | 285 | return szResult; 286 | } 287 | 288 | SM4.SM4MACGenerated = function (szData, szSM4Key) { 289 | if (szSM4Key.length !== 32) { 290 | console.log("传入密钥[" + szSM4Key + "]长度不为32位"); 291 | return ""; 292 | } 293 | var len = szData.length 294 | var count = Math.floor(len / 32) 295 | if (len % 32 !== 0) { 296 | count += 1; 297 | var dvalue = count * 32 - len 298 | while (dvalue--) szData += '0'; 299 | len = count * 32 300 | } 301 | 302 | var szResult = '', macString = ''; 303 | for (var i = 0; i < count; i++) { 304 | macString = szData.slice(32 * i, 32 * (i + 1)) 305 | if (i > 0) { 306 | macString = HEXStrXOR(macString, szResult); 307 | } 308 | szResult = SM4.SM4CryptECB(macString, 1, szSM4Key); 309 | } 310 | return szResult 311 | } 312 | })(); 313 | 314 | let m = SM4.SM4CryptECB("123456", "123456", "12345678901234567890123456789001"); 315 | console.log(m, m == "C00D998041758B8103432D5D42BB5C34") 316 | 317 | try { 318 | module.exports = SM4 319 | } catch (error) { 320 | 321 | } -------------------------------------------------------------------------------- /test/output.js: -------------------------------------------------------------------------------- 1 | (function interpreter(parentScope, index, stack, constantPool, bytecode, option = {}, args) { 2 | let localScope = {}; 3 | localScope[constantPool[0]] = option.t || this; 4 | localScope[constantPool[1]] = args; 5 | if (option.n) localScope[option.n] = parentScope[option.f]; 6 | localScope.__proto__ = parentScope; 7 | function getScope(scope, name) { 8 | if (!scope || name == constantPool[2]) return null; 9 | if (scope.hasOwnProperty(name)) return scope; 10 | return getScope(Object.getPrototypeOf(scope), name); 11 | } 12 | if (option.e) { 13 | localScope[constantPool[bytecode[index + 1]]] = option.e; 14 | } 15 | while (index < bytecode.length) { 16 | let t0, t1, t2, t3, t4, t5; 17 | let instruction = bytecode[index++]; 18 | if (instruction == 3) { 19 | t0 = bytecode[index++]; 20 | t1 = constantPool[t0]; 21 | localScope[t1] = undefined; 22 | } 23 | if (instruction == 13) { 24 | stack.push(window); 25 | } 26 | if (instruction == 19) { 27 | t2 = bytecode[index++]; 28 | t3 = bytecode[index++]; 29 | t4 = bytecode[index++]; 30 | t5 = bytecode[index++]; 31 | try { 32 | t1 = interpreter(localScope, t3, stack, constantPool, bytecode, { 33 | t: localScope[constantPool[0]] 34 | }); 35 | if (t1 > 0) { 36 | if (option.r) { 37 | return stack.pop(); 38 | } 39 | return t1; 40 | } 41 | } catch (e) { 42 | t1 = interpreter(localScope, t4, stack, constantPool, bytecode, { 43 | t: localScope[constantPool[0]], 44 | e: e 45 | }); 46 | if (t1 > 0) { 47 | if (option.r) { 48 | return stack.pop(); 49 | } 50 | return t1; 51 | } 52 | } finally { 53 | t1 = interpreter(localScope, t5, stack, constantPool, bytecode, { 54 | t: localScope[constantPool[0]] 55 | }); 56 | if (t1 > 0) { 57 | if (option.r) { 58 | return stack.pop(); 59 | } 60 | return t1; 61 | } 62 | } 63 | index = t2; 64 | } 65 | if (instruction == 12) { 66 | stack.push(localScope); 67 | } 68 | if (instruction == 16) { 69 | return; 70 | } 71 | if (instruction == 28) { 72 | stack.push({}); 73 | } 74 | if (instruction == 14) { 75 | t0 = bytecode[index++]; 76 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, { 77 | t: localScope[constantPool[0]] 78 | }); 79 | if (t1 === undefined) { 80 | index = t0; 81 | } else { 82 | if (option.r) { 83 | return stack.pop(); 84 | } 85 | return t1; 86 | } 87 | } 88 | if (instruction == 27) { 89 | t0 = stack.pop(); 90 | t1 = typeof t0; 91 | t5 = bytecode[index++]; 92 | if (t5) stack.push(t1); 93 | } 94 | if (instruction == 58) { 95 | t0 = stack.pop(); 96 | t1 = !t0; 97 | t5 = bytecode[index++]; 98 | if (t5) stack.push(t1); 99 | } 100 | if (instruction == 32) { 101 | t0 = stack.pop(); 102 | t1 = void t0; 103 | t5 = bytecode[index++]; 104 | if (t5) stack.push(t1); 105 | } 106 | if (instruction == 30) { 107 | t0 = bytecode[index++]; 108 | t1 = []; 109 | for (t2 = 0; t2 < t0; t2++) { 110 | t3 = stack.pop(); 111 | t1.unshift(t3); 112 | } 113 | t5 = bytecode[index++]; 114 | if (t5) stack.push(t1); 115 | } 116 | if (instruction == 11) { 117 | if (option.r) { 118 | return stack.pop(); 119 | } 120 | return bytecode[index++]; 121 | } 122 | if (instruction == 8) { 123 | t0 = stack.pop(); 124 | t1 = stack.pop(); 125 | t2 = bytecode[index++]; 126 | if (t1 == -1) t1 = t2; 127 | t1 = t0[t1]; 128 | index = t1; 129 | } 130 | if (instruction == 57) { 131 | t0 = stack.pop(); 132 | t1 = ~t0; 133 | t5 = bytecode[index++]; 134 | if (t5) stack.push(t1); 135 | } 136 | if (instruction == 23) { 137 | t0 = stack.pop(); 138 | t1 = stack.pop(); 139 | t3 = new RegExp(t1, t0); 140 | stack.push(t3); 141 | } 142 | if (instruction == 31) { 143 | t0 = stack.pop(); 144 | t1 = stack.pop(); 145 | t2 = bytecode[index++]; 146 | args = []; 147 | for (t3 = 0; t3 < t2; t3++) args.unshift(stack.pop()); 148 | t4 = new t1[t0](...args); 149 | t5 = bytecode[index++]; 150 | if (t5) stack.push(t4); 151 | } 152 | if (instruction == undefined) { 153 | throw new Error("当前指令不存在,请检查指令集!"); 154 | } 155 | if (instruction == 5) { 156 | t0 = constantPool[bytecode[index++]]; 157 | t1 = localScope; 158 | t2 = t1[t0]; 159 | t5 = bytecode[index++]; 160 | if (t5) stack.push(t2); 161 | } 162 | if (instruction == 2) { 163 | t0 = bytecode[index++]; 164 | t1 = stack.pop(); 165 | t2 = stack.pop(); 166 | args = []; 167 | for (t3 = 0; t3 < t0; t3++) args.unshift(stack.pop()); 168 | if (t2 === 0) { 169 | t4 = t1.apply(localScope, args); 170 | } else { 171 | t4 = t2[t1].apply(t2, args); 172 | } 173 | t5 = bytecode[index++]; 174 | if (t5) stack.push(t4); 175 | } 176 | if (instruction == 15) { 177 | t0 = bytecode[index++]; 178 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, { 179 | t: localScope[constantPool[0]] 180 | }); 181 | if (!t1) { 182 | index = t0; 183 | } else { 184 | if (t1 === 1) { 185 | return; 186 | } else { 187 | if (option.r) { 188 | return stack.pop(); 189 | } 190 | return t1; 191 | } 192 | } 193 | } 194 | if (33 < instruction && instruction < 57) { 195 | t0 = stack.pop(); 196 | t1 = stack.pop(); 197 | if (instruction == 45) { 198 | t2 = t1 == t0; 199 | } 200 | if (instruction == 40) { 201 | t2 = t1 || t0; 202 | } 203 | if (instruction == 44) { 204 | t2 = t1 <= t0; 205 | } 206 | if (instruction == 51) { 207 | t2 = t1 + t0; 208 | } 209 | if (instruction == 54) { 210 | t2 = t1 / t0; 211 | } 212 | if (instruction == 39) { 213 | t2 = t1 | t0; 214 | } 215 | if (instruction == 48) { 216 | t2 = t1 !== t0; 217 | } 218 | if (instruction == 35) { 219 | t2 = t1 in t0; 220 | } 221 | if (instruction == 43) { 222 | t2 = t1 >= t0; 223 | } 224 | if (instruction == 47) { 225 | t2 = t1 === t0; 226 | } 227 | if (instruction == 55) { 228 | t2 = t1 % t0; 229 | } 230 | if (instruction == 41) { 231 | t2 = t1 & t0; 232 | } 233 | if (instruction == 56) { 234 | t2 = t1 ^ t0; 235 | } 236 | if (instruction == 46) { 237 | t2 = t1 != t0; 238 | } 239 | if (instruction == 37) { 240 | t2 = t1 >> t0; 241 | } 242 | if (instruction == 38) { 243 | t2 = t1 << t0; 244 | } 245 | if (instruction == 34) { 246 | t2 = t1 instanceof t0; 247 | } 248 | if (instruction == 50) { 249 | t2 = t1 > t0; 250 | } 251 | if (instruction == 36) { 252 | t2 = t1 >>> t0; 253 | } 254 | if (instruction == 53) { 255 | t2 = t1 * t0; 256 | } 257 | if (instruction == 42) { 258 | t2 = t1 && t0; 259 | } 260 | if (instruction == 49) { 261 | t2 = t1 < t0; 262 | } 263 | if (instruction == 52) { 264 | t2 = t1 - t0; 265 | } 266 | t3 = bytecode[index++]; 267 | if (t3) stack.push(t2); 268 | } 269 | if (instruction == 29) { 270 | t0 = stack.pop(); 271 | t1 = stack.pop(); 272 | t2 = stack.pop(); 273 | t2[t1] = t0; 274 | t5 = bytecode[index++]; 275 | if (t5) stack.push(t2); 276 | } 277 | if (instruction == 0) { 278 | t0 = stack.pop(); 279 | t1 = stack.pop(); 280 | t2 = stack.pop(); 281 | t4 = bytecode[index++]; 282 | t3 = getScope(t1, t0) || t1; 283 | t3[t0] = t2; 284 | if (t4) stack.push(t2); 285 | } 286 | if (instruction == 6) { 287 | t0 = bytecode[index++]; 288 | index = t0; 289 | } 290 | if (instruction == 26) { 291 | t0 = bytecode[index++]; 292 | t1 = stack.pop(); 293 | t2 = stack.pop(); 294 | t3 = getScope(t2, t1) || t2; 295 | t4 = !t0 ? t3[t1]-- : --t3[t1]; 296 | t5 = bytecode[index++]; 297 | if (t5) stack.push(t4); 298 | } 299 | if (instruction == 24) { 300 | debugger; 301 | } 302 | if (instruction == 18) { 303 | t0 = stack.pop(); 304 | t0 = Number(t0); 305 | if (t0 == NaN) t0 = -1; 306 | stack.push(t0); 307 | } 308 | if (instruction == 4) { 309 | t0 = bytecode[index++]; 310 | stack.push(constantPool[t0]); 311 | } 312 | if (instruction == 1) { 313 | t0 = stack.pop(); 314 | t1 = stack.pop(); 315 | t5 = bytecode[index++]; 316 | if (t5) stack.push(t1[t0]); 317 | } 318 | if (instruction == 20) { 319 | throw stack.pop(); 320 | } 321 | if (instruction == 21) { 322 | stack.push(`${stack.pop()}`); 323 | } 324 | if (instruction == 25) { 325 | t0 = bytecode[index++]; 326 | t1 = stack.pop(); 327 | t2 = stack.pop(); 328 | t3 = getScope(t2, t1) || t2; 329 | t4 = !t0 ? t3[t1]++ : ++t3[t1]; 330 | t5 = bytecode[index++]; 331 | if (t5) stack.push(t4); 332 | } 333 | if (instruction == 17) { 334 | t0 = bytecode[index++]; 335 | t1 = stack.pop(); 336 | for (t2 = 0; t2 < t0; t2++) stack.pop(); 337 | t5 = bytecode[index++]; 338 | if (t5) stack.push(t1); 339 | } 340 | if (instruction == 33) { 341 | t0 = stack.pop(); 342 | t1 = stack.pop(); 343 | t2 = delete t1[t0]; 344 | t5 = bytecode[index++]; 345 | if (t5) stack.push(t2); 346 | } 347 | if (instruction == 10) { 348 | t0 = bytecode[index++]; 349 | if (!args) args = [].concat(stack); 350 | for (t1 = t0; t1 >= 0; t1--) { 351 | t2 = stack.pop(); 352 | localScope[t2] = args[t1]; 353 | } 354 | } 355 | if (instruction == 9) { 356 | t0 = stack.pop(); 357 | t1 = bytecode[index++]; 358 | t2 = bytecode[index++]; 359 | t3 = stack[stack.length - 1]; 360 | t4 = function () { 361 | return interpreter(localScope, t1, stack, constantPool, bytecode, { 362 | t: this, 363 | n: t0, 364 | f: t0 || t3, 365 | r: 1 366 | }, arguments); 367 | }; 368 | if (t2) { 369 | stack.push(t4); 370 | } else { 371 | localScope[t0] = t4; 372 | } 373 | } 374 | if (instruction == 22) { 375 | t0 = bytecode[index++]; 376 | t2 = ""; 377 | for (t1 = 0; t1 < t0; t1++) { 378 | t2 += stack.pop(); 379 | } 380 | t5 = bytecode[index++]; 381 | if (t5) stack.push(t2); 382 | } 383 | if (instruction == 7) { 384 | t0 = stack.pop(); 385 | t1 = bytecode[index++]; 386 | if (!t0) index = t1; 387 | } 388 | } 389 | })(typeof window !== 'undefined' ? window : (window = global, window), 0, [],["@faceless","arguments","__proto__","a","b","_faceless_all_keys","o","_keys","l",1,"Object","keys","concat","length",0,"console","log",2,3,"c","d","arr","pro","e",4,"_F_i","_F_li","element","set","Set","_F_iterator","Symbol","iterator","next","done","value","str","Hello","char",123,"x"], [3,3,3,4,4,5,9,11,0,6,117,4,6,10,0,3,7,30,0,1,12,4,7,0,0,3,8,14,111,15,108,4,9,7,106,5,6,1,12,4,10,1,1,4,11,2,1,1,12,4,8,0,0,5,8,1,12,4,7,1,1,4,12,2,1,1,12,4,7,0,0,12,4,6,1,1,4,2,1,1,12,4,6,0,0,12,4,8,1,1,4,13,1,1,58,1,7,105,14,103,11,1,16,6,105,16,11,1,6,29,16,5,7,1,11,2,16,28,4,3,4,14,29,1,4,4,4,9,29,1,4,3,1,1,12,4,3,0,1,17,0,0,28,4,3,4,14,29,1,4,4,4,9,29,1,4,4,1,1,12,4,4,0,1,17,0,0,5,3,1,5,4,1,12,4,15,1,1,4,16,2,2,0,4,17,4,18,30,2,1,4,14,1,1,13,4,19,0,0,4,17,4,18,30,2,1,4,9,1,1,13,4,20,0,0,5,19,1,5,20,1,12,4,15,1,1,4,16,2,2,0,3,21,28,4,3,4,14,29,1,4,4,4,9,29,1,4,19,4,17,29,1,12,4,21,0,0,3,22,28,4,20,4,18,29,1,4,23,4,24,29,1,12,4,22,0,0,5,22,1,12,4,21,1,1,4,2,0,0,14,378,3,25,4,14,12,4,25,0,0,3,26,5,21,1,12,4,5,2,1,1,12,4,26,0,0,15,369,5,25,1,12,4,26,1,1,4,13,1,1,49,1,7,367,3,27,12,4,26,1,1,12,4,25,1,1,1,1,12,4,27,0,0,5,27,1,12,4,15,1,1,4,16,2,1,0,16,11,1,12,4,25,25,0,0,6,316,16,3,28,4,9,4,17,4,18,30,3,1,12,4,29,31,1,1,12,4,28,0,0,14,508,3,30,12,4,28,1,1,12,4,31,1,1,4,32,1,1,2,0,1,12,4,30,0,0,3,25,12,4,30,1,1,4,33,2,0,1,12,4,25,0,0,15,490,12,4,25,1,1,4,34,1,1,58,1,7,488,3,27,12,4,25,1,1,4,35,1,1,12,4,27,0,0,5,27,1,12,4,15,1,1,4,16,2,1,0,16,11,1,12,4,30,1,1,4,33,2,0,1,12,4,25,0,0,6,443,16,3,36,4,37,12,4,36,0,0,14,625,3,30,12,4,36,1,1,12,4,31,1,1,4,32,1,1,2,0,1,12,4,30,0,0,3,25,12,4,30,1,1,4,33,2,0,1,12,4,25,0,0,15,607,12,4,25,1,1,4,34,1,1,58,1,7,605,3,38,12,4,25,1,1,4,35,1,1,12,4,38,0,0,5,38,1,12,4,15,1,1,4,16,2,1,0,16,11,1,12,4,30,1,1,4,33,2,0,1,12,4,25,0,0,6,560,16,4,39,4,14,4,14,4,14,4,14,9,640,1,6,658,4,40,10,0,5,40,1,12,4,15,1,1,4,16,2,1,0,16,17,2,1,2,1,0]) -------------------------------------------------------------------------------- /tools/dump.js: -------------------------------------------------------------------------------- 1 | // path:/pass/MD5.js MD5反编译示例 2 | require("../tools/babelPlugins"); 3 | let body = []; 4 | (function interpreter(parentScope, index, stack, constantPool, bytecode, option = {}, args, body, params, isIf) { 5 | let localScope = {}; 6 | localScope[constantPool[0]] = option.t || this; 7 | localScope[constantPool[1]] = args; 8 | if (option.n) localScope[option.n] = parentScope[option.f]; 9 | localScope.__proto__ = parentScope; 10 | 11 | function getScope(scope, name) { 12 | if (!scope || name == constantPool[2]) return null; 13 | if (scope.hasOwnProperty(name)) return scope; 14 | return getScope(Object.getPrototypeOf(scope), name); 15 | } 16 | 17 | if (option.e) { 18 | localScope[constantPool[bytecode[index + 1]]] = option.e; 19 | } 20 | 21 | while (index < bytecode.length) { 22 | let t0, t1, t2, t3, t4, t5; 23 | let instruction = bytecode[index++]; 24 | if ([4, 9, 6, 12, 1, 2, 3, 0, 5, 10, 7, 17, 14, 15, 16, 25, 11, 18, 57].indexOf(instruction) === -1) { 25 | if (!(33 < instruction && instruction < 57)) { 26 | console.log("未反编译指令", instruction) 27 | debugger 28 | } 29 | } 30 | 31 | if (instruction == 4) { 32 | t0 = bytecode[index++]; 33 | stack.push(types.valueToNode(constantPool[t0])); 34 | } 35 | if (instruction == 58) { 36 | t0 = stack.pop(); 37 | t1 = !t0; 38 | t5 = bytecode[index++]; 39 | if (t5) stack.push(t1); 40 | } 41 | if (instruction == 3) { 42 | t0 = bytecode[index++]; 43 | t1 = constantPool[t0]; 44 | localScope[t1] = undefined; 45 | body.push(types.VariableDeclaration("var", [ 46 | types.VariableDeclarator(types.Identifier(t1), null) 47 | ])) 48 | } 49 | if (instruction == 27) { 50 | t0 = stack.pop(); 51 | t1 = typeof t0; 52 | t5 = bytecode[index++]; 53 | if (t5) stack.push(t1); 54 | } 55 | if (33 < instruction && instruction < 57) { 56 | t0 = stack.pop(); 57 | t1 = stack.pop(); 58 | if (instruction == 45) { 59 | t2 = t1 == t0; 60 | t2 = types.BinaryExpression("==", t1, t0) 61 | } 62 | if (instruction == 42) { 63 | t2 = t1 && t0; 64 | t2 = types.BinaryExpression("&&", t1, t0) 65 | } 66 | if (instruction == 56) { 67 | t2 = t1 ^ t0; 68 | t2 = types.BinaryExpression("^", t1, t0) 69 | } 70 | if (instruction == 54) { 71 | t2 = t1 / t0; 72 | t2 = types.BinaryExpression("/", t1, t0) 73 | } 74 | if (instruction == 48) { 75 | t2 = t1 !== t0; 76 | t2 = types.BinaryExpression("!==", t1, t0) 77 | } 78 | if (instruction == 38) { 79 | t2 = t1 << t0; 80 | t2 = types.BinaryExpression("<<", t1, t0) 81 | } 82 | if (instruction == 53) { 83 | t2 = t1 * t0; 84 | t2 = types.BinaryExpression("*", t1, t0) 85 | } 86 | if (instruction == 51) { 87 | t2 = t1 + t0; 88 | t2 = types.BinaryExpression("+", t1, t0) 89 | } 90 | if (instruction == 40) { 91 | t2 = t1 || t0; 92 | t2 = types.BinaryExpression("||", t1, t0) 93 | } 94 | if (instruction == 43) { 95 | t2 = t1 >= t0; 96 | t2 = types.BinaryExpression(">=", t1, t0) 97 | } 98 | if (instruction == 39) { 99 | t2 = t1 | t0; 100 | t2 = types.BinaryExpression("|", t1, t0) 101 | } 102 | if (instruction == 49) { 103 | t2 = t1 < t0; 104 | t2 = types.BinaryExpression("<", t1, t0) 105 | } 106 | if (instruction == 44) { 107 | t2 = t1 <= t0; 108 | t2 = types.BinaryExpression("<=", t1, t0) 109 | } 110 | if (instruction == 37) { 111 | t2 = t1 >> t0; 112 | t2 = types.BinaryExpression(">>", t1, t0) 113 | } 114 | if (instruction == 55) { 115 | t2 = t1 % t0; 116 | t2 = types.BinaryExpression("%", t1, t0) 117 | } 118 | if (instruction == 41) { 119 | t2 = t1 & t0; 120 | t2 = types.BinaryExpression("&", t1, t0) 121 | } 122 | if (instruction == 46) { 123 | t2 = t1 != t0; 124 | t2 = types.BinaryExpression("!=", t1, t0) 125 | } 126 | if (instruction == 52) { 127 | t2 = t1 - t0; 128 | t2 = types.BinaryExpression("-", t1, t0) 129 | } 130 | if (instruction == 36) { 131 | t2 = t1 >>> t0; 132 | t2 = types.BinaryExpression(">>>", t1, t0) 133 | } 134 | if (instruction == 47) { 135 | t2 = t1 === t0; 136 | t2 = types.BinaryExpression("===", t1, t0) 137 | } 138 | if (instruction == 50) { 139 | t2 = t1 > t0; 140 | t2 = types.BinaryExpression(">", t1, t0) 141 | } 142 | if (instruction == 35) { 143 | t2 = t1 in t0; 144 | t2 = types.BinaryExpression("in", t1, t0) 145 | } 146 | if (instruction == 34) { 147 | t2 = t1 instanceof t0; 148 | t2 = types.BinaryExpression("instanceof", t1, t0) 149 | } 150 | t3 = bytecode[index++]; 151 | if (t3) stack.push(t2); 152 | } 153 | if (instruction == 23) { 154 | t0 = stack.pop(); 155 | t1 = stack.pop(); 156 | t3 = new RegExp(t1, t0); 157 | stack.push(t3); 158 | } 159 | if (instruction == 6) { 160 | t0 = bytecode[index++]; 161 | index = t0; 162 | } 163 | if (instruction == 22) { 164 | t0 = bytecode[index++]; 165 | t2 = ""; 166 | for (t1 = 0; t1 < t0; t1++) { 167 | t2 += stack.pop(); 168 | } 169 | t5 = bytecode[index++]; 170 | if (t5) stack.push(t2); 171 | } 172 | if (instruction == 32) { 173 | t0 = stack.pop(); 174 | t1 = void t0; 175 | t5 = bytecode[index++]; 176 | if (t5) stack.push(t1); 177 | } 178 | if (instruction == 24) { 179 | debugger; 180 | } 181 | if (instruction == 19) { 182 | t2 = bytecode[index++]; 183 | t3 = bytecode[index++]; 184 | t4 = bytecode[index++]; 185 | t5 = bytecode[index++]; 186 | try { 187 | t1 = interpreter(localScope, t3, stack, constantPool, bytecode, { 188 | t: localScope[constantPool[0]] 189 | }, undefined, body, params, isIf); 190 | if (t1 > 0) { 191 | if (option.r) { 192 | return stack.pop(); 193 | } 194 | return t1; 195 | } 196 | } catch (e) { 197 | t1 = interpreter(localScope, t4, stack, constantPool, bytecode, { 198 | t: localScope[constantPool[0]], 199 | e: e 200 | }, undefined, body, params, isIf); 201 | if (t1 > 0) { 202 | if (option.r) { 203 | return stack.pop(); 204 | } 205 | return t1; 206 | } 207 | } finally { 208 | t1 = interpreter(localScope, t5, stack, constantPool, bytecode, { 209 | t: localScope[constantPool[0]] 210 | }, undefined, body, params, isIf); 211 | if (t1 > 0) { 212 | if (option.r) { 213 | return stack.pop(); 214 | } 215 | return t1; 216 | } 217 | } 218 | index = t2; 219 | } 220 | 221 | if (instruction == 0) { 222 | t0 = stack.pop(); 223 | t1 = stack.pop(); 224 | t2 = stack.pop(); 225 | t4 = bytecode[index++]; 226 | t3 = getScope(t1, t0) || t1; 227 | t5 = t0.value ? types.Identifier(t0.value) : t0; 228 | if (types.isBinaryExpression(t0)) { 229 | t0 = types.MemberExpression(t3, t5, true) 230 | } 231 | body.push(types.ExpressionStatement(types.AssignmentExpression("=", t0.type && !t0.value ? t0 : types.Identifier(t0.value), t2))); 232 | if (t4) stack.push(t5); 233 | } 234 | if (instruction == 9) { 235 | t0 = stack.pop(); 236 | t1 = bytecode[index++]; 237 | t2 = bytecode[index++]; 238 | t3 = stack[stack.length - 1]; 239 | let _params = []; 240 | let _body = []; 241 | t4 = (function () { 242 | return interpreter(localScope, t1, stack, constantPool, bytecode, { 243 | t: this, 244 | n: t0, 245 | f: t0 || t3, 246 | r: 1, 247 | }, arguments, _body, _params, isIf); 248 | })(); 249 | _body.push(types.ReturnStatement(t4)) 250 | t4 = types.FunctionExpression(null, _params, types.BlockStatement(_body)); 251 | if (t2) { 252 | stack.push(t4); 253 | } else { 254 | localScope[t0.value] = t4; 255 | body.push(types.ExpressionStatement(types.AssignmentExpression("=", types.Identifier(t0.value), t4))) 256 | } 257 | } 258 | if (instruction == undefined) { 259 | throw new Error("当前指令不存在,请检查指令集!"); 260 | } 261 | if (instruction == 57) { 262 | t0 = stack.pop(); 263 | // t1 = ~t0; 264 | t1 = types.UnaryExpression("~", typeof t0.value == "number" || types.isIdentifier(t0) ? t0 : types.Identifier(t0.value)) 265 | t5 = bytecode[index++]; 266 | if (t5) stack.push(t1); 267 | } 268 | if (instruction == 25) { 269 | t0 = bytecode[index++]; 270 | t1 = stack.pop(); 271 | t2 = stack.pop(); 272 | t3 = getScope(t2, t1) || t2; 273 | if (t3.type) { 274 | t1 = types.MemberExpression(t3, types.Identifier(t1.value)) 275 | } else { 276 | t1 = types.Identifier(t1.value) 277 | } 278 | t4 = types.UpdateExpression("++", t1, Boolean(t0)) 279 | t5 = bytecode[index++]; 280 | if (t5) { 281 | stack.push(t4) 282 | } 283 | body.push(types.ExpressionStatement(t4)) 284 | } 285 | if (instruction == 2) { 286 | t0 = bytecode[index++]; 287 | t1 = stack.pop(); 288 | t2 = stack.pop(); 289 | args = []; 290 | for (t3 = 0; t3 < t0; t3++) args.unshift(stack.pop()); 291 | let callee = t1; 292 | if (t2 === 0) { 293 | // t4 = t1.apply(localScope, args); 294 | callee = types.Identifier(t1.value) 295 | } else { 296 | // t4 = t2[t1].apply(t2, args); 297 | if (t2.type) { 298 | callee = types.MemberExpression(t2.type === "Identifier" ? t2 : types.Identifier(t2.value), t1, true) 299 | } else { 300 | callee = types.Identifier(t1.value) 301 | } 302 | } 303 | t4 = types.CallExpression(callee, args); 304 | t5 = bytecode[index++]; 305 | if (t5) stack.push(t4); else body.push(types.ExpressionStatement(t4)); 306 | } 307 | if (instruction == 20) { 308 | throw stack.pop(); 309 | } 310 | if (instruction == 10) { 311 | t0 = bytecode[index++]; 312 | if (!args) args = [].concat(stack); 313 | for (t1 = t0; t1 >= 0; t1--) { 314 | t2 = stack.pop(); 315 | localScope[t2.value] = args[t1]; 316 | params.unshift(types.Identifier(t2.value)) 317 | } 318 | } 319 | if (instruction == 29) { 320 | t0 = stack.pop(); 321 | t1 = stack.pop(); 322 | t2 = stack.pop(); 323 | t2[t1] = t0; 324 | t5 = bytecode[index++]; 325 | if (t5) stack.push(t2); 326 | } 327 | if (instruction == 16) { 328 | return; 329 | } 330 | if (instruction == 1) { 331 | t0 = stack.pop(); 332 | t1 = stack.pop(); 333 | t5 = bytecode[index++]; 334 | if (!t1.type) { // 判断是否是ast节点 335 | t2 = types.Identifier(t0.value) 336 | } else { 337 | t2 = types.MemberExpression(t1, t0, true) 338 | } 339 | if (t5) stack.push(t2); 340 | } 341 | if (instruction == 12) { 342 | stack.push(localScope); 343 | } 344 | if (instruction == 17) { 345 | t0 = bytecode[index++]; 346 | t1 = stack.pop(); 347 | for (t2 = 0; t2 < t0; t2++) stack.pop(); 348 | t5 = bytecode[index++]; 349 | if (t5) stack.push(t1); 350 | } 351 | if (instruction == 28) { 352 | stack.push({}); 353 | } 354 | if (instruction == 7) { 355 | t0 = stack.pop(); 356 | t1 = bytecode[index++]; 357 | let block1 = [], block2 = []; 358 | t3 = interpreter(localScope, index, stack, constantPool, bytecode, option, undefined, block1, params, isIf) 359 | t2 = interpreter(localScope, t1, stack, constantPool, bytecode, option, undefined, block2, params, isIf) 360 | if (!block2.length && t2) { 361 | if (!isIf) { 362 | t2 = interpreter(localScope, t1 + 2, stack, constantPool, bytecode, option, undefined, block2, [], 1) 363 | } 364 | if (block2.length) { 365 | body.push(types.ForStatement(null, t0, block2[0].expression, types.BlockStatement(block1))) 366 | } 367 | index = t1; 368 | } else { 369 | body.push(types.IfStatement(t0, types.BlockStatement(block1), block2.length ? types.BlockStatement(block2) : null)) 370 | if (t2 === undefined) { 371 | index = t1; 372 | } else { 373 | return t2; 374 | } 375 | } 376 | } 377 | if (instruction == 21) { 378 | stack.push(`${stack.pop()}`); 379 | } 380 | if (instruction == 5) { 381 | t0 = constantPool[bytecode[index++]]; 382 | t1 = localScope; 383 | // t2 = t1[t0]; 384 | t2 = types.Identifier(t0) 385 | t5 = bytecode[index++]; 386 | if (t5) stack.push(t2); 387 | } 388 | if (instruction == 33) { 389 | t0 = stack.pop(); 390 | t1 = stack.pop(); 391 | t2 = delete t1[t0]; 392 | t5 = bytecode[index++]; 393 | if (t5) stack.push(t2); 394 | } 395 | if (instruction == 13) { 396 | stack.push(window); 397 | } 398 | if (instruction == 26) { 399 | t0 = bytecode[index++]; 400 | t1 = stack.pop(); 401 | t2 = stack.pop(); 402 | t3 = getScope(t2, t1) || t2; 403 | t4 = !t0 ? t3[t1]-- : --t3[t1]; 404 | t5 = bytecode[index++]; 405 | if (t5) stack.push(t4); 406 | } 407 | if (instruction == 18) { 408 | t0 = stack.pop(); 409 | // t0 = Number(t0); 410 | // if (t0 == NaN) t0 = -1; 411 | stack.push(t0); 412 | } 413 | if (instruction == 14) { 414 | t0 = bytecode[index++]; 415 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, { 416 | t: localScope[constantPool[0]] 417 | }, undefined, body, params, isIf); 418 | if (t1 === undefined) { 419 | index = t0; 420 | } else { 421 | if (option.r) { 422 | return stack.pop(); 423 | } 424 | return t1; 425 | } 426 | } 427 | if (instruction == 31) { 428 | t0 = stack.pop(); 429 | t1 = stack.pop(); 430 | t2 = bytecode[index++]; 431 | args = []; 432 | for (t3 = 0; t3 < t2; t3++) args.unshift(stack.pop()); 433 | t4 = new t1[t0](...args); 434 | t5 = bytecode[index++]; 435 | if (t5) stack.push(t4); 436 | } 437 | if (instruction == 11) { 438 | if (option.r) { 439 | return stack.pop(); 440 | } 441 | return bytecode[index++]; 442 | } 443 | if (instruction == 8) { 444 | t0 = stack.pop(); 445 | t1 = stack.pop(); 446 | t2 = bytecode[index++]; 447 | if (t1 == -1) t1 = t2; 448 | t1 = t0[t1]; 449 | index = t1; 450 | } 451 | if (instruction == 30) { 452 | t0 = bytecode[index++]; 453 | t1 = []; 454 | for (t2 = 0; t2 < t0; t2++) { 455 | t3 = stack.pop(); 456 | t1.unshift(t3); 457 | } 458 | t5 = bytecode[index++]; 459 | if (t5) stack.push(t1); 460 | } 461 | if (instruction == 15) { 462 | t0 = bytecode[index++]; 463 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, { 464 | t: localScope[constantPool[0]] 465 | }, undefined, body, params, isIf); 466 | if (!t1) { 467 | index = t0; 468 | } else { 469 | if (t1 === 1) { 470 | return; 471 | } else { 472 | if (option.r) { 473 | return stack.pop(); 474 | } 475 | return t1; 476 | } 477 | } 478 | } 479 | } 480 | })(typeof window !== 'undefined' ? window : (window = global, window), 0, [], 481 | ["@faceless", "arguments", "__proto__", "toMd5Hex", "text", "hexcase", "chrsz", "binl2hex", "binarray", "hex_tab", "str", "i", "0123456789ABCDEF", "0123456789abcdef", "", 0, "length", 4, 2, 8, 15, "charAt", "str2binl", "bin", "mask", "Array", 1, 5, "charCodeAt", 32, "bit_rol", "num", "cnt", "safe_add", "x", "y", "lsw", "msw", 65535, 16, "md5_ii", "a", "b", "c", "d", "s", "t", "md5_cmn", "md5_hh", "md5_gg", "md5_ff", "q", "core_md5", "len", "olda", "oldb", "oldc", "oldd", 128, 64, 9, 14, 1732584193, 271733879, 1732584194, 271733878, 7, 680876936, 12, 389564586, 17, 606105819, 3, 22, 1044525330, 176418897, 1200080426, 6, 1473231341, 45705983, 1770035416, 1958414417, 10, 42063, 11, 1990404162, 1804603682, 13, 40341101, 1502002290, 1236535329, 165796510, 1069501632, 643717713, 20, 373897302, 701558691, 38016083, 660478335, 405537848, 568446438, 1019803690, 187363961, 1163531501, 1444681467, 51403784, 1735328473, 1926607734, 378558, 2022574463, 1839030562, 23, 35309556, 1530992060, 1272893353, 155497632, 1094730640, 681279174, 358537222, 722521979, 76029189, 640364487, 421815835, 530742520, 995338651, 198630844, 1126891415, 1416354905, 21, 57434055, 1700485571, 1894986606, 1051523, 2054922799, 1873313359, 30611744, 1560198380, 1309151649, 145523070, 1120210379, 718787259, 343485551, "执行耗时", "console", "time", "123456", "e10adc3949ba59abbe56e057f20f883e", "log", "timeEnd"], 482 | [4, 3, 9, 7, 0, 6, 4033, 4, 4, 10, 0, 3, 5, 3, 6, 4, 7, 9, 22, 0, 6, 211, 4, 8, 10, 0, 3, 9, 3, 10, 3, 11, 5, 5, 1, 7, 41, 4, 12, 6, 43, 4, 13, 12, 4, 9, 0, 1, 17, 0, 0, 4, 14, 12, 4, 10, 0, 1, 17, 0, 0, 14, 205, 4, 15, 12, 4, 11, 0, 1, 17, 0, 0, 15, 196, 5, 11, 1, 12, 4, 8, 1, 1, 4, 16, 1, 1, 4, 17, 53, 1, 49, 1, 7, 194, 5, 10, 1, 12, 4, 8, 1, 1, 5, 11, 1, 4, 18, 37, 1, 1, 1, 5, 11, 1, 4, 17, 55, 1, 4, 19, 53, 1, 4, 17, 51, 1, 37, 1, 4, 20, 41, 1, 12, 4, 9, 1, 1, 4, 21, 2, 1, 1, 12, 4, 8, 1, 1, 5, 11, 1, 4, 18, 37, 1, 1, 1, 5, 11, 1, 4, 17, 55, 1, 4, 19, 53, 1, 37, 1, 4, 20, 41, 1, 12, 4, 9, 1, 1, 4, 21, 2, 1, 1, 51, 1, 51, 1, 12, 4, 10, 0, 0, 16, 11, 1, 12, 4, 11, 25, 0, 0, 6, 73, 16, 5, 10, 1, 11, 2, 16, 4, 22, 9, 218, 0, 6, 383, 4, 10, 10, 0, 3, 23, 3, 24, 3, 11, 12, 4, 25, 2, 0, 1, 12, 4, 23, 0, 1, 17, 0, 0, 4, 26, 5, 6, 1, 38, 1, 4, 26, 52, 1, 12, 4, 24, 0, 1, 17, 0, 0, 14, 377, 4, 15, 12, 4, 11, 0, 1, 17, 0, 0, 15, 361, 5, 11, 1, 12, 4, 10, 1, 1, 4, 16, 1, 1, 5, 6, 1, 53, 1, 49, 1, 7, 359, 12, 4, 23, 1, 1, 5, 11, 1, 4, 27, 37, 1, 1, 1, 5, 11, 1, 5, 6, 1, 54, 1, 12, 4, 10, 1, 1, 4, 28, 2, 1, 1, 5, 24, 1, 41, 1, 5, 11, 1, 4, 29, 55, 1, 38, 1, 39, 1, 12, 4, 23, 1, 1, 5, 11, 1, 4, 27, 37, 1, 0, 0, 16, 11, 1, 5, 11, 1, 5, 6, 1, 51, 1, 12, 4, 11, 0, 0, 6, 273, 16, 5, 23, 1, 11, 2, 16, 4, 30, 9, 390, 0, 6, 421, 4, 31, 4, 32, 10, 1, 5, 31, 1, 5, 32, 1, 38, 1, 5, 31, 1, 4, 29, 5, 32, 1, 52, 1, 36, 1, 39, 1, 11, 2, 16, 4, 33, 9, 428, 0, 6, 514, 4, 34, 4, 35, 10, 1, 3, 36, 3, 37, 5, 34, 1, 4, 38, 41, 1, 5, 35, 1, 4, 38, 41, 1, 51, 1, 12, 4, 36, 0, 1, 17, 0, 0, 5, 34, 1, 4, 39, 37, 1, 5, 35, 1, 4, 39, 37, 1, 51, 1, 5, 36, 1, 4, 39, 37, 1, 51, 1, 12, 4, 37, 0, 1, 17, 0, 0, 5, 37, 1, 4, 39, 38, 1, 5, 36, 1, 4, 38, 41, 1, 39, 1, 11, 2, 16, 4, 40, 9, 521, 0, 6, 577, 4, 41, 4, 42, 4, 43, 4, 44, 4, 34, 4, 45, 4, 46, 10, 6, 5, 43, 1, 5, 42, 1, 5, 44, 1, 18, 57, 1, 39, 1, 56, 1, 5, 41, 1, 5, 42, 1, 5, 34, 1, 5, 45, 1, 5, 46, 1, 12, 4, 47, 2, 6, 1, 11, 2, 16, 4, 48, 9, 584, 0, 6, 637, 4, 41, 4, 42, 4, 43, 4, 44, 4, 34, 4, 45, 4, 46, 10, 6, 5, 42, 1, 5, 43, 1, 56, 1, 5, 44, 1, 56, 1, 5, 41, 1, 5, 42, 1, 5, 34, 1, 5, 45, 1, 5, 46, 1, 12, 4, 47, 2, 6, 1, 11, 2, 16, 4, 49, 9, 644, 0, 6, 705, 4, 41, 4, 42, 4, 43, 4, 44, 4, 34, 4, 45, 4, 46, 10, 6, 5, 42, 1, 5, 44, 1, 41, 1, 5, 43, 1, 5, 44, 1, 18, 57, 1, 41, 1, 39, 1, 5, 41, 1, 5, 42, 1, 5, 34, 1, 5, 45, 1, 5, 46, 1, 12, 4, 47, 2, 6, 1, 11, 2, 16, 4, 50, 9, 712, 0, 6, 773, 4, 41, 4, 42, 4, 43, 4, 44, 4, 34, 4, 45, 4, 46, 10, 6, 5, 42, 1, 5, 43, 1, 41, 1, 5, 42, 1, 18, 57, 1, 5, 44, 1, 41, 1, 39, 1, 5, 41, 1, 5, 42, 1, 5, 34, 1, 5, 45, 1, 5, 46, 1, 12, 4, 47, 2, 6, 1, 11, 2, 16, 4, 47, 9, 780, 0, 6, 845, 4, 51, 4, 41, 4, 42, 4, 34, 4, 45, 4, 46, 10, 5, 5, 41, 1, 5, 51, 1, 12, 4, 33, 2, 2, 1, 5, 34, 1, 5, 46, 1, 12, 4, 33, 2, 2, 1, 12, 4, 33, 2, 2, 1, 5, 45, 1, 12, 4, 30, 2, 2, 1, 5, 42, 1, 12, 4, 33, 2, 2, 1, 11, 2, 16, 4, 52, 9, 852, 0, 6, 3975, 4, 34, 4, 53, 10, 1, 3, 41, 3, 42, 3, 43, 3, 44, 3, 11, 3, 54, 3, 55, 3, 56, 3, 57, 12, 4, 34, 1, 1, 5, 53, 1, 4, 27, 37, 1, 1, 1, 4, 58, 5, 53, 1, 4, 29, 55, 1, 38, 1, 39, 1, 12, 4, 34, 1, 1, 5, 53, 1, 4, 27, 37, 1, 0, 0, 5, 53, 1, 12, 4, 34, 1, 1, 5, 53, 1, 4, 59, 51, 1, 4, 60, 36, 1, 4, 17, 38, 1, 4, 61, 51, 1, 0, 0, 4, 62, 12, 4, 41, 0, 1, 17, 0, 0, 4, 15, 4, 63, 52, 1, 12, 4, 42, 0, 1, 17, 0, 0, 4, 15, 4, 64, 52, 1, 12, 4, 43, 0, 1, 17, 0, 0, 4, 65, 12, 4, 44, 0, 1, 17, 0, 0, 14, 3954, 4, 15, 12, 4, 11, 0, 1, 17, 0, 0, 15, 3939, 5, 11, 1, 12, 4, 34, 1, 1, 4, 16, 1, 1, 49, 1, 7, 3937, 5, 41, 1, 12, 4, 54, 0, 1, 17, 0, 0, 5, 42, 1, 12, 4, 55, 0, 1, 17, 0, 0, 5, 43, 1, 12, 4, 56, 0, 1, 17, 0, 0, 5, 44, 1, 12, 4, 57, 0, 1, 17, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 15, 51, 1, 1, 1, 4, 66, 4, 15, 4, 67, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 26, 51, 1, 1, 1, 4, 68, 4, 15, 4, 69, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 18, 51, 1, 1, 1, 4, 70, 4, 71, 12, 4, 50, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 72, 51, 1, 1, 1, 4, 73, 4, 15, 4, 74, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 17, 51, 1, 1, 1, 4, 66, 4, 15, 4, 75, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 27, 51, 1, 1, 1, 4, 68, 4, 76, 12, 4, 50, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 77, 51, 1, 1, 1, 4, 70, 4, 15, 4, 78, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 66, 51, 1, 1, 1, 4, 73, 4, 15, 4, 79, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 19, 51, 1, 1, 1, 4, 66, 4, 80, 12, 4, 50, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 60, 51, 1, 1, 1, 4, 68, 4, 15, 4, 81, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 82, 51, 1, 1, 1, 4, 70, 4, 15, 4, 83, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 84, 51, 1, 1, 1, 4, 73, 4, 15, 4, 85, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 68, 51, 1, 1, 1, 4, 66, 4, 86, 12, 4, 50, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 87, 51, 1, 1, 1, 4, 68, 4, 15, 4, 88, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 61, 51, 1, 1, 1, 4, 70, 4, 15, 4, 89, 52, 1, 12, 4, 50, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 20, 51, 1, 1, 1, 4, 73, 4, 90, 12, 4, 50, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 26, 51, 1, 1, 1, 4, 27, 4, 15, 4, 91, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 77, 51, 1, 1, 1, 4, 60, 4, 15, 4, 92, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 84, 51, 1, 1, 1, 4, 61, 4, 93, 12, 4, 49, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 15, 51, 1, 1, 1, 4, 94, 4, 15, 4, 95, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 27, 51, 1, 1, 1, 4, 27, 4, 15, 4, 96, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 82, 51, 1, 1, 1, 4, 60, 4, 97, 12, 4, 49, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 20, 51, 1, 1, 1, 4, 61, 4, 15, 4, 98, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 17, 51, 1, 1, 1, 4, 94, 4, 15, 4, 99, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 60, 51, 1, 1, 1, 4, 27, 4, 100, 12, 4, 49, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 61, 51, 1, 1, 1, 4, 60, 4, 15, 4, 101, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 72, 51, 1, 1, 1, 4, 61, 4, 15, 4, 102, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 19, 51, 1, 1, 1, 4, 94, 4, 103, 12, 4, 49, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 87, 51, 1, 1, 1, 4, 27, 4, 15, 4, 104, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 18, 51, 1, 1, 1, 4, 60, 4, 15, 4, 105, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 66, 51, 1, 1, 1, 4, 61, 4, 106, 12, 4, 49, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 68, 51, 1, 1, 1, 4, 94, 4, 15, 4, 107, 52, 1, 12, 4, 49, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 27, 51, 1, 1, 1, 4, 17, 4, 15, 4, 108, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 19, 51, 1, 1, 1, 4, 84, 4, 15, 4, 109, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 84, 51, 1, 1, 1, 4, 39, 4, 110, 12, 4, 48, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 61, 51, 1, 1, 1, 4, 111, 4, 15, 4, 112, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 26, 51, 1, 1, 1, 4, 17, 4, 15, 4, 113, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 17, 51, 1, 1, 1, 4, 84, 4, 114, 12, 4, 48, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 66, 51, 1, 1, 1, 4, 39, 4, 15, 4, 115, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 82, 51, 1, 1, 1, 4, 111, 4, 15, 4, 116, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 87, 51, 1, 1, 1, 4, 17, 4, 117, 12, 4, 48, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 15, 51, 1, 1, 1, 4, 84, 4, 15, 4, 118, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 72, 51, 1, 1, 1, 4, 39, 4, 15, 4, 119, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 77, 51, 1, 1, 1, 4, 111, 4, 120, 12, 4, 48, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 60, 51, 1, 1, 1, 4, 17, 4, 15, 4, 121, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 68, 51, 1, 1, 1, 4, 84, 4, 15, 4, 122, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 20, 51, 1, 1, 1, 4, 39, 4, 123, 12, 4, 48, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 18, 51, 1, 1, 1, 4, 111, 4, 15, 4, 124, 52, 1, 12, 4, 48, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 15, 51, 1, 1, 1, 4, 77, 4, 15, 4, 125, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 66, 51, 1, 1, 1, 4, 82, 4, 126, 12, 4, 40, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 61, 51, 1, 1, 1, 4, 20, 4, 15, 4, 127, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 27, 51, 1, 1, 1, 4, 128, 4, 15, 4, 129, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 68, 51, 1, 1, 1, 4, 77, 4, 130, 12, 4, 40, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 72, 51, 1, 1, 1, 4, 82, 4, 15, 4, 131, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 82, 51, 1, 1, 1, 4, 20, 4, 15, 4, 132, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 26, 51, 1, 1, 1, 4, 128, 4, 15, 4, 133, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 19, 51, 1, 1, 1, 4, 77, 4, 134, 12, 4, 40, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 20, 51, 1, 1, 1, 4, 82, 4, 15, 4, 135, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 77, 51, 1, 1, 1, 4, 20, 4, 15, 4, 136, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 87, 51, 1, 1, 1, 4, 128, 4, 137, 12, 4, 40, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 17, 51, 1, 1, 1, 4, 77, 4, 15, 4, 138, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 41, 0, 0, 5, 44, 1, 5, 41, 1, 5, 42, 1, 5, 43, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 84, 51, 1, 1, 1, 4, 82, 4, 15, 4, 139, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 44, 0, 0, 5, 43, 1, 5, 44, 1, 5, 41, 1, 5, 42, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 18, 51, 1, 1, 1, 4, 20, 4, 140, 12, 4, 40, 2, 7, 1, 12, 4, 43, 0, 0, 5, 42, 1, 5, 43, 1, 5, 44, 1, 5, 41, 1, 12, 4, 34, 1, 1, 5, 11, 1, 4, 60, 51, 1, 1, 1, 4, 128, 4, 15, 4, 141, 52, 1, 12, 4, 40, 2, 7, 1, 12, 4, 42, 0, 0, 5, 41, 1, 5, 54, 1, 12, 4, 33, 2, 2, 1, 12, 4, 41, 0, 0, 5, 42, 1, 5, 55, 1, 12, 4, 33, 2, 2, 1, 12, 4, 42, 0, 0, 5, 43, 1, 5, 56, 1, 12, 4, 33, 2, 2, 1, 12, 4, 43, 0, 0, 5, 44, 1, 5, 57, 1, 12, 4, 33, 2, 2, 1, 12, 4, 44, 0, 0, 16, 11, 1, 5, 11, 1, 4, 39, 51, 1, 12, 4, 11, 0, 0, 6, 1006, 16, 5, 41, 1, 5, 42, 1, 5, 43, 1, 5, 44, 1, 12, 4, 25, 2, 4, 1, 11, 2, 16, 4, 15, 12, 4, 5, 0, 1, 17, 0, 0, 4, 19, 12, 4, 6, 0, 1, 17, 0, 0, 5, 4, 1, 12, 4, 22, 2, 1, 1, 12, 4, 4, 1, 1, 4, 16, 1, 1, 5, 6, 1, 53, 1, 12, 4, 52, 2, 2, 1, 12, 4, 7, 2, 1, 1, 11, 2, 16, 4, 142, 12, 4, 143, 1, 1, 4, 144, 2, 1, 0, 3, 4, 4, 145, 12, 4, 3, 2, 1, 1, 12, 4, 4, 0, 0, 5, 4, 1, 5, 4, 1, 4, 146, 45, 1, 12, 4, 143, 1, 1, 4, 147, 2, 2, 0, 4, 142, 12, 4, 143, 1, 1, 4, 148, 2, 1, 0], undefined, undefined, body, []); 483 | // 打印反编译结果 484 | console.log(generator(types.Program(body)).code) 485 | 486 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /test/main.js: -------------------------------------------------------------------------------- 1 | if (typeof window === "undefined") { 2 | require("../tools/babelPlugins"); 3 | var {readFileSync, writeFileSync} = require("fs"); 4 | process.argv.length > 2 ? sourceFile = process.argv[2] : sourceFile = "./source.js"; 5 | process.argv.length > 3 ? outputFile = process.argv[3] : outputFile = "./output.js"; 6 | process.argv.length > 4 ? preprocessFile = process.argv[4] : preprocessFile = "./preprocess.js"; 7 | var sourceCode = readFileSync(sourceFile, {encoding: "utf-8"}); 8 | window = { 9 | "exports": exports, 10 | "require": require, 11 | "module": module, 12 | "__dirname": __dirname, 13 | "__filename": __filename, 14 | }; 15 | window.__proto__ = global; 16 | } 17 | 18 | // 选项配置 19 | const CONFIG = { 20 | NAME: "faceless", // faceless man 21 | ENCODING: true, 22 | COMPRESS_CODE: false, 23 | EXPORT_JSVMP: true, 24 | SHOW_DETAIL: false, 25 | } 26 | const { 27 | NAME, // logo 28 | ENCODING, // 指令编码 29 | COMPRESS_CODE, // 压缩输出代码 30 | EXPORT_JSVMP, // 导出加固代码(需同时开启ENCODING) 注: 开启后运行此文件不会执行解释器 31 | SHOW_DETAIL, // 显示详细内容 32 | } = CONFIG; 33 | 34 | // 日志列表 35 | const LOG_LIST = [` 36 | 注: 由于项目开源导致加固代码很容易被反编译, 37 | 请勿将加固后的代码用于生产环境。 38 | `]; 39 | // logo log 40 | if (NAME) { 41 | console.log(facelessLogo); 42 | for (let i = 0; i < LOG_LIST.length; i++) { 43 | console.log(LOG_LIST[i]) 44 | } 45 | } 46 | // 字节码 47 | let bytecode = []; 48 | // 常量池 49 | let constantPool = [`@${NAME}`, "arguments", "__proto__"]; 50 | // 指令映射表 51 | let IMT = {}; 52 | // 自定义指令集 53 | let instruction = [ 54 | "=", // 赋值 55 | "get", // 获取属性 56 | "call", // 调用 57 | "def_v", // 声明变量 58 | "lod_c", // 读取常量 59 | "lod_v", // 读取变量 60 | "jump", // 无条件跳转 61 | "ifJump", // 条件跳转 62 | "switchJump", // 63 | "defFunc", // 定义函数 64 | "params", // 参数映射 65 | "return", // 返回值 66 | "localScope", // 当前作用域 67 | "globalScope", // 全局作用域 68 | "block", // 块 69 | "loopBlock", //循环块 70 | "blockEnd", // 块结束地址 71 | "sequence", // 序列表达式 72 | "tryNumber", //尝试转换为数字 失败则返回-1 73 | "try", 74 | "throw", 75 | // "yield", 76 | "TemplateExpressions", // 尝试转换结果为字符串 77 | "Template", // 样板 例子: let a = 0; console.log(`${a}`) -> 输出 0 78 | "RegExpLiteral", // 正则 79 | "debugger", 80 | "++", 81 | "--", 82 | "typeof", 83 | "object", 84 | "property", 85 | "array", 86 | "new", 87 | "void", 88 | "delete", 89 | ]; 90 | // 运算符指令 91 | let operator = [ 92 | "instanceof", 93 | "in", 94 | ">>>", 95 | ">>", 96 | "<<", 97 | "|", 98 | "||", 99 | "&", 100 | "&&", 101 | ">=", 102 | "<=", 103 | "==", 104 | "!=", 105 | "===", 106 | "!==", 107 | "<", 108 | ">", 109 | "+", 110 | "-", 111 | "*", 112 | "/", 113 | "%", 114 | "^", 115 | "~", 116 | "!", 117 | ]; 118 | // 全局变量 119 | let globalVariable = []; 120 | let _ = "------------------"; 121 | 122 | // 未解析的节点 123 | function unresolvedNode(node) { 124 | let s = _ + "code" + _; 125 | let msg = `源代码第${node.loc.start.line}行未解析: type -> ${node.type}\n${s}\n${generator(node).code}\n${s}`; 126 | console.log(msg) 127 | debugger 128 | throw new TypeError(msg) 129 | } 130 | 131 | // 源代码预处理 132 | function preprocess(ast) { 133 | // 编译前处理 变量提升特性 语法转换等待 134 | const ARRAY_PATTERN = template("A = B[C]") 135 | const ARROW = template("{ return A }"); 136 | const FOR_OF_LET = template("let A = _F_i.value"); 137 | const FOR_OF = template("for (let _F_iterator = A[Symbol.iterator](), _F_i = _F_iterator.next();!_F_i.done;_F_i = _F_iterator.next()) B"); 138 | const FOR_IN_LET = template("let A = _F_li[_F_i]"); 139 | const FOR_IN = template("for (let _F_i = 0, _F_li = _faceless_all_keys(A); _F_i < _F_li.length; _F_i++) B"); 140 | const ALL_KEYS = template("function _faceless_all_keys(o){let _keys=[],l;while(1){l=Object.keys(o);_keys=_keys.concat(l);o=o.__proto__;if(!l.length){break}}return _keys}"); 141 | const liftingFunction = { 142 | FunctionDeclaration(path) { 143 | let block = path.findParent(p => p.isBlockStatement() || p.isProgram()).node.body; 144 | let funcNode = block.splice(block.indexOf(path.node), 1); 145 | block.splice(0, 0, funcNode[0]); 146 | } 147 | }; 148 | const promoteVariable = { 149 | /** 150 | * 基于 es6 语法的变量提升特性 151 | * 函数内 var 声明提升至当前函数作用域 152 | * 其他情况 var 声明提升至全局作用域 153 | * let 、const 只在当前块作用域(函数作用域)有效(不需要提升) 154 | * @param path 155 | * @constructor 156 | */ 157 | "FunctionDeclaration|FunctionExpression|Program"(path) { 158 | let {body, params} = path.node; 159 | let _params = [], var_body = []; 160 | if (params) { 161 | params.forEach(n => _params.push(n.name)); 162 | body = body.body; 163 | } else { 164 | for (const name in path.scope.globals) { 165 | globalVariable.push(name); 166 | } 167 | } 168 | path.traverse({ 169 | VariableDeclaration(_path) { 170 | let parent = _path.findParent(p => p.isFunctionDeclaration() 171 | || p.isFunctionExpression() || p.isProgram()); 172 | if (parent != path) return; 173 | let {kind, declarations} = _path.node; 174 | if (kind !== "var") return; 175 | let sequence_body = []; 176 | for (let j = 0; j < declarations.length; j++) { 177 | let {id, init} = declarations[j]; 178 | if (!_params.includes(id.name)) { 179 | var_body.push(types.VariableDeclarator(id, null)) 180 | } 181 | if (init) { 182 | sequence_body.push(types.AssignmentExpression("=", id, init)) 183 | } 184 | } 185 | if (sequence_body.length) { 186 | if (_path.parentPath.isForStatement()) { 187 | _path.replaceInline(types.SequenceExpression(sequence_body)); 188 | } else { 189 | _path.replaceInline(types.ExpressionStatement(types.SequenceExpression(sequence_body))); 190 | } 191 | } else { 192 | _path.remove() 193 | } 194 | } 195 | }); 196 | if (var_body.length) { 197 | body.unshift(types.VariableDeclaration("var", var_body)) 198 | } 199 | } 200 | }; 201 | const adapt = { 202 | /** 203 | * 适配箭头(匿名)函数 (加括号) (x...) => 0,0...; -> (x...) => { return 0,0... }; 204 | * @param path 205 | * @constructor 206 | */ 207 | ArrowFunctionExpression(path) { 208 | let body = path.get("body"); 209 | if (body.isBlockStatement()) return; 210 | body.replaceInline(ARROW({A: body.node})); 211 | }, 212 | /** 213 | * 转换为可编译语法 214 | * 处理前 215 | * let {a} = {a: {b: {c: {}}}}; 216 | * var {b} = a; 217 | * const {c} = a.b; 218 | * 处理后 219 | * let a = {a: {b: {c: {}}}}.a; 220 | * var b = a.b; 221 | * const c = a.b.c; 222 | * @param path 223 | * @constructor 224 | */ 225 | ObjectPattern(path) { 226 | let {properties} = path.node; 227 | let parentPath = path.parentPath; 228 | if (!parentPath.isVariableDeclarator()) return; 229 | let {kind} = path.parentPath.parentPath.node; 230 | let {init} = parentPath.node; 231 | properties.forEach(n => { 232 | let {key, value} = n; 233 | let body = [types.VariableDeclarator(key, types.MemberExpression(init, value || key))]; 234 | parentPath.parentPath.insertBefore(types.VariableDeclaration(kind, body)); 235 | }) 236 | parentPath.parentPath.remove(); 237 | }, 238 | /** 239 | * 原理同上 240 | * @param path 241 | * @constructor 242 | */ 243 | ArrayPattern(path) { 244 | let {elements} = path.node; 245 | let parentPath = path.parentPath; 246 | let {right} = parentPath.node; 247 | for (let i = 0; i < elements.length; i++) { 248 | let element = elements[i]; 249 | parentPath.insertBefore(ARRAY_PATTERN({A: element, B: right, C: types.NumericLiteral(i)})) 250 | } 251 | parentPath.remove(); 252 | }, 253 | /** 254 | * 偷懒亿下下,能跑就行了 255 | * 将 for of | for in 语法转换为 for i 256 | 处理前 257 | for (const char of str) { 258 | console.log(char); 259 | } 260 | 处理后 261 | for (let _F_iterator = str[Symbol.iterator](), _F_i = _F_iterator.next(); !_F_i.done; _F_i = _F_iterator.next()) { 262 | let char = _F_i.value; 263 | console.log(char); 264 | } 265 | for in 的转换同理 266 | * @param path 267 | * @constructor 268 | */ 269 | "ForOfStatement|ForInStatement"(path) { 270 | let {left, right, body} = path.node; 271 | let FOR = FOR_OF, LET = FOR_OF_LET; 272 | if (path.isForInStatement()) { 273 | FOR = FOR_IN, LET = FOR_IN_LET; 274 | ast.program.body.unshift(ALL_KEYS()); 275 | } 276 | let name = left; 277 | if (types.isVariableDeclaration(left)) { 278 | name = left.declarations[0].id; 279 | } 280 | body.body.unshift(LET({A: name})); 281 | path.replaceInline(FOR({A: right, B: body})); 282 | }, 283 | }; 284 | traverse(ast, liftingFunction); 285 | traverse(ast, adapt); 286 | traverse(ast, promoteVariable); 287 | // 预处理代码保存 288 | if (typeof global !== "undefined") { 289 | writeFileSync(preprocessFile, generator(ast).code, (e) => { 290 | }) 291 | } 292 | 293 | return ast 294 | } 295 | 296 | // 虚拟化源代码 297 | function virtualizationSourceCode(sourceCode) { 298 | constantPool = [`@${NAME}`, "arguments", "__proto__"],bytecode = [],globalVariable = []; 299 | // 解析源代码为AST 300 | let ast = parser.parse(sourceCode); 301 | // 添加运算符 302 | instruction = instruction.concat(operator); 303 | instruction.forEach(k => IMT[k] = k); 304 | console.info(`${_}编译器输出结果${_}\n`) 305 | console.time("编译耗时") 306 | // 预处理源代码 307 | let {program} = preprocess(ast); 308 | let nodes = program.body; 309 | 310 | for (let i = 0; i < nodes.length; i++) { 311 | let node = nodes[i]; 312 | sourceToByte(node); 313 | } 314 | // 指令编码 315 | if (ENCODING) { 316 | // 指令集keys 317 | let IKA = Object.keys(IMT); 318 | for (let i = 0; i < IKA.length; i++) { 319 | IMT[IKA[i]] = i 320 | } 321 | for (let i = 0; i < bytecode.length; i++) { 322 | let j = bytecode[i]; 323 | if (typeof j == "number") continue; 324 | bytecode[i] = IMT[j]; 325 | } 326 | } 327 | console.timeEnd("编译耗时") 328 | // 检查字节码信息 329 | let errorIndex = bytecode.indexOf(undefined); 330 | if (errorIndex === -1) { 331 | console.info(`编译结果正常 | 字节码长度:${bytecode.length} | 常量池长度:${constantPool.length}`) 332 | if (SHOW_DETAIL) { 333 | console.info("info -> 常量池 :", constantPool) 334 | console.info("info -> 字节码 :", bytecode) 335 | // if (ENCODING) console.info(`info -> 指令映射表 :${JSON.stringify(IMT)}`); 336 | } 337 | } else { 338 | debugger 339 | throw new Error(`编译失败,错误地址:${errorIndex}`) 340 | } 341 | console.info(`\n${_}解释器输出结果${_}\n`) 342 | if (ENCODING && EXPORT_JSVMP) { 343 | // 保存加固代码 344 | let handlerCode = outputHandlerCode(parser.parse(interpreter.toString())); 345 | let appendCode = ")(typeof window !== 'undefined' ? window : (window = global, window)" 346 | + `, 0, [],${JSON.stringify(constantPool)}, ${JSON.stringify(bytecode)})`; 347 | return `(${handlerCode + appendCode}`; 348 | } else { 349 | // 执行测试 350 | interpreter(window, 0, [], constantPool, bytecode) 351 | } 352 | } 353 | 354 | // 输出加固代码处理程序 355 | function outputHandlerCode(ast) { 356 | traverse(ast, { 357 | MemberExpression(path) { 358 | let {object, property} = path.node; 359 | if (object.name !== "IMT") return; 360 | let value = IMT[property.value]; 361 | path.replaceInline(types.valueToNode(value)); 362 | let parentPath = path.parentPath; 363 | if (parentPath.isSwitchCase() && !parentPath.node.consequent.length) { 364 | parentPath.remove() 365 | } 366 | }, 367 | SwitchStatement: { 368 | exit(path) { 369 | let parentPath = path.parentPath; 370 | if (parentPath.isSwitchCase()) { 371 | parentPath.get('test').replaceInline(types.BinaryExpression( 372 | ">", types.NumericLiteral(parentPath.get('consequent.2.cases.0.test').evaluate().value - 1), 373 | types.NumericLiteral(parentPath.get('test').evaluate().value + 1) 374 | )) 375 | } 376 | } 377 | } 378 | }) 379 | traverse(ast, { 380 | SwitchStatement: { 381 | exit(path) { 382 | let {cases, discriminant} = path.node; 383 | let tempBody = []; 384 | for (let i = 0; i < cases.length; i++) { 385 | let {consequent, test} = cases[i]; 386 | if (!test) continue; 387 | if (types.isContinueStatement(consequent[consequent.length - 1])) { 388 | consequent.pop() 389 | } 390 | let block = types.BlockStatement(consequent); 391 | let _test; 392 | if (types.isBinaryExpression(test)) { 393 | let left = types.BinaryExpression("<", test.left, discriminant) 394 | let right = types.BinaryExpression("<", discriminant, test.right) 395 | _test = types.LogicalExpression("&&", left, right) 396 | } else { 397 | _test = types.BinaryExpression("==", discriminant, test); 398 | } 399 | tempBody.push(types.IfStatement(_test, block)) 400 | } 401 | // 打乱body 402 | tempBody = tempBody.sort(() => 0.5 - Math.random()) 403 | path.replaceInline(tempBody) 404 | } 405 | }, 406 | BreakStatement(path) { 407 | path.replaceInline(types.continueStatement()) 408 | } 409 | }) 410 | return generator(ast, {minified: COMPRESS_CODE, comments: false}).code; 411 | } 412 | 413 | // 源代码转字节码 414 | function sourceToByte(node, option = {}) { 415 | if (!node) return; 416 | let t0, t1, t2, t3, t4, t5; 417 | switch (node.type) { 418 | case "Identifier": 419 | poolIndex("lod_c", node.name, option) 420 | break 421 | case "VariableDeclaration": 422 | node.declarations.forEach(n => sourceToByte(n)) 423 | break 424 | case "VariableDeclarator": 425 | if (!types.isIdentifier(node.id)) { 426 | throw new TypeError("特殊情况 节点id不是标识符") 427 | } 428 | sourceToByte(node.id, {pool: "def_v"}) 429 | if (node.init) { 430 | sourceToByte(node.init,{pool: "lod_v"}) 431 | if (types.isIdentifier(node.id)) { 432 | bytecode.push(IMT['localScope']) 433 | } 434 | sourceToByte(node.id) 435 | bytecode.push(IMT['=']) 436 | bytecode.push(0) 437 | } 438 | break 439 | case "AssignmentPattern": 440 | case "AssignmentExpression": 441 | if (node.operator == '=') { 442 | // 值为成员表达式则获取其值 443 | if (types.isIdentifier(node.right)) { 444 | sourceToByte(node.right, {pool: "lod_v"}) 445 | } else if (types.isMemberExpression(node.right)) { 446 | sourceToByte(node.right) 447 | } else { 448 | sourceToByte(node.right, {notReadProperty: 1}) 449 | } 450 | // 被赋值为标识符推送当前作用域 451 | if (types.isIdentifier(node.left)) { 452 | if (globalVariable.includes(node.left.name)) { 453 | bytecode.push(IMT['globalScope']) 454 | } else { 455 | bytecode.push(IMT['localScope']) 456 | } 457 | } 458 | sourceToByte(node.left, {notReadProperty: 1}) 459 | bytecode.push(IMT["="]) 460 | bytecode.push(Number(!option.notPushStack)) 461 | } else if (node.operator.length > 1 && node.operator[node.operator.length - 1] == "=") { 462 | t0 = node.operator.substring(0, node.operator.length - 1) 463 | if (types.isIdentifier(node.left)) { 464 | sourceToByte(node.left, {pool: "lod_v"}) 465 | } else 466 | // if (types.isMemberExpression(node.left)) { 467 | // sourceToByte(node.left) 468 | // } else 469 | { 470 | sourceToByte(node.left) 471 | } 472 | if (types.isIdentifier(node.right)) { 473 | sourceToByte(node.right, {pool: "lod_v"}) 474 | } else { 475 | sourceToByte(node.right) 476 | } 477 | if (IMT[t0] == undefined) { 478 | unresolvedNode(node) // 监控意外情况 479 | } 480 | bytecode.push(IMT[t0]); 481 | bytecode.push(1) 482 | if (types.isIdentifier(node.left)) { 483 | bytecode.push(IMT['localScope']) 484 | } 485 | sourceToByte(node.left, {notReadProperty: 1}) 486 | bytecode.push(IMT['=']) 487 | bytecode.push(Number(!option.notPushStack)) 488 | } else { 489 | unresolvedNode(node) // 监控意外情况 490 | } 491 | break 492 | case "LogicalExpression": 493 | if (types.isIdentifier(node.left)) { 494 | sourceToByte(node.left, {pool: "lod_v"}) 495 | } else { 496 | sourceToByte(node.left) 497 | } 498 | sourceToByte(node.right) 499 | bytecode.push(IMT[node.operator]) 500 | bytecode.push(Number(!option.notPushStack)) 501 | break 502 | case "BinaryExpression": 503 | if (types.isIdentifier(node.left)) { 504 | sourceToByte(node.left, {pool: "lod_v"}) 505 | } else { 506 | sourceToByte(node.left) 507 | } 508 | if (types.isIdentifier(node.right)) { 509 | sourceToByte(node.right, {pool: "lod_v"}) 510 | } else { 511 | sourceToByte(node.right) 512 | } 513 | bytecode.push(IMT[node.operator]) 514 | bytecode.push(Number(!option.notPushStack)) 515 | break 516 | // case "CommentLine": 517 | case "BooleanLiteral": 518 | case "NumericLiteral": 519 | case "NullLiteral": 520 | case "StringLiteral": 521 | poolIndex("lod_c", node.value) 522 | break 523 | case "UnaryExpression": 524 | if (node.operator == IMT['-']) { 525 | poolIndex("lod_c", 0) 526 | } 527 | sourceToByte(node.argument, {pool: "lod_v"}) 528 | if (node.operator == IMT['~']) { 529 | bytecode.push(IMT["tryNumber"]) 530 | } 531 | bytecode.push(IMT[node.operator]) 532 | bytecode.push(Number(!option.notPushStack)) 533 | break 534 | case "UpdateExpression": 535 | if (types.isIdentifier(node.argument)) { 536 | bytecode.push(IMT['localScope']) 537 | } 538 | sourceToByte(node.argument) // 这里获取标识符 539 | bytecode.push(IMT[node.operator]) 540 | bytecode.push(Number(node.prefix)) 541 | bytecode.push(Number(!option.notPushStack)) 542 | break 543 | case "ExpressionStatement": 544 | sourceToByte(node.expression, {notPushStack: 1}) 545 | break 546 | case "SequenceExpression": 547 | node.expressions.forEach(n => sourceToByte(n)) 548 | bytecode.push(IMT['sequence']) 549 | bytecode.push(node.expressions.length - 1) 550 | bytecode.push(Number(!option.notPushStack)) 551 | break 552 | case "ConditionalExpression": 553 | case "IfStatement": 554 | sourceToByte(node.test, {pool: "lod_v"}) 555 | bytecode.push(IMT["ifJump"]) 556 | t0 = bytecode.length; 557 | bytecode.push(t0) 558 | sourceToByte(node.consequent) 559 | bytecode.push(IMT["jump"]) 560 | t1 = bytecode.length; 561 | bytecode.push(t1) 562 | bytecode[t0] = bytecode.length; 563 | sourceToByte(node.alternate) 564 | bytecode[t1] = bytecode.length; 565 | break 566 | case "CallExpression": 567 | node.arguments.forEach(n => sourceToByte(n, {pool: "lod_v"})) 568 | if (types.isFunctionExpression(node.callee) || types.isSequenceExpression(node.callee)) { 569 | poolIndex("lod_c", 0) 570 | } 571 | if (types.isIdentifier(node.callee)) { 572 | bytecode.push(IMT['localScope']) 573 | } 574 | sourceToByte(node.callee, {notReadProperty: 1}) 575 | bytecode.push(IMT['call']) 576 | bytecode.push(node.arguments.length) 577 | bytecode.push(Number(!option.notPushStack)) 578 | break 579 | case "ForInStatement": 580 | unresolvedNode(node) // 通过语法转换实现 581 | break 582 | case "ForOfStatement": 583 | unresolvedNode(node) // 通过语法转换实现 584 | break 585 | case "ForStatement": 586 | bytecode.push(IMT["block"]); 587 | t0 = bytecode.length; 588 | bytecode.push(t0); 589 | sourceToByte(node.init, {notPushStack: 1}); 590 | t1 = bytecode.length; 591 | bytecode.push(IMT["loopBlock"]); // 循环体开始 592 | bytecode.push(t1); 593 | if (node.test) { 594 | sourceToByte(node.test, {pool: "lod_v"}); 595 | } else { 596 | poolIndex("lod_c", 1); 597 | } 598 | bytecode.push(IMT["ifJump"]); // 跳至结束 599 | t2 = bytecode.length; 600 | bytecode.push(t2); 601 | sourceToByte(node.body, {specialBlock: 1}); 602 | bytecode.push(IMT["blockEnd"]); // 结束当此循环 603 | bytecode[t2] = bytecode.length; // 循环体结束地址 604 | bytecode.push(IMT["return"]); // 循环体结束 605 | bytecode.push(1); 606 | bytecode[t1 + 1] = bytecode.length; 607 | sourceToByte(node.update, {notPushStack: 1}); 608 | bytecode.push(IMT["jump"]); // 跳转至 loopBlock 609 | bytecode.push(t1); 610 | bytecode.push(IMT["blockEnd"]); // 循环结束 611 | bytecode[t0] = bytecode.length; // 循环结束地址 612 | break 613 | case "WhileStatement": 614 | bytecode.push(IMT["block"]); 615 | t0 = bytecode.length; 616 | bytecode.push(t0); 617 | t1 = bytecode.length; 618 | bytecode.push(IMT["loopBlock"]); 619 | bytecode.push(t1); 620 | sourceToByte(node.test, {pool: "lod_v"}); 621 | bytecode.push(IMT["ifJump"]); // 跳至结束 622 | t2 = bytecode.length; 623 | bytecode.push(t2); 624 | sourceToByte(node.body, {specialBlock: 1}) 625 | bytecode.push(IMT["blockEnd"]); // 结束当此循环 626 | bytecode[t2] = bytecode.length; // 循环体结束地址 627 | bytecode.push(IMT["return"]); // 循环体结束 628 | bytecode.push(1); 629 | bytecode[t1 + 1] = bytecode.length; 630 | bytecode.push(IMT["jump"]); 631 | bytecode.push(t1); 632 | bytecode.push(IMT["blockEnd"]); 633 | bytecode[t0] = bytecode.length; 634 | break 635 | case "DoWhileStatement": 636 | bytecode.push(IMT["block"]); 637 | t0 = bytecode.length; 638 | bytecode.push(t0); 639 | t1 = bytecode.length; 640 | bytecode.push(IMT["loopBlock"]); 641 | bytecode.push(t1); 642 | sourceToByte(node.body, {specialBlock: 1}) 643 | sourceToByte(node.test, {pool: "lod_v"}); 644 | bytecode.push(IMT["ifJump"]); // 跳至结束 645 | t2 = bytecode.length; 646 | bytecode.push(t2); 647 | bytecode.push(IMT["blockEnd"]); // 结束当此循环 648 | bytecode[t2] = bytecode.length; // 循环体结束地址 649 | bytecode.push(IMT["return"]); // 循环体结束 650 | bytecode.push(1); 651 | bytecode[t1 + 1] = bytecode.length; 652 | bytecode.push(IMT["jump"]); 653 | bytecode.push(t1); 654 | bytecode.push(IMT["blockEnd"]); 655 | bytecode[t0] = bytecode.length; 656 | break 657 | case "MemberExpression": 658 | // object为标识符时推送当前作用域 659 | if (types.isIdentifier(node.object)) { 660 | bytecode.push(IMT['localScope']) 661 | sourceToByte(node.object) 662 | bytecode.push(IMT['get']) 663 | bytecode.push(1) 664 | } else { 665 | sourceToByte(node.object) 666 | } 667 | // 处理property是可计算的情况 668 | if (node.computed) { 669 | if (types.isIdentifier(node.property)) { 670 | bytecode.push(IMT['localScope']) 671 | sourceToByte(node.property) 672 | bytecode.push(IMT['get']) 673 | bytecode.push(1) 674 | } else { 675 | sourceToByte(node.property) 676 | } 677 | } else { 678 | sourceToByte(node.property) 679 | } 680 | bytecode.push(IMT['get']) 681 | bytecode.push(Number(!option.notPushStack)) 682 | if (option.notReadProperty) { 683 | bytecode.pop() 684 | bytecode.pop() 685 | } 686 | break 687 | case "FunctionExpression": 688 | case "ArrowFunctionExpression": 689 | case "FunctionDeclaration": 690 | // 三种情况 匿名函数 函数定义 函数表达式 691 | t1 = node.id ? node.id.name : 0; 692 | poolIndex("lod_c", t1) // 函数名称 匿名为 number 0 693 | bytecode.push(IMT["defFunc"]) // 仅声明函数 694 | bytecode.push(bytecode.length + 4)// 函数指针 695 | bytecode.push(Number(node.type !== "FunctionDeclaration")) // 函数声明类型 696 | bytecode.push(IMT["jump"]) // 跳过函数内容 697 | t0 = bytecode.length; 698 | bytecode.push(t0); 699 | node.params.forEach(n => poolIndex("lod_c", n.name)) // 形参处理 700 | bytecode.push(IMT["params"]) 701 | bytecode.push(node.params.length - 1) // 形参数量 702 | sourceToByte(node.body, {specialBlock: 1}) 703 | bytecode.push(IMT["blockEnd"]) 704 | bytecode[t0] = bytecode.length; // 函数结束指针 705 | break 706 | case "NewExpression": 707 | node.arguments.forEach(n => sourceToByte(n, {pool: "lod_v"})) 708 | if (types.isIdentifier(node.callee)) { 709 | bytecode.push(IMT['localScope']) 710 | } 711 | sourceToByte(node.callee) 712 | bytecode.push(IMT['new']) 713 | bytecode.push(node.arguments.length) 714 | bytecode.push(Number(!option.notPushStack)) 715 | break 716 | case "ThisExpression": 717 | bytecode.push(IMT['localScope']) 718 | poolIndex("lod_c", constantPool[0]) 719 | bytecode.push(IMT['get']) 720 | bytecode.push(Number(!option.notPushStack)) 721 | break 722 | case "BlockStatement": 723 | if (option.specialBlock) { 724 | node.body.forEach(n => sourceToByte(n)) 725 | } else { 726 | bytecode.push(IMT["block"]) 727 | t0 = bytecode.length 728 | bytecode.push(t0) 729 | node.body.forEach(n => sourceToByte(n)) 730 | bytecode.push(IMT["blockEnd"]) 731 | bytecode[t0] = bytecode.length; 732 | } 733 | break 734 | case "ArrayExpression": 735 | node.elements.forEach(n => sourceToByte(n)) 736 | bytecode.push(IMT["array"]) 737 | bytecode.push(node.elements.length) 738 | bytecode.push(Number(!option.notPushStack)) 739 | break 740 | case "ObjectExpression": 741 | bytecode.push(IMT['object']) 742 | node.properties.forEach(n => sourceToByte(n)) 743 | break 744 | case "ObjectProperty": 745 | sourceToByte(node.key) 746 | sourceToByte(node.value) 747 | bytecode.push(IMT["property"]) 748 | bytecode.push(Number(!option.notPushStack)) 749 | break 750 | case "LabeledStatement": 751 | unresolvedNode(node) // 没意义不处理 752 | break 753 | case "TemplateElement": 754 | poolIndex("lod_c", node.value.raw); // raw|cooked 755 | break 756 | case "TemplateLiteral": 757 | t0 = node.quasis.concat(node.expressions); 758 | t0.sort((a, b) => b.start - a.start); 759 | for (t1 = 0; t1 < t0.length; t1++) { 760 | t2 = t0[t1] 761 | if (t2.type == "TemplateElement") { 762 | sourceToByte(t2) 763 | } else { 764 | sourceToByte(t2, {pool: "lod_v"}) 765 | bytecode.push(IMT['TemplateExpressions']) 766 | } 767 | } 768 | bytecode.push(IMT['Template']) 769 | bytecode.push(t0.length) 770 | bytecode.push(Number(!option.notPushStack)) 771 | break 772 | case "ReturnStatement": 773 | sourceToByte(node.argument, {pool: "lod_v"}) 774 | bytecode.push(IMT['return']) 775 | bytecode.push(2) 776 | break 777 | case "BreakStatement": 778 | // node.label 779 | bytecode.push(IMT['return']) 780 | bytecode.push(1) 781 | break 782 | case "ContinueStatement": 783 | bytecode.push(IMT['return']) 784 | bytecode.push(0) 785 | break 786 | case "SwitchStatement": 787 | bytecode.push(IMT["loopBlock"]) 788 | t0 = bytecode.length; 789 | bytecode.push(t0); 790 | sourceToByte(node.discriminant, {pool: "lod_v"}); 791 | t4 = -1; 792 | node.cases.forEach(n => sourceToByte(n.test || 793 | (t4 = node.cases.indexOf(n), types.StringLiteral("@faceless_switch_default")))); // 这里有个小问题,不会修,就这样吧 794 | bytecode.push(IMT["array"]); 795 | bytecode.push(node.cases.length); 796 | bytecode.push(1) 797 | poolIndex("lod_c", "indexOf") 798 | bytecode.push(IMT["call"]) 799 | bytecode.push(1) 800 | bytecode.push(1) 801 | t1 = bytecode.length; 802 | t2 = t1 + node.cases.length * 2; 803 | bytecode.length = t2; 804 | bytecode.push(IMT["array"]) 805 | bytecode.push(node.cases.length) 806 | bytecode.push(1) 807 | bytecode.push(IMT["switchJump"]) 808 | bytecode.push(t4) 809 | t3 = []; 810 | node.cases.forEach(n => t3.push(sourceToByte(n))); 811 | for (let i = 0; i < t3.length; i++) { 812 | let _index = t3[i]; 813 | bytecode[i * 2 + t1] = IMT["lod_c"]; 814 | let c_index = poolIndex(null, _index); 815 | bytecode[i * 2 + t1 + 1] = c_index; 816 | } 817 | bytecode.push(IMT["blockEnd"]); 818 | bytecode[t0] = bytecode.length; 819 | break 820 | case "SwitchCase": 821 | t0 = bytecode.length; 822 | node.consequent.forEach(n => sourceToByte(n)); 823 | return t0; 824 | case "RegExpLiteral": 825 | poolIndex("lod_c", node.pattern) 826 | poolIndex("lod_c", node.flags) 827 | bytecode.push(IMT['RegExpLiteral']) 828 | break 829 | case "TryStatement": 830 | bytecode.push(IMT['try']); 831 | t0 = bytecode.length; 832 | bytecode.push(t0) 833 | bytecode.length = bytecode.length + 3; 834 | bytecode[t0 + 1] = bytecode.length; 835 | sourceToByte(node.block, {specialBlock: 1}) 836 | bytecode.push(IMT["blockEnd"]); 837 | bytecode[t0 + 2] = bytecode.length 838 | sourceToByte(node.handler.body, {specialBlock: 1}) 839 | bytecode.push(IMT["blockEnd"]); 840 | bytecode[t0 + 3] = bytecode.length 841 | sourceToByte(node.finalizer, {specialBlock: 1}); 842 | bytecode.push(IMT["blockEnd"]); 843 | bytecode[t0] = bytecode.length 844 | break 845 | // case "CatchClause": 846 | case "ThrowStatement": 847 | sourceToByte(node.argument) 848 | bytecode.push(IMT["throw"]) 849 | break 850 | case "ObjectPattern": 851 | unresolvedNode(node) // 通过语法转换实现 852 | break 853 | case "ObjectMethod": 854 | sourceToByte(node.key) 855 | // 三种情况 匿名函数 函数定义 函数表达式 856 | t1 = node.id ? node.id.name : 0; 857 | poolIndex("lod_c", t1) // 函数名称 匿名为 number 0 858 | bytecode.push(IMT["defFunc"]) // 仅声明函数 859 | bytecode.push(bytecode.length + 4)// 函数指针 860 | bytecode.push(Number(node.type !== "FunctionDeclaration")) // 函数声明类型 861 | bytecode.push(IMT["jump"]) // 跳过函数内容 862 | t0 = bytecode.length; 863 | bytecode.push(t0); 864 | node.params.forEach(n => poolIndex("lod_c", n.name)) // 形参处理 865 | bytecode.push(IMT["params"]) 866 | bytecode.push(node.params.length - 1) // 形参数量 867 | sourceToByte(node.body, {specialBlock: 1}) 868 | bytecode.push(IMT["blockEnd"]) 869 | bytecode[t0] = bytecode.length; // 函数结束指针 870 | bytecode.push(IMT["property"]) 871 | bytecode.push(Number(!option.notPushStack)) 872 | break 873 | case "EmptyStatement": 874 | break 875 | case "ArrayPattern": 876 | unresolvedNode(node) // 通过语法转换实现 877 | break 878 | case "YieldExpression": 879 | unresolvedNode(node) // 不知道怎样实现,先搁置 880 | break 881 | case "DebuggerStatement": 882 | if (!EXPORT_JSVMP) { 883 | bytecode.push(IMT["debugger"]) 884 | } 885 | break 886 | default: 887 | unresolvedNode(node) // 其他类型监测 888 | } 889 | } 890 | 891 | // 池索引 892 | function poolIndex(poolName, value, option = {}) { 893 | poolName = option.pool || poolName; 894 | let index = constantPool.indexOf(value); 895 | // 不在池中则推入 896 | if (index === -1) { 897 | index = constantPool.length; 898 | constantPool.push(value); 899 | } 900 | if (poolName) { 901 | bytecode.push(IMT[poolName]); 902 | bytecode.push(index); 903 | if (poolName == "lod_v") bytecode.push(Number(!option.notPushStack)); 904 | } else { 905 | return index; 906 | } 907 | } 908 | 909 | // 解释器 910 | function interpreter(parentScope, index, stack, constantPool, bytecode, option = {}, args) { 911 | let localScope = {}; 912 | localScope[constantPool[0]] = option.t || this; 913 | localScope[constantPool[1]] = args; 914 | if (option.n) localScope[option.n] = parentScope[option.f]; 915 | localScope.__proto__ = parentScope; 916 | 917 | // 获取最近的含某属性的原型对象 918 | function getScope(scope, name) { 919 | if (!scope || name == constantPool[2]) return null; 920 | if (scope.hasOwnProperty(name)) return scope; 921 | return getScope(Object.getPrototypeOf(scope), name); 922 | } 923 | 924 | if (option.e) { 925 | localScope[constantPool[bytecode[index + 1]]] = option.e; 926 | } 927 | while (index < bytecode.length) { 928 | let t0, t1, t2, t3, t4, t5; 929 | let instruction = bytecode[index++]; 930 | switch (instruction) { 931 | case IMT["="]: 932 | t0 = stack.pop() // 标识符 933 | t1 = stack.pop() // 对象 934 | t2 = stack.pop() // 值 935 | t4 = bytecode[index++] // 入栈 936 | t3 = getScope(t1, t0) || t1 937 | t3[t0] = t2 // 赋值 938 | if (t4) stack.push(t2); 939 | break 940 | case IMT["instanceof"]: 941 | case IMT["in"]: 942 | case IMT[">>>"]: 943 | case IMT[">>"]: 944 | case IMT["<<"]: 945 | case IMT["|"]: 946 | case IMT["||"]: 947 | case IMT["&"]: 948 | case IMT["&&"]: 949 | case IMT[">="]: 950 | case IMT["<="]: 951 | case IMT["=="]: 952 | case IMT["!="]: 953 | case IMT["==="]: 954 | case IMT["!=="]: 955 | case IMT["<"]: 956 | case IMT[">"]: 957 | case IMT["+"]: 958 | case IMT["-"]: 959 | case IMT["*"]: 960 | case IMT["/"]: 961 | case IMT["%"]: 962 | case IMT["^"]: 963 | t0 = stack.pop() // 值1 964 | t1 = stack.pop() // 值2 965 | switch (instruction) { 966 | case IMT["instanceof"]: 967 | t2 = t1 instanceof t0; 968 | break 969 | case IMT["in"]: 970 | t2 = t1 in t0; 971 | break 972 | case IMT[">>>"]: 973 | t2 = t1 >>> t0; 974 | break 975 | case IMT[">>"]: 976 | t2 = t1 >> t0; 977 | break 978 | case IMT["<<"]: 979 | t2 = t1 << t0; 980 | break 981 | case IMT["|"]: 982 | t2 = t1 | t0; 983 | break 984 | case IMT["||"]: 985 | t2 = t1 || t0; 986 | break 987 | case IMT["&"]: 988 | t2 = t1 & t0; 989 | break 990 | case IMT["&&"]: 991 | t2 = t1 && t0; 992 | break 993 | case IMT[">="]: 994 | t2 = t1 >= t0; 995 | break 996 | case IMT["<="]: 997 | t2 = t1 <= t0; 998 | break 999 | case IMT["=="]: 1000 | t2 = t1 == t0; 1001 | break 1002 | case IMT["!="]: 1003 | t2 = t1 != t0; 1004 | break 1005 | case IMT["==="]: 1006 | t2 = t1 === t0; 1007 | break 1008 | case IMT["<"]: 1009 | t2 = t1 < t0; 1010 | break 1011 | case IMT["!=="]: 1012 | t2 = t1 !== t0; 1013 | break 1014 | case IMT[">"]: 1015 | t2 = t1 > t0; 1016 | break 1017 | case IMT["+"]: 1018 | t2 = t1 + t0; 1019 | break 1020 | case IMT["-"]: 1021 | t2 = t1 - t0; 1022 | break 1023 | case IMT["*"]: 1024 | t2 = t1 * t0; 1025 | break 1026 | case IMT["/"]: 1027 | t2 = t1 / t0; 1028 | break 1029 | case IMT["%"]: 1030 | t2 = t1 % t0; 1031 | break 1032 | case IMT["^"]: 1033 | t2 = t1 ^ t0; 1034 | break 1035 | } 1036 | t3 = bytecode[index++] 1037 | if (t3) stack.push(t2); 1038 | break 1039 | case IMT["~"]: 1040 | t0 = stack.pop() 1041 | t1 = ~t0; 1042 | t5 = bytecode[index++] 1043 | if (t5) stack.push(t1); 1044 | break 1045 | case IMT["!"]: 1046 | t0 = stack.pop() 1047 | t1 = !t0; 1048 | t5 = bytecode[index++] 1049 | if (t5) stack.push(t1); 1050 | break 1051 | case IMT["typeof"]: 1052 | t0 = stack.pop() // 1053 | t1 = typeof t0; 1054 | t5 = bytecode[index++]; 1055 | if (t5) stack.push(t1); 1056 | break 1057 | case IMT["void"]: 1058 | t0 = stack.pop(); 1059 | t1 = void t0; 1060 | t5 = bytecode[index++]; 1061 | if (t5) stack.push(t1); 1062 | break 1063 | 1064 | case IMT["++"]: 1065 | t0 = bytecode[index++] // prefix 1066 | t1 = stack.pop() // 标识符 1067 | t2 = stack.pop() // 对象 1068 | t3 = getScope(t2, t1) || t2; 1069 | t4 = !t0 ? t3[t1]++ : ++t3[t1]; 1070 | t5 = bytecode[index++]; 1071 | if (t5) stack.push(t4); 1072 | break 1073 | case IMT["--"]: 1074 | t0 = bytecode[index++] // prefix 1075 | t1 = stack.pop() // 标识符 1076 | t2 = stack.pop() // 对象 1077 | t3 = getScope(t2, t1) || t2; 1078 | t4 = !t0 ? t3[t1]-- : --t3[t1]; 1079 | t5 = bytecode[index++]; 1080 | if (t5) stack.push(t4); 1081 | break 1082 | case IMT["get"]: 1083 | t0 = stack.pop() // 标识符 1084 | t1 = stack.pop() // 对象 1085 | t5 = bytecode[index++]; 1086 | if (t5) stack.push(t1[t0]); 1087 | break 1088 | case IMT['localScope']: 1089 | stack.push(localScope); 1090 | break 1091 | case IMT['globalScope']: 1092 | stack.push(window); 1093 | break 1094 | case IMT["def_v"]: 1095 | t0 = bytecode[index++] 1096 | t1 = constantPool[t0] 1097 | localScope[t1] = undefined; 1098 | break 1099 | 1100 | case IMT["call"]: 1101 | t0 = bytecode[index++] // 参数数量 1102 | t1 = stack.pop() // 标识符 1103 | t2 = stack.pop() // 对象 1104 | args = []; 1105 | for (t3 = 0; t3 < t0; t3++) args.unshift(stack.pop()); 1106 | if (t2 === 0) { 1107 | t4 = t1.apply(localScope, args); 1108 | } else { 1109 | t4 = t2[t1].apply(t2, args); 1110 | } 1111 | t5 = bytecode[index++]; 1112 | if (t5) stack.push(t4); 1113 | break 1114 | case IMT["lod_v"]: 1115 | t0 = constantPool[bytecode[index++]]; // 标识符 1116 | t1 = localScope 1117 | t2 = t1[t0] 1118 | t5 = bytecode[index++]; 1119 | if (t5) stack.push(t2); 1120 | break 1121 | case IMT["lod_c"]: 1122 | t0 = bytecode[index++] 1123 | stack.push(constantPool[t0]) 1124 | break 1125 | case IMT["defFunc"]: 1126 | t0 = stack.pop(); // 函数名 1127 | t1 = bytecode[index++]; // 函数指针 1128 | t2 = bytecode[index++]; // 是否入栈 1129 | t3 = stack[stack.length - 1]; 1130 | t4 = function () { 1131 | return interpreter(localScope, t1, stack, constantPool, bytecode, { 1132 | t: this, 1133 | n: t0, 1134 | f: t0 || t3, 1135 | r: 1, 1136 | }, arguments); 1137 | } 1138 | if (t2) { 1139 | stack.push(t4) 1140 | } else { 1141 | localScope[t0] = t4 1142 | } 1143 | break 1144 | case IMT["params"]: 1145 | t0 = bytecode[index++]; // 参数数量 1146 | if (!args) args = [].concat(stack); 1147 | for (t1 = t0; t1 >= 0; t1--) { 1148 | t2 = stack.pop(); 1149 | localScope[t2] = args[t1] 1150 | } 1151 | break 1152 | case IMT["object"]: 1153 | stack.push({}); 1154 | break 1155 | case IMT["RegExpLiteral"]: 1156 | t0 = stack.pop() 1157 | t1 = stack.pop() 1158 | t3 = new RegExp(t1, t0) 1159 | stack.push(t3); 1160 | break 1161 | case IMT["new"]: 1162 | t0 = stack.pop() 1163 | t1 = stack.pop() 1164 | t2 = bytecode[index++]; 1165 | args = []; 1166 | for (t3 = 0; t3 < t2; t3++) args.unshift(stack.pop()); 1167 | t4 = new t1[t0](...args); 1168 | t5 = bytecode[index++]; 1169 | if (t5) stack.push(t4); 1170 | break 1171 | case IMT["return"]: 1172 | if (option.r) { 1173 | return stack.pop() 1174 | } 1175 | return bytecode[index++]; 1176 | case IMT["property"]: 1177 | t0 = stack.pop(); 1178 | t1 = stack.pop(); 1179 | t2 = stack.pop(); 1180 | t2[t1] = t0; 1181 | t5 = bytecode[index++]; 1182 | if (t5) stack.push(t2); 1183 | break 1184 | case IMT["sequence"]: 1185 | t0 = bytecode[index++]; 1186 | t1 = stack.pop(); 1187 | for (t2 = 0; t2 < t0; t2++) stack.pop(); 1188 | t5 = bytecode[index++]; 1189 | if (t5) stack.push(t1); 1190 | break 1191 | case IMT["blockEnd"]: 1192 | return 1193 | case IMT["jump"]: 1194 | t0 = bytecode[index++] 1195 | index = t0; 1196 | break 1197 | case IMT["switchJump"]: 1198 | t0 = stack.pop() 1199 | t1 = stack.pop() 1200 | t2 = bytecode[index++]; 1201 | if (t1 == -1) t1 = t2; 1202 | t1 = t0[t1] 1203 | index = t1; 1204 | break 1205 | case IMT["ifJump"]: 1206 | t0 = stack.pop() // 条件 1207 | t1 = bytecode[index++] // 指针 1208 | if (!t0) index = t1; 1209 | break 1210 | case IMT["debugger"]: 1211 | debugger 1212 | break 1213 | case IMT["try"]: 1214 | t2 = bytecode[index++]; 1215 | t3 = bytecode[index++]; 1216 | t4 = bytecode[index++]; 1217 | t5 = bytecode[index++]; 1218 | try { 1219 | t1 = interpreter(localScope, t3, stack, constantPool, bytecode, {t: localScope[constantPool[0]]}); 1220 | if (t1 > 0) { 1221 | // 处理 return 1222 | if (option.r) { 1223 | return stack.pop() 1224 | } 1225 | return t1; 1226 | } 1227 | } catch (e) { 1228 | t1 = interpreter(localScope, t4, stack, constantPool, bytecode, { 1229 | t: localScope[constantPool[0]], 1230 | e: e 1231 | }); 1232 | if (t1 > 0) { 1233 | // 处理 return 1234 | if (option.r) { 1235 | return stack.pop() 1236 | } 1237 | return t1; 1238 | } 1239 | } finally { 1240 | t1 = interpreter(localScope, t5, stack, constantPool, bytecode, {t: localScope[constantPool[0]]}); 1241 | if (t1 > 0) { 1242 | // 处理 return 1243 | if (option.r) { 1244 | return stack.pop() 1245 | } 1246 | return t1; 1247 | } 1248 | } 1249 | index = t2; 1250 | break 1251 | case IMT["tryNumber"]: 1252 | t0 = stack.pop() 1253 | t0 = Number(t0) 1254 | if (t0 == NaN) t0 = -1; 1255 | stack.push(t0) 1256 | break 1257 | case IMT["delete"]: 1258 | t0 = stack.pop() 1259 | t1 = stack.pop() 1260 | t2 = delete t1[t0]; 1261 | t5 = bytecode[index++]; 1262 | if (t5) stack.push(t2); 1263 | break 1264 | case IMT["TemplateExpressions"]: 1265 | stack.push(`${stack.pop()}`) 1266 | break 1267 | case IMT["throw"]: 1268 | throw stack.pop() 1269 | case IMT["Template"]: 1270 | t0 = bytecode[index++]; 1271 | t2 = ""; 1272 | for (t1 = 0; t1 < t0; t1++) { 1273 | t2 += stack.pop() 1274 | } 1275 | t5 = bytecode[index++]; 1276 | if (t5) stack.push(t2); 1277 | break 1278 | case IMT["block"]: 1279 | t0 = bytecode[index++]; 1280 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, {t: localScope[constantPool[0]]}); 1281 | if (t1 === undefined) { 1282 | index = t0 1283 | } else { 1284 | // 处理 return 1285 | if (option.r) { 1286 | return stack.pop() 1287 | } 1288 | return t1; 1289 | } 1290 | break 1291 | case IMT["loopBlock"]: 1292 | t0 = bytecode[index++]; // 结束块指针 1293 | t1 = interpreter(localScope, index, stack, constantPool, bytecode, {t: localScope[constantPool[0]]}); 1294 | if (!t1) { 1295 | // 处理 continue 和 正常循环 1296 | index = t0; 1297 | } else { 1298 | if (t1 === 1) { 1299 | // 处理 break 1300 | return 1301 | } else { 1302 | // 处理 return 1303 | if (option.r) { 1304 | return stack.pop() 1305 | } 1306 | return t1 1307 | } 1308 | } 1309 | break 1310 | case IMT["array"]: 1311 | t0 = bytecode[index++] // 长度 1312 | t1 = []; 1313 | for (t2 = 0; t2 < t0; t2++) { 1314 | t3 = stack.pop() // 元素 1315 | t1.unshift(t3) 1316 | } 1317 | t5 = bytecode[index++]; 1318 | if (t5) stack.push(t1); 1319 | break 1320 | case undefined: 1321 | throw new Error("当前指令不存在,请检查指令集!") 1322 | default: 1323 | let msg = `没有解析!指令: "${instruction}" 指针:${index}`; 1324 | debugger 1325 | throw new Error(msg) 1326 | } 1327 | } 1328 | } 1329 | 1330 | if (typeof global !== "undefined") { 1331 | let code = virtualizationSourceCode(sourceCode); 1332 | writeFileSync(outputFile, code, (e) => { 1333 | }) 1334 | console.info(`info -> 加固代码已保存至 ${__dirname}\\output.js!\n`) 1335 | } --------------------------------------------------------------------------------