AST解混淆插件函数

存在复用性的插件与函数,不定期补充。

# 字面量解混淆

1
2
3
4
5
6
7
8
9
10
11
12
13
const simplifyLiteral = {
NumericLiteral({ node }) {
if (node.extra && /^0[obx]/i.test(node.extra.raw)) {
//特征匹配
node.extra = undefined;
}
},
StringLiteral({ node }) {
if (node.extra && /\\[ux]/gi.test(node.extra.raw)) {
node.extra = undefined;
}
},
};

# 规范块语句

示例

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
let i = 0;
if (i) console.log(i);
else console.log(1);
for (let j = 0; j < 2; j++) console.log(j);
while (i < 2) i++, console.log(i);
const set = new Set([1, 2, 3]);
for (let element of set) console.log(element);
const str = "Hello";
for (let char of str) console.log(char);
//-----------------------------------------
let i = 0;
if (i) {
console.log(i);
} else {
console.log(1);
}
for (let j = 0; j < 2; j++) {
console.log(j);
}
while (i < 2) {
i++, console.log(i);
}
const set = new Set([1, 2, 3]);
for (let element of set) {
console.log(element);
}
const str = "Hello";
for (let char of str) {
console.log(char);
}

插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const BlockSyntax = {
"ForStatement|WhileStatement|ForInStatement|ForOfStatement"({ node }) {
if (!types.isBlockStatement(node.body)) {
node.body = types.BlockStatement([node.body]);
}
},
IfStatement(path) {
let nodes = ["consequent", "alternate"];
for (let i = 0; i < nodes.length; i++) {
let _path = path.get(nodes[i]);
if (_path.node && !_path.isBlockStatement()) {
_path.replaceInline(types.BlockStatement([_path.node]));
}
}
},
};