Skip to content

Commit 8700041

Browse files
committed
obfuscator: Split variable declarations before processing string array #114
Signed-off-by: echo094 <20028238+echo094@users.noreply.github.com>
1 parent d8b4e16 commit 8700041

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/plugin/obfuscator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,12 @@ module.exports = function (code) {
944944
// IllegalReturn
945945
const deleteIllegalReturn = require('../visitor/delete-illegal-return')
946946
traverse(ast, deleteIllegalReturn)
947+
// Lint before split statements
948+
const lintIfStatement = require('../visitor/lint-if-statement')
949+
traverse(ast, lintIfStatement)
950+
// Split declarations to avoid bugs
951+
const splitVarDeclaration = require('../visitor/split-variable-declaration')
952+
traverse(ast, splitVarDeclaration)
947953
// 清理二进制显示内容
948954
traverse(ast, {
949955
StringLiteral: ({ node }) => {

src/visitor/lint-if-statement.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const t = require('@babel/types')
2+
3+
function LintIfStatement(path) {
4+
let { test, consequent, alternate } = path.node
5+
let changed = false
6+
if (!t.isBlockStatement(consequent)) {
7+
consequent = t.blockStatement([consequent])
8+
changed = true
9+
}
10+
if (alternate && !t.isBlockStatement(alternate)) {
11+
alternate = t.blockStatement([alternate])
12+
changed = true
13+
}
14+
if (!changed) {
15+
return
16+
}
17+
path.replaceWith(t.ifStatement(test, consequent, alternate))
18+
}
19+
20+
module.exports = {
21+
IfStatement: { exit: LintIfStatement },
22+
}

0 commit comments

Comments
 (0)