Skip to content

Commit

Permalink
sojsonv7: fix bug when the rotateFunction is not in a sequenceExpress…
Browse files Browse the repository at this point in the history
…ion #78

Signed-off-by: echo094 <[email protected]>
  • Loading branch information
echo094 authored Mar 9, 2024
1 parent 4e2c5af commit 26aab29
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/plugin/sojsonv7.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,17 @@ function decodeGlobal(ast) {
}
refs.string_path.remove()
// iterate refs
let cache = undefined
for (let bind of binds.referencePaths) {
if (bind.findParent((path) => path.removed)) {
continue
}
const parent = bind.parentPath
if (parent.isCallExpression() && bind.listKey === 'arguments') {
// This is the rotate function.
// However, we can delete it later.
// If it's in a sequence expression, it can be handled together.
// Or, we should handle it after this iteration.
cache = parent
continue
}
if (parent.isSequenceExpression()) {
Expand All @@ -189,7 +192,7 @@ function decodeGlobal(ast) {
}
continue
}
if (t.isVariableDeclarator(parent.node)) {
if (parent.isVariableDeclarator()) {
// main decrypt val
let top = parent.getFunctionParent()
while (top.getFunctionParent()) {
Expand All @@ -200,7 +203,8 @@ function decodeGlobal(ast) {
top.remove()
continue
}
if (t.isCallExpression(parent.node) && !parent.node.arguments.length) {
if (parent.isCallExpression() && !parent.node.arguments.length) {
// main decrypt val
if (!t.isVariableDeclarator(parent.parentPath.node)) {
continue
}
Expand All @@ -211,7 +215,23 @@ function decodeGlobal(ast) {
decrypt_code[2] = top.node
decrypt_val = top.node.id.name
top.remove()
continue
}
if (parent.isExpressionStatement()) {
parent.remove()
continue
}
console.warn(`Unexpected ref var_string_table: ${parent}`)
}
// If rotateFunction is detected but not handled, we should handle it now.
if (decrypt_code.length === 3 && cache) {
if (cache.parentPath.isExpressionStatement()) {
decrypt_code.push(cache.parent)
cache = cache.parentPath
} else {
decrypt_code.push(t.expressionStatement(cache.node))
}
cache.remove()
}
if (!decrypt_val) {
console.error('Cannot find decrypt variable')
Expand Down

0 comments on commit 26aab29

Please sign in to comment.