-
Notifications
You must be signed in to change notification settings - Fork 3
/
deobfuscate8.js
40 lines (37 loc) · 1.16 KB
/
deobfuscate8.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import traverse from "@babel/traverse";
import { parse } from "@babel/parser";
import generate from "@babel/generator";
import * as types from "@babel/types";
import fs from "fs";
const code = fs.readFileSync("obfuscates/code8.js", "utf-8");
let ast = parse(code);
traverse(ast, {
"IfStatement|ConditionalExpression"(path) {
let { consequent, alternate } = path.node;
let testPath = path.get("test");
const evaluateTest = path.evaluateTruthy();
if (evaluateTest === true) {
path.replaceWithMultiple(consequent);
} else if (evaluateTest === false) {
if (alternate != null) {
path.replaceWithMultiple(alternate);
} else {
path.remove();
}
}
},
EmptyStatement(path) {
path.remove();
},
"VariableDeclarator|FunctionDeclaration"(path) {
//在setTimeout函数或者eval函数里无法检测是否被引用,所以慎用。
let { node, scope } = path;
let binding = scope.getBinding(node.id.name);
if (binding && !binding.referenced && binding.constant) {
//没有被引用,也没有被改变
path.remove();
}
},
});
const { code: output } = generate(ast);
console.log(output);