Skip to content

Commit 1abcbc5

Browse files
committed
fix bug
1 parent 215e6d6 commit 1abcbc5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/visitor/jsconfuser/global-concealing.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ function getGlobalConcealingNames(glo_fn_path) {
5656
const obj = {}
5757
glo_fn_path.traverse({
5858
SwitchCase(path) {
59-
const key = parseInt(generator(path.node.test).code)
59+
const code = generator(path.node.test).code
60+
const key = parseInt(code)
61+
if (Number.isNaN(key)) {
62+
console.error(`[GlobalConcealing] concealed key: ${code}`)
63+
obj['invalid'] = true
64+
return
65+
}
6066
let consequent = path.node.consequent[0]
6167
if (t.isReturnStatement(consequent)) {
6268
obj[key] = consequent.argument.property.value
@@ -113,15 +119,20 @@ const deGlobalConcealing = {
113119
const glo_vars = getGlobalConcealingNames(obj.glo_fn_path)
114120
console.log(`[GlobalConcealing] globalFn: ${obj.glo_fn_name}`)
115121
let binding = obj.glo_fn_path.parentPath.scope.getBinding(obj.glo_fn_name)
122+
let remain = false
116123
for (const ref of binding.referencePaths) {
117124
const repl_path = ref.parentPath
118125
if (ref.key !== 'callee' || !repl_path.isCallExpression()) {
119126
continue
120127
}
121128
const key = parseInt(generator(repl_path.node.arguments[0]).code)
122-
repl_path.replaceWith(t.identifier(glo_vars[key]))
129+
if (glo_vars[key]) {
130+
repl_path.replaceWith(t.identifier(glo_vars[key]))
131+
} else {
132+
remain = true
133+
}
123134
}
124-
if (safeDeleteNode(obj.glo_fn_name, obj.glo_fn_path)) {
135+
if (!remain && safeDeleteNode(obj.glo_fn_name, obj.glo_fn_path)) {
125136
obj.tmp_path.remove()
126137
}
127138
},

src/visitor/jsconfuser/stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function processStackParam(path, len) {
293293
while (changed) {
294294
checkStackInvalid(path, invalid)
295295
if (!checkChangeValid(invalid, used)) {
296-
path.replaceWith(parse(orig_code))
296+
path.replaceWith(parse(orig_code).program.body[0])
297297
used = {}
298298
}
299299
changed = tryStackReplace(path, len, invalid, used)

0 commit comments

Comments
 (0)