Skip to content

Commit

Permalink
obfuscator: Split variable declarations before processing string array
Browse files Browse the repository at this point in the history
…#114

Signed-off-by: echo094 <[email protected]>
  • Loading branch information
echo094 committed Aug 21, 2024
1 parent d8b4e16 commit 8700041
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/plugin/obfuscator.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,12 @@ module.exports = function (code) {
// IllegalReturn
const deleteIllegalReturn = require('../visitor/delete-illegal-return')
traverse(ast, deleteIllegalReturn)
// Lint before split statements
const lintIfStatement = require('../visitor/lint-if-statement')
traverse(ast, lintIfStatement)
// Split declarations to avoid bugs
const splitVarDeclaration = require('../visitor/split-variable-declaration')
traverse(ast, splitVarDeclaration)
// 清理二进制显示内容
traverse(ast, {
StringLiteral: ({ node }) => {
Expand Down
22 changes: 22 additions & 0 deletions src/visitor/lint-if-statement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const t = require('@babel/types')

function LintIfStatement(path) {
let { test, consequent, alternate } = path.node
let changed = false
if (!t.isBlockStatement(consequent)) {
consequent = t.blockStatement([consequent])
changed = true
}
if (alternate && !t.isBlockStatement(alternate)) {
alternate = t.blockStatement([alternate])
changed = true
}
if (!changed) {
return
}
path.replaceWith(t.ifStatement(test, consequent, alternate))
}

module.exports = {
IfStatement: { exit: LintIfStatement },
}

0 comments on commit 8700041

Please sign in to comment.