Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
echo094 committed Feb 1, 2025
1 parent 215e6d6 commit 1abcbc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/visitor/jsconfuser/global-concealing.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ function getGlobalConcealingNames(glo_fn_path) {
const obj = {}
glo_fn_path.traverse({
SwitchCase(path) {
const key = parseInt(generator(path.node.test).code)
const code = generator(path.node.test).code
const key = parseInt(code)
if (Number.isNaN(key)) {
console.error(`[GlobalConcealing] concealed key: ${code}`)
obj['invalid'] = true
return
}
let consequent = path.node.consequent[0]
if (t.isReturnStatement(consequent)) {
obj[key] = consequent.argument.property.value
Expand Down Expand Up @@ -113,15 +119,20 @@ const deGlobalConcealing = {
const glo_vars = getGlobalConcealingNames(obj.glo_fn_path)
console.log(`[GlobalConcealing] globalFn: ${obj.glo_fn_name}`)
let binding = obj.glo_fn_path.parentPath.scope.getBinding(obj.glo_fn_name)
let remain = false
for (const ref of binding.referencePaths) {
const repl_path = ref.parentPath
if (ref.key !== 'callee' || !repl_path.isCallExpression()) {
continue
}
const key = parseInt(generator(repl_path.node.arguments[0]).code)
repl_path.replaceWith(t.identifier(glo_vars[key]))
if (glo_vars[key]) {
repl_path.replaceWith(t.identifier(glo_vars[key]))
} else {
remain = true
}
}
if (safeDeleteNode(obj.glo_fn_name, obj.glo_fn_path)) {
if (!remain && safeDeleteNode(obj.glo_fn_name, obj.glo_fn_path)) {
obj.tmp_path.remove()
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/visitor/jsconfuser/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function processStackParam(path, len) {
while (changed) {
checkStackInvalid(path, invalid)
if (!checkChangeValid(invalid, used)) {
path.replaceWith(parse(orig_code))
path.replaceWith(parse(orig_code).program.body[0])
used = {}
}
changed = tryStackReplace(path, len, invalid, used)
Expand Down

0 comments on commit 1abcbc5

Please sign in to comment.