用于 javascript-obfuscator 5.x 输出的反混淆器。输入混淆后的 JS,返回可读且运行结果相同的 JS。
需要 Node 18+。
git clone https://github.com/lolcaken/javascript-deobfuscator.git
cd javascript-deobfuscator
npm install
npm run build
反混淆一个文件(除非指定 -o,否则在输入文件旁写入 <name>.deob.js):
node dist/src/cli.js input.ob.js -o output.js --stats
参数:
| 参数 | 作用 |
|---|---|
-o <file> | 输出路径(默认:<input>.deob.js) |
--no-rename | 保留 _0x… 标识符,不重命名 |
--stats | 打印每个处理阶段所做的更改 |
-h | 用法说明 |
或者在 npm link 之后,可在任意位置使用:
deobfuscate input.ob.js -o output.js
作为库使用:
import { deobfuscate } from 'javascript-deobfuscator';
const { code, stats } = deobfuscate(obfuscatedSource, { rename: true });
console.log(code);
发布后从 npm 安装:
npm install javascript-deobfuscator
输入 — test/fixtures/source.js 经 javascript-obfuscator 混淆(字符串数组 + 轮转、拆分字符串、控制流平坦化、死代码注入、对象键变换、数字表达式),共 3690 字节,如下所示:
function _0x54b6(_0xb7919b,_0x500140){_0xb7919b=_0xb7919b-(0x1f8d+-0x1*-0xb9d+0x2a06*-0x1);const _0x229d59=_0x1598();let _0x3ccc27=_0x229d59[_0xb7919b];return _0x3ccc27;}const _0x822f89=_0x54b6;function _0x1598(){const _0x23b861=['com/','http','ies','log','join','uiXo','alic','fqAn','oint','bob','2zqCUix','PJTj','3161739tTCvqO','?r=','5dPKAUt','727970ZDbPoX','ple.','caro','neg','s://',…];_0x1598=function(){return _0x23b861;};return _0x1598();}(function(_0x5e6e6e,_0x257dcb){const _0x5ed3d4=_0x54b6,_0x860095=_0x5e6e6e();while(!![]){try{const _0x44a344=-parseInt(_0x5ed3d4(0x138))/(0xb*-0x281+0x1c08+0x2*-0x3e)+…;if(_0x44a344===_0x257dcb)break;else _0x860095['push'](https://github.com/lolcaken/javascript-deobfuscator/blob/main/_0x860095%5B%27shift%27%5D%28));}catch(_0x1f2aee){_0x860095['push'](https://github.com/lolcaken/javascript-deobfuscator/blob/main/_0x860095%5B%27shift%27%5D%28));}}}(_0x1598,…));const greeting=_0x822f89(0x12e)+'o';function greet(_0x35652d){…}const users=[_0x822f89(0x12c)+'e',_0x822f89(0x12d),_0x822f89(0x138)+'l'];
(完整的混淆文件位于 test/fixtures/demo.ob.js。)
输出 — 2359 字节,运行结果完全相同:
const greeting = "Hello";
function greet(p) {
const q = f,
r = {};
r[q(0x12b) + 'i'] = function (u, v) {
return u + v;
}, r[q(0x140) + 'X'] = function (w, x) {
return w + x;
};
const s = r,
t = s[q(0x12b) + 'i'](https://github.com/lolcaken/javascript-deobfuscator/blob/main/s%5Bq%280x12b) + 'i'](s[q(0x140) + 'X'](https://github.com/lolcaken/javascript-deobfuscator/blob/main/greeting%2C ",\x20"), p), '!');
return t;
}
const users = ["alice", "bob", "carol"];
let total = 0;
for (let i = 0; i < users.length; i++) {
total += users[i].length, console.log(greet(users[i]));
}
(完整输出:test/fixtures/demo.deob.js。)
两者都输出:
Hello, alice!
Hello, bob!
Hello, carol!
https://api.example.com/v1?r=3 13 zero|pos|pos
while(true){switch…})、死代码注入_0x… 重命名npm test 使用 javascript-obfuscator 5.9.0 在三种预设(default、medium、heavy)下混淆示例程序,并断言反混淆后的代码输出完全相同且能干净地重新解析。目前 9/9 通过。
ISC — 参见 LICENSE。